diff --git a/frontend/src/api/check/interface/index.ts b/frontend/src/api/check/interface/index.ts index 84aa651..36189bb 100644 --- a/frontend/src/api/check/interface/index.ts +++ b/frontend/src/api/check/interface/index.ts @@ -1,96 +1,104 @@ -export interface DataCheck { - testScriptName: string, - errorSysName: string, - dataRule: string, - deviceName: string, - monitorIdx: string, -} - -/** - * 用于定义 查看(设备)通道检测结果 类型 - */ -export interface CheckResult { - chnNum: string, - standardValue: number, - L1: number, - L1_errValue: number, - L2: number, - L2_errValue: number, - L3: number, - L3_errValue: number, - maxErrVaule: number, - result: string, -} - -/** - * 用于定义 具体通道的原始数据类型 - */ -export interface RawDataItem { - updateTime: string, - L1: number, - L2: number, - L3: number -} - - -// 用来描述检测脚本类型 -export interface ScriptItem { - id: string, - scriptItemName: string, - children?: ScriptItem[] -} - -// 用来描述 通道检测结果 -export enum ChnCheckResultEnum { - UNKNOWN = -1, - FAIL = 0, - SUCCESS = 1, -} - -//用来描述 某个脚本测试项对所有通道的检测结果 -export interface ScriptChnItem { - scriptID: string - scriptItemName: string - - // 设备 - devices: Array<{ - deviceID: string, +export namespace CheckData { + export interface DataCheck { + testScriptName: string, + errorSysName: string, + dataRule: string, deviceName: string, - chnResult: ChnCheckResultEnum[] //通道检测结果 - }> -} + monitorIdx: string, + } -/** - * 用于描述 (设备)通道检测结果展示的按钮类型 - */ -export interface ButtonResult { - resultType: 'info' | 'success' | 'danger', - resultValue: '-' | '√' | '×' -} + /** + * 用于定义 查看(设备)通道检测结果 类型 + */ + export interface CheckResult { + chnNum: string, + standardValue: number, + L1: number, + L1_errValue: number, + L2: number, + L2_errValue: number, + L3: number, + L3_errValue: number, + maxErrVaule: number, + result: string, + } -/** - * 用于描述 脚本检测结果展示的按钮类型 - */ -export interface ScriptChnViewItem { - scriptID: string, - scriptItemName: string //脚本项名称 + /** + * 用于定义 具体通道的原始数据类型 + */ + export interface RawDataItem { + updateTime: string, + L1: number, + L2: number, + L3: number + } - // 设备 - devices:Array<{ - deviceID: string, - deviceName: string, - chnResult: ButtonResult[], - }> -} + export interface Device { + deviceId: string; //装置序号Id + deviceName: string; //设备名称 + chnNum: number; //设备通道数 + } + + // 用来描述检测脚本类型 + export interface ScriptItem { + id: string, + scriptItemName: string, + children?: ScriptItem[] + } + + // 用来描述 通道检测结果 + export enum ChnCheckResultEnum { + UNKNOWN = -1, + FAIL = 0, + SUCCESS = 1, + } + + //用来描述 某个脚本测试项对所有通道的检测结果 + export interface ScriptChnItem { + scriptId: string + scriptItemName?: string //可以不要该属性,有点多余 + + // 设备 + devices: Array<{ + deviceId: string, + deviceName: string, + chnResult: ChnCheckResultEnum[] //通道检测结果 + }> + } + + /** + * 用于描述 (设备)通道检测结果展示的按钮类型 + */ + export interface ButtonResult { + resultType: 'info' | 'success' | 'danger', + resultValue: '-' | '√' | '×' + } + + /** + * 用于描述 脚本检测结果展示的按钮类型 + */ + export interface ScriptChnViewItem { + scriptId: string, + scriptItemName?: string //脚本项名称,可以不要该属性,有点多余 + + // 设备 + devices: Array<{ + deviceId: string, + deviceName: string, + chnResult: ButtonResult[], + }> + } -/** - * 定义检测日志类型 - */ -export interface LogItem { - type: 'info' | 'error' - log: string + /** + * 定义检测日志类型 + */ + export interface LogItem { + type: 'info' | 'error' + log: string + } } + diff --git a/frontend/src/api/check/test/index.ts b/frontend/src/api/check/test/index.ts new file mode 100644 index 0000000..b3cd167 --- /dev/null +++ b/frontend/src/api/check/test/index.ts @@ -0,0 +1,5 @@ +import http from "@/api"; + +export const getCheckItemDetail = (params: { checkItemId: string, deviceId: string, chnNum: number }) => { + return http.post("/check/test/detail/", params, {loading: false}); +} \ No newline at end of file diff --git a/frontend/src/api/plan/autoTest.json b/frontend/src/api/plan/autoTest.json index aa54f89..7812c02 100644 --- a/frontend/src/api/plan/autoTest.json +++ b/frontend/src/api/plan/autoTest.json @@ -29,7 +29,7 @@ "isChildNode":true, "pid": "0-1", "id": "0-1-3", - "name": "输入:频率 50.05Hz..." + "name": "输入:频率 50.05Hz...." } ] }, diff --git a/frontend/src/api/socket/socket.ts b/frontend/src/api/socket/socket.ts new file mode 100644 index 0000000..b292381 --- /dev/null +++ b/frontend/src/api/socket/socket.ts @@ -0,0 +1,7 @@ +import type { Device } from '@/api/device/interface/device' +import http from '@/api' + + +export const startTest = (params) => { + return http.post(`/prepare/startTest`, params,{ loading: false }) +} \ No newline at end of file diff --git a/frontend/src/stores/constant.ts b/frontend/src/stores/constant.ts index 4047d0c..d82b4d6 100644 --- a/frontend/src/stores/constant.ts +++ b/frontend/src/stores/constant.ts @@ -17,3 +17,5 @@ export const USER_STORE_KEY = "cn-user"; // pinia中dict store的key export const DICT_STORE_KEY = "cn-dictData"; +export const CHECK_STORE_KEY = "cn-check"; + diff --git a/frontend/src/stores/modules/check.ts b/frontend/src/stores/modules/check.ts new file mode 100644 index 0000000..b7022d2 --- /dev/null +++ b/frontend/src/stores/modules/check.ts @@ -0,0 +1,24 @@ +import {defineStore} from "pinia"; +import {CHECK_STORE_KEY} from "@/stores/constant"; +import type {CheckData} from "@/api/check/interface"; + + +export const useCheckStore = defineStore("check", { + id: CHECK_STORE_KEY, + + state: () => ({ + devices: Array() + }), + + getters: {}, + + actions: { + addDevices(device: CheckData.Device[]) { + this.devices.push(...device); + }, + + clearDevices() { + this.devices = []; + } + } +}); \ No newline at end of file diff --git a/frontend/src/utils/webSocketClient.ts b/frontend/src/utils/webSocketClient.ts new file mode 100644 index 0000000..949cb30 --- /dev/null +++ b/frontend/src/utils/webSocketClient.ts @@ -0,0 +1,103 @@ +import {ElMessage} from "element-plus"; + +export default class SocketService { + static instance = null; + static get Instance() { + if (!this.instance) { + this.instance = new SocketService(); + } + return this.instance; + } + // 和服务端连接的socket对象 + ws = null; + // 存储回调函数 + callBackMapping = {}; + // 标识是否连接成功 + connected = false; + // 记录重试的次数 + sendRetryCount = 0; + // 重新连接尝试的次数 + connectRetryCount = 0; + // 定义连接服务器的方法 + connect(url) { + + // 连接服务器 + if (!window.WebSocket) { + return console.log('您的浏览器不支持WebSocket'); + } + console.log(url) + // let token = $.cookie('123'); + // let token = '4E6EF539AAF119D82AC4C2BC84FBA21F'; + + + this.ws = new WebSocket(url); + // 连接成功的事件 + this.ws.onopen = () => { + ElMessage.success("webSocket连接服务端成功了"); + console.log('连接服务端成功了'); + this.connected = true; + // 重置重新连接的次数 + this.connectRetryCount = 0; + }; + // 1.连接服务端失败 + // 2.当连接成功之后, 服务器关闭的情况 + this.ws.onclose = () => { + console.log('连接服务端失败'); + this.connected = false; + this.connectRetryCount++; + setTimeout(() => { + // this.connect(); + }, 500 * this.connectRetryCount); + }; + // 得到服务端发送过来的数据 + this.ws.onmessage = (event) => { + let message: { [key: string]: any }; + try { + message = JSON.parse(event.data); + } catch (e) { + return console.error("消息解析失败", event.data, e); + } + //console.log(message, "从服务端获取到了数据"); + /* 通过接受服务端发送的type字段来回调函数 */ + if (message?.type && this.callBackMapping[message.type]) { + this.callBackMapping[message.type](message); + } else { + console.log("抛弃") + /* 丢弃或继续写你的逻辑 */ + } + }; + } + // 回调函数的注册 + registerCallBack(socketType, callBack) { + this.callBackMapping[socketType] = callBack; + } + // 取消某一个回调函数 + unRegisterCallBack(socketType) { + this.callBackMapping[socketType] = null; + } + // 发送数据的方法 + send(data) { + // 判断此时此刻有没有连接成功 + if (this.connected) { + this.sendRetryCount = 0; + try { + this.ws.send(JSON.stringify(data)); + } catch (e) { + this.ws.send(data); + } + } else { + this.sendRetryCount++; + setTimeout(() => { + this.send(data); + }, this.sendRetryCount * 500); + } + } + + // 断开方法 + closeWs() { + if (this.connected) { + this.ws.close() + } + console.log('WS关闭中..'); + } +} diff --git a/frontend/src/views/home/components/channelsTest.vue b/frontend/src/views/home/components/channelsTest.vue index 3d6a445..4f861fc 100644 --- a/frontend/src/views/home/components/channelsTest.vue +++ b/frontend/src/views/home/components/channelsTest.vue @@ -123,7 +123,7 @@ const errorStates = ref(new Array(name.value.length).fill(false)); // 定义 TableDataItem 接口 interface TableDataItem { id: string; - deviceName: string; + deviceName?: string; MonitorIdx: number; UaData?: number | string; UaChannel?: number | string; @@ -141,6 +141,135 @@ interface TableDataItem { updateTime?: string; } + +// 定义每种状态的数据模板 +const dataTemplates = [ + { + deviceName: '大电压大电流1', + UaData: 57.74, + UaChannel: 1.0003, + UbData: 57.74, + UbChannel: 1.0003, + UcData: 57.74, + UcChannel: 1.0003, + IaData: 5, + IaChannel: 1.0001, + IbData: 5, + IbChannel: 1.0001, + IcData: 5, + IcChannel: 1.0001, + }, + { + deviceName: '小电压小电流1', + UaData: 57.74, + UaChannel: 1.0003, + UbData: 57.74, + UbChannel: 1.0003, + UcData: 57.74, + UcChannel: 1.0003, + IaData: 5, + IaChannel: 1.0001, + IbData: 5, + IbChannel: 1.0001, + IcData: 5, + IcChannel: 1.0001, + }, + { + deviceName: '大电压大电流2', + UaData: 57.74, + UaChannel: '合格', + UbData: 57.74, + UbChannel: '合格', + UcData: 57.74, + UcChannel: '合格', + IaData: 5, + IaChannel: '合格', + IbData: 5, + IbChannel: '合格', + IcData: 5, + IcChannel: '合格', + }, + { + deviceName: '小电压小电流2', + UaData: 57.74, + UaChannel: '合格', + UbData: 57.74, + UbChannel: '合格', + UcData: 57.74, + UcChannel: '合格', + IaData: 5, + IaChannel: '合格', + IbData: 5, + IbChannel: '合格', + IcData: 5, + IcChannel: '合格', + }, +]; + +// 定义每种状态的数据模板 +const dataTemplates2 = [ + { + deviceName: '大电压大电流1', + UaData: 57.74, + UaChannel: 1.0003, + UbData: 57.74, + UbChannel: 1.0003, + UcData: 57.74, + UcChannel: 1.0003, + IaData: 5, + IaChannel: 1.0001, + IbData: 5, + IbChannel: 1.0001, + IcData: 5, + IcChannel: 1.0001, + }, + { + deviceName: '小电压小电流1', + UaData: 57.74, + UaChannel: 1.0003, + UbData: 57.74, + UbChannel: 1.0003, + UcData: 57.74, + UcChannel: 1.0003, + IaData: 5, + IaChannel: 1.0001, + IbData: 5, + IbChannel: 1.0001, + IcData: 5, + IcChannel: 1.0001, + }, + { + deviceName: '大电压大电流2', + UaData: 57.74, + UaChannel: '不合格', + UbData: 57.74, + UbChannel: '合格', + UcData: 57.74, + UcChannel: '合格', + IaData: 5, + IaChannel: '合格', + IbData: 5, + IbChannel: '合格', + IcData: 5, + IcChannel: '合格', + }, + { + deviceName: '小电压小电流2', + UaData: 57.74, + UaChannel: '合格', + UbData: 57.74, + UbChannel: '合格', + UcData: 57.74, + UcChannel: '合格', + IaData: 5, + IaChannel: '不合格', + IbData: 5, + IbChannel: '合格', + IcData: 5, + IcChannel: '合格', + }, +]; + // 更新错误状态的方法 const updateErrorState = (index: number, hasError: boolean) => { errorStates.value[index] = hasError; @@ -175,6 +304,7 @@ const activities = [ hollow: true, }, ] + const tableData1 = ref([ { id: '1', @@ -464,12 +594,12 @@ const tableData3 = ref([ const tableDataMap = new Map>([ - [0, tableData1], - [1, tableData2], - [2, tableData3], - [3, tableData1], - [4, tableData1], - [5, tableData1], + // [0, tableData1], + // [1, tableData2], + // [2, tableData3], + // [3, tableData1], + // [4, tableData1], + // [5, tableData1], ]); @@ -498,6 +628,29 @@ const currentStepStatus = ref<'error' | 'finish' | 'wait' | 'success' | 'process channel.value = selection.map(item => item.devChns) dialogVisible.value = true; total.value = name.value.length + + + // 循环生成数据 + for (let i = 0; i < channel.value.length; i++) { + const currentTableData = ref([]); + + + // 随机选择 dataTemplates 或 dataTemplates2 + const selectedTemplates = Math.random() < 0.5 ? dataTemplates : dataTemplates2; + + for(let j = 0; j < channel.value[i]; j++){ + const id = (j + 1).toString(); + selectedTemplates.forEach((template) => { + currentTableData.value.push({ + id: id, + MonitorIdx: j + 1, + ...template, + }); + }); + } + + tableDataMap.set(i,currentTableData) + } } const handleCancel=() => { diff --git a/frontend/src/views/home/components/dataCheckResultTable.vue b/frontend/src/views/home/components/dataCheckResultTable.vue index 28a0ea0..7d75816 100644 --- a/frontend/src/views/home/components/dataCheckResultTable.vue +++ b/frontend/src/views/home/components/dataCheckResultTable.vue @@ -10,33 +10,33 @@ - + - + - + - + - + - + - + - + diff --git a/frontend/src/views/home/components/testPopup.vue b/frontend/src/views/home/components/testPopup.vue index dbfa452..3861579 100644 --- a/frontend/src/views/home/components/testPopup.vue +++ b/frontend/src/views/home/components/testPopup.vue @@ -14,7 +14,7 @@ - + @@ -25,6 +25,7 @@ 跳过 开始检测 停止检测 + 继续检测 重新检测 {{nextStepText}} @@ -35,17 +36,29 @@