检测计划数据源字段显示bug、脚本大项启用/禁用功能

This commit is contained in:
caozehui
2025-05-12 15:57:19 +08:00
parent f0b3bdd37c
commit f8b7c224b7
2 changed files with 59 additions and 7 deletions

View File

@@ -19,6 +19,17 @@
<el-tab-pane v-for="tab in tabData" :key="tab.value" :label="tab.label" :name="tab.value">
<div v-if="activeName == tab.value">
<div class="dialog-footer">
<el-switch v-model="value1"
inline-prompt
:active-value="1"
:inactive-value="0"
active-text="启用"
inactive-text="禁用"
@change="enableScript"
size="large"
width="80px"
style="margin-right: 10px;"
/>
<el-button :icon="CirclePlus" type="primary" @click="openDialog('add')">新增</el-button>
</div>
<div style="display: flex">
@@ -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<TestScript.ResTestScript> = {}) => {
@@ -404,7 +420,7 @@ const copyRow = async (row: any) => {
// 查看
const view = (row: Partial<TestScript.ResTestScript> = {}) => {
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;
}

View File

@@ -247,19 +247,22 @@ const columns = reactive<ColumnProps<Plan.ReqPlan>[]>([
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
},
},