diff --git a/frontend/src/views/machine/testScript/components/testScriptDetail.vue b/frontend/src/views/machine/testScript/components/testScriptDetail.vue index c2aae9b..769db75 100644 --- a/frontend/src/views/machine/testScript/components/testScriptDetail.vue +++ b/frontend/src/views/machine/testScript/components/testScriptDetail.vue @@ -19,6 +19,17 @@
@@ -241,6 +252,7 @@ const props = defineProps({ type: Boolean } }) +const value1 = ref(0) // 假设初始状态为禁用(0) const showDialog = ref(false) const viewDialog = ref(false) const dictStore = useDictStore() @@ -268,13 +280,13 @@ const column = ref([ ]) // 获取树 const getTree = () => { - console.log('props.formContent.id', props.formContent.id) + // console.log('props.formContent.id', props.formContent.id) getTreeData({ scriptId: props.formContent.id }).then(res => { if (res.code === 'A0000') { treeData.value = res.data - console.log('tree', treeData.value) + //console.log('tree', treeData.value) // 添加tab子项 props.options.forEach((k: any, i: number) => { tabData.value[i].children = [] @@ -317,7 +329,7 @@ const setTab = row => { const copyActiveName = ref('') // 获取通讯脚本点击 const getCommunication = () => { - console.log('123123', communRef.value[0]?.getData()) + //console.log('123123', communRef.value[0]?.getData()) communicationList.value = communRef.value[0]?.getData() } // 切换大tab控制小tab @@ -354,8 +366,12 @@ const inquireTable = () => { }) tableData.value = res.data + // 设置 value1:只要有一个 enable === 1,就启用开关 + value1.value = tableData.value.some(item => item.enable === 1) ? 1 : 0 } }) + + } // 打开 drawer(新增、编辑) const openDialog = (titleType: string, row: Partial = {}) => { @@ -404,7 +420,7 @@ const copyRow = async (row: any) => { // 查看 const view = (row: Partial = {}) => { getCommunication() - console.log('communicationList', communicationList.value) + // console.log('communicationList', communicationList.value) //当前点击的一级tab const parentTabName = communicationList.value.find(t => t.id === activeName.value)?.name || '未找到对应名称' //当前点击的二级tab @@ -449,6 +465,38 @@ const enableRow = async (row: any) => { row.enable = row.enable == 0 ? 1 : 0 }) } + + +// 启用/禁用脚本的方法 +const enableScript = async () => { + const willEnable = value1.value === 1 + const confirmText = willEnable ? '启用' : '禁用' + + try { + await ElMessageBox.confirm(`是否${confirmText}当前检测脚本?`, '温馨提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + draggable: true + }) + + // 调用接口更新状态 + await updateDtls({ + enable: value1.value, + scriptType: activeName.value, + scriptId: props.formContent.id + }) + + ElMessage.success(`${confirmText}成功!`) + getTree() // 刷新树数据 + } catch (error) { + // 用户取消或请求失败,回滚状态 + value1.value = value1.value === 1 ? 0 : 1 + console.error('操作失败:', error) + } +} + + // 获取左边树数据 // 新增保存 const addTab = (row: any) => { @@ -458,7 +506,7 @@ const addTab = (row: any) => { const saveTheNewsletter = () => {} onMounted(() => { getTree() - console.log('testScriptDetail', props.options) + //console.log('testScriptDetail', props.options) props.options.forEach((item: any) => { tabData.value.push({ label: item.label.replace(/准确度|检测/g, ''), @@ -505,6 +553,7 @@ onMounted(() => { margin-bottom: 10px; } + .divider-container { display: flex; } diff --git a/frontend/src/views/plan/planList/index.vue b/frontend/src/views/plan/planList/index.vue index 7b69422..a1f986d 100644 --- a/frontend/src/views/plan/planList/index.vue +++ b/frontend/src/views/plan/planList/index.vue @@ -247,19 +247,22 @@ const columns = reactive[]>([ if (!codes) { return '/' } + // 确保 codes 是一个字符串 const codeString = Array.isArray(codes) ? codes.join(',') : codes const codeArray = codeString.split(',') if (codeArray.length > 1) { + // 查找与每个 code 值匹配的 name,然后拼接成逗号分割的字符串 const names = codeArray.map(code => { - const dictItem = dictStore.getDictData(dataSourceType.value).find(item => item.value === code) + const dictItem = dictStore.getDictData(dataSourceType.value).find(item => item.code === code) + return dictItem ? dictItem.name : '/' // 如果找到匹配的项,返回对应的 name }) return names.join(', ') // 用逗号连接所有的 name } // 查找单个 code 对应的 name - const dictItem = dictStore.getDictData(dataSourceType.value).find(item => item.value === codeArray[0]) + const dictItem = dictStore.getDictData(dataSourceType.value).find(item => item.code === codeArray[0]) return dictItem ? dictItem.name : '/' // 如果找到匹配的项,返回对应的 name }, },