feat: 优化设备功能模拟与属性展示逻辑

- 注释掉事件面板中不必要的字段过滤逻辑
- 实时面板属性初始化时增加显示条件筛选
- 功能模拟组件重构提交流程,分离参数校验与提交逻辑
- 增加功能提交前预检查处理机制
- 产品元数据属性新增show字段控制是否显示
- 元数据组件移除调试日志并清理模拟数据代码
This commit is contained in:
fhysy 2025-10-17 15:39:24 +08:00
parent 4541f97faf
commit db7bd59c89
5 changed files with 82 additions and 110 deletions

View File

@ -94,7 +94,7 @@ const loadList = async () => {
const params: any = {
deviceKey: props.deviceInfo.deviceKey,
productKey: props.deviceInfo.productObj.productKey,
fields: selectedEventId.value || undefined,
// fields: selectedEventId.value || undefined,
orderType: 2,
current: pagination.value.current,
size: pagination.value.pageSize,

View File

@ -121,12 +121,20 @@ const unsubscribeRealtimeData = () => {
};
const initRuntime = () => {
const properties = (props.metadata?.properties || []).map((prop: any) => ({
const list =
props.metadata?.properties.filter((item) => item.show === true) || [];
const properties = list.map((prop: any) => ({
...prop,
value: null,
timestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'),
}));
runtimeProperties.value = properties;
// const properties = (props.metadata?.properties || []).map((prop: any) => ({
// ...prop,
// value: null,
// timestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'),
// }));
// runtimeProperties.value = properties;
};
//

View File

@ -58,6 +58,8 @@ const selectedRowKeys = ref([]);
//
const formData = ref({});
const submitFunctionParameters = ref({});
//
const preCheckVisible = ref(false);
const preCheckType = ref('');
@ -307,7 +309,7 @@ const checkPreCheck = () => {
};
//
const executeSubmit = async (checkValue?: string) => {
const submitCheckFormatParams = async () => {
try {
let parameters = {};
@ -417,13 +419,68 @@ const executeSubmit = async (checkValue?: string) => {
return;
}
}
submitFunctionParameters.value = parameters;
if (checkPreCheck()) {
return; //
}
submitFunction(null);
// //
// const submitData: any = {
// productKey: props.deviceInfo.productObj.productKey,
// deviceKey: props.deviceInfo.deviceKey,
// funcId: selectedFunctionId.value,
// params: parameters,
// };
// //
// if (checkValue) {
// submitData.checkValue = checkValue;
// }
// //
// parameterContent.value = JSON.stringify(submitData, null, 2);
// await deviceOperateFunc(submitData);
// // API
// console.log(':', submitData);
// console.log('keys:', selectedRowKeys.value);
// console.log(':', parameters);
// //
// const mockResult = {
// success: true,
// message: '',
// data: {
// deviceKey: props.deviceInfo.deviceKey,
// funcId: selectedFunctionId.value,
// executeTime: new Date().toISOString(),
// result: 'OK',
// },
// };
// submitResult.value = JSON.stringify(mockResult, null, 2);
// message.success('');
} catch (error) {
if (error.errorFields[0].errors[0]) {
message.error(error.errorFields[0].errors[0]);
} else {
message.error('执行失败');
}
console.error('执行错误:', error);
}
};
const submitFunction = async (checkValue: any) => {
try {
//
const submitData: any = {
productKey: props.deviceInfo.productObj.productKey,
deviceKey: props.deviceInfo.deviceKey,
funcId: selectedFunctionId.value,
params: parameters,
params: submitFunctionParameters.value,
};
//
@ -456,24 +513,14 @@ const executeSubmit = async (checkValue?: string) => {
// submitResult.value = JSON.stringify(mockResult, null, 2);
// message.success('');
} catch (error) {
if (error.errorFields[0].errors[0]) {
message.error(error.errorFields[0].errors[0]);
} else {
message.error('执行失败');
}
console.error('执行错误:', error);
console.error('提交功能时出错:', error);
}
};
//
const handleSubmit = async () => {
//
if (checkPreCheck()) {
return; //
}
//
await executeSubmit();
await submitCheckFormatParams();
};
//
@ -482,7 +529,6 @@ const handlePreCheckConfirm = async () => {
await preCheckFormRef.value.validate();
let checkValue = '';
// checkValue
switch (preCheckType.value) {
case 'staticPassword': {
@ -504,7 +550,7 @@ const handlePreCheckConfirm = async () => {
preCheckVisible.value = false;
//
await executeSubmit(checkValue);
await submitFunction(checkValue);
} catch (error) {
console.error('预检查验证失败:', error);
}

View File

@ -20,7 +20,7 @@ import TSLViewer from './metadata/TSLViewer.vue';
const props = defineProps<{
productId: string;
productInfo: ProductVO;
productInfo: any;
}>();
const emit = defineEmits<{
@ -102,7 +102,6 @@ const handleTSLClose = () => {
//
const loadMetadata = async () => {
console.log('加载物模型数据');
const defaultMetadata = {
properties: [],
functions: [],
@ -113,96 +112,6 @@ const loadMetadata = async () => {
currentMetadata.value = props.productInfo.metadata
? JSON.parse(props.productInfo.metadata)
: JSON.parse(JSON.stringify(defaultMetadata));
// API
// const res = await getProductMetadata(props.productId);
// currentMetadata.value = res.data || { properties: [], functions: [], events: [] };
//
// currentMetadata.value = {
// properties: [
// {
// id: 'switch',
// name: '',
// sort: 1,
// description: '',
// required: false,
// expands: {
// source: 'device',
// type: 'R',
// },
// valueParams: {
// dataType: 'boolean',
// formType: 'switch',
// min: 0,
// max: 1,
// length: 1,
// viewType: 'switch',
// enumConf: [],
// arrayConf: { type: 'string' },
// objectConf: [],
// unit: '',
// scale: 2,
// format: 'YYYY-MM-DD HH:mm:ss',
// },
// },
// ],
// functions: [
// {
// id: 'changeswitch',
// name: '',
// sort: 1,
// description: '',
// async: false,
// expands: {},
// inputs: [
// {
// id: 'switch',
// name: '',
// required: true,
// valueParams: {
// dataType: 'boolean',
// formType: 'switch',
// min: 0,
// max: 1,
// length: 1,
// viewType: 'switch',
// enumConf: [],
// objectConf: [],
// unit: '',
// scale: 2,
// format: 'YYYY-MM-DD HH:mm:ss',
// },
// expands: {},
// },
// ],
// outputs: [],
// },
// ],
// events: [
// {
// id: 'event1',
// name: '1',
// sort: 1,
// description: '1',
// outputs: [
// {
// id: 'param1',
// name: '1',
// expands: {},
// valueParams: {
// type: 'string',
// expands: {},
// enumConf: [],
// objectConf: [],
// unit: '',
// scale: 2,
// format: 'YYYY-MM-DD HH:mm:ss',
// },
// },
// ],
// },
// ],
// };
//
originalMetadata.value = JSON.parse(JSON.stringify(currentMetadata.value));

View File

@ -37,6 +37,7 @@ interface PropertyData {
sort: number;
description: string;
required: boolean;
show: boolean;
expands: {
source: string;
type: string;
@ -146,6 +147,7 @@ const defaultPropertyData: PropertyData = {
sort: 1,
description: '',
required: false,
show: true,
expands: {
source: 'device',
type: 'R',
@ -539,6 +541,13 @@ watch(
</FormItem>
</Col>
<!-- 属性特有字段 -->
<Col :span="12">
<FormItem label="是否显示" name="show">
<Switch v-model:checked="formData.show" />
</FormItem>
</Col>
<Col :span="12">
<FormItem label="排序" name="sort">
<InputNumber