add common filter

This commit is contained in:
g7hoo 2022-08-10 10:58:21 +08:00
parent ffd095b6b8
commit df3b11b6dd
2 changed files with 13 additions and 10 deletions

7
src/utils/filters.js Normal file
View File

@ -0,0 +1,7 @@
/** filters */
export const dictFilter = dictTypeId => {
return val => {
return JSON.parse(localStorage.getItem('dictList'))[dictTypeId].find(item => item.dictValue === val)?.dictLabel || '-'
}
}

View File

@ -66,17 +66,17 @@ import TableTextComponent from '@/components/base-table/components/detailCompone
import BaseDialog from '@/components/base-dialog/addOrUpdate' import BaseDialog from '@/components/base-dialog/addOrUpdate'
import moment from 'moment' import moment from 'moment'
import dictListMixin from '@/mixins/dictlist-module' import dictListMixin from '@/mixins/dictlist-module'
import { dictFilter } from '@/utils/filters'
const UnitDictTypeId = '1557173812109242370' const UnitDictTypeId = '1557173812109242370'
const ProductTypeDictTypeId = '1557179530308616193' const ProductTypeDictTypeId = '1557179530308616193'
const tableConfigs = [ const tableConfigs = [
{ type: 'index', name: '序号' }, { type: 'index', name: '序号' },
{ prop: 'updateTime', name: '添加时间', filter: val => (val ? moment(val).format('YYYY-MM-DD hh:mm:ss') : '-') }, { prop: 'updateTime', name: '添加时间', filter: val => (val ? moment(val).format('YYYY-MM-DD hh:mm:ss') : '-') },
{ prop: 'name', name: '产品名称' }, { prop: 'name', name: '产品名称'},
{ prop: 'code', name: '产品编码' }, { prop: 'code', name: '产品编码' },
{ prop: 'specifications', name: '规格' }, { prop: 'specifications', name: '规格' },
{ prop: 'unitDictValue', name: '单位' }, { prop: 'unitDictValue', name: '单位', filter: dictFilter(UnitDictTypeId) },
// { prop: 'unitDictValue', name: 'valuelabel_value' }, // { prop: 'unitDictValue', name: 'valuelabel_value' },
{ prop: 'operations', name: '操作', fixed: 'right', width: 180, subcomponent: TableOperateComponent, options: ['viewAttr', 'delete'] } { prop: 'operations', name: '操作', fixed: 'right', width: 180, subcomponent: TableOperateComponent, options: ['viewAttr', 'delete'] }
@ -135,8 +135,6 @@ const addOrUpdateConfigs = {
type: 'select', type: 'select',
options: [ options: [
// //
{ label: 'ces', value: 1 },
{ label: 'sec', value: 2 }
] ]
}, },
{ {
@ -145,8 +143,6 @@ const addOrUpdateConfigs = {
type: 'select', type: 'select',
options: [ options: [
// //
{ label: 'h', value: 'h' },
{ label: 'l', value: 'l' }
] ]
} }
], ],
@ -257,10 +253,10 @@ export default {
}) })
}, },
// //
handleOperations({type, data}) { handleOperations({ type, data }) {
switch(type) { switch (type) {
case 'viewAttr': // <== tableConfig case 'viewAttr': // <== tableConfig
return this.addOrUpdateHandle(data) return this.addOrUpdateHandle(data)
case 'delete': case 'delete':
return this.deleteHandle(data) return this.deleteHandle(data)
} }