這周工做中遇到了一個多層表格篩選列本地化的東西。最後的解決方式是用vux + core一塊兒實現多層嵌套篩選項的本地化。
app
filterable-columns.jsspa
const byGoodsCol = [ { prop: 'all', label: '全選', children: [ { prop: 'weidu1', label: '維度分類1', children: [ { prop: 'a', label: 'a' }, { prop: 'b', label: 'b' } ] }, { prop: 'weidu2', label: '維度分類2', children: [ { prop: 'c', label: 'c' }, { prop: 'd', label: 'd' } ] } ] } ] export function outCol(type) { return { byGoodsCol: byGoodsCol, byPlatfomrCol: byPlatfomrCol }[type] }
config/local-settings.jscode
import { outCol } from './filterable-columns' const byGoodsCol = outCol('byGoodsCol') function initDefaultCol(data) { data.forEach(item => { if (item.children) { initDefaultCol(item.children) } item.checked = true }) return data } export default { byGoodsCol: initDefaultCol(byGoodsCol) }
core.jsrouter
import defaultSettings from '@/config/local-settings' export default function Initializer() { store.commit('goods/goods_col', Vue.ls.get('BY_GOODS_COL', defaultSettings.byGoodsCol)) }
main.jsblog
import initial from "./core/initial"; new Vue({ el: "#app", router, store, created() { initial(); }, render: h => h(App) });