feat: 优化设备功能模拟与属性展示逻辑
- 注释掉事件面板中不必要的字段过滤逻辑 - 实时面板属性初始化时增加显示条件筛选 - 功能模拟组件重构提交流程,分离参数校验与提交逻辑 - 增加功能提交前预检查处理机制 - 产品元数据属性新增show字段控制是否显示 - 元数据组件移除调试日志并清理模拟数据代码
This commit is contained in:
parent
4541f97faf
commit
db7bd59c89
|
@ -94,7 +94,7 @@ const loadList = async () => {
|
||||||
const params: any = {
|
const params: any = {
|
||||||
deviceKey: props.deviceInfo.deviceKey,
|
deviceKey: props.deviceInfo.deviceKey,
|
||||||
productKey: props.deviceInfo.productObj.productKey,
|
productKey: props.deviceInfo.productObj.productKey,
|
||||||
fields: selectedEventId.value || undefined,
|
// fields: selectedEventId.value || undefined,
|
||||||
orderType: 2,
|
orderType: 2,
|
||||||
current: pagination.value.current,
|
current: pagination.value.current,
|
||||||
size: pagination.value.pageSize,
|
size: pagination.value.pageSize,
|
||||||
|
|
|
@ -121,12 +121,20 @@ const unsubscribeRealtimeData = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const initRuntime = () => {
|
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,
|
...prop,
|
||||||
value: null,
|
value: null,
|
||||||
timestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
timestamp: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
}));
|
}));
|
||||||
runtimeProperties.value = properties;
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 属性分组选项
|
// 属性分组选项
|
||||||
|
|
|
@ -58,6 +58,8 @@ const selectedRowKeys = ref([]);
|
||||||
// 表单数据
|
// 表单数据
|
||||||
const formData = ref({});
|
const formData = ref({});
|
||||||
|
|
||||||
|
const submitFunctionParameters = ref({});
|
||||||
|
|
||||||
// 预检查弹窗相关
|
// 预检查弹窗相关
|
||||||
const preCheckVisible = ref(false);
|
const preCheckVisible = ref(false);
|
||||||
const preCheckType = ref('');
|
const preCheckType = ref('');
|
||||||
|
@ -307,7 +309,7 @@ const checkPreCheck = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// 执行实际提交
|
// 执行实际提交
|
||||||
const executeSubmit = async (checkValue?: string) => {
|
const submitCheckFormatParams = async () => {
|
||||||
try {
|
try {
|
||||||
let parameters = {};
|
let parameters = {};
|
||||||
|
|
||||||
|
@ -417,13 +419,68 @@ const executeSubmit = async (checkValue?: string) => {
|
||||||
return;
|
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 = {
|
const submitData: any = {
|
||||||
productKey: props.deviceInfo.productObj.productKey,
|
productKey: props.deviceInfo.productObj.productKey,
|
||||||
deviceKey: props.deviceInfo.deviceKey,
|
deviceKey: props.deviceInfo.deviceKey,
|
||||||
funcId: selectedFunctionId.value,
|
funcId: selectedFunctionId.value,
|
||||||
params: parameters,
|
params: submitFunctionParameters.value,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 如果有预检查值,添加到提交数据中
|
// 如果有预检查值,添加到提交数据中
|
||||||
|
@ -456,24 +513,14 @@ const executeSubmit = async (checkValue?: string) => {
|
||||||
// submitResult.value = JSON.stringify(mockResult, null, 2);
|
// submitResult.value = JSON.stringify(mockResult, null, 2);
|
||||||
// message.success('执行成功');
|
// message.success('执行成功');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.errorFields[0].errors[0]) {
|
console.error('提交功能时出错:', error);
|
||||||
message.error(error.errorFields[0].errors[0]);
|
|
||||||
} else {
|
|
||||||
message.error('执行失败');
|
|
||||||
}
|
|
||||||
console.error('执行错误:', error);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 主要的提交函数
|
// 主要的提交函数
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
// 检查是否需要预检查
|
|
||||||
if (checkPreCheck()) {
|
|
||||||
return; // 显示预检查弹窗,等待用户输入
|
|
||||||
}
|
|
||||||
|
|
||||||
// 直接执行提交
|
// 直接执行提交
|
||||||
await executeSubmit();
|
await submitCheckFormatParams();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 预检查确认
|
// 预检查确认
|
||||||
|
@ -482,7 +529,6 @@ const handlePreCheckConfirm = async () => {
|
||||||
await preCheckFormRef.value.validate();
|
await preCheckFormRef.value.validate();
|
||||||
|
|
||||||
let checkValue = '';
|
let checkValue = '';
|
||||||
|
|
||||||
// 根据预检查类型构造checkValue
|
// 根据预检查类型构造checkValue
|
||||||
switch (preCheckType.value) {
|
switch (preCheckType.value) {
|
||||||
case 'staticPassword': {
|
case 'staticPassword': {
|
||||||
|
@ -504,7 +550,7 @@ const handlePreCheckConfirm = async () => {
|
||||||
preCheckVisible.value = false;
|
preCheckVisible.value = false;
|
||||||
|
|
||||||
// 执行实际提交
|
// 执行实际提交
|
||||||
await executeSubmit(checkValue);
|
await submitFunction(checkValue);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('预检查验证失败:', error);
|
console.error('预检查验证失败:', error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import TSLViewer from './metadata/TSLViewer.vue';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
productId: string;
|
productId: string;
|
||||||
productInfo: ProductVO;
|
productInfo: any;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
@ -102,7 +102,6 @@ const handleTSLClose = () => {
|
||||||
|
|
||||||
// 加载物模型数据
|
// 加载物模型数据
|
||||||
const loadMetadata = async () => {
|
const loadMetadata = async () => {
|
||||||
console.log('加载物模型数据');
|
|
||||||
const defaultMetadata = {
|
const defaultMetadata = {
|
||||||
properties: [],
|
properties: [],
|
||||||
functions: [],
|
functions: [],
|
||||||
|
@ -113,96 +112,6 @@ const loadMetadata = async () => {
|
||||||
currentMetadata.value = props.productInfo.metadata
|
currentMetadata.value = props.productInfo.metadata
|
||||||
? JSON.parse(props.productInfo.metadata)
|
? JSON.parse(props.productInfo.metadata)
|
||||||
: JSON.parse(JSON.stringify(defaultMetadata));
|
: 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));
|
originalMetadata.value = JSON.parse(JSON.stringify(currentMetadata.value));
|
||||||
|
|
|
@ -37,6 +37,7 @@ interface PropertyData {
|
||||||
sort: number;
|
sort: number;
|
||||||
description: string;
|
description: string;
|
||||||
required: boolean;
|
required: boolean;
|
||||||
|
show: boolean;
|
||||||
expands: {
|
expands: {
|
||||||
source: string;
|
source: string;
|
||||||
type: string;
|
type: string;
|
||||||
|
@ -146,6 +147,7 @@ const defaultPropertyData: PropertyData = {
|
||||||
sort: 1,
|
sort: 1,
|
||||||
description: '',
|
description: '',
|
||||||
required: false,
|
required: false,
|
||||||
|
show: true,
|
||||||
expands: {
|
expands: {
|
||||||
source: 'device',
|
source: 'device',
|
||||||
type: 'R',
|
type: 'R',
|
||||||
|
@ -539,6 +541,13 @@ watch(
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
|
<!-- 属性特有字段 -->
|
||||||
|
<Col :span="12">
|
||||||
|
<FormItem label="是否显示" name="show">
|
||||||
|
<Switch v-model:checked="formData.show" />
|
||||||
|
</FormItem>
|
||||||
|
</Col>
|
||||||
|
|
||||||
<Col :span="12">
|
<Col :span="12">
|
||||||
<FormItem label="排序" name="sort">
|
<FormItem label="排序" name="sort">
|
||||||
<InputNumber
|
<InputNumber
|
||||||
|
|
Loading…
Reference in New Issue