Browse Source

fix: 优化产品相关代码及报红提示

yanglzh 1 year ago
parent
commit
3e33b64f5e

+ 54 - 41
src/views/iot/device/product/component/editEvent.vue

@@ -24,7 +24,7 @@
 							<div>参数名称:{{ item.name }}</div>
 							<div>数据类型:{{ item.valueType.type }}</div>
 							<div class="jsonoption">
-								<el-link type="primary"  @click="editjson(index, 'fun')">编辑</el-link>
+								<el-link type="primary" @click="editjson(index, 'fun')">编辑</el-link>
 								<el-link type="primary" @click="deljson(index, 'fun')">删除</el-link>
 							</div>
 						</div>
@@ -32,7 +32,9 @@
 
 					<div style="display: block; width: 100%">
 						<div class="input-options" @click="addJson('fun')">
-							<el-icon><Plus /></el-icon>
+							<el-icon>
+								<Plus />
+							</el-icon>
 							<div>添加参数</div>
 						</div>
 					</div>
@@ -59,25 +61,42 @@ import api from '/@/api/device';
 import { Plus, Minus, Right } from '@element-plus/icons-vue';
 import EditOption from './editOption.vue';
 import { validateNoSpace } from '/@/utils/validator';
-
-import { ElMessage, UploadProps } from 'element-plus';
+import { ElMessage } from 'element-plus';
 
 interface RuleFormState {
-	id: number;
+	id?: number;
 	productKey: string;
-	level: number;
+	level: number | null;
+	key: string;
+	type: string;
 	name: string;
-	dictType: string;
-	inputs: Object;
-	outputs: Object [];
+	outputs: any[];
 	status: number;
 	desc: string;
 }
 interface DicState {
 	isShowDialog: boolean;
 	ruleForm: RuleFormState;
-	typeData: RuleFormState[];
-	rules: {};
+	type: string;
+	types: string;
+	productKey: string;
+	typeData: any[];
+	jsondata: any[];
+	enumdata: any[];
+	outputsdata: any[];
+	elementType: any;
+	rules: any;
+}
+
+const form = {
+	productKey: '',
+	type: '',
+	name: '',
+	level: null,
+	key: '',
+	status: 1,
+	outputs: [],
+	desc: '',
 }
 
 export default defineComponent({
@@ -102,33 +121,26 @@ export default defineComponent({
 					value: '',
 				},
 			],
-
 			jsondata: [],
 			outputsdata: [],
-
-			ruleForm: {
-				productKey: '',
-				name: '',
-				key: '',
-				outputs: [],
-				desc: '',
-			},
+			ruleForm: JSON.parse(JSON.stringify(form)),
 			rules: {
-				name: [ { required: true, message: '事件定义名称不能为空', trigger: 'blur' },
-        				{ max: 32, message: '事件定义名称不能超过32个字符', trigger: 'blur' },
-						{ validator: validateNoSpace, message: '事件定义名称不能包含空格', trigger: 'blur' }
-					],
+				name: [
+					{ required: true, message: '事件定义名称不能为空', trigger: 'blur' },
+					{ max: 32, message: '事件定义名称不能超过32个字符', trigger: 'blur' },
+					{ validator: validateNoSpace, message: '事件定义名称不能包含空格', trigger: 'blur' }
+				],
 				key: [{ required: true, message: '事件定义标识不能为空', trigger: 'blur' }],
 				type: [{ required: true, message: '请选择数据类型', trigger: 'blur' }],
 			},
 		});
 
 		// 打开弹窗
-		const openDialog = (row: RuleFormState | null, productKey: string | null) => {
+		const openDialog = (row: RuleFormState, productKey: string) => {
 			resetForm();
 
 			api.product.getDataType({ status: -1 }).then((res: any) => {
-				const datat = Object.values(res.dataType);
+				const datat: any[] = Object.values(res.dataType);
 				datat.forEach((item, index) => {
 					if (index == 0) {
 						datat[index]['label'] = '基础类型';
@@ -150,23 +162,18 @@ export default defineComponent({
 			state.isShowDialog = true;
 		};
 		const resetForm = () => {
-			state.ruleForm = {
-				name: '',
-				key: '',
-				status: 1,
-				desc: '',
-			};
+			state.ruleForm = JSON.parse(JSON.stringify(form))
 			state.type = '';
 			state.types = '';
 			state.outputsdata = [];
 			state.elementType = [];
 		};
 
-		const seletChange = (val) => {
+		const seletChange = (val: string) => {
 			state.type = val;
 			state.ruleForm.type = val;
 		};
-		const seletChanges = (val) => {
+		const seletChanges = (val: string) => {
 			state.types = val;
 		};
 
@@ -176,18 +183,18 @@ export default defineComponent({
 				value: '',
 			});
 		};
-		const delEnum = (index) => {
+		const delEnum = (index: number) => {
 			state.enumdata.splice(index, 1);
 		};
 
-		const deljson = (index, type) => {
+		const deljson = (index: number, type: string) => {
 			if (type == 'fun') {
 				state.outputsdata.splice(index, 1);
 			} else {
 				state.jsondata.splice(index, 1);
 			}
 		};
-		const editjson=(index,type)=>{
+		const editjson = (index: number, type: string) => {
 			if (type == 'fun') {
 				editOptionRef.value.openDialog(state.outputsdata[index]);
 			} else {
@@ -196,10 +203,10 @@ export default defineComponent({
 			}
 		}
 
-		const addJson = (type) => {
+		const addJson = (type: string) => {
 			editOptionRef.value.openDialog({ productKey: '', id: 0, type_data: type });
 		};
-		const getOptionData = (data, type_data) => {
+		const getOptionData = (data: any, type_data: any) => {
 			if (type_data == 'fun') {
 				state.outputsdata.push(data);
 			} else {
@@ -264,35 +271,41 @@ export default defineComponent({
 	justify-content: space-between;
 	margin-top: 10px;
 }
+
 .input-option {
 	line-height: 30px;
 	padding-top: 5px;
 	width: 140px;
 }
+
 .input-option i {
 	margin: 0px 5px;
 	border: 1px solid #c3c3c3;
 	font-size: 16px;
 }
+
 .input-options {
 	display: flex;
 	align-items: center;
 	color: #409eff;
 	cursor: pointer;
 }
+
 .jslist {
 	width: 100%;
 	border: 1px solid #e8e8e8;
 	padding: 10px;
 	margin-bottom: 10px;
 }
+
 .jsonlist {
 	display: flex;
 	flex-direction: row;
 	justify-content: space-between;
 }
-.jsonoption {
-}
+
+.jsonoption {}
+
 .jsonoption a {
 	margin: 0px 10px;
 }

+ 54 - 57
src/views/iot/device/product/component/editFun.vue

@@ -16,7 +16,7 @@
 							<div>参数名称:{{ item.name }}</div>
 							<div>数据类型:{{ item.valueType.type }}</div>
 							<div class="jsonoption">
-								<el-link type="primary"  @click="editjson(index, 'fun')">编辑</el-link>
+								<el-link type="primary" @click="editjson(index, 'fun')">编辑</el-link>
 								<el-link type="primary" @click="deljson(index, 'fun')">删除</el-link>
 							</div>
 						</div>
@@ -39,7 +39,7 @@
 							<div>参数名称:{{ item.name }}</div>
 							<div>数据类型:{{ item.valueType.type }}</div>
 							<div class="jsonoption">
-								<el-link type="primary" @click="editjsonOut(index, 'fun')">编辑</el-link>
+								<el-link type="primary" @click="editjsonOut(index)">编辑</el-link>
 								<el-link type="primary" @click="deljsonOut(index, 'fun')">删除</el-link>
 							</div>
 						</div>
@@ -66,8 +66,8 @@
 				</span>
 			</template>
 		</el-dialog>
-		<EditOption ref="editOptionRef" key="editOptionRef" @typeList="getOptionData"  @editTypeList="editOptionDataOut" />
-		<EditOption ref="editOptionOutRef" key="editOptionOutRef" @typeList="getOptionDataOut"  @editTypeList="editOptionDataOut"/>
+		<EditOption ref="editOptionRef" key="editOptionRef" @typeList="getOptionData" />
+		<EditOption ref="editOptionOutRef" key="editOptionOutRef" @typeList="getOptionDataOut" />
 	</div>
 </template>
 
@@ -78,26 +78,53 @@ import { Plus, Minus, Right } from '@element-plus/icons-vue';
 import EditOption from './editOption.vue';
 import { validateNoSpace } from '/@/utils/validator';
 
-import { ElMessage, UploadProps } from 'element-plus';
+import { ElMessage } from 'element-plus';
 
 interface RuleFormState {
-	id: number;
+	id?: number;
+	key: string;
 	productKey: string;
 	name: string;
+	type: string;
 	dictType: string;
 	valueType: Object;
-	inputs: Object;
-	output: Object;
+	inputs: any;
+	outputs: any;
 	status: number;
 	desc: string;
 }
 interface DicState {
 	isShowDialog: boolean;
+	productKey: string;
+	type: string;
+	types: string;
 	ruleForm: RuleFormState;
-	typeData: RuleFormState[];
+	typeData: any[];
+	inputsdata: any[];
+	outputsdata: any[];
+	jsondata: any[];
+	elementType: any;
+	enumdata: any;
+	valueType: any;
 	rules: {};
 }
 
+const form = {
+	productKey: '',
+	type: '',
+	name: '',
+	key: '',
+	status: 1,
+	dictType: '',
+	inputs: [],
+	outputs: [],
+	valueType: {
+		type: '',
+		maxLength: '',
+	},
+	desc: '',
+}
+
 export default defineComponent({
 	name: 'deviceEditPro',
 	components: { Plus, Minus, Right, EditOption },
@@ -129,36 +156,22 @@ export default defineComponent({
 					value: '',
 				},
 			],
-
 			jsondata: [],
 			inputsdata: [],
 			outputsdata: [],
-
-			ruleForm: {
-				productKey: '',
-				name: '',
-				key: '',
-				inputs: [],
-				outputs: [],
-				valueType: {
-					type: '',
-					maxLength: '',
-				},
-
-				desc: '',
-			},
+			ruleForm: JSON.parse(JSON.stringify(form)),
 			rules: {
-				name: [ { required: true, message: '功能定义名称不能为空', trigger: 'blur' },
-        				{ max: 32, message: '功能定义名称不能超过32个字符', trigger: 'blur' },
-						{ validator: validateNoSpace, message: '功能定义名称不能包含空格', trigger: 'blur' }
-					],
+				name: [{ required: true, message: '功能定义名称不能为空', trigger: 'blur' },
+				{ max: 32, message: '功能定义名称不能超过32个字符', trigger: 'blur' },
+				{ validator: validateNoSpace, message: '功能定义名称不能包含空格', trigger: 'blur' }
+				],
 				key: [{ required: true, message: '功能定义标识不能为空', trigger: 'blur' }],
 				type: [{ required: true, message: '请选择数据类型', trigger: 'blur' }],
 			},
 		});
 
 		// 打开弹窗
-		const openDialog = (row: RuleFormState | null, productKey: string | null) => {
+		const openDialog = (row: RuleFormState, productKey: string) => {
 			resetForm();
 			state.ruleForm = row;
 			state.productKey = productKey;
@@ -168,17 +181,7 @@ export default defineComponent({
 
 		};
 		const resetForm = () => {
-			state.ruleForm = {
-				name: '',
-				key: '',
-				status: 1,
-				valueType: {
-					type: '',
-					maxLength: '',
-				},
-
-				desc: '',
-			};
+			state.ruleForm = JSON.parse(JSON.stringify(form))
 			state.type = '';
 			state.types = '';
 			state.inputsdata = [];
@@ -187,12 +190,12 @@ export default defineComponent({
 			state.valueType = {};
 		};
 
-		const seletChange = (val) => {
+		const seletChange = (val: string) => {
 			state.type = val;
 			state.ruleForm.type = val;
 
 		};
-		const seletChanges = (val) => {
+		const seletChanges = (val: string) => {
 			state.types = val;
 		};
 
@@ -202,11 +205,11 @@ export default defineComponent({
 				value: '',
 			});
 		};
-		const delEnum = (index) => {
+		const delEnum = (index: number) => {
 			state.enumdata.splice(index, 1);
 		};
 
-		const editjson=(index,type)=>{
+		const editjson = (index: number, type: string) => {
 			if (type == 'fun') {
 				editOptionRef.value.openDialog(state.inputsdata[index]);
 			} else {
@@ -215,7 +218,7 @@ export default defineComponent({
 			}
 		}
 
-		const deljson = (index, type) => {
+		const deljson = (index: number, type: string) => {
 			if (type == 'fun') {
 				state.inputsdata.splice(index, 1);
 			} else {
@@ -223,7 +226,7 @@ export default defineComponent({
 			}
 		};
 
-		const deljsonOut = (index, type) => {
+		const deljsonOut = (index: number, type: string) => {
 			if (type == 'fun') {
 				state.outputsdata.splice(index, 1);
 			} else {
@@ -231,37 +234,32 @@ export default defineComponent({
 			}
 		};
 
-		const editjsonOut=(index,type)=>{
+		const editjsonOut = (index: number) => {
 			editOptionOutRef.value.openDialog(state.outputsdata[index]);
 		}
 
-		const addJson = (type) => {
+		const addJson = (type: string) => {
 			editOptionRef.value.openDialog({ productKey: '', id: 0, type_data: type });
 		};
 
-		const addJsonOut = (type) => {
+		const addJsonOut = (type: string) => {
 			editOptionOutRef.value.openDialog({ productKey: '', id: 0, type_data: type });
 		};
 
-		const getOptionData = (data, type_data) => {
+		const getOptionData = (data: any, type_data: any) => {
 			if (type_data == 'fun') {
 				state.inputsdata.push(data);
 			} else {
 				state.jsondata.push(data);
 			}
 		};
-		const getOptionDataOut = (data, type_data) => {
-
+		const getOptionDataOut = (data: any, type_data: any) => {
 			if (type_data == 'fun') {
 				state.outputsdata.push(data);
 			} else {
 				state.outputsdata.push(data);
 			}
-
-			
 		};
-		const editOptionDataOut =(data,type_data)=>{
-		}
 		// 关闭弹窗
 		const closeDialog = () => {
 			state.isShowDialog = false;
@@ -299,7 +297,6 @@ export default defineComponent({
 		return {
 			editOptionRef,
 			editOptionOutRef,
-			editOptionDataOut,
 			getOptionData,
 			getOptionDataOut,
 			openDialog,

+ 30 - 30
src/views/iot/device/product/component/editOption.vue

@@ -3,7 +3,7 @@
 		<el-dialog :title="(typeof ruleForm.valueType !== 'undefined' ? '修改' : '添加') + '参数'" v-model="isShowDialog" width="769px">
 			<el-form :model="ruleForm" ref="formRef" :rules="rules" label-width="120px">
 				<el-form-item label="参数标识" prop="key">
-					<el-input v-model="ruleForm.key" placeholder="请输入参数标识"  />
+					<el-input v-model="ruleForm.key" placeholder="请输入参数标识" />
 				</el-form-item>
 				<el-form-item label="参数名称" prop="name">
 					<el-input v-model="ruleForm.name" placeholder="请输入参数名称" />
@@ -12,7 +12,6 @@
 				<el-form-item label="数据类型" prop="type">
 					<el-select v-model="valueType.type" placeholder="请选择数据类型" @change="seletChange">
 						<el-option-group v-for="group in typeData" :key="group.label" :label="group.label">
-							<!-- <el-option v-for="item in group.options" :key="item.type" :label="item.title" :value="item.type" :disabled="item.type == 'object'" /> -->
 							<el-option v-for="item in group.options" :key="item.type" :label="item.title" :value="item.type" />
 						</el-option-group>
 					</el-select>
@@ -24,7 +23,6 @@
 						<el-select v-model="elementType.type" placeholder="请选择元素类型" @change="seletChanges">
 							<el-option-group v-for="group in typeData" :key="group.label" :label="group.label">
 								<el-option v-for="item in group.options" :key="item.type" :label="item.title" :value="item.type" :disabled="['array', 'enum'].includes(item.type)" />
-								<!-- <el-option v-for="item in group.options" :key="item.type" :label="item.title" :value="item.type" :disabled="['array', 'object', 'enum', 'date'].includes(item.type)" /> -->
 							</el-option-group>
 						</el-select>
 					</el-form-item>
@@ -53,10 +51,15 @@ import { Plus, Minus, Right } from '@element-plus/icons-vue';
 import { ElMessage } from 'element-plus';
 import { validateNoSpace } from '/@/utils/validator';
 
-interface RuleFormState {
-	id: number;
-	name: string;
-	desc: string;
+interface stateType {
+	isShowDialog: boolean
+	rules: any
+	ruleForm: any
+	valueType: any
+	typeData: any
+	elementType: any
+	type: string
+	[key: string]: any
 }
 
 const valueTypeBase = {
@@ -98,7 +101,7 @@ export default defineComponent({
 	setup(prop, { emit }) {
 		const formRef = ref<HTMLElement | null>(null);
 
-		const state = reactive<any>({
+		const state = reactive<stateType>({
 			isShowDialog: false,
 			typeData: [], //
 			type: '',
@@ -112,7 +115,6 @@ export default defineComponent({
 					'value': '',
 				},
 			],
-
 			ruleForm: {
 				id: 0,
 				name: '',
@@ -120,27 +122,27 @@ export default defineComponent({
 				transportProtocol: '',
 				accessMode: '0',
 				status: 1,
-				valueType: {
-				},
+				valueType: {},
 				desc: '',
 			},
 			rules: {
-				name: [ { required: true, message: '参数名称不能为空', trigger: 'blur' },
-        				{ max: 32, message: '参数名称不能超过32个字符', trigger: 'blur' },
-						{ validator: validateNoSpace, message: '参数名称不能包含空格', trigger: 'blur' }
-					],
+				name: [
+					{ required: true, message: '参数名称不能为空', trigger: 'blur' },
+					{ max: 32, message: '参数名称不能超过32个字符', trigger: 'blur' },
+					{ validator: validateNoSpace, message: '参数名称不能包含空格', trigger: 'blur' }
+				],
 				key: [{ required: true, message: '参数标识不能为空', trigger: 'blur' }],
 				accessMode: [{ required: true, message: '请选择是否只读', trigger: 'blur' }],
 			},
 		});
 
 		// 打开弹窗
-		const openDialog = (row: RuleFormState | null,type='add') => {
+		const openDialog = (row?: any) => {
 			resetForm();
 
 			api.product.getDataType({ status: -1 }).then((res: any) => {
 				const datat: any = Object.values(res.dataType);
-				datat.forEach((item, index) => {
+				datat.forEach((item: any, index: number) => {
 					if (index == 0) {
 						datat[index]['label'] = '基础类型';
 						datat[index]['options'] = item;
@@ -153,17 +155,16 @@ export default defineComponent({
 			});
 
 			if (row) {
-
 				if (typeof row.valueType !== 'undefined') {
-					state.type=row.valueType.type;
+					state.type = row.valueType.type;
 
-					if (typeof row.valueType.elementType !== 'undefined')state.elementType=row.valueType.elementType;
-					if (typeof row.valueType.elements !== 'undefined')state.enumdata=row.valueType.elements;
-					if (typeof row.valueType.properties !== 'undefined')state.properties=row.valueType.properties;
-					if (typeof row.valueType.type !== 'undefined')state.valueType.type=row.valueType.type;
+					if (typeof row.valueType.elementType !== 'undefined') state.elementType = row.valueType.elementType;
+					if (typeof row.valueType.elements !== 'undefined') state.enumdata = row.valueType.elements;
+					if (typeof row.valueType.properties !== 'undefined') state.properties = row.valueType.properties;
+					if (typeof row.valueType.type !== 'undefined') state.valueType.type = row.valueType.type;
 
 					const fieldCount = Object.keys(row.valueType).length;
-					if(fieldCount>1)state.valueType=row.valueType;
+					if (fieldCount > 1) state.valueType = row.valueType;
 				}
 
 				state.ruleForm = row;
@@ -183,11 +184,11 @@ export default defineComponent({
 			state.elementType = JSON.parse(JSON.stringify(valueType));
 		};
 
-		const seletChange = (val) => {
+		const seletChange = (val: string) => {
 
 			state.type = val;
 		};
-		const seletChanges = (val) => {
+		const seletChanges = (val: string) => {
 			state.types = val;
 		};
 
@@ -197,7 +198,7 @@ export default defineComponent({
 				'value': '',
 			});
 		};
-		const delEnum = (index) => {
+		const delEnum = (index: number) => {
 			state.enumdata.splice(index, 1);
 		}
 
@@ -217,7 +218,7 @@ export default defineComponent({
 				if (valid) {
 					if (typeof state.ruleForm.valueType !== 'undefined') {
 						//修改
-				
+
 						if (state.type == 'array') {
 							state.valueType.elementType = state.elementType;
 						}
@@ -228,12 +229,11 @@ export default defineComponent({
 						emit('editTypeList', state.ruleForm, state.ruleForm.type_data);
 					} else {
 						// //添加
-				
+
 						if (state.type == 'array') {
 							state.valueType.elementType = state.elementType;
 						}
 
-
 						state.ruleForm.valueType = state.valueType;
 						ElMessage.success('参数类型添加成功');
 						closeDialog(); // 关闭弹窗

+ 42 - 33
src/views/iot/device/product/component/editPro.vue

@@ -20,8 +20,8 @@
 						</template>
 					</el-cascader>
 
-          <!-- 添加产品分类 -->
-          <el-button type="success" @click="onOpenAddCategory()" style="margin-left: 5px;">添加产品分类</el-button>
+					<!-- 添加产品分类 -->
+					<el-button type="success" @click="onOpenAddCategory()" style="margin-left: 5px;">添加产品分类</el-button>
 				</el-form-item>
 
 				<el-form-item label="消息协议" prop="messageProtocol">
@@ -96,7 +96,7 @@
 				</span>
 			</template>
 		</el-dialog>
-    <EditCategory ref="editCategoryRef" @getCateList="getCategoryList" />
+		<EditCategory ref="editCategoryRef" @getCateList="getCategoryList" />
 	</div>
 </template>
 
@@ -118,9 +118,11 @@ interface RuleFormState {
 	transportProtocol: string
 	deviceType: string
 	name: string
-	authType: string
+	key: string
+	authType: number| null
 	status: number
 	desc: string
+	icon: string
 	authUser: string
 	authPasswd: string
 	accessToken: string
@@ -129,24 +131,28 @@ interface RuleFormState {
 interface DicState {
 	isShowDialog: boolean
 	ruleForm: RuleFormState
-	cateData: RuleFormState[]
-	deptData: RuleFormState[]
-	messageData: RuleFormState[]
-	tranData: RuleFormState[]
-	rules: {},
+	cateData: any[]
+	deptData: any[]
+	messageData: any[]
+	network_protocols: any[]
+	tranData: any[]
+	rules: {}
 	imageUrl: string
+	singleImg: string
 }
 
 const form = {
 	id: 0,
 	name: '',
+	key: '',
 	categoryId: '',
 	messageProtocol: '',
 	transportProtocol: '',
 	deviceType: '设备',
 	status: 1,
 	desc: '',
-	authType: '',
+	icon: '',
+	authType: null,
 	authUser: '',
 	authPasswd: '',
 	accessToken: '',
@@ -156,7 +162,7 @@ const form = {
 
 export default defineComponent({
 	name: 'deviceEditPro',
-	components: {EditCategory, uploadVue },
+	components: { EditCategory, uploadVue },
 	setup(prop, { emit }) {
 		const formRef = ref<HTMLElement | null>(null)
 		const baseURL: string | undefined | boolean = getOrigin(import.meta.env.VITE_API_URL)
@@ -164,11 +170,11 @@ export default defineComponent({
 		const { proxy } = getCurrentInstance() as any
 		const { network_server_type } = proxy.useDict('network_server_type')
 
-		const certList = ref([])
+		const certList = ref<any[]>([])
 		const submitLoading = ref(false)
-    const editCategoryRef = ref();
+		const editCategoryRef = ref();
 
-		const state = reactive<DicState | any>({
+		const state = reactive<DicState>({
 			isShowDialog: false,
 			cateData: [], // 分类数据
 			deptData: [], //
@@ -181,12 +187,15 @@ export default defineComponent({
 				...form
 			},
 			rules: {
-				name: [{ required: true, message: '产品名称不能为空', trigger: 'change' },
-				{ max: 32, message: '产品名称不能超过32个字符', trigger: 'change' },
-				{ validator: validateNoSpace, message: '产品名称不能包含空格', trigger: 'change' }
+				name: [
+					{ required: true, message: '产品名称不能为空', trigger: 'change' },
+					{ max: 32, message: '产品名称不能超过32个字符', trigger: 'change' },
+					{ validator: validateNoSpace, message: '产品名称不能包含空格', trigger: 'change' }
+				],
+				key: [
+					{ required: true, message: '产品标识不能为空', trigger: 'change' },
+					{ validator: validateNoSpace, message: '产品标识不能包含空格', trigger: 'change' }
 				],
-				key: [{ required: true, message: '产品标识不能为空', trigger: 'change' },
-				{ validator: validateNoSpace, message: '产品标识不能包含空格', trigger: 'change' }],
 				messageProtocol: [{ required: true, message: '消息协议不能为空', trigger: 'change' }],
 				transportProtocol: [{ required: true, message: '接入方式不能为空', trigger: 'change' }],
 				categoryId: [{ required: true, message: '产品分类不能为空', trigger: 'change' }],
@@ -200,7 +209,7 @@ export default defineComponent({
 		}
 
 		// 打开弹窗
-		const openDialog = (row: RuleFormState | null) => {
+		const openDialog = (row?: any) => {
 			resetForm()
 			api.category.getList({ status: 1 }).then((res: any) => {
 				state.cateData = res.category || []
@@ -285,31 +294,31 @@ export default defineComponent({
 				}
 			})
 		}
-    // 打开新增产品分类弹窗
-    const onOpenAddCategory = () => {
-      editCategoryRef.value.openDialog();
-    };
-    // 获取产品分类列表
-    const getCategoryList = () => {
-      api.category.getList({ status: 1 }).then((res: any) => {
-        state.cateData = res.category || []
-      })
-    }
+		// 打开新增产品分类弹窗
+		const onOpenAddCategory = () => {
+			editCategoryRef.value.openDialog();
+		};
+		// 获取产品分类列表
+		const getCategoryList = () => {
+			api.category.getList({ status: 1 }).then((res: any) => {
+				state.cateData = res.category || []
+			})
+		}
 
 		return {
 			transportProtocolChange,
 			submitLoading,
 			certList,
 			openDialog,
-      onOpenAddCategory,
+			onOpenAddCategory,
 			handleAvatarSuccess,
 			closeDialog,
 			onCancel,
 			onSubmit,
 			network_server_type,
-      getCategoryList,
+			getCategoryList,
 			formRef,
-      editCategoryRef,
+			editCategoryRef,
 			...toRefs(state),
 		}
 	},

+ 45 - 43
src/views/iot/device/product/component/editTab.vue

@@ -197,21 +197,48 @@ import { ElMessage } from 'element-plus';
 
 interface RuleFormState {
 	id: number;
-	productKey: number;
+	productKey: string;
 	accessMode: number;
 	name: string;
+	key: string;
+	type: string;
+	transportProtocol: string;
 	dictType: string;
-	valueType: Object;
+	valueType: any;
 	status: number;
 	desc: string;
 }
 interface DicState {
 	isShowDialog: boolean;
+	productKey: string;
+	type: string;
+	types: string;
+	valueType: any;
+	elementType: any;
 	ruleForm: RuleFormState;
-	typeData: RuleFormState[];
+	jsondata: any;
+	typeData: any[];
+	enumdata: any[];
 	rules: {};
 }
 
+const ruleForm = {
+	id: 0,
+	productKey: '',
+	name: '',
+	dictType: '',
+	type: '',
+	key: '',
+	transportProtocol: '',
+	accessMode: 1,
+	status: 1,
+	valueType: {
+		type: '',
+		maxLength: '',
+	},
+	desc: '',
+}
+
 export default defineComponent({
 	name: 'deviceEditPro',
 	components: { Plus, Minus, Right, EditOption },
@@ -223,7 +250,7 @@ export default defineComponent({
 			typeData: [], //
 			type: '',
 			types: '',
-			productKey: 0,
+			productKey: '',
 			valueType: {
 				type: '',
 				maxLength: '',
@@ -245,26 +272,13 @@ export default defineComponent({
 
 			jsondata: [],
 
-			ruleForm: {
-				id: 0,
-				productKey: 0,
-				name: '',
-				key: '',
-				transportProtocol: '',
-				accessMode: 1,
-				status: 1,
-				valueType: {
-					type: '',
-					maxLength: '',
-				},
-
-				desc: '',
-			},
+			ruleForm: JSON.parse(JSON.stringify(ruleForm)),
 			rules: {
-				name: [ { required: true, message: '标签定义名称不能为空', trigger: 'blur' },
-        				{ max: 32, message: '标签定义名称不能超过32个字符', trigger: 'blur' },
-						{ validator: validateNoSpace, message: '标签定义名称不能包含空格', trigger: 'blur' }
-					],
+				name: [
+					{ required: true, message: '标签定义名称不能为空', trigger: 'blur' },
+					{ max: 32, message: '标签定义名称不能超过32个字符', trigger: 'blur' },
+					{ validator: validateNoSpace, message: '标签定义名称不能包含空格', trigger: 'blur' }
+				],
 				key: [{ required: true, message: '标签定义标识不能为空', trigger: 'blur' }],
 				accessMode: [{ required: true, message: '请选择是否只读', trigger: 'blur' }],
 				type: [{ required: true, message: '请选择数据类型', trigger: 'blur' }],
@@ -272,11 +286,11 @@ export default defineComponent({
 		});
 
 		// 打开弹窗
-		const openDialog = (row: RuleFormState | null, productKey: number | null) => {
+		const openDialog = (row: RuleFormState, productKey: string) => {
 			resetForm();
 
 			api.product.getDataType({ status: -1 }).then((res: any) => {
-				const datat = Object.values(res.dataType);
+				const datat = Object.values(res.dataType) as any[];
 				datat.forEach((item, index) => {
 					if (index == 0) {
 						datat[index]['label'] = '基础类型';
@@ -323,19 +337,7 @@ export default defineComponent({
 			state.isShowDialog = true;
 		};
 		const resetForm = () => {
-			state.ruleForm = {
-				name: '',
-				key: '',
-				transportProtocol: '',
-				accessMode: 1,
-				status: 1,
-				valueType: {
-					type: '',
-					maxLength: '',
-				},
-
-				desc: '',
-			};
+			state.ruleForm = JSON.parse(JSON.stringify(ruleForm))
 			state.type = '';
 			state.types = '';
 			state.valueType = {};
@@ -347,12 +349,12 @@ export default defineComponent({
 			},];
 		};
 
-		const seletChange = (val) => {
+		const seletChange = (val: string) => {
 			state.type = val;
 			state.ruleForm.type = val;
 
 		};
-		const seletChanges = (val) => {
+		const seletChanges = (val: string) => {
 			state.types = val;
 		};
 
@@ -362,18 +364,18 @@ export default defineComponent({
 				value: '',
 			});
 		};
-		const delEnum = (index) => {
+		const delEnum = (index: number) => {
 			state.enumdata.splice(index, 1);
 		};
 
-		const deljson = (index) => {
+		const deljson = (index: number) => {
 			state.jsondata.splice(index, 1);
 		};
 
 		const addJson = () => {
 			editOptionRef.value.openDialog({ productKey: '', id: 0 });
 		};
-		const getOptionData = (data) => {
+		const getOptionData = (data: any) => {
 			state.jsondata.push(data);
 		};
 		// 关闭弹窗

+ 0 - 2
src/views/iot/device/product/detail.vue

@@ -170,9 +170,7 @@
 							导出物模型
 						</el-button>
 					</div>
-
 				</div>
-
 				<pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="getList()" />
 			</el-tab-pane>
 			<el-tab-pane label="设备接入" name="3">