Files
pqs-9100_client/frontend/src/views/machine/testScript/components/testScriptDetail.vue

542 lines
22 KiB
Vue
Raw Normal View History

2024-12-24 20:22:36 +08:00
<template>
2025-02-19 16:54:54 +08:00
<div>
<div class="divider-container">
2025-02-27 15:09:09 +08:00
<el-divider style="width: 260px" content-position="left">检测脚本信息</el-divider>
2025-02-20 16:39:15 +08:00
<!-- <el-divider style="width: 400px" content-position="left">通讯脚本</el-divider> -->
2025-02-19 16:54:54 +08:00
<el-divider style="flex: 1" content-position="left">检测项目概要信息</el-divider>
2025-02-17 08:39:18 +08:00
</div>
2025-02-19 16:54:54 +08:00
<div class="data-check-content">
<div class="content-tree">
2025-02-27 15:09:09 +08:00
<Tree :treeData="treeData" @setTab="setTab" />
2025-02-19 16:54:54 +08:00
</div>
2025-02-13 16:15:26 +08:00
2025-02-27 15:09:09 +08:00
<div class="content-right-Tabs" style="height: calc(100vh - 315px); width: 100px">
2025-02-19 16:54:54 +08:00
<el-tabs type="border-card" style="height: 100%" v-model="activeName" @tab-change="tabChange">
<el-tab-pane v-for="tab in tabData" :key="tab.value" :label="tab.label" :name="tab.value">
2025-02-24 16:45:39 +08:00
<div v-if="activeName == tab.value">
<div class="dialog-footer">
<el-button :icon="CirclePlus" type="primary" @click="openDialog('add')">新增</el-button>
</div>
<div style="display: flex">
<!-- 通信脚本 -->
<el-tabs type="border-card" v-model="firstName" style="height: 100%">
<el-tab-pane label="通讯脚本" name="first">
<Commun
:activeName="activeName"
:formContent="props.formContent"
:options="props.options"
2025-02-27 15:09:09 +08:00
style="width: 360px"
2025-02-24 16:45:39 +08:00
:disabled="tab.children.length == 0 ? false : true"
ref="communRef"
/>
</el-tab-pane>
</el-tabs>
<!-- 2级tab -->
<el-tabs
type="border-card"
style="flex: 1; margin-left: 10px"
v-model="childActiveName"
@tab-change="inquireTable"
2025-02-20 16:39:15 +08:00
>
2025-02-24 16:45:39 +08:00
<el-tab-pane
v-for="subTab in tab.children || []"
:key="subTab.value"
:label="subTab.label"
:name="subTab.value"
2025-02-20 16:39:15 +08:00
style="width: 100%"
2025-02-19 16:54:54 +08:00
>
2025-02-24 16:45:39 +08:00
<el-table
:data="tableData"
:header-cell-style="{
textAlign: 'center',
backgroundColor: '#003078',
color: '#fff'
}"
stripe
:cell-style="{ textAlign: 'center' }"
2025-02-27 15:09:09 +08:00
height="calc(100vh - 480px)"
2025-02-24 16:45:39 +08:00
style="width: 100%"
>
<el-table-column type="index" label="组次" width="60" />
2025-02-27 15:09:09 +08:00
<el-table-column prop="ffreq" label="频率(Hz)" width="90" />
2025-02-24 16:45:39 +08:00
<el-table-column
:label="item.label"
v-for="item in column"
:key="item.label"
>
<template #default="{ row }">
<table class="tableL">
<tbody>
<tr>
<td class="theFirst">V</td>
<td>
{{
row.channelList[item.num].famp == null
? '/'
2025-02-27 15:09:09 +08:00
: '' +
row.channelList[item.num]?.famp +
(valueCode == 'Absolute' ? 'V' : '%')
}}
</td>
<td>
{{
row.channelList[item.num].fphase == null
? '/'
2025-02-27 15:09:09 +08:00
: '' +
row.channelList[item.num].fphase +
'°'
}}
</td>
</tr>
<tr>
<td class="theFirst">I</td>
<td>
{{
row.channelList[item.num + 1].famp == null
? '/'
2025-02-27 15:09:09 +08:00
: '' +
row.channelList[item.num + 1].famp +
(valueCode == 'Absolute' ? 'V' : '%')
}}
</td>
<td>
{{
row.channelList[item.num + 1].fphase == null
? '/'
2025-02-27 15:09:09 +08:00
: '' +
row.channelList[item.num + 1].fphase +
'°'
}}
</td>
</tr>
</tbody>
2025-02-24 16:45:39 +08:00
</table>
</template>
</el-table-column>
2025-02-27 15:09:09 +08:00
<el-table-column label="是否启用" width="85">
2025-02-24 16:45:39 +08:00
<template #default="{ row }">
<el-switch
v-model="row.enable"
:active-value="1"
:inactive-value="0"
@change="enableRow(row)"
>
<template #active-action>
<span></span>
</template>
<template #inactive-action>
<span>×</span>
</template>
</el-switch>
</template>
</el-table-column>
2025-02-28 13:58:15 +08:00
<el-table-column label="操作" width="165">
2025-02-24 16:45:39 +08:00
<template #default="{ row }">
2025-02-28 13:58:15 +08:00
<div class="actionButtons">
<el-button
type="primary"
link
:icon="CopyDocument"
@click="copyRow(row)"
>
复制
</el-button>
<el-button type="primary" link :icon="View" @click="view(row)">
查看
</el-button>
<el-button
type="primary"
link
:icon="EditPen"
@click="openDialog('edit', row)"
>
编辑
</el-button>
<el-button
type="primary"
link
:icon="Delete"
@click="deleteRow(row)"
>
删除
</el-button>
</div>
2025-02-24 16:45:39 +08:00
</template>
</el-table-column>
</el-table>
</el-tab-pane>
</el-tabs>
</div>
2025-02-20 16:39:15 +08:00
</div>
2025-02-19 16:54:54 +08:00
</el-tab-pane>
</el-tabs>
</div>
2024-12-24 20:22:36 +08:00
</div>
2024-12-26 09:28:19 +08:00
2025-02-19 16:54:54 +08:00
<TestProjectPopup
ref="testProjectPopupRef"
:options="props.options"
:activeName="activeName"
2025-02-20 16:39:15 +08:00
:childActiveName="childActiveName"
2025-02-19 16:54:54 +08:00
:formContent="props.formContent"
2025-02-24 16:45:39 +08:00
:communicationList="communicationList"
2025-02-20 16:39:15 +08:00
@addTab="addTab"
2025-02-24 16:45:39 +08:00
@getCommunication="getCommunication"
2025-02-20 16:39:15 +08:00
@close="showDialog = false"
v-if="showDialog"
2025-02-19 16:54:54 +08:00
/>
2025-02-28 13:58:15 +08:00
<!-- 查看 -->
2025-03-05 11:19:16 +08:00
<ViewRow ref="viewRowRef"
2025-03-04 09:35:41 +08:00
:activeName="activeName"
:formContent="props.formContent"
2025-03-05 11:19:16 +08:00
@close="viewDialog = false"
v-if="viewDialog"
2025-03-04 09:35:41 +08:00
/>
2025-02-19 16:54:54 +08:00
</div>
2024-12-24 20:22:36 +08:00
</template>
<script setup lang="ts">
2025-02-17 08:39:18 +08:00
import { type PropType, ref, nextTick } from 'vue'
2025-02-13 16:15:26 +08:00
import Tree from './tree.vue'
2025-02-17 08:39:18 +08:00
import Commun from './communication.vue'
2025-02-13 16:15:26 +08:00
import type { CascaderOption } from 'element-plus'
2025-02-19 16:54:54 +08:00
import { getTreeData } from '@/api/check/test'
2025-02-28 13:58:15 +08:00
import { CirclePlus, Delete, Check, CopyDocument, View, EditPen } from '@element-plus/icons-vue'
2025-02-13 16:15:26 +08:00
import type { TestScript } from '@/api/device/interface/testScript'
import TestProjectPopup from '@/views/machine/testScript/components/testProjectPopup.vue'
2025-02-19 16:54:54 +08:00
import { CheckData } from '@/api/check/interface'
2025-02-24 08:38:54 +08:00
import { dlsDetails, deleteDtls, updateDtls, addScriptDtls, checkDataList } from '@/api/device/testScript'
2025-02-19 16:54:54 +08:00
import { useDictStore } from '@/stores/modules/dict'
2025-02-20 16:39:15 +08:00
import { useHandleData } from '@/hooks/useHandleData'
import { scriptDtlsCheckDataList } from '@/api/device/testScript/index'
2025-03-05 11:19:16 +08:00
import ViewRow from '@/views/machine/testScript/components/viewRow.vue'
2024-12-26 09:28:19 +08:00
interface TabOption {
2025-02-18 16:36:54 +08:00
label?: string
name?: string
value?: string
code?: string
2025-02-13 16:15:26 +08:00
children?: TabOption[]
2024-12-26 09:28:19 +08:00
}
2025-02-24 16:45:39 +08:00
const communRef = ref()
2025-02-19 16:54:54 +08:00
const treeData = ref<CheckData.TreeItem[]>([])
const valueCode = ref('') //Absolute绝对值
2024-12-26 09:28:19 +08:00
const props = defineProps({
options: {
2025-02-13 16:15:26 +08:00
type: Array as PropType<TabOption[]>,
required: true
2025-02-17 16:44:02 +08:00
},
2025-02-18 16:36:54 +08:00
formContent: {
type: Object,
2025-02-17 16:44:02 +08:00
required: true
2025-02-13 16:15:26 +08:00
}
})
2025-02-20 16:39:15 +08:00
const showDialog = ref(false)
2025-03-05 11:19:16 +08:00
const viewDialog = ref(false)
2025-02-19 16:54:54 +08:00
const dictStore = useDictStore()
2025-02-17 08:39:18 +08:00
const activeName = ref('')
2025-02-19 16:54:54 +08:00
const childActiveName = ref('')
2025-02-20 16:39:15 +08:00
const firstName = 'first'
2025-02-28 13:58:15 +08:00
const viewRowRef = ref()
2025-02-24 16:45:39 +08:00
const communicationList = ref([])
2025-02-18 16:36:54 +08:00
const testProjectPopupRef = ref()
2025-02-19 16:54:54 +08:00
const tableData: any = ref([])
2025-02-17 08:39:18 +08:00
const tabData: any = ref([])
2025-02-19 16:54:54 +08:00
const column = ref([
{
label: 'L1',
num: 0
},
{
label: 'L2',
num: 2
},
{
label: 'L3',
num: 4
}
])
// 获取树
const getTree = () => {
getTreeData({
scriptId: props.formContent.id
}).then(res => {
if (res.code === 'A0000') {
treeData.value = res.data
// 添加tab子项
props.options.forEach((k: any, i: number) => {
tabData.value[i].children = []
treeData.value.forEach((item: any) => {
if (k.value == item.scriptTypeCode) {
item.children.forEach((s: any) => {
k.children.forEach((P: any) => {
if (P.code == s.scriptTypeCode) {
tabData.value[i].children.push({
label: P.label,
value: P.code,
children: []
})
} else {
s.children.forEach((j: any) => {
if (j.scriptTypeCode == P.code) {
tabData.value[i].children.push({
label: P.label,
value: P.code,
children: []
})
}
})
}
})
})
}
})
})
tabChange()
}
})
}
2025-02-27 15:09:09 +08:00
// 设置树点击tab
const setTab = row => {
activeName.value = row.activeName
childActiveName.value = row.childActiveName
getTree()
}
2025-02-19 16:54:54 +08:00
const copyActiveName = ref('')
2025-02-24 16:45:39 +08:00
// 获取通讯脚本点击
const getCommunication = () => {
communicationList.value = communRef.value[0]?.getData()
}
2025-02-19 16:54:54 +08:00
// 切换大tab控制小tab
const tabChange = () => {
if (copyActiveName.value != activeName.value) {
copyActiveName.value == activeName.value
if (
tabData.value
.filter((item: any) => item.value == activeName.value)[0]
?.children.filter((item: any) => item.value == childActiveName.value).length == 0
) {
childActiveName.value =
tabData.value.filter((item: any) => item.value == activeName.value)[0]?.children[0]?.value || ''
}
2025-02-19 16:54:54 +08:00
}
inquireTable()
}
//根据脚本id查询检测脚本详情
const inquireTable = () => {
const sortOrder = ['Ua', 'Ia', 'Ub', 'Ib', 'Uc', 'Ic']
dlsDetails({
scriptId: props.formContent.id,
scriptType: activeName.value,
scriptSubType: childActiveName.value
}).then((res: any) => {
if (res.code === 'A0000') {
res.data.forEach((item: any) => {
2025-02-20 16:39:15 +08:00
item.channelList = item.channelList.sort((a: any, b: any) => {
2025-02-19 16:54:54 +08:00
const indexA = sortOrder.indexOf(a.channelType)
const indexB = sortOrder.indexOf(b.channelType)
return indexA - indexB
})
})
2025-02-20 16:39:15 +08:00
2025-02-19 16:54:54 +08:00
tableData.value = res.data
}
})
2025-03-04 09:35:41 +08:00
2025-02-19 16:54:54 +08:00
}
2024-12-26 09:28:19 +08:00
// 打开 drawer(新增、编辑)
const openDialog = (titleType: string, row: Partial<TestScript.ResTestScript> = {}) => {
2025-02-20 16:39:15 +08:00
showDialog.value = true
setTimeout(() => {
testProjectPopupRef.value?.open(titleType, row)
}, 0)
}
// 复制
const copyRow = async (row: any) => {
let checkDataList: any = []
await communRef.value[0]?.getData().forEach((item: any) => {
item.children.forEach((k: any) => {
if (k.enable != 0 || k.errorFlag != 0) {
checkDataList.push({
pid: k.pid,
valueType: k.id,
dataType: k.dataType,
enable: k.enable,
errorFlag: k.errorFlag
})
}
})
})
let { data } = await scriptDtlsCheckDataList({ checkDataList: checkDataList, ...row, retryCompute: true })
2025-02-20 16:39:15 +08:00
let copyRow = JSON.parse(JSON.stringify(row))
delete copyRow.index
await addScriptDtls({ ...copyRow, scriptType: activeName.value, checkDataList: data }).then(res => {
2025-02-20 16:39:15 +08:00
if (res.code === 'A0000') {
ElMessage.success({
message: '复制成功!',
type: 'success'
})
getTree()
}
})
}
2025-02-28 13:58:15 +08:00
// 查看
2025-03-04 09:35:41 +08:00
const view = (row: Partial<TestScript.ResTestScript> = {}) => {
getCommunication()
//当前点击的一级tab
const parentTabName = communicationList.value.find(t => t.id === activeName.value)?.name || '未找到对应名称';
//当前点击的二级tab
const childrenTabName = ref('')
tabData.value.forEach((item: any) => {
if (item.value == activeName.value) {
item.children.forEach((k: any) => {
if (k.value == childActiveName.value) {
childrenTabName.value = k.label
}
})
}
})
2025-03-05 11:19:16 +08:00
viewDialog.value = true
setTimeout(() => {
viewRowRef.value?.open(row, communicationList.value, parentTabName, childrenTabName.value)
}, 0)
2025-02-28 13:58:15 +08:00
}
2025-02-20 16:39:15 +08:00
// 删除
const deleteRow = async (row: any) => {
await useHandleData(deleteDtls, { enable: row.enable, index: row.index, scriptId: row.scriptId }, `删除`)
getTree()
}
// 启用
const enableRow = async (row: any) => {
ElMessageBox.confirm(`是否${row.enable == 0 ? `禁用` : `启用`}?`, '温馨提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
draggable: true
})
.then(async () => {
updateDtls({ enable: row.enable, index: row.index, scriptId: row.scriptId }).then(res => {
ElMessage({
type: 'success',
message: `${row.enable == 0 ? `禁用` : `启用`}成功!`
})
getTree()
})
})
.catch(() => {
row.enable = row.enable == 0 ? 1 : 0
})
2024-12-26 09:28:19 +08:00
}
2025-02-19 16:54:54 +08:00
// 获取左边树数据
2025-02-17 08:39:18 +08:00
// 新增保存
const addTab = (row: any) => {
2025-02-19 16:54:54 +08:00
getTree()
2025-02-24 08:38:54 +08:00
}
// 保存通信脚本
2025-02-24 16:45:39 +08:00
const saveTheNewsletter = () => {}
2025-02-17 08:39:18 +08:00
onMounted(() => {
2025-02-19 16:54:54 +08:00
getTree()
props.options.forEach((item: any) => {
2025-02-17 08:39:18 +08:00
tabData.value.push({
label: item.label.replace(/准确度|检测/g, ''),
value: item.value,
2025-02-18 16:36:54 +08:00
code: item.code,
2025-02-17 08:39:18 +08:00
children: []
})
})
activeName.value = tabData.value[0].value
2025-02-19 16:54:54 +08:00
valueCode.value = dictStore
.getDictData('Script_Value_Type')
.filter(item => item.id == props.formContent.valueType)[0].code
2025-02-17 08:39:18 +08:00
})
2024-12-24 20:22:36 +08:00
</script>
2025-02-19 16:54:54 +08:00
<style lang="scss" scoped>
2024-12-24 20:22:36 +08:00
.data-check-content {
2025-02-13 16:15:26 +08:00
display: flex;
gap: 10px;
2024-12-24 20:22:36 +08:00
}
.content-tree {
2025-02-27 15:09:09 +08:00
width: 260px;
height: calc(100vh - 315px);
2025-02-13 16:15:26 +08:00
border: 1px solid #dcdfe6;
border-radius: 4px;
2025-02-27 15:09:09 +08:00
// margin-right: 10px;
2025-02-13 16:15:26 +08:00
overflow: auto; /* 同时启用垂直和水平滚动 */
2025-02-17 08:39:18 +08:00
overflow-x: hidden;
2024-12-24 20:22:36 +08:00
}
2025-02-20 16:39:15 +08:00
.scriptTree {
height: calc(100vh - 520px);
}
2024-12-24 20:22:36 +08:00
/* 确保 el-tree 内容可以超出容器宽度 */
.el-tree {
2025-02-13 16:15:26 +08:00
width: fit-content; /* 根据内容自适应宽度 */
2024-12-24 20:22:36 +08:00
}
.content-right-Tabs {
2025-02-13 16:15:26 +08:00
flex: 1; /* 根据需要调整宽度比例 */
2024-12-24 20:22:36 +08:00
}
2024-12-26 09:28:19 +08:00
2025-02-13 16:15:26 +08:00
.dialog-footer {
display: flex;
justify-content: flex-end;
margin-bottom: 10px;
2024-12-26 09:28:19 +08:00
}
.divider-container {
2025-02-13 16:15:26 +08:00
display: flex;
2024-12-26 09:28:19 +08:00
}
.divider-container .el-divider {
2025-02-13 16:15:26 +08:00
margin-right: 30px; /* 根据需要调整间距 */
}
:deep(.el-descriptions__body .el-descriptions__table:not(.is-bordered) .el-descriptions__cell) {
padding: 3px 11px;
2024-12-26 09:28:19 +08:00
}
2025-02-19 16:54:54 +08:00
:deep(.el-loading-mask) {
z-index: 3000;
}
.tableL {
border-collapse: collapse;
width: 100%;
td {
border: 1px solid #ccc;
padding: 5px;
width: 45%;
}
.theFirst {
background-color: #003078;
color: #fff;
width: 20px !important;
}
}
2025-02-28 13:58:15 +08:00
.actionButtons {
.el-button {
margin-left: 0px;
margin: 5px 6px;
}
}
2024-12-24 20:22:36 +08:00
</style>
2025-02-20 16:39:15 +08:00
<style>
input::-webkit-inner-spin-button {
-webkit-appearance: none !important;
}
input::-webkit-outer-spin-button {
-webkit-appearance: none !important;
}
2025-02-27 15:09:09 +08:00
.el-divider--horizontal {
margin: 4px 0 24px 0;
}
.el-tabs--border-card > .el-tabs__content {
padding: 10px;
}
2025-02-20 16:39:15 +08:00
</style>