From ffd095b6b8423d11cb81414a8c9ab49054756b67 Mon Sep 17 00:00:00 2001 From: g7hoo Date: Wed, 10 Aug 2022 10:47:12 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base-dialog/addOrUpdate/index.vue | 4 +- .../components/operationComponent.js | 7 +++- src/components/base-table/index.vue | 2 +- src/mixins/dictlist-module.js | 24 ++++++++++++ .../monitoring/product-add-or-update.vue | 38 +++++++++---------- src/views/modules/monitoring/product.vue | 35 ++++++++++++++--- 6 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 src/mixins/dictlist-module.js diff --git a/src/components/base-dialog/addOrUpdate/index.vue b/src/components/base-dialog/addOrUpdate/index.vue index aa5cd65..971d78b 100644 --- a/src/components/base-dialog/addOrUpdate/index.vue +++ b/src/components/base-dialog/addOrUpdate/index.vue @@ -25,7 +25,7 @@ v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]" clearable > - + @@ -272,7 +272,7 @@ export default { message: btn.name === 'save' ? '添加成功!' : '更新成功!', type: 'success', duration: 1500, - onClose() { + onClose: () => { this.$emit('refreshDataList') this.visible = false } diff --git a/src/components/base-table/components/operationComponent.js b/src/components/base-table/components/operationComponent.js index 409499f..33e400b 100644 --- a/src/components/base-table/components/operationComponent.js +++ b/src/components/base-table/components/operationComponent.js @@ -27,7 +27,7 @@ export default { // add more... }, text: { - // for i18n inject: + // TODO: i18n edit: '编辑', detail: '详情', delete: '删除', @@ -38,12 +38,15 @@ export default { }, methods: { // 发射事件 + emit(eventType) { + this.$emit('emit-data', { type: eventType, data: this.injectData.head?.emitFullData ? this.injectData : this.injectData.id }) + } }, render: function (h) { let btns = [] for (const optionStr of this.injectData.head?.options) { // btns.push(h('el-button', { props: { type: this.btnTypes[optionStr] } }, optionStr)) - btns.push(h('el-button', { props: { type: 'text' }, style: { color: this.colors[optionStr] || '#409EFF' } }, this.text[optionStr])) + btns.push(h('el-button', { props: { type: 'text' }, style: { color: this.colors[optionStr] || '#409EFF' }, on: { click: this.emit.bind(null, optionStr) } }, this.text[optionStr])) } return h('span', null, btns) } diff --git a/src/components/base-table/index.vue b/src/components/base-table/index.vue index 43ea43f..fd377fb 100644 --- a/src/components/base-table/index.vue +++ b/src/components/base-table/index.vue @@ -30,7 +30,7 @@ > diff --git a/src/mixins/dictlist-module.js b/src/mixins/dictlist-module.js new file mode 100644 index 0000000..0c4d17e --- /dev/null +++ b/src/mixins/dictlist-module.js @@ -0,0 +1,24 @@ + +export default { + data() { + return { + dictList: {} + } + }, + methods: { + initDictList(dictTypeIdList) { + const allDictList = JSON.parse(localStorage.getItem('dictList')) + if (!Object.keys(allDictList).length) { + return this.$message({ + // TODO: i18n + message: '未能获取数据字典', + type: 'error', + duration: 2000 + }) + } + dictTypeIdList.forEach(id => { + this.dictList[id] = allDictList[id].map(item => ({ label: item.dictLabel, value: item.dictValue })) + }) + } + } +} \ No newline at end of file diff --git a/src/views/modules/monitoring/product-add-or-update.vue b/src/views/modules/monitoring/product-add-or-update.vue index 6011f40..922ea52 100644 --- a/src/views/modules/monitoring/product-add-or-update.vue +++ b/src/views/modules/monitoring/product-add-or-update.vue @@ -129,25 +129,25 @@ export default { params: this.$http.adornParams() }).then(({ data }) => { if (data && data.code === 0) { - this.dataForm.code = data.product.code - this.dataForm.name = data.product.name - this.dataForm.description = data.product.description - this.dataForm.externalCode = data.product.externalCode - this.dataForm.specifications = data.product.specifications - this.dataForm.unitDictValue = data.product.unitDictValue - this.dataForm.area = data.product.area - this.dataForm.processTime = data.product.processTime - this.dataForm.typeDictValue = data.product.typeDictValue - this.dataForm.enabled = data.product.enabled - this.dataForm.remark = data.product.remark - this.dataForm.valid = data.product.valid - this.dataForm.creatorId = data.product.creatorId - this.dataForm.creatorName = data.product.creatorName - this.dataForm.createTime = data.product.createTime - this.dataForm.updaterId = data.product.updaterId - this.dataForm.updaterName = data.product.updaterName - this.dataForm.updateTime = data.product.updateTime - this.dataForm.version = data.product.version + this.dataForm.code = data.data.code + this.dataForm.name = data.data.name + this.dataForm.description = data.data.description + this.dataForm.externalCode = data.data.externalCode + this.dataForm.specifications = data.data.specifications + this.dataForm.unitDictValue = data.data.unitDictValue + this.dataForm.area = data.data.area + this.dataForm.processTime = data.data.processTime + this.dataForm.typeDictValue = data.data.typeDictValue + this.dataForm.enabled = data.data.enabled + this.dataForm.remark = data.data.remark + this.dataForm.valid = data.data.valid + this.dataForm.creatorId = data.data.creatorId + this.dataForm.creatorName = data.data.creatorName + this.dataForm.createTime = data.data.createTime + this.dataForm.updaterId = data.data.updaterId + this.dataForm.updaterName = data.data.updaterName + this.dataForm.updateTime = data.data.updateTime + this.dataForm.version = data.data.version } }) } diff --git a/src/views/modules/monitoring/product.vue b/src/views/modules/monitoring/product.vue index b6d3b86..056c749 100644 --- a/src/views/modules/monitoring/product.vue +++ b/src/views/modules/monitoring/product.vue @@ -40,7 +40,7 @@ --> - + 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: 'code', name: '产品编码' }, { prop: 'specifications', name: '规格' }, @@ -151,8 +152,8 @@ const addOrUpdateConfigs = { ], operations: [ { name: 'reset', url: true }, - { name: 'save', url: '/monitoring/product', permission: "" }, - { name: 'update', url: '/monitoring/product', permission: "" } + { name: 'save', url: '/monitoring/product', permission: '' }, + { name: 'update', url: '/monitoring/product', permission: '' } ] // extraComponents: [ // { @@ -164,9 +165,9 @@ const addOrUpdateConfigs = { } export default { + mixins: [dictListMixin], data() { return { - tableConfigs, tableConfigs, dataForm: { key: '' @@ -187,6 +188,19 @@ export default { BaseTable, BaseDialog }, + created() { + this.initDictList([UnitDictTypeId, ProductTypeDictTypeId]) + this.addOrUpdateConfigs.fields.forEach(item => { + if (item.name) { + if (item.name === 'typeDictValue') { + console.log('dict : ', this.dictList) + item.options = this.dictList[ProductTypeDictTypeId] + } else if (item.name === 'unitDictValue') { + item.options = this.dictList[UnitDictTypeId] + } + } + }) + }, activated() { this.getDataList() }, @@ -242,6 +256,15 @@ export default { this.$refs.addOrUpdate.init(id) }) }, + // 表格操作事件管理 + handleOperations({type, data}) { + switch(type) { + case 'viewAttr': // <== 对照 tableConfig + return this.addOrUpdateHandle(data) + case 'delete': + return this.deleteHandle(data) + } + }, // 删除 deleteHandle(id) { var ids = id