diff --git a/src/lang/zh-CN/product.json b/src/lang/zh-CN/product.json index a69235d..d6ef6c0 100644 --- a/src/lang/zh-CN/product.json +++ b/src/lang/zh-CN/product.json @@ -248,7 +248,7 @@ "product.product-things-model.142341-1": "导入通用物模型", "product.product-things-model.142341-2": "刷新", "product.product-things-model.142341-3": "查看物模型", - "product.product-things-model.142341-4": "注意:标识符不能重复", + "product.product-things-model.142341-4": "注意:同设备类型下标识符不能重复", "product.product-things-model.142341-5": "请选择设备从机:", "product.product-things-model.142341-6": "请选择设备从机", "product.product-things-model.142341-7": "网关物模型", @@ -377,6 +377,10 @@ "product.product-things-model.142341-133": "搜索", "product.product-things-model.142341-134": "重置", "product.product-things-model.142341-135": "分组", + "product.product-things-model.142341-136": "设备类型", + "product.product-things-model.142341-137": "请选择设备类型", + "product.product-things-model.142341-138": "模型名称", + "product.product-things-model.142341-139": "请选择模型名称", "product.product-modbus.562372-0": "网关子设备配置", "product.product-modbus.562372-1": "网关子设备配置默认的子设备地址,轮询方式", "product.product-modbus.562372-2": "编辑设备配置", diff --git a/src/views/iot/product/product-things-model.vue b/src/views/iot/product/product-things-model.vue index 48bd89b..78b2c92 100644 --- a/src/views/iot/product/product-things-model.vue +++ b/src/views/iot/product/product-things-model.vue @@ -1,28 +1,30 @@ + + + @@ -133,6 +140,11 @@ {{ $t('product.product-things-model.142341-33') }} + + + + + { - let tempForm = response.data; - this.open = true; - this.title = this.$t('product.product-things-model.142341-100'); - // Json转对象 - tempForm.specs = JSON.parse(tempForm.specs); - if (!tempForm.specs.enumList) { - tempForm.specs.showWay = 'select'; - tempForm.specs.enumList = [ - { - value: '', - text: '', - }, - ]; - } - if (!tempForm.specs.arrayType) { - tempForm.specs.arrayType = 'integer'; - } - if (!tempForm.specs.arrayCount) { - tempForm.specs.arrayCount = 5; - } - if (!tempForm.specs.params) { - tempForm.specs.params = []; - } - // 对象和数组中参数删除前缀 - if ((tempForm.specs.type == 'array' && tempForm.specs.arrayType == 'object') || tempForm.specs.type == 'object') { - for (let i = 0; i < tempForm.specs.params.length; i++) { - tempForm.specs.params[i].id = String(tempForm.specs.params[i].id).substring(String(tempForm.identifier).length + 1); - } - } - this.form = tempForm; - }); - }, - /**查看物模型 */ + /** 修改按钮操作 */ + handleUpdate(row) { + this.reset(); + const modelId = row.modelId; + getModel(modelId).then((response) => { + let tempForm = response.data; + this.open = true; + this.title = this.$t('product.product-things-model.142341-100'); + // devType类型转换,确保与下拉选项类型一致(String类型) + if (tempForm.devType != null && tempForm.devType !== '') { + tempForm.devType = String(tempForm.devType); + } else { + tempForm.devType = undefined; + } + // Json转对象 + tempForm.specs = JSON.parse(tempForm.specs); + if (!tempForm.specs.enumList) { + tempForm.specs.showWay = 'select'; + tempForm.specs.enumList = [ + { + value: '', + text: '', + }, + ]; + } + if (!tempForm.specs.arrayType) { + tempForm.specs.arrayType = 'integer'; + } + if (!tempForm.specs.arrayCount) { + tempForm.specs.arrayCount = 5; + } + if (!tempForm.specs.params) { + tempForm.specs.params = []; + } + // 对象和数组中参数删除前缀 + if ((tempForm.specs.type == 'array' && tempForm.specs.arrayType == 'object') || tempForm.specs.type == 'object') { + for (let i = 0; i < tempForm.specs.params.length; i++) { + tempForm.specs.params[i].id = String(tempForm.specs.params[i].id).substring(String(tempForm.identifier).length + 1); + } + } + this.form = tempForm; + // 强制更新视图 + this.$nextTick(() => { + this.$set(this.form, 'devType', this.form.devType); + }); + }); + }, + + /**查看物模型 */ handleOpenThingsModel() { this.title = this.$t('product.product-things-model.142341-101'); // 生成物模型 @@ -702,74 +730,87 @@ export default { // 使用正则表达式检查值中是否包含下划线 return /_/.test(value); }, - /** 提交按钮 */ - submitForm() { - this.$refs['form'].validate((valid) => { - if (valid) { - // 验证对象或对象数组中的参数不能为空 - if (this.form.datatype == 'object' || (this.form.datatype == 'array' && this.form.specs.arrayType == 'object')) { - if (!this.form.specs.params || this.form.specs.params == 0) { - this.$modal.msgError(this.$t('product.product-things-model.142341-102')); - return; - } - if (this.containsUnderscore(this.form.identifier)) { - this.$modal.msgError(this.$t('product.product-things-model.142341-103')); - return; - } - } - // 验证对象参数标识符不能相同 - if (this.form.specs.params && this.form.specs.params.length > 0) { - let arr = this.form.specs.params.map((item) => item.id).sort(); - for (let i = 0; i < arr.length; i++) { - if (arr[i] == arr[i + 1]) { - this.$modal.msgError('参数标识 ' + arr[i] + ' 重复'); - return; - } - } - } - //验证模型特性为图表展示时,数据类型是否为整数或者小数 - if (this.form.isChart == 1 && this.form.datatype != 'integer' && this.form.isChart == 1 && this.form.datatype != 'decimal') { - this.$modal.msgError(this.$t('product.product-things-model.142341-106')); - } else if (this.form.modelId != null) { - // 格式化specs - let tempForm = JSON.parse(JSON.stringify(this.form)); - tempForm.specs = this.formatThingsSpecs(); - if (this.form.type == 2) { - tempForm.isMonitor = 0; - tempForm.isChart = 0; - } else if (this.form.type == 3) { - tempForm.isMonitor = 0; - tempForm.isChart = 0; - } - updateModel(tempForm).then((response) => { - this.$modal.msgSuccess(this.$t('product.product-things-model.142341-107')); - this.open = false; - this.getList(); - this.$emit('updateModel'); - }); - } else { - // 格式化specs - let tempForm = JSON.parse(JSON.stringify(this.form)); - tempForm.specs = this.formatThingsSpecs(); - tempForm.productId = this.productInfo.productId; - tempForm.productName = this.productInfo.productName; - if (this.form.type == 2) { - tempForm.isMonitor = 0; - } else if (this.form.type == 3) { - tempForm.isMonitor = 0; - tempForm.isChart = 0; - } - addModel(tempForm).then((response) => { - this.$modal.msgSuccess(this.$t('product.product-things-model.142341-108')); - this.open = false; - this.getList(); - this.$emit('updateModel'); - }); - } + /** 提交按钮 */ + submitForm() { + this.$refs['form'].validate((valid) => { + if (valid) { + // 验证对象或对象数组中的参数不能为空 + if (this.form.datatype == 'object' || (this.form.datatype == 'array' && this.form.specs.arrayType == 'object')) { + if (!this.form.specs.params || this.form.specs.params == 0) { + this.$modal.msgError(this.$t('product.product-things-model.142341-102')); + return; + } + if (this.containsUnderscore(this.form.identifier)) { + this.$modal.msgError(this.$t('product.product-things-model.142341-103')); + return; + } + } + // 验证对象参数标识符不能相同 + if (this.form.specs.params && this.form.specs.params.length > 0) { + let arr = this.form.specs.params.map((item) => item.id).sort(); + for (let i = 0; i < arr.length; i++) { + if (arr[i] == arr[i + 1]) { + this.$modal.msgError('参数标识 ' + arr[i] + ' 重复'); + return; } - }); - }, - /** 删除按钮操作 */ + } + } + //验证模型特性为图表展示时,数据类型是否为整数或者小数 + if (this.form.isChart == 1 && this.form.datatype != 'integer' && this.form.isChart == 1 && this.form.datatype != 'decimal') { + this.$modal.msgError(this.$t('product.product-things-model.142341-106')); + } else if (this.form.modelId != null) { + // 格式化specs + let tempForm = JSON.parse(JSON.stringify(this.form)); + tempForm.specs = this.formatThingsSpecs(); + // devType类型转换:String转Number(如果devType有值) + if (tempForm.devType != null && tempForm.devType !== '' && tempForm.devType !== undefined) { + tempForm.devType = Number(tempForm.devType); + } else { + tempForm.devType = null; + } + if (this.form.type == 2) { + tempForm.isMonitor = 0; + tempForm.isChart = 0; + } else if (this.form.type == 3) { + tempForm.isMonitor = 0; + tempForm.isChart = 0; + } + updateModel(tempForm).then((response) => { + this.$modal.msgSuccess(this.$t('product.product-things-model.142341-107')); + this.open = false; + this.getList(); + this.$emit('updateModel'); + }); + } else { + // 格式化specs + let tempForm = JSON.parse(JSON.stringify(this.form)); + tempForm.specs = this.formatThingsSpecs(); + // devType类型转换:String转Number(如果devType有值) + if (tempForm.devType != null && tempForm.devType !== '' && tempForm.devType !== undefined) { + tempForm.devType = Number(tempForm.devType); + } else { + tempForm.devType = null; + } + tempForm.productId = this.productInfo.productId; + tempForm.productName = this.productInfo.productName; + if (this.form.type == 2) { + tempForm.isMonitor = 0; + } else if (this.form.type == 3) { + tempForm.isMonitor = 0; + tempForm.isChart = 0; + } + addModel(tempForm).then((response) => { + this.$modal.msgSuccess(this.$t('product.product-things-model.142341-108')); + this.open = false; + this.getList(); + this.$emit('updateModel'); + }); + } + } + }); + }, + + /** 删除按钮操作 */ handleDelete(row) { const modelIds = row.modelId; this.$modal