forked from mt-fe-group/mt-yd-ui
		
	update 数据字典相关逻辑“
This commit is contained in:
		@@ -25,7 +25,7 @@
 | 
				
			|||||||
							v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
 | 
												v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"
 | 
				
			||||||
							clearable
 | 
												clearable
 | 
				
			||||||
						>
 | 
											>
 | 
				
			||||||
							<el-option v-for="opt in configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].options" :key="opt.label" :value="opt.value" />
 | 
												<el-option v-for="opt in configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].options" :key="opt.label" :label="opt.label" :value="opt.value" />
 | 
				
			||||||
						</el-select>
 | 
											</el-select>
 | 
				
			||||||
						<el-switch v-if="getType(n, c) === 'switch'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-switch>
 | 
											<el-switch v-if="getType(n, c) === 'switch'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-switch>
 | 
				
			||||||
						<el-cascader v-if="getType(n, c) === 'tree'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-cascader>
 | 
											<el-cascader v-if="getType(n, c) === 'tree'" v-model="dataForm[configs.fields[(n - 1) * COLUMN_PER_ROW + (c - 1)].name]"></el-cascader>
 | 
				
			||||||
@@ -272,7 +272,7 @@ export default {
 | 
				
			|||||||
										message: btn.name === 'save' ? '添加成功!' : '更新成功!',
 | 
															message: btn.name === 'save' ? '添加成功!' : '更新成功!',
 | 
				
			||||||
										type: 'success',
 | 
															type: 'success',
 | 
				
			||||||
										duration: 1500,
 | 
															duration: 1500,
 | 
				
			||||||
										onClose() {
 | 
															onClose: () => {
 | 
				
			||||||
											this.$emit('refreshDataList')
 | 
																this.$emit('refreshDataList')
 | 
				
			||||||
											this.visible = false
 | 
																this.visible = false
 | 
				
			||||||
										}
 | 
															}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,7 @@ export default {
 | 
				
			|||||||
        // add more...
 | 
					        // add more...
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
      text: {
 | 
					      text: {
 | 
				
			||||||
        // for i18n inject:
 | 
					        // TODO: i18n
 | 
				
			||||||
        edit: '编辑',
 | 
					        edit: '编辑',
 | 
				
			||||||
        detail: '详情',
 | 
					        detail: '详情',
 | 
				
			||||||
        delete: '删除',
 | 
					        delete: '删除',
 | 
				
			||||||
@@ -38,12 +38,15 @@ export default {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  methods: {
 | 
					  methods: {
 | 
				
			||||||
    // 发射事件
 | 
					    // 发射事件
 | 
				
			||||||
 | 
					    emit(eventType) {
 | 
				
			||||||
 | 
					      this.$emit('emit-data', { type: eventType, data: this.injectData.head?.emitFullData ? this.injectData : this.injectData.id })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  render: function (h) {
 | 
					  render: function (h) {
 | 
				
			||||||
    let btns = []
 | 
					    let btns = []
 | 
				
			||||||
    for (const optionStr of this.injectData.head?.options) {
 | 
					    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: 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)
 | 
					    return h('span', null, btns)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,7 +30,7 @@
 | 
				
			|||||||
				>
 | 
									>
 | 
				
			||||||
					<!-- 子组件 -->
 | 
										<!-- 子组件 -->
 | 
				
			||||||
					<template v-if="head.prop" slot-scope="scope">
 | 
										<template v-if="head.prop" slot-scope="scope">
 | 
				
			||||||
						<component v-if="head.subcomponent" :is="head.subcomponent" :key="idx + 'sub'" :inject-data="{ ...scope.row, head }" @emitData="handleSubEmitData" />
 | 
											<component v-if="head.subcomponent" :is="head.subcomponent" :key="idx + 'sub'" :inject-data="{ ...scope.row, head }" @emit-data="handleSubEmitData" />
 | 
				
			||||||
						<!-- 直接展示数据或应用过滤器 -->
 | 
											<!-- 直接展示数据或应用过滤器 -->
 | 
				
			||||||
						<span v-else>{{ scope.row[head.prop] | commonFilter(head.filter) }}</span>
 | 
											<span v-else>{{ scope.row[head.prop] | commonFilter(head.filter) }}</span>
 | 
				
			||||||
					</template>
 | 
										</template>
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								src/mixins/dictlist-module.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/mixins/dictlist-module.js
									
									
									
									
									
										Normal file
									
								
							@@ -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 }))
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -129,25 +129,25 @@ export default {
 | 
				
			|||||||
						params: this.$http.adornParams()
 | 
											params: this.$http.adornParams()
 | 
				
			||||||
					}).then(({ data }) => {
 | 
										}).then(({ data }) => {
 | 
				
			||||||
						if (data && data.code === 0) {
 | 
											if (data && data.code === 0) {
 | 
				
			||||||
							this.dataForm.code = data.product.code
 | 
												this.dataForm.code = data.data.code
 | 
				
			||||||
							this.dataForm.name = data.product.name
 | 
												this.dataForm.name = data.data.name
 | 
				
			||||||
							this.dataForm.description = data.product.description
 | 
												this.dataForm.description = data.data.description
 | 
				
			||||||
							this.dataForm.externalCode = data.product.externalCode
 | 
												this.dataForm.externalCode = data.data.externalCode
 | 
				
			||||||
							this.dataForm.specifications = data.product.specifications
 | 
												this.dataForm.specifications = data.data.specifications
 | 
				
			||||||
							this.dataForm.unitDictValue = data.product.unitDictValue
 | 
												this.dataForm.unitDictValue = data.data.unitDictValue
 | 
				
			||||||
							this.dataForm.area = data.product.area
 | 
												this.dataForm.area = data.data.area
 | 
				
			||||||
							this.dataForm.processTime = data.product.processTime
 | 
												this.dataForm.processTime = data.data.processTime
 | 
				
			||||||
							this.dataForm.typeDictValue = data.product.typeDictValue
 | 
												this.dataForm.typeDictValue = data.data.typeDictValue
 | 
				
			||||||
							this.dataForm.enabled = data.product.enabled
 | 
												this.dataForm.enabled = data.data.enabled
 | 
				
			||||||
							this.dataForm.remark = data.product.remark
 | 
												this.dataForm.remark = data.data.remark
 | 
				
			||||||
							this.dataForm.valid = data.product.valid
 | 
												this.dataForm.valid = data.data.valid
 | 
				
			||||||
							this.dataForm.creatorId = data.product.creatorId
 | 
												this.dataForm.creatorId = data.data.creatorId
 | 
				
			||||||
							this.dataForm.creatorName = data.product.creatorName
 | 
												this.dataForm.creatorName = data.data.creatorName
 | 
				
			||||||
							this.dataForm.createTime = data.product.createTime
 | 
												this.dataForm.createTime = data.data.createTime
 | 
				
			||||||
							this.dataForm.updaterId = data.product.updaterId
 | 
												this.dataForm.updaterId = data.data.updaterId
 | 
				
			||||||
							this.dataForm.updaterName = data.product.updaterName
 | 
												this.dataForm.updaterName = data.data.updaterName
 | 
				
			||||||
							this.dataForm.updateTime = data.product.updateTime
 | 
												this.dataForm.updateTime = data.data.updateTime
 | 
				
			||||||
							this.dataForm.version = data.product.version
 | 
												this.dataForm.version = data.data.version
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					})
 | 
										})
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@
 | 
				
			|||||||
			</el-table-column>
 | 
								</el-table-column>
 | 
				
			||||||
		</el-table> -->
 | 
							</el-table> -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		<base-table :data="dataList" :table-head-configs="tableConfigs" :max-height="500" />
 | 
							<base-table :data="dataList" :table-head-configs="tableConfigs" :max-height="500" @operate-event="handleOperations" @refreshDataList="getDataList" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		<el-pagination
 | 
							<el-pagination
 | 
				
			||||||
			@size-change="sizeChangeHandle"
 | 
								@size-change="sizeChangeHandle"
 | 
				
			||||||
@@ -65,13 +65,14 @@ import TableOperateComponent from '@/components/base-table/components/operationC
 | 
				
			|||||||
import TableTextComponent from '@/components/base-table/components/detailComponent'
 | 
					import TableTextComponent from '@/components/base-table/components/detailComponent'
 | 
				
			||||||
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'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const UnitDictTypeId = '1557173812109242370'
 | 
					const UnitDictTypeId = '1557173812109242370'
 | 
				
			||||||
const ProductTypeDictTypeId = ' '
 | 
					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: '规格' },
 | 
				
			||||||
@@ -151,8 +152,8 @@ const addOrUpdateConfigs = {
 | 
				
			|||||||
	],
 | 
						],
 | 
				
			||||||
	operations: [
 | 
						operations: [
 | 
				
			||||||
		{ name: 'reset', url: true },
 | 
							{ name: 'reset', url: true },
 | 
				
			||||||
		{ name: 'save', url: '/monitoring/product', permission: "" },
 | 
							{ name: 'save', url: '/monitoring/product', permission: '' },
 | 
				
			||||||
		{ name: 'update', url: '/monitoring/product', permission: "" }
 | 
							{ name: 'update', url: '/monitoring/product', permission: '' }
 | 
				
			||||||
	]
 | 
						]
 | 
				
			||||||
	// extraComponents: [
 | 
						// extraComponents: [
 | 
				
			||||||
	// 	{
 | 
						// 	{
 | 
				
			||||||
@@ -164,9 +165,9 @@ const addOrUpdateConfigs = {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
 | 
						mixins: [dictListMixin],
 | 
				
			||||||
	data() {
 | 
						data() {
 | 
				
			||||||
		return {
 | 
							return {
 | 
				
			||||||
			tableConfigs,
 | 
					 | 
				
			||||||
			tableConfigs,
 | 
								tableConfigs,
 | 
				
			||||||
			dataForm: {
 | 
								dataForm: {
 | 
				
			||||||
				key: ''
 | 
									key: ''
 | 
				
			||||||
@@ -187,6 +188,19 @@ export default {
 | 
				
			|||||||
		BaseTable,
 | 
							BaseTable,
 | 
				
			||||||
		BaseDialog
 | 
							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() {
 | 
						activated() {
 | 
				
			||||||
		this.getDataList()
 | 
							this.getDataList()
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
@@ -242,6 +256,15 @@ export default {
 | 
				
			|||||||
				this.$refs.addOrUpdate.init(id)
 | 
									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) {
 | 
							deleteHandle(id) {
 | 
				
			||||||
			var ids = id
 | 
								var ids = id
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user