From df3b11b6dde98a9341e29db4d84ecdb97eed598b Mon Sep 17 00:00:00 2001 From: g7hoo Date: Wed, 10 Aug 2022 10:58:21 +0800 Subject: [PATCH] add common filter --- src/utils/filters.js | 7 +++++++ src/views/modules/monitoring/product.vue | 16 ++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 src/utils/filters.js diff --git a/src/utils/filters.js b/src/utils/filters.js new file mode 100644 index 0000000..46188dc --- /dev/null +++ b/src/utils/filters.js @@ -0,0 +1,7 @@ +/** filters */ + +export const dictFilter = dictTypeId => { + return val => { + return JSON.parse(localStorage.getItem('dictList'))[dictTypeId].find(item => item.dictValue === val)?.dictLabel || '-' + } +} \ No newline at end of file diff --git a/src/views/modules/monitoring/product.vue b/src/views/modules/monitoring/product.vue index 056c749..8032eae 100644 --- a/src/views/modules/monitoring/product.vue +++ b/src/views/modules/monitoring/product.vue @@ -66,17 +66,17 @@ import TableTextComponent from '@/components/base-table/components/detailCompone import BaseDialog from '@/components/base-dialog/addOrUpdate' import moment from 'moment' import dictListMixin from '@/mixins/dictlist-module' +import { dictFilter } from '@/utils/filters' const UnitDictTypeId = '1557173812109242370' const ProductTypeDictTypeId = '1557179530308616193' - const tableConfigs = [ { type: 'index', name: '序号' }, { 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: 'specifications', name: '规格' }, - { prop: 'unitDictValue', name: '单位' }, + { prop: 'unitDictValue', name: '单位', filter: dictFilter(UnitDictTypeId) }, // { prop: 'unitDictValue', name: '单位value,对应到数据字典label_value' }, { prop: 'operations', name: '操作', fixed: 'right', width: 180, subcomponent: TableOperateComponent, options: ['viewAttr', 'delete'] } @@ -135,8 +135,6 @@ const addOrUpdateConfigs = { type: 'select', options: [ // 动态获取 - { label: 'ces', value: 1 }, - { label: 'sec', value: 2 } ] }, { @@ -145,8 +143,6 @@ const addOrUpdateConfigs = { type: 'select', options: [ // 动态获取 - { label: 'h', value: 'h' }, - { label: 'l', value: 'l' } ] } ], @@ -257,10 +253,10 @@ export default { }) }, // 表格操作事件管理 - handleOperations({type, data}) { - switch(type) { + handleOperations({ type, data }) { + switch (type) { case 'viewAttr': // <== 对照 tableConfig - return this.addOrUpdateHandle(data) + return this.addOrUpdateHandle(data) case 'delete': return this.deleteHandle(data) }