Эх сурвалжийг харах

fix: 修复deviceId为deviceKey及相关device的传参问题 。修复所有设计productId和deviceId修改页面的语法报红,及代码优化等。

yanglzh 1 жил өмнө
parent
commit
140b479202

+ 15 - 108
src/views/iot/ota-update/update/component/check.vue

@@ -1,12 +1,4 @@
 <template>
 <template>
-  <!-- <el-dialog
-    class="api-edit"
-    v-model="showDialog"
-    :title="`${formData.id ? '编辑批次' : '新增批次'}`"
-    width="768px"
-    :close-on-click-modal="false"
-    :close-on-press-escape="false">
-    <el-form ref="formRef" :model="formData" :rules="ruleForm" label-width="160px"> -->
   <div class="ota-edit-module-container">
   <div class="ota-edit-module-container">
     <el-dialog :title="'操作升级包'" v-model="isShowDialog" width="769px">
     <el-dialog :title="'操作升级包'" v-model="isShowDialog" width="769px">
       <el-form :model="ruleForm" ref="formRef" :rules="rules" label-width="160px">
       <el-form :model="ruleForm" ref="formRef" :rules="rules" label-width="160px">
@@ -21,10 +13,6 @@
           <el-input v-model="ruleForm.name" placeholder="请输入批次名称" />
           <el-input v-model="ruleForm.name" placeholder="请输入批次名称" />
         </el-form-item>
         </el-form-item>
 
 
-        <!--        <el-form-item label="待升级版本号" prop="waitVersion">-->
-        <!--          <el-input v-model="ruleForm.waitVersion" placeholder="请输入待升级版本号" />-->
-        <!--        </el-form-item>-->
-
         <el-form-item label="协议方式" prop="method">
         <el-form-item label="协议方式" prop="method">
           <el-radio-group v-model="ruleForm.method" @change="getMethod">
           <el-radio-group v-model="ruleForm.method" @change="getMethod">
             <el-radio label="1">http</el-radio>
             <el-radio label="1">http</el-radio>
@@ -34,9 +22,6 @@
         </el-form-item>
         </el-form-item>
 
 
         <el-form-item label="所属设备" prop="devices" v-if="deviceShow">
         <el-form-item label="所属设备" prop="devices" v-if="deviceShow">
-<!--          <el-select v-model="ruleForm.devices" filterable multiple placeholder="请选择设备" class="width100">-->
-<!--            <el-option v-for="item in productData" :key="item.id" :label="item.name" :value="item.id.toString()" />-->
-<!--          </el-select>-->
 
 
           <!-- 回显已选设备 -->
           <!-- 回显已选设备 -->
           <template v-if="deviceNameShow">
           <template v-if="deviceNameShow">
@@ -61,10 +46,10 @@
         </el-form-item>
         </el-form-item>
       </el-form>
       </el-form>
       <template #footer>
       <template #footer>
-				<span class="dialog-footer">
-				<el-button @click="onCancel">取 消</el-button>
-				<el-button type="primary" @click="onSubmit">{{ruleForm.id!==0?'修 改':'添 加'}}</el-button>
-				</span>
+        <span class="dialog-footer">
+          <el-button @click="onCancel">取 消</el-button>
+          <el-button type="primary" @click="onSubmit">{{ ruleForm.id !== 0 ? '修 改' : '添 加' }}</el-button>
+        </span>
       </template>
       </template>
     </el-dialog>
     </el-dialog>
 
 
@@ -74,11 +59,10 @@
 </template>
 </template>
 
 
 <script lang="ts">
 <script lang="ts">
-import { reactive, toRefs, defineComponent, onMounted, ref, unref} from 'vue';
+import { reactive, toRefs, defineComponent, onMounted, ref, unref } from 'vue';
 import { ElMessage } from 'element-plus';
 import { ElMessage } from 'element-plus';
 import api from '/@/api/ota';
 import api from '/@/api/ota';
 import rule from "/@/api/rule";
 import rule from "/@/api/rule";
-import Device from "/@/views/iot/device/instance/index.vue";
 import DeviceBind from "/@/views/iot/ota-update/update/component/deviceBind.vue";
 import DeviceBind from "/@/views/iot/ota-update/update/component/deviceBind.vue";
 
 
 interface RuleFormState {
 interface RuleFormState {
@@ -86,7 +70,7 @@ interface RuleFormState {
   name: string;
   name: string;
   waitVersion: string;
   waitVersion: string;
   method: string;
   method: string;
-  devices: [];
+  devices: string[];
   stratege: string;
   stratege: string;
   devOtaFirmwareId: number;
   devOtaFirmwareId: number;
   push: string;
   push: string;
@@ -106,7 +90,7 @@ interface UpdateState {
 
 
 export default defineComponent({
 export default defineComponent({
   name: 'otaEditUpdateData',
   name: 'otaEditUpdateData',
-  components: {DeviceBind},
+  components: { DeviceBind },
   computed: {
   computed: {
     rule() {
     rule() {
       return rule
       return rule
@@ -137,7 +121,7 @@ export default defineComponent({
         stratege: [{ required: true, message: '升级方式不能为空', trigger: 'blur' }],
         stratege: [{ required: true, message: '升级方式不能为空', trigger: 'blur' }],
         push: [{ required: true, message: '推送方式不能为空', trigger: 'blur' }],
         push: [{ required: true, message: '推送方式不能为空', trigger: 'blur' }],
         types: [{ required: true, message: '类型不能为空', trigger: 'blur' }],
         types: [{ required: true, message: '类型不能为空', trigger: 'blur' }],
-        devices: [{ required: true, message: '所属设备不能为空', trigger: 'blue'}],
+        devices: [{ required: true, message: '所属设备不能为空', trigger: 'blue' }],
       },
       },
       deviceShow: false, // 所属设备是否显示
       deviceShow: false, // 所属设备是否显示
       deviceNameShow: false, // 回显设备名称状态
       deviceNameShow: false, // 回显设备名称状态
@@ -145,7 +129,6 @@ export default defineComponent({
     });
     });
     // 页面加载时
     // 页面加载时
     onMounted(() => {
     onMounted(() => {
-      // getProductList();
       getFormType();
       getFormType();
     });
     });
     // 获取操作升级包类型
     // 获取操作升级包类型
@@ -153,8 +136,7 @@ export default defineComponent({
       // 如果是验证类型,设备信息必填项
       // 如果是验证类型,设备信息必填项
       if (state.ruleForm.types === "1") {
       if (state.ruleForm.types === "1") {
         state.deviceShow = true;
         state.deviceShow = true;
-      } else { // 如果是升级类型,设备可选可不选
-        delete (state.rules.devices);
+      } else {
         state.deviceShow = false;
         state.deviceShow = false;
       }
       }
     };
     };
@@ -162,23 +144,18 @@ export default defineComponent({
     const getMethod = () => {
     const getMethod = () => {
       // 如果是http、https协议则主动推送为否
       // 如果是http、https协议则主动推送为否
       // if (state.ruleForm.method === '1') {
       // if (state.ruleForm.method === '1') {
-        state.ruleForm.push = '2';
-        state.ruleForm.pushDisabled = true;
+      state.ruleForm.push = '2';
+      state.ruleForm.pushDisabled = true;
       // }
       // }
       // if (state.ruleForm.method === '2') {
       // if (state.ruleForm.method === '2') {
       //   state.ruleForm.push = '2';
       //   state.ruleForm.push = '2';
       //   state.ruleForm.pushDisabled = true;
       //   state.ruleForm.pushDisabled = true;
       // }
       // }
-      if (state.ruleForm.method === '3'){
+      if (state.ruleForm.method === '3') {
         state.ruleForm.pushDisabled = false;
         state.ruleForm.pushDisabled = false;
         state.ruleForm.push = '1';
         state.ruleForm.push = '1';
       }
       }
     };
     };
-    const getProductList = () => {
-      api.batch.getDeviceList({ productKey: state.ruleForm.productKey}).then((res: any) => {
-        state.productData = res.device
-      })
-    }
     // 打开弹窗
     // 打开弹窗
     const openDialog = (row: RuleFormState | null) => {
     const openDialog = (row: RuleFormState | null) => {
       resetForm();
       resetForm();
@@ -225,6 +202,7 @@ export default defineComponent({
       if (!formWrap) return;
       if (!formWrap) return;
       formWrap.validate((valid: boolean) => {
       formWrap.validate((valid: boolean) => {
         if (valid) {
         if (valid) {
+          // 如果是升级类型,设备可选可不选
           if (state.ruleForm.id !== 0) {
           if (state.ruleForm.id !== 0) {
             //修改
             //修改
             api.batch.edit(state.ruleForm).then(() => {
             api.batch.edit(state.ruleForm).then(() => {
@@ -244,8 +222,8 @@ export default defineComponent({
       });
       });
     };
     };
     // 获取设备列表
     // 获取设备列表
-    const getDeviceTableData = (deviceIdList: any, deviceNameList: any) => {
-      state.ruleForm.devices = deviceIdList;
+    const getDeviceTableData = (deviceKeyList: any, deviceNameList: any) => {
+      state.ruleForm.devices = deviceKeyList;
       state.deviceNameList = deviceNameList;
       state.deviceNameList = deviceNameList;
       state.deviceNameShow = true;
       state.deviceNameShow = true;
     };
     };
@@ -269,77 +247,6 @@ export default defineComponent({
   },
   },
 });
 });
 
 
-
-// import { ref, reactive, nextTick } from 'vue'
-// import api from '/@/api/ota'
-// import { ruleRequired } from '/@/utils/validator'
-// import { ElMessage } from 'element-plus'
-
-
-// const emit = defineEmits(['getList'])
-
-// const showDialog = ref(false)
-// const formRef = ref()
-
-// const productData = ref([
-// 	{
-// 		id: '',
-// 		name: '',
-// 	},
-// ])
-// const baseForm = {
-// 	id: undefined,
-// 	method: '1',
-// 	push: '1',
-// 	name: '',
-// 	devices: '',
-// 	stratege: '1',
-// 	waitVersion: '',
-// 	devOtaFirmwareId: '',
-// 	productKey:'',
-// }
-
-// const formData = reactive({
-// 	...baseForm,
-// })
-
-// const ruleForm = {
-// 	method: [ruleRequired('请选择批次类型')],
-// 	name: [ruleRequired('批次名称不能为空')],
-// 	productKey: [ruleRequired('请选择所属产品')],
-// 	devices: [ruleRequired('请选择批次模块')],
-// 	stratege: [ruleRequired('批次版本号不能为空')],
-// 	waitVersion: [ruleRequired('升级后版本号不能为空')],
-// }
-
-
-// const onSubmit = async () => {
-// 	await formRef.value.validate()
-
-// 	const theApi = formData.id ? api.batch.edit : api.batch.add
-// 	await theApi(formData)
-// 	ElMessage.success('操作成功')
-// 	resetForm()
-// 	showDialog.value = false
-// 	emit('getList')
-// }
-
-// const resetForm = async () => {
-// 	Object.assign(formData, { ...baseForm })
-// 	formRef.value && formRef.value.resetFields()
-// }
-
-// const open = async (row: any) => {
-// 	resetForm()
-// 	showDialog.value = true
-// 	nextTick(() => {
-// 		Object.assign(formData, { ...row })
-// 		getProductList()
-
-// 	})
-// }
-
-// defineExpose({ open })
 </script>
 </script>
 
 
 <style lang="scss" scoped>
 <style lang="scss" scoped>

+ 7 - 16
src/views/iot/ota-update/update/component/deviceBind.vue

@@ -34,20 +34,14 @@
 <script lang="ts">
 <script lang="ts">
 import { toRefs, reactive, defineComponent, nextTick, getCurrentInstance } from 'vue'
 import { toRefs, reactive, defineComponent, nextTick, getCurrentInstance } from 'vue'
 import { ElMessageBox, ElMessage } from 'element-plus'
 import { ElMessageBox, ElMessage } from 'element-plus'
-
-import 'vue3-json-viewer/dist/index.css'
-
-import { useRoute } from 'vue-router'
-
 import api from '/@/api/device'
 import api from '/@/api/device'
 
 
 interface TableDataState {
 interface TableDataState {
   isShowDialog: boolean,
   isShowDialog: boolean,
   productData: object[],
   productData: object[],
   deviceKeyList: string[];
   deviceKeyList: string[];
-  deviceIdList: string[];
   deviceNameList: string[];
   deviceNameList: string[];
-  checkIdList: string[];
+  checkKeyList: string[];
   tableData: {
   tableData: {
     data: []
     data: []
     total: number
     total: number
@@ -69,14 +63,12 @@ export default defineComponent({
 
 
   setup(prop, { emit }) {
   setup(prop, { emit }) {
     const { proxy } = getCurrentInstance() as any;
     const { proxy } = getCurrentInstance() as any;
-    const route = useRoute()
     const state = reactive<TableDataState>({
     const state = reactive<TableDataState>({
       deviceKeyList: [],
       deviceKeyList: [],
-      deviceIdList: [],
       deviceNameList: [],
       deviceNameList: [],
       isShowDialog: false,
       isShowDialog: false,
       productData: [],
       productData: [],
-      checkIdList: [],
+      checkKeyList: [],
       tableData: {
       tableData: {
         data: [],
         data: [],
         total: 0,
         total: 0,
@@ -120,8 +112,8 @@ export default defineComponent({
       });
       });
     };
     };
 
 
-    const openDialog = (checkIdData: any, productKey: any) => {
-      state.checkIdList = checkIdData;
+    const openDialog = (checkKeyList: string[], productKey: any) => {
+      state.checkKeyList = checkKeyList;
       state.tableData.param.productKey = productKey;
       state.tableData.param.productKey = productKey;
       getDeviceList()
       getDeviceList()
     };
     };
@@ -129,7 +121,6 @@ export default defineComponent({
     // 多选框选中数据
     // 多选框选中数据
     const handleSelectionChange = (selection: any[]) => {
     const handleSelectionChange = (selection: any[]) => {
       state.deviceKeyList = selection.map((item) => item.key);
       state.deviceKeyList = selection.map((item) => item.key);
-      state.deviceIdList = selection.map((item) => item.id);
       state.deviceNameList = selection.map((item) => item.name);
       state.deviceNameList = selection.map((item) => item.name);
     };
     };
 
 
@@ -144,7 +135,7 @@ export default defineComponent({
         cancelButtonText: '取消',
         cancelButtonText: '取消',
         type: 'warning',
         type: 'warning',
       }).then(() => {
       }).then(() => {
-        emit('bindSuccess', state.deviceIdList, state.deviceNameList)
+        emit('bindSuccess', state.deviceKeyList, state.deviceNameList)
         state.isShowDialog = false;
         state.isShowDialog = false;
       })
       })
     };
     };
@@ -156,8 +147,8 @@ export default defineComponent({
 
 
     const changeSelect = () => {
     const changeSelect = () => {
       nextTick(() => {
       nextTick(() => {
-        state.tableData.data.forEach((item) => {
-          if (state.checkIdList.includes(item.key)) {
+        state.tableData.data.forEach((item: any) => {
+          if (state.checkKeyList.includes(item.key)) {
             proxy.$refs.multipleTable.toggleRowSelection(item, true);
             proxy.$refs.multipleTable.toggleRowSelection(item, true);
           }
           }
         })
         })

+ 5 - 5
src/views/iot/ota-update/update/component/edit.vue

@@ -219,7 +219,7 @@ export default defineComponent({
       state.productNameShow = false;
       state.productNameShow = false;
 
 
       // 获取上传格式
       // 获取上传格式
-      apiSystem.getInfoByKey({ ConfigKey: 'sys.uploadFile.fileType' }).then((res: any) => {
+      apiSystem.getInfoByKey('sys.uploadFile.fileType').then((res: any) => {
         if (res.data) {
         if (res.data) {
           let fileType = res.data.configValue.split(",");
           let fileType = res.data.configValue.split(",");
           for (let i = 0; i < fileType.length; i++) {
           for (let i = 0; i < fileType.length; i++) {
@@ -262,7 +262,7 @@ export default defineComponent({
     const selectChange = (val: string) => {
     const selectChange = (val: string) => {
       getModuleList(val);
       getModuleList(val);
     };
     };
-    const getModuleList = (productKey: string) => {
+    const getModuleList = (productKey?: string) => {
       state.ruleForm.module = '';
       state.ruleForm.module = '';
       if (!productKey) {
       if (!productKey) {
         productKey = state.ruleForm.productKey
         productKey = state.ruleForm.productKey
@@ -317,9 +317,9 @@ export default defineComponent({
       productRef.value.openDialog();
       productRef.value.openDialog();
     }
     }
     // 获取产品回显数据
     // 获取产品回显数据
-    const getProductTableData = (deviceIdList: any, deviceNameList: any) => {
-      state.ruleForm.productKey = deviceIdList[0];
-      selectChange(deviceIdList[0]);
+    const getProductTableData = (productKeyList: any, deviceNameList: any) => {
+      state.ruleForm.productKey = productKeyList[0];
+      selectChange(productKeyList[0]);
       state.productName = deviceNameList[0];
       state.productName = deviceNameList[0];
       state.productNameShow = true;
       state.productNameShow = true;
     }
     }

+ 7 - 11
src/views/iot/ota-update/update/component/productBind.vue

@@ -17,24 +17,20 @@
         <el-table-column label="消息协议" prop="messageProtocol" show-overflow-tooltip v-col="'messageProtocol'" />
         <el-table-column label="消息协议" prop="messageProtocol" show-overflow-tooltip v-col="'messageProtocol'" />
         <el-table-column label="接入方式" prop="transportProtocol" show-overflow-tooltip v-col="'transportProtocol'" />
         <el-table-column label="接入方式" prop="transportProtocol" show-overflow-tooltip v-col="'transportProtocol'" />
         <el-table-column label="类型" prop="deviceType" show-overflow-tooltip v-col="'deviceType'" />
         <el-table-column label="类型" prop="deviceType" show-overflow-tooltip v-col="'deviceType'" />
-
         <el-table-column prop="status" label="状态" width="100" align="center" v-col="'status'">
         <el-table-column prop="status" label="状态" width="100" align="center" v-col="'status'">
           <template #default="scope">
           <template #default="scope">
             <el-tag type="success" size="small" v-if="scope.row.status">已发布</el-tag>
             <el-tag type="success" size="small" v-if="scope.row.status">已发布</el-tag>
             <el-tag type="info" size="small" v-else>未发布</el-tag>
             <el-tag type="info" size="small" v-else>未发布</el-tag>
           </template>
           </template>
         </el-table-column>
         </el-table-column>
-
       </el-table>
       </el-table>
       <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="getProductList" />
       <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="getProductList" />
-
     </el-dialog>
     </el-dialog>
   </div>
   </div>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
 import { toRefs, reactive, defineComponent, nextTick, getCurrentInstance, ref } from 'vue'
 import { toRefs, reactive, defineComponent, nextTick, getCurrentInstance, ref } from 'vue'
 import { ElMessageBox, ElMessage } from 'element-plus'
 import { ElMessageBox, ElMessage } from 'element-plus'
-import 'vue3-json-viewer/dist/index.css'
 import api from '/@/api/device'
 import api from '/@/api/device'
 
 
 interface TableDataState {
 interface TableDataState {
@@ -42,7 +38,7 @@ interface TableDataState {
   productData: object[],
   productData: object[],
   deviceKeyList: string[];
   deviceKeyList: string[];
   deviceNameList: string[];
   deviceNameList: string[];
-  checkIdList: string[];
+  checkKeyList: string[];
   tableData: {
   tableData: {
     data: []
     data: []
     total: number
     total: number
@@ -65,7 +61,7 @@ export default defineComponent({
       deviceNameList: [],
       deviceNameList: [],
       isShowDialog: false,
       isShowDialog: false,
       productData: [],
       productData: [],
-      checkIdList: [],
+      checkKeyList: [],
       tableData: {
       tableData: {
         data: [],
         data: [],
         total: 0,
         total: 0,
@@ -89,8 +85,8 @@ export default defineComponent({
       }).finally(() => (state.tableData.loading = false));
       }).finally(() => (state.tableData.loading = false));
     };
     };
 
 
-    const openDialog = (checkIdData: any) => {
-      state.checkIdList = checkIdData;
+    const openDialog = (checkKeyList: string[]) => {
+      state.checkKeyList = checkKeyList;
       getProductList()
       getProductList()
     };
     };
 
 
@@ -127,9 +123,9 @@ export default defineComponent({
 
 
     const changeSelect = () => {
     const changeSelect = () => {
       nextTick(() => {
       nextTick(() => {
-        state.tableData.data.forEach((item) => {
-          if (state.checkIdList) {
-            if (state.checkIdList.includes(item.key)) {
+        state.tableData.data.forEach((item: any) => {
+          if (state.checkKeyList) {
+            if (state.checkKeyList.includes(item.key)) {
               proxy.$refs.multipleTable.toggleRowSelection(item, true);
               proxy.$refs.multipleTable.toggleRowSelection(item, true);
             }
             }
           }
           }