This commit is contained in:
caozehui
2025-03-08 16:04:43 +08:00
parent 70531a0729
commit cb5a9050f2

View File

@@ -1,40 +1,40 @@
<template> <template>
<div> <div>
<el-card style="margin-bottom: 10px" class="cardTop"> <el-card style="margin-bottom: 10px" class="cardTop">
<el-form <el-form
:inline="true" :inline="true"
label-width="auto" label-width="auto"
ref="dialogFormRef" ref="dialogFormRef"
class="form-five" class="form-five"
> >
<el-form-item label='检测源' prop='sourceId' > <el-form-item label='检测源' prop='sourceId' >
<el-select v-model="controlContent.sourceId" collapse-tags placeholder="请选择检测源"> <el-select v-model="controlContent.sourceId" collapse-tags placeholder="请选择检测源">
<el-option <el-option
v-for="(option, index) in pqSourceArray" v-for="(option, index) in pqSourceArray"
:key="index" :key="index"
:label="option.label" :label="option.label"
:value="option.value" :value="option.value"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<div class="formBut"> <div class="formBut">
<el-button type="primary" :icon="Select" @click="start()" :disabled="connectDisabeld">通讯校验</el-button> <el-button type="primary" :icon="Select" @click="start()" :disabled="connectDisabeld">通讯校验</el-button>
</div> </div>
</el-form-item> </el-form-item>
</el-form> </el-form>
</el-card> </el-card>
<el-card v-if="show"> <el-card v-if="show">
<ControlSourceDetail v-if="secondLevelOptions.length > 0" :options="secondLevelOptions" :formContent="formContent" :formControl="controlContent" <ControlSourceDetail v-if="secondLevelOptions.length > 0" :options="secondLevelOptions" :formContent="formContent" :formControl="controlContent"
@update:activeName="handleActiveNameChange" @update:activeName="handleActiveNameChange"
@update:active-index="handleActiveIndexChange" @update:active-index="handleActiveIndexChange"
v-model:startDisabeld="startDisabeld" v-model:startDisabeld="startDisabeld"
@update:startDisabeld="startDisabeld=$event" @update:startDisabeld="startDisabeld=$event"
v-model:pauseDisabled="pauseDisabled" v-model:pauseDisabled="pauseDisabled"
@update:pauseDisabled="pauseDisabled=$event"/> @update:pauseDisabled="pauseDisabled=$event"/>
</el-card> </el-card>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, nextTick, onMounted, onBeforeMount, reactive, watch } from 'vue' import { ref, nextTick, onMounted, onBeforeMount, reactive, watch } from 'vue'
@@ -65,24 +65,24 @@ const pqSourceList=ref<TestSource.ResTestSource[]>([])//获取指定模式下所
const modeStore = useModeStore() const modeStore = useModeStore()
const pqSourceArray = ref<{ label: string; value: string; }[]>() const pqSourceArray = ref<{ label: string; value: string; }[]>()
const formContent = ref<TestScript.ResTestScript>({ const formContent = ref<TestScript.ResTestScript>({
id : '9ff96807cf8c7524587982ed8baa8b57', id : '9ff96807cf8c7524587982ed8baa8b57',
name: '测试', name: '测试',
type: '1', type: '1',
valueType: '2973cb938b591b93d0df2547599b87d8', valueType: '2973cb938b591b93d0df2547599b87d8',
pattern: modeId.value, pattern: modeId.value,
standardName: 'GBT 19862', standardName: 'GBT 19862',
standardTime: '2025', standardTime: '2025',
state: 1 state: 1
}) })
const connectDisabeld = ref(false) const connectDisabeld = ref(false)
const startDisabeld = ref(false) const startDisabeld = ref(true)
const pauseDisabled = ref(true) const pauseDisabled = ref(true)
const controlContent = ref<controlSource.ResControl>({ const controlContent = ref<controlSource.ResControl>({
userPageId: '', userPageId: '',
scriptId: '', scriptId: '',
scriptIndex: 0, scriptIndex: 0,
sourceId: '', sourceId: '',
}) })
//开始创建webSocket客户端 //开始创建webSocket客户端
const dataSocket = reactive({ const dataSocket = reactive({
@@ -91,58 +91,58 @@ const dataSocket = reactive({
const webMsgSend = ref()//webSocket推送的数据 const webMsgSend = ref()//webSocket推送的数据
onMounted(async () => { onMounted(async () => {
// 检查 socketClient.Instance 是否存在 // 检查 socketClient.Instance 是否存在
if (!socketClient.Instance) { if (!socketClient.Instance) {
console.error('WebSocket 客户端实例不存在'); console.error('WebSocket 客户端实例不存在');
return; return;
} }
socketClient.Instance.connect(); socketClient.Instance.connect();
dataSocket.socketServe = socketClient.Instance; dataSocket.socketServe = socketClient.Instance;
dataSocket.socketServe.registerCallBack('aaa', (res: { code: number; }) => { dataSocket.socketServe.registerCallBack('aaa', (res: { code: number; }) => {
// 处理来自服务器的消息 // 处理来自服务器的消息
//console.log('Received message:', res) //console.log('Received message:', res)
// 根据需要在这里添加更多的处理逻辑 // 根据需要在这里添加更多的处理逻辑
if (res.code === 20000) { if (res.code === 20000) {
ElMessage.error(message.message) ElMessage.error(message.message)
loading.close() loading.close()
} else { } else {
webMsgSend.value = res webMsgSend.value = res
} }
}) })
const pqSource_Result = await getTestSourceList({ const pqSource_Result = await getTestSourceList({
'pattern': "a303b2224845fcc6f60098b8ca73dca7", 'pattern': "a303b2224845fcc6f60098b8ca73dca7",
datasourceIds: '', datasourceIds: '',
sourceIds: '', sourceIds: '',
planId: '', planId: '',
scriptName: '', scriptName: '',
errorSysName: '', errorSysName: '',
sourceName: '', sourceName: '',
devIds: [], devIds: [],
id: '', id: '',
name: '', name: '',
dataSourceId: '', dataSourceId: '',
scriptId: '', scriptId: '',
errorSysId: '', errorSysId: '',
timeCheck: 0, timeCheck: 0,
testState: 0, testState: 0,
reportState: 0, reportState: 0,
result: 0, result: 0,
code: 0, code: 0,
state: 1 state: 1
}) })
pqSourceList.value = pqSource_Result.data as TestSource.ResTestSource[]; pqSourceList.value = pqSource_Result.data as TestSource.ResTestSource[];
const sourceArray1 = Array.isArray(pqSourceList.value) ? pqSourceList.value : [] const sourceArray1 = Array.isArray(pqSourceList.value) ? pqSourceList.value : []
// 将 pqSource_Result 转换成 { label, value } 数组 // 将 pqSource_Result 转换成 { label, value } 数组
pqSourceArray.value = sourceArray1.map(item => ({ pqSourceArray.value = sourceArray1.map(item => ({
label: item.name || '', label: item.name || '',
value: item.id value: item.id
})); }));
nextTick(async () => { nextTick(async () => {
await treeInfo(modeStore.currentMode) await treeInfo(modeStore.currentMode)
formContent.value.pattern = modeId.value formContent.value.pattern = modeId.value
show.value = true show.value = true
}) })
}) })
watch(webMsgSend, function (newValue, oldValue) { watch(webMsgSend, function (newValue, oldValue) {
@@ -179,17 +179,22 @@ watch(webMsgSend, function (newValue, oldValue) {
case 'INIT_GATHER': case 'INIT_GATHER':
if (newValue.code == 10200) { if (newValue.code == 10200) {
ElMessage.success('源连接成功!') ElMessage.success('源连接成功!')
startDisabeld.value = false
} else if(newValue.code !== 10201) { } else if(newValue.code !== 10201) {
ElMessage.error('源连接失败!') ElMessage.error('源连接失败!')
console.log('错误信息:',webMsgSend) console.log('错误信息:',webMsgSend)
} startDisabeld.value = true
pauseDisabled.value = true
}
break; break;
} }
break; break;
case 'connect': case 'connect':
switch (newValue.operateCode) { switch (newValue.operateCode) {
case "Source": case "Source":
ElMessage.error('源连接失败!') ElMessage.error('源连接失败!')
} }
break; break;
case 'server_error': case 'server_error':
@@ -210,59 +215,59 @@ watch(webMsgSend, function (newValue, oldValue) {
}) })
// 获取树字典 // 获取树字典
const treeInfo = async (currentMode: string) => { const treeInfo = async (currentMode: string) => {
const data: Dict.ResDictTree = { const data: Dict.ResDictTree = {
name: '', name: '',
id: '', id: '',
pid: '', pid: '',
pids: '', pids: '',
code: 'Script_Indicator_Items', code: 'Script_Indicator_Items',
sort: 0 sort: 0
} }
const result = await getDictTreeByCode(data) const result = await getDictTreeByCode(data)
const result1 = (await getDictTreeByCode({ ...data, code: 'Script_Error' })).data[0].children const result1 = (await getDictTreeByCode({ ...data, code: 'Script_Error' })).data[0].children
const allOptions = await convertToOptions(result.data as Dict.ResDictTree[]) const allOptions = await convertToOptions(result.data as Dict.ResDictTree[])
const setAllTree = await setTree(allOptions[0]?.children, result1) const setAllTree = await setTree(allOptions[0]?.children, result1)
secondLevelOptions.push(...(setAllTree || [])) secondLevelOptions.push(...(setAllTree || []))
modeId.value = dictStore.getDictData('Pattern').find(item => item.name === currentMode)?.id modeId.value = dictStore.getDictData('Pattern').find(item => item.name === currentMode)?.id
} }
const setTree = async (data, data1) => { const setTree = async (data, data1) => {
data.forEach(item => { data.forEach(item => {
data1.forEach(item1 => { data1.forEach(item1 => {
if (item.label.replace(/准确度|检测/g, '') == item1.name) { if (item.label.replace(/准确度|检测/g, '') == item1.name) {
item.value = item1.id item.value = item1.id
} }
})
}) })
return data })
return data
} }
// 转换函数 // 转换函数
const convertToOptions = (dictTree: Dict.ResDictTree[]): CascaderOption[] => { const convertToOptions = (dictTree: Dict.ResDictTree[]): CascaderOption[] => {
return dictTree.map(item => ({ return dictTree.map(item => ({
value: item.id, value: item.id,
code: item.code.split('-')[1] || item.code.split('-')[0], code: item.code.split('-')[1] || item.code.split('-')[0],
label: item.name, label: item.name,
children: item.children ? convertToOptions(item.children) : undefined children: item.children ? convertToOptions(item.children) : undefined
})) }))
} }
const scriptId = ref('') const scriptId = ref('')
const scriptIndex = ref(0) const scriptIndex = ref(0)
const handleActiveNameChange = (newActiveName: string) => { const handleActiveNameChange = (newActiveName: string) => {
scriptId.value = newActiveName scriptId.value = newActiveName
} }
const handleActiveIndexChange = (newActiveIndex: number) => { const handleActiveIndexChange = (newActiveIndex: number) => {
scriptIndex.value = newActiveIndex scriptIndex.value = newActiveIndex
} }
const start = async () => { const start = async () => {
controlContent.value.userPageId = 'cdf' controlContent.value.userPageId = 'cdf'
controlContent.value.scriptId = '9ff96807cf8c7524587982ed8baa8b57' controlContent.value.scriptId = '9ff96807cf8c7524587982ed8baa8b57'
controlContent.value.scriptIndex = scriptIndex.value controlContent.value.scriptIndex = scriptIndex.value
await checkSimulate(controlContent.value) await checkSimulate(controlContent.value)
} }
// 对外映射 // 对外映射
@@ -273,32 +278,32 @@ defineExpose({ open })
padding: 10px; padding: 10px;
} */ } */
:deep(.cardTop) { :deep(.cardTop) {
.el-card__body { .el-card__body {
padding: 20px 0 0 20px; padding: 20px 0 0 20px;
} }
} }
.formBut { .formBut {
width: 50%; width: 50%;
display: flex; display: flex;
justify-content: end; justify-content: end;
} }
.form-five { .form-five {
display: flex;
flex-wrap: wrap;
// justify-content: space-between;
.el-form-item {
display: flex; display: flex;
flex-wrap: wrap; width: 22.8%;
// justify-content: space-between;
.el-form-item {
display: flex;
width: 22.8%;
.el-form-item__content { .el-form-item__content {
flex: 1; flex: 1;
.el-select, .el-select,
.el-cascader, .el-cascader,
.el-input__inner, .el-input__inner,
.el-date-editor { .el-date-editor {
width: 100%; width: 100%;
} }
}
} }
}
} }
</style> </style>