diff --git a/vue/.vscode/settings.json b/vue/.vscode/settings.json new file mode 100644 index 00000000..a7210597 --- /dev/null +++ b/vue/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "i18n-ally.localesPaths": [ + "src/lang" + ] +} \ No newline at end of file diff --git a/vue/src/views/iot/product/product-edit.vue b/vue/src/views/iot/product/product-edit.vue index 2d63e85a..6e88bf11 100644 --- a/vue/src/views/iot/product/product-edit.vue +++ b/vue/src/views/iot/product/product-edit.vue @@ -34,7 +34,7 @@ - + @@ -48,7 +48,7 @@ - + diff --git a/vue/src/views/iot/product/product-things-model.vue b/vue/src/views/iot/product/product-things-model.vue index d7e794e6..346be0ad 100644 --- a/vue/src/views/iot/product/product-things-model.vue +++ b/vue/src/views/iot/product/product-things-model.vue @@ -1,343 +1,339 @@ @@ -349,637 +345,666 @@ import thingsParameter from '../template/parameter'; import { listModel, getModel, delModel, addModel, updateModel, importModel } from '@/api/iot/model'; export default { - name: 'product-things-model', - dicts: ['iot_things_type', 'iot_data_type', 'iot_yes_no'], - components: { - productSelectTemplate, - thingsParameter, - JsonViewer, - }, - props: { - product: { - type: Object, - default: null, + name: 'product-things-model', + dicts: ['iot_things_type', 'iot_data_type', 'iot_yes_no'], + components: { + productSelectTemplate, + thingsParameter, + JsonViewer, }, - }, - watch: { - // 获取到父组件传递的productId后,刷新列表 - product: function (newVal, oldVal) { - this.productInfo = newVal; - if (this.productInfo && this.productInfo.productId != 0) { - this.queryParams.productId = this.productInfo.productId; - this.queryParams.isModbus = this.productInfo.isModbus; - this.getList(); - } - }, - }, - data() { - return { - // 物模型 - thingsModel: {}, - // 父组件接收的产品信息 - productInfo: {}, - // 子组件选中的id数组 - templateIds: [], - // 遮罩层 - loading: false, - // 选中数组 - ids: [], - // 非单个禁用 - single: true, - // 非多个禁用 - multiple: true, - // 显示搜索条件 - showSearch: true, - // 总条数 - total: 0, - // 产品物模型表格数据 - modelList: [], - //是否为小数的判断 - isDecimal: '', - isDecimalMax: '', - // 弹出层标题 - title: '', - // 是否显示弹出层 - open: false, - openSelect: false, - openThingsModel: false, - // 查询参数 - queryParams: { - productId: 0, - pageNum: 1, - pageSize: 100, - }, - // 表单参数 - form: {}, - // 对象类型参数 - paramData: { - index: -1, - parameter: {}, - }, - //是否是modbus - isModbus: false, - slaveList: [], - slave: {}, - // 表单校验 - rules: { - modelName: [ - { - required: true, - message: this.$t('product.product-things-model.142341-94'), - trigger: 'blur', - }, - { - min: 1, - max: 64, - message: this.$i18n.t('product.product-things-model.142341-94'), - trigger: 'blur', - }, - ], - identifier: [ - { - required: true, - message: this.$t('product.product-things-model.142341-95'), - trigger: 'blur', - }, - { - min: 1, - max: 32, - message: this.$i18n.t('product.product-things-model.142341-95'), - trigger: 'blur', - }, - ], - modelOrder: [ - { - required: true, - message: this.$t('product.product-things-model.142341-96'), - trigger: 'blur', - }, { - type: 'number', - min: -2147483648, - max: 2147483647, - message: this.$t('product.product-things-model.142341-96'), - trigger: 'blur', - }, - ], - type: [ - { - required: true, - message: this.$t('product.product-things-model.142341-97'), - trigger: 'change', - }, - - ], - datatype: [ - { - required: true, - message: this.$t('product.product-things-model.142341-98'), - trigger: 'change', - }, - ], - }, - }; - }, - created() { }, - methods: { - /**查询产品物模型列表 */ - getList() { - this.loading = true; - listModel(this.queryParams).then((response) => { - this.modelList = response.rows; - this.total = response.total; - this.loading = false; - }); - }, - // 取消按钮 - cancel() { - this.open = false; - this.reset(); - }, - // 表单重置 - reset() { - this.form = { - templateId: null, - templateName: null, - userId: null, - userName: null, - tenantId: null, - tenantName: null, - identifier: null, - modelOrder: 0, - type: 1, - datatype: 'integer', - isSys: null, - isChart: 1, - isHistory: 1, - isSharePerm: 1, - isMonitor: 1, - isReadonly: 1, - delFlag: null, - createBy: null, - createTime: null, - updateBy: null, - updateTime: null, - remark: null, - specs: { - enumList: [ - { - value: '', - text: '', - }, - ], - arrayType: 'integer', - arrayCount: 5, - showWay: 'select', // 显示方式select=下拉选择框,button=按钮 - params: [], + props: { + product: { + type: Object, + default: null, }, - }; - this.resetForm('form'); }, - /** 搜索按钮操作 */ - handleQuery() { - this.queryParams.pageNum = 1; - this.getList(); + watch: { + // 获取到父组件传递的productId后,刷新列表 + product: function (newVal, oldVal) { + this.productInfo = newVal; + if (this.productInfo && this.productInfo.productId != 0) { + this.queryParams.productId = this.productInfo.productId; + this.queryParams.isModbus = this.productInfo.isModbus; + this.getList(); + } + }, }, - /** 重置按钮操作 */ - resetQuery() { - this.resetForm('queryForm'); - this.handleQuery(); - }, - /** 新增按钮操作 */ - handleAdd() { - this.reset(); - this.open = true; - this.title = this.$t('product.product-things-model.142341-99'); - }, - /** 修改按钮操作 */ - 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'); - // Json转对象 - tempForm.specs = JSON.parse(tempForm.specs); - if (!tempForm.specs.enumList) { - tempForm.specs.showWay = 'select'; - tempForm.specs.enumList = [ - { - value: '', - text: '', + data() { + return { + // 物模型 + thingsModel: {}, + // 父组件接收的产品信息 + productInfo: {}, + // 子组件选中的id数组 + templateIds: [], + // 遮罩层 + loading: false, + // 选中数组 + ids: [], + // 非单个禁用 + single: true, + // 非多个禁用 + multiple: true, + // 显示搜索条件 + showSearch: true, + // 总条数 + total: 0, + // 产品物模型表格数据 + modelList: [], + //是否为小数的判断 + isDecimal: '', + isDecimalMax: '', + // 弹出层标题 + title: '', + // 是否显示弹出层 + open: false, + openSelect: false, + openThingsModel: false, + // 查询参数 + queryParams: { + productId: 0, + pageNum: 1, + pageSize: 100, + }, + // 表单参数 + form: {}, + // 对象类型参数 + paramData: { + index: -1, + parameter: {}, + }, + //是否是modbus + isModbus: false, + slaveList: [], + slave: {}, + // 表单校验 + rules: { + modelName: [ + { + required: true, + message: this.$t('product.product-things-model.142341-94'), + trigger: 'blur', + }, + { + min: 1, + max: 64, + message: this.$i18n.t('product.product-things-model.142341-94'), + trigger: 'blur', + }, + ], + identifier: [ + { + required: true, + message: this.$t('product.product-things-model.142341-95'), + trigger: 'blur', + }, + { + min: 1, + max: 32, + message: this.$i18n.t('product.product-things-model.142341-95'), + trigger: 'blur', + }, + ], + modelOrder: [ + { + required: true, + message: this.$t('product.product-things-model.142341-96'), + trigger: 'blur', + }, + { + type: 'number', + min: -2147483648, + max: 2147483647, + message: this.$t('product.product-things-model.142341-96'), + trigger: 'blur', + }, + ], + type: [ + { + required: true, + message: this.$t('product.product-things-model.142341-97'), + trigger: 'change', + }, + ], + datatype: [ + { + required: true, + message: this.$t('product.product-things-model.142341-98'), + trigger: 'change', + }, + ], }, - ]; - } - 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; - }); - }, - /**查看物模型 */ - handleOpenThingsModel() { - this.title = this.$t('product.product-things-model.142341-101'); - // 生成物模型 - this.thingsModel = { - properties: [], - functions: [], - events: [], - }; - for (var i = 0; i < this.modelList.length; i++) { - let thingsItem = {}; - thingsItem.id = this.modelList[i].identifier; - thingsItem.name = this.modelList[i].modelName; - if (this.modelList[i].type == 1) { - //属性 - thingsItem.isChart = this.modelList[i].isChart; - thingsItem.isMonitor = this.modelList[i].isMonitor; - thingsItem.isHistory = this.modelList[i].isHistory; - thingsItem.isSharePerm = this.modelList[i].isSharePerm; - thingsItem.isReadonly = this.modelList[i].isReadonly; - thingsItem.datatype = JSON.parse(this.modelList[i].specs); - this.thingsModel.properties.push(thingsItem); - } else if (this.modelList[i].type == 2) { - // 功能 - thingsItem.isHistory = this.modelList[i].isHistory; - thingsItem.isSharePerm = this.modelList[i].isSharePerm; - thingsItem.isReadonly = this.modelList[i].isReadonly; - thingsItem.datatype = JSON.parse(this.modelList[i].specs); - this.thingsModel.functions.push(thingsItem); - } else if (this.modelList[i].type == 3) { - // 事件 - thingsItem.isHistory = this.modelList[i].isHistory; - thingsItem.isSharePerm = this.modelList[i].isSharePerm; - thingsItem.isReadonly = this.modelList[i].isReadonly; - thingsItem.datatype = JSON.parse(this.modelList[i].specs); - this.thingsModel.events.push(thingsItem); - } - } - - this.openThingsModel = true; - }, - /**关闭物模型 */ - handleCloseThingsModel() { - this.openThingsModel = false; - }, - /** 选择物模型 */ - handleSelect() { - this.openSelect = true; - this.title = this.$t('product.product-things-model.142341-1'); - this.form.type = 1; - this.form.datatype = 'integer'; - this.form.specs = { - enumList: [], - }; - }, - // 取消导入通用物模型按钮 - cancelSelect() { - this.openSelect = false; - this.$refs.productSelectTemplate.$refs.selectTemplateTable.clearSelection(); - }, - // 获取子组件的值 - getChildData(data) { - this.templateIds = data; - }, - // 导入通用物模型按钮 - importSelect() { - if (this.templateIds != null && this.templateIds.length > 0) { - var importData = { - productId: this.productInfo.productId, - productName: this.productInfo.productName, - templateIds: this.templateIds, }; - importModel(importData).then((response) => { - this.$modal.msgSuccess(response.msg); - this.openSelect = false; - this.$refs.productSelectTemplate.$refs.selectTemplateTable.clearSelection(); - this.getList(); - }); - } }, - /** 提交按钮 */ - 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.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(this.$i18n.t('product.product-things-model.142341-105', [arr[i]])); - return; - } - } - } - //验证输入的取值范围最大值不能小于最小值 - if (this.form.datatype == 'integer' || this.form.datatype == 'decimal') { - if (parseFloat(this.form.specs.min) > parseFloat(this.form.specs.max)) { - this.$modal.msgError(this.$t('product.product-things-model.142341-143')); - return; - } - } - if (this.form.datatype == 'decimal') { - this.hasDecimalPoint(); - this.hasDecimalPointMax(); - if (this.isDecimal === false || this.isDecimalMax === false) { - this.$modal.msgError(this.$t('product.product-things-model.142341-144')); - 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(); + created() {}, + methods: { + /**查询产品物模型列表 */ + getList() { + this.loading = true; + listModel(this.queryParams).then((response) => { + this.modelList = response.rows; + this.total = response.total; + this.loading = false; }); - } 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(); - }); - } - } - }); - }, - /** 删除按钮操作 */ - handleDelete(row) { - const modelIds = row.modelId; - // if (!this.queryParams.isModbus) { - this.$modal - .confirm(this.$i18n.t('product.product-things-model.142341-109', [modelIds])) - .then(function () { - return delModel(modelIds); - }) - .then(() => { - this.getList(); - this.$modal.msgSuccess(this.$t('product.product-things-model.142341-111')); - }) - .catch(() => { }); - // } else { - // this.$modal.alert('采集点删除请在采集点模板修改'); - // } - }, - /** 导出按钮操作 */ - handleExport() { - this.download( - 'iot/model/export', - { - ...this.queryParams, }, - `model_${new Date().getTime()}.xlsx` - ); + // 取消按钮 + cancel() { + this.open = false; + this.reset(); + }, + // 表单重置 + reset() { + this.form = { + templateId: null, + templateName: null, + userId: null, + userName: null, + tenantId: null, + tenantName: null, + identifier: null, + modelOrder: 0, + type: 1, + datatype: 'integer', + isSys: null, + isChart: 1, + isHistory: 1, + isSharePerm: 1, + isMonitor: 1, + isReadonly: 1, + delFlag: null, + createBy: null, + createTime: null, + updateBy: null, + updateTime: null, + remark: null, + specs: { + enumList: [ + { + value: '', + text: '', + }, + ], + arrayType: 'integer', + arrayCount: 5, + showWay: 'select', // 显示方式select=下拉选择框,button=按钮 + params: [], + }, + }; + this.resetForm('form'); + }, + /** 搜索按钮操作 */ + handleQuery() { + this.queryParams.pageNum = 1; + this.getList(); + }, + /** 重置按钮操作 */ + resetQuery() { + this.resetForm('queryForm'); + this.handleQuery(); + }, + /** 新增按钮操作 */ + handleAdd() { + this.reset(); + this.open = true; + this.title = this.$t('product.product-things-model.142341-99'); + }, + /** 修改按钮操作 */ + 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'); + // 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; + }); + }, + /**查看物模型 */ + handleOpenThingsModel() { + this.title = this.$t('product.product-things-model.142341-101'); + // 生成物模型 + this.thingsModel = { + properties: [], + functions: [], + events: [], + }; + for (var i = 0; i < this.modelList.length; i++) { + let thingsItem = {}; + thingsItem.id = this.modelList[i].identifier; + thingsItem.name = this.modelList[i].modelName; + if (this.modelList[i].type == 1) { + //属性 + thingsItem.isChart = this.modelList[i].isChart; + thingsItem.isMonitor = this.modelList[i].isMonitor; + thingsItem.isHistory = this.modelList[i].isHistory; + thingsItem.isSharePerm = this.modelList[i].isSharePerm; + thingsItem.isReadonly = this.modelList[i].isReadonly; + thingsItem.datatype = JSON.parse(this.modelList[i].specs); + this.thingsModel.properties.push(thingsItem); + } else if (this.modelList[i].type == 2) { + // 功能 + thingsItem.isHistory = this.modelList[i].isHistory; + thingsItem.isSharePerm = this.modelList[i].isSharePerm; + thingsItem.isReadonly = this.modelList[i].isReadonly; + thingsItem.datatype = JSON.parse(this.modelList[i].specs); + this.thingsModel.functions.push(thingsItem); + } else if (this.modelList[i].type == 3) { + // 事件 + thingsItem.isHistory = this.modelList[i].isHistory; + thingsItem.isSharePerm = this.modelList[i].isSharePerm; + thingsItem.isReadonly = this.modelList[i].isReadonly; + thingsItem.datatype = JSON.parse(this.modelList[i].specs); + this.thingsModel.events.push(thingsItem); + } + } + + this.openThingsModel = true; + }, + /**关闭物模型 */ + handleCloseThingsModel() { + this.openThingsModel = false; + }, + /** 选择物模型 */ + handleSelect() { + this.openSelect = true; + this.title = this.$t('product.product-things-model.142341-1'); + this.form.type = 1; + this.form.datatype = 'integer'; + this.form.specs = { + enumList: [], + }; + }, + // 取消导入通用物模型按钮 + cancelSelect() { + this.openSelect = false; + this.$refs.productSelectTemplate.$refs.selectTemplateTable.clearSelection(); + }, + // 获取子组件的值 + getChildData(data) { + this.templateIds = data; + }, + // 导入通用物模型按钮 + importSelect() { + if (this.templateIds != null && this.templateIds.length > 0) { + var importData = { + productId: this.productInfo.productId, + productName: this.productInfo.productName, + templateIds: this.templateIds, + }; + importModel(importData).then((response) => { + this.$modal.msgSuccess(response.msg); + this.openSelect = false; + this.$refs.productSelectTemplate.$refs.selectTemplateTable.clearSelection(); + this.getList(); + }); + } + }, + /** 提交按钮 */ + 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.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(this.$i18n.t('product.product-things-model.142341-105', [arr[i]])); + return; + } + } + } + //验证输入的取值范围最大值不能小于最小值 + if (this.form.datatype == 'integer' || this.form.datatype == 'decimal') { + if (parseFloat(this.form.specs.min) > parseFloat(this.form.specs.max)) { + this.$modal.msgError(this.$t('product.product-things-model.142341-143')); + return; + } + } + if (this.form.datatype == 'decimal') { + this.hasDecimalPoint(); + this.hasDecimalPointMax(); + if (this.isDecimal === false || this.isDecimalMax === false) { + this.$modal.msgError(this.$t('product.product-things-model.142341-144')); + 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(); + }); + } 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(); + }); + } + } + }); + }, + /** 删除按钮操作 */ + handleDelete(row) { + const modelIds = row.modelId; + // if (!this.queryParams.isModbus) { + this.$modal + .confirm(this.$i18n.t('product.product-things-model.142341-109', [modelIds])) + .then(function () { + return delModel(modelIds); + }) + .then(() => { + this.getList(); + this.$modal.msgSuccess(this.$t('product.product-things-model.142341-111')); + }) + .catch(() => {}); + // } else { + // this.$modal.alert('采集点删除请在采集点模板修改'); + // } + }, + /** 导出按钮操作 */ + handleExport() { + this.download( + 'iot/model/export', + { + ...this.queryParams, + }, + `model_${new Date().getTime()}.xlsx` + ); + }, + // 类型改变 + typeChange(type) { + if (type == 1) { + this.form.isChart = 1; + this.form.isHistory = 1; + this.form.isSharePerm = 1; + this.form.isMonitor = 1; + this.form.isReadonly = 1; + this.form.datatype = 'integer'; + } else if (type == 2) { + this.form.isChart = 0; + this.form.isHistory = 1; + this.form.isSharePerm = 1; + this.form.isMonitor = 0; + this.form.isReadonly = 0; + } else if (type == 3) { + this.form.isChart = 0; + this.form.isHistory = 1; + this.form.isSharePerm = 0; + this.form.isMonitor = 0; + this.form.isReadonly = 1; + } + }, + // 是否图表展示改变 + isChartChange() { + if (this.form.isChart == 1) { + this.form.isReadonly = 1; + } else { + this.form.isMonitor = 0; + } + }, + // 是否实时监测改变 + isMonitorChange() { + if (this.form.isMonitor == 1) { + this.form.isReadonly = 1; + this.form.isChart = 1; + } + }, + // 是否只读数据改变 + isReadonlyChange() { + if (this.form.isReadonly == 0) { + this.form.isMonitor = 0; + this.form.isChart = 0; + } + }, + // 格式化物模型 + formatThingsSpecs() { + var data = {}; + data.type = this.form.datatype; + if (this.form.datatype == 'integer' || this.form.datatype == 'decimal') { + data.min = Number(this.form.specs.min ? this.form.specs.min : 0); + data.max = Number(this.form.specs.max ? this.form.specs.max : 100); + data.unit = this.form.specs.unit ? this.form.specs.unit : ''; + data.step = Number(this.form.specs.step ? this.form.specs.step : 1); + } else if (this.form.datatype == 'string') { + data.maxLength = Number(this.form.specs.maxLength ? this.form.specs.maxLength : 1024); + } else if (this.form.datatype == 'bool') { + data.falseText = this.form.specs.falseText ? this.form.specs.falseText : this.$t('product.product-things-model.142341-113'); + data.trueText = this.form.specs.trueText ? this.form.specs.trueText : this.$t('product.product-things-model.142341-114'); + } else if (this.form.datatype == 'enum') { + data.showWay = this.form.specs.showWay; + if (this.form.specs.enumList && this.form.specs.enumList[0].text != '') { + data.enumList = this.form.specs.enumList; + } else { + data.showWay = 'select'; + data.enumList = [ + { + value: '0', + text: this.$t('product.product-things-model.142341-115'), + }, + { + value: '1', + text: this.$t('product.product-things-model.142341-116'), + }, + ]; + } + } else if (this.form.datatype == 'array') { + data.arrayType = this.form.specs.arrayType; + data.arrayCount = this.form.specs.arrayCount ? this.form.specs.arrayCount : 5; + if (data.arrayType == 'object') { + data.params = this.form.specs.params; + // 物模型名称作为参数的标识符前缀 + for (let i = 0; i < data.params.length; i++) { + data.params[i].id = this.form.identifier + '_' + data.params[i].id; + } + } + } else if (this.form.datatype == 'object') { + data.params = this.form.specs.params; + // 物模型名称作为参数的标识符前缀 + for (let i = 0; i < data.params.length; i++) { + data.params[i].id = this.form.identifier + '_' + data.params[i].id; + } + } + return JSON.stringify(data); + }, + /** 数据类型改变 */ + dataTypeChange(val) { + this.form.specs = { + enumList: [ + { + value: '', + text: '', + }, + ], + arrayType: 'integer', + arrayCount: 5, + showWay: 'select', + params: [], + }; + }, + /** 添加枚举项 */ + addEnumItem() { + this.form.specs.enumList.push({ + value: '', + text: '', + }); + }, + /** 删除枚举项 */ + removeEnumItem(index) { + this.form.specs.enumList.splice(index, 1); + }, + /** 格式化显示数据定义 */ + formatSpecsDisplay(json) { + let specs = JSON.parse(json); + if (specs.type === 'integer' || specs.type === 'decimal' || specs.type === 'INT16' || specs.type === 'INT') { + return ( + "" + + this.$t('product.product-things-model.142341-117') + + '' + + specs.max + + '' + + this.$t('product.product-things-model.142341-118') + + '' + + specs.min + + "
" + + this.$t('product.product-things-model.142341-119') + + '' + + specs.step + + '' + + this.$t('product.product-things-model.142341-120') + + '' + + specs.unit + ); + } else if (specs.type === 'string') { + return this.$t('product.product-things-model.142341-121') + '' + specs.maxLength + ''; + } else if (specs.type === 'array') { + return ( + "" + + this.$t('product.product-things-model.142341-122') + + '' + + specs.arrayType + + '' + + this.$t('product.product-things-model.142341-123') + + '' + + specs.arrayCount + ); + } else if (specs.type === 'enum') { + let items = ''; + for (let i = 0; i < specs.enumList.length; i++) { + items = items + "" + specs.enumList[i].value + ":" + specs.enumList[i].text + ''; + if (i > 0 && i % 2 != 0) { + items = items + '
'; + } + } + return items; + } else if (specs.type === 'bool') { + return '0:' + specs.falseText + '1:' + specs.trueText; + } else if (specs.type === 'object') { + let items = ''; + for (let i = 0; i < specs.params.length; i++) { + items = items + "" + specs.params[i].name + ":" + specs.params[i].datatype.type + ''; + if (i > 0 && i % 2 != 0) { + items = items + '
'; + } + } + return items; + } + }, + /** 添加参数 */ + addParameter() { + this.paramData = { + index: -1, + parameter: {}, + }; + }, + /** 编辑参数*/ + editParameter(data, index) { + this.paramData = null; + this.paramData = { + index: index, + parameter: data, + }; + }, + /** 删除动作 */ + removeParameter(index) { + this.form.specs.params.splice(index, 1); + }, + /**获取设置的参数对象*/ + getParamData(data) { + if (data.index == -1) { + this.form.specs.params.push(data.parameter); + } else { + this.form.specs.params[data.index] = data.parameter; + // 解决数组在界面中不更新问题 + this.$set(this.form.specs.params, data.index, this.form.specs.params[data.index]); + } + }, + // 在输入最小值改变时触发 + handleEdit(e) { + let value = e.replace(/[^\-\d]/g, ''); // 只能输入-和数字 + value = value.replace(/\-{2,}/g, '-'); // -只能保留一个 + value = value.replace(/(\d)\-/g, '$1'); // 数字后面不能接-,不能出现类似-11-2,12-,11-23 + value = value.replace(/(-)0+/g, '$1'); // 不能出现-0,-001,-0001类似 + value = value.replace(/(-\d{10})\d*/, '$1'); // 最多保留10位整数 + this.form.specs.min = value; + }, + // 在输入最大值改变时触发 + handleEditmax(e) { + let value = e.replace(/[^\-\d]/g, ''); // 只能输入-和数字 + value = value.replace(/\-{2,}/g, '-'); // -只能保留一个 + value = value.replace(/(\d)\-/g, '$1'); // 数字后面不能接-,不能出现类似-11-2,12-,11-23 + value = value.replace(/(-)0+/g, '$1'); // 不能出现-0,-001,-0001类似 + value = value.replace(/(-\d{10})\d*/, '$1'); // 最多保留10位整数 + this.form.specs.max = value; + }, + //数据类型为小数的校验 + hasDecimalPoint() { + const regex = /^-?\d+\.\d+$/; // 使用正则表达式匹配小数点格式 + this.isDecimal = regex.test(this.form.specs.min); + return this.isDecimal; + }, + hasDecimalPointMax() { + const regex = /^-?\d+\.\d+$/; // 使用正则表达式匹配小数点格式 + this.isDecimalMax = regex.test(this.form.specs.max); + return this.isDecimalMax; + }, }, - // 类型改变 - typeChange(type) { - if (type == 1) { - this.form.isChart = 1; - this.form.isHistory = 1; - this.form.isSharePerm = 1; - this.form.isMonitor = 1; - this.form.isReadonly = 1; - this.form.datatype = 'integer'; - } else if (type == 2) { - this.form.isChart = 0; - this.form.isHistory = 1; - this.form.isSharePerm = 1; - this.form.isMonitor = 0; - this.form.isReadonly = 0; - } else if (type == 3) { - this.form.isChart = 0; - this.form.isHistory = 1; - this.form.isSharePerm = 0; - this.form.isMonitor = 0; - this.form.isReadonly = 1; - } - }, - // 是否图表展示改变 - isChartChange() { - if (this.form.isChart == 1) { - this.form.isReadonly = 1; - } else { - this.form.isMonitor = 0; - } - }, - // 是否实时监测改变 - isMonitorChange() { - if (this.form.isMonitor == 1) { - this.form.isReadonly = 1; - this.form.isChart = 1; - } - }, - // 是否只读数据改变 - isReadonlyChange() { - if (this.form.isReadonly == 0) { - this.form.isMonitor = 0; - this.form.isChart = 0; - } - }, - // 格式化物模型 - formatThingsSpecs() { - var data = {}; - data.type = this.form.datatype; - if (this.form.datatype == 'integer' || this.form.datatype == 'decimal') { - data.min = Number(this.form.specs.min ? this.form.specs.min : 0); - data.max = Number(this.form.specs.max ? this.form.specs.max : 100); - data.unit = this.form.specs.unit ? this.form.specs.unit : ''; - data.step = Number(this.form.specs.step ? this.form.specs.step : 1); - } else if (this.form.datatype == 'string') { - data.maxLength = Number(this.form.specs.maxLength ? this.form.specs.maxLength : 1024); - } else if (this.form.datatype == 'bool') { - data.falseText = this.form.specs.falseText ? this.form.specs.falseText : this.$t('product.product-things-model.142341-113'); - data.trueText = this.form.specs.trueText ? this.form.specs.trueText : this.$t('product.product-things-model.142341-114'); - } else if (this.form.datatype == 'enum') { - data.showWay = this.form.specs.showWay; - if (this.form.specs.enumList && this.form.specs.enumList[0].text != '') { - data.enumList = this.form.specs.enumList; - } else { - data.showWay = 'select'; - data.enumList = [ - { - value: '0', - text: this.$t('product.product-things-model.142341-115'), - }, - { - value: '1', - text: this.$t('product.product-things-model.142341-116'), - }, - ]; - } - } else if (this.form.datatype == 'array') { - data.arrayType = this.form.specs.arrayType; - data.arrayCount = this.form.specs.arrayCount ? this.form.specs.arrayCount : 5; - if (data.arrayType == 'object') { - data.params = this.form.specs.params; - // 物模型名称作为参数的标识符前缀 - for (let i = 0; i < data.params.length; i++) { - data.params[i].id = this.form.identifier + '_' + data.params[i].id; - } - } - } else if (this.form.datatype == 'object') { - data.params = this.form.specs.params; - // 物模型名称作为参数的标识符前缀 - for (let i = 0; i < data.params.length; i++) { - data.params[i].id = this.form.identifier + '_' + data.params[i].id; - } - } - return JSON.stringify(data); - }, - /** 数据类型改变 */ - dataTypeChange(val) { }, - /** 添加枚举项 */ - addEnumItem() { - this.form.specs.enumList.push({ - value: '', - text: '', - }); - }, - /** 删除枚举项 */ - removeEnumItem(index) { - this.form.specs.enumList.splice(index, 1); - }, - /** 格式化显示数据定义 */ - formatSpecsDisplay(json) { - let specs = JSON.parse(json); - if (specs.type === 'integer' || specs.type === 'decimal' || specs.type === 'INT16' || specs.type === 'INT') { - return ( - '' + this.$t('product.product-things-model.142341-117') + '' + - specs.max + - '' + this.$t('product.product-things-model.142341-118') + '' + - specs.min + - '
' + this.$t('product.product-things-model.142341-119') + '' + - specs.step + - '' + this.$t('product.product-things-model.142341-120') + '' + - specs.unit - ); - } else if (specs.type === 'string') { - return this.$t('product.product-things-model.142341-121') + '' + specs.maxLength + ''; - } else if (specs.type === 'array') { - return '' + this.$t('product.product-things-model.142341-122') + '' + specs.arrayType + '' + this.$t('product.product-things-model.142341-123') + '' + specs.arrayCount; - } else if (specs.type === 'enum') { - let items = ''; - for (let i = 0; i < specs.enumList.length; i++) { - items = items + "" + specs.enumList[i].value + ":" + specs.enumList[i].text + ''; - if (i > 0 && i % 2 != 0) { - items = items + '
'; - } - } - return items; - } else if (specs.type === 'bool') { - return '0:' + specs.falseText + '1:' + specs.trueText; - } else if (specs.type === 'object') { - let items = ''; - for (let i = 0; i < specs.params.length; i++) { - items = items + "" + specs.params[i].name + ":" + specs.params[i].datatype.type + ''; - if (i > 0 && i % 2 != 0) { - items = items + '
'; - } - } - return items; - } - }, - /** 添加参数 */ - addParameter() { - this.paramData = { - index: -1, - parameter: {}, - }; - }, - /** 编辑参数*/ - editParameter(data, index) { - this.paramData = null; - this.paramData = { - index: index, - parameter: data, - }; - }, - /** 删除动作 */ - removeParameter(index) { - this.form.specs.params.splice(index, 1); - }, - /**获取设置的参数对象*/ - getParamData(data) { - if (data.index == -1) { - this.form.specs.params.push(data.parameter); - } else { - this.form.specs.params[data.index] = data.parameter; - // 解决数组在界面中不更新问题 - this.$set(this.form.specs.params, data.index, this.form.specs.params[data.index]); - } - }, - // 在输入最小值改变时触发 - handleEdit(e) { - let value = e.replace(/[^\-\d]/g, ""); // 只能输入-和数字 - value = value.replace(/\-{2,}/g, "-"); // -只能保留一个 - value = value.replace(/(\d)\-/g, "$1"); // 数字后面不能接-,不能出现类似-11-2,12-,11-23 - value = value.replace(/(-)0+/g, "$1"); // 不能出现-0,-001,-0001类似 - value = value.replace(/(-\d{10})\d*/, '$1') // 最多保留10位整数 - this.form.specs.min = value; - }, - // 在输入最大值改变时触发 - handleEditmax(e) { - let value = e.replace(/[^\-\d]/g, ""); // 只能输入-和数字 - value = value.replace(/\-{2,}/g, "-"); // -只能保留一个 - value = value.replace(/(\d)\-/g, "$1"); // 数字后面不能接-,不能出现类似-11-2,12-,11-23 - value = value.replace(/(-)0+/g, "$1"); // 不能出现-0,-001,-0001类似 - value = value.replace(/(-\d{10})\d*/, '$1') // 最多保留10位整数 - this.form.specs.max = value; - }, - //数据类型为小数的校验 - hasDecimalPoint() { - const regex = /^-?\d+\.\d+$/; // 使用正则表达式匹配小数点格式 - this.isDecimal = regex.test(this.form.specs.min); - return this.isDecimal; - }, - hasDecimalPointMax() { - const regex = /^-?\d+\.\d+$/; // 使用正则表达式匹配小数点格式 - this.isDecimalMax = regex.test(this.form.specs.max); - return this.isDecimalMax; - }, - }, }; diff --git a/vue/src/views/iot/template/index.vue b/vue/src/views/iot/template/index.vue index 4c8b4836..c5859397 100644 --- a/vue/src/views/iot/template/index.vue +++ b/vue/src/views/iot/template/index.vue @@ -766,7 +766,18 @@ export default { }, /** 数据类型改变 */ dataTypeChange(val) { - this.form.specs = {}; + this.form.specs = { + enumList: [ + { + value: '', + text: '', + }, + ], + arrayType: 'integer', + arrayCount: 5, + showWay: 'select', + params: [], + }; }, /** 添加枚举项 */ addEnumItem() {