重构设备管理新增逻辑

This commit is contained in:
ChenYi 2025-12-23 10:45:49 +08:00
parent eb12d8f38a
commit 0ffc2a3098
2 changed files with 372 additions and 757 deletions

View File

@ -52,6 +52,23 @@ const router = useRouter();
const route = useRoute(); const route = useRoute();
const formOptions: VbenFormProps = { const formOptions: VbenFormProps = {
schema: querySchema.value, schema: querySchema.value,
submitOnChange: false,
handleValuesChange: async (values, changedFields) => {
//
if (changedFields.includes('ioTPlatformProductId')) {
//
await nextTick();
if (gridApi?.reload && gridApi?.formApi) {
try {
// reload
const latestValues = await gridApi.formApi.getValues();
await gridApi.reload(latestValues);
} catch (error) {
console.error('重新加载数据时出错:', error);
}
}
}
},
}; };
const gridOptions: VxeGridProps<any> = { const gridOptions: VxeGridProps<any> = {
checkboxConfig: { checkboxConfig: {
@ -71,11 +88,19 @@ const gridOptions: VxeGridProps<any> = {
proxyConfig: { proxyConfig: {
ajax: { ajax: {
query: async ({ page }, formValues) => { query: async ({ page }, formValues) => {
// APIformValues
const currentFormValues = gridApi?.formApi
? await gridApi.formApi.getValues()
: formValues || {};
// 使API使formValues
const finalFormValues = { ...(formValues || {}), ...currentFormValues };
const { data } = await postDeviceInfoPage({ const { data } = await postDeviceInfoPage({
body: { body: {
pageIndex: page.currentPage, pageIndex: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
...formValues, ...finalFormValues,
}, },
}); });
return data; return data;
@ -180,12 +205,8 @@ watch(
} }
if (newQuery.ioTPlatformDeviceOpenInfo) { if (newQuery.ioTPlatformDeviceOpenInfo) {
// ID // ID
if (newQuery.ioTPlatform === '2' || newQuery.ioTPlatform === 2) { filterValues.ioTPlatformProductId = newQuery.ioTPlatformDeviceOpenInfo;
filterValues.oneNETProductId = newQuery.ioTPlatformDeviceOpenInfo;
} else if (newQuery.ioTPlatform === '1' || newQuery.ioTPlatform === 1) {
filterValues.ctWingProductId = newQuery.ioTPlatformDeviceOpenInfo;
}
// //
filterValues.ioTPlatformDeviceOpenInfo = newQuery.ioTPlatformDeviceOpenInfo; filterValues.ioTPlatformDeviceOpenInfo = newQuery.ioTPlatformDeviceOpenInfo;
} }
@ -211,22 +232,14 @@ watch(
() => gridApi?.formApi?.getValues, () => gridApi?.formApi?.getValues,
(formValues) => { (formValues) => {
if (formValues) { if (formValues) {
const { oneNETProductId, ctWingProductId } = formValues; const { ioTPlatformProductId } = formValues;
// OneNETioTPlatformDeviceOpenInfo // ioTPlatformDeviceOpenInfo
if (oneNETProductId) { if (ioTPlatformProductId) {
console.log('检测到OneNET产品选择变化:', oneNETProductId); console.log('检测到产品选择变化:', ioTPlatformProductId);
gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', oneNETProductId); gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', ioTPlatformProductId);
console.log('已设置ioTPlatformDeviceOpenInfo为:', oneNETProductId); console.log('已设置ioTPlatformDeviceOpenInfo为:', ioTPlatformProductId);
} } else {
// CTWingioTPlatformDeviceOpenInfo
else if (ctWingProductId) {
console.log('检测到CTWing产品选择变化:', ctWingProductId);
gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', ctWingProductId);
console.log('已设置ioTPlatformDeviceOpenInfo为:', ctWingProductId);
}
// ioTPlatformDeviceOpenInfo
else if (!oneNETProductId && !ctWingProductId) {
console.log('清空产品选择'); console.log('清空产品选择');
gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', ''); gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', '');
} }
@ -379,6 +392,12 @@ const [AddForm, addFormApi] = useVbenForm({
showCollapseButton: false, showCollapseButton: false,
showDefaultActions: false, showDefaultActions: false,
wrapperClass: 'grid-cols-2', wrapperClass: 'grid-cols-2',
handleValuesChange: async (values, changedFields) => {
//
if (changedFields.includes('ioTPlatformAccountId')) {
await addFormApi.setFieldValue('ioTPlatformProductId', undefined);
}
},
}); });
const [EditForm, editFormApi] = useVbenForm({ const [EditForm, editFormApi] = useVbenForm({
@ -397,6 +416,12 @@ const [EditForm, editFormApi] = useVbenForm({
showCollapseButton: false, showCollapseButton: false,
showDefaultActions: false, showDefaultActions: false,
wrapperClass: 'grid-cols-2', wrapperClass: 'grid-cols-2',
handleValuesChange: async (values, changedFields) => {
//
if (changedFields.includes('ioTPlatformAccountId')) {
await editFormApi.setFieldValue('ioTPlatformProductId', undefined);
}
},
}); });
const [CommandForm, commandFormApi] = useVbenForm({ const [CommandForm, commandFormApi] = useVbenForm({
@ -477,6 +502,12 @@ const [BatchAddForm, batchAddFormApi] = useVbenForm({
wrapperClass: 'grid-cols-2', wrapperClass: 'grid-cols-2',
// //
autoSubmitOnEnter: false, autoSubmitOnEnter: false,
handleValuesChange: async (values, changedFields) => {
//
if (changedFields.includes('ioTPlatformAccountId')) {
await batchAddFormApi.setFieldValue('ioTPlatformProductId', undefined);
}
},
}); });
const [BatchAddModal, batchAddModalApi] = useVbenModal({ const [BatchAddModal, batchAddModalApi] = useVbenModal({
@ -513,36 +544,13 @@ async function submit() {
const formValues = await formApi.getValues(); const formValues = await formApi.getValues();
//
const processedFormValues = { ...formValues };
if (formValues.ioTPlatform === 2 || formValues.ioTPlatform === '2') {
// OneNET
processedFormValues.ioTPlatformAccountId = formValues.oneNETAccountId;
processedFormValues.ioTPlatformProductId = formValues.oneNETProductId;
//
delete processedFormValues.oneNETAccountId;
delete processedFormValues.oneNETProductId;
delete processedFormValues.ctWingAccountId;
delete processedFormValues.ctWingProductId;
} else if (formValues.ioTPlatform === 1 || formValues.ioTPlatform === '1') {
// CTWing
processedFormValues.ioTPlatformAccountId = formValues.ctWingAccountId;
processedFormValues.ioTPlatformProductId = formValues.ctWingProductId;
//
delete processedFormValues.ctWingAccountId;
delete processedFormValues.ctWingProductId;
delete processedFormValues.oneNETAccountId;
delete processedFormValues.oneNETProductId;
}
const fetchParams: any = isEdit const fetchParams: any = isEdit
? { ? {
id: editRow.value.id, id: editRow.value.id,
...processedFormValues, ...formValues,
} }
: { : {
...processedFormValues, ...formValues,
}; };
try { try {
@ -574,7 +582,7 @@ async function onEdit(record: any) {
editRow.value = record; editRow.value = record;
userModalApi.open(); userModalApi.open();
// //
const formValues = { ...record }; const formValues = { ...record };
// ioTPlatformApiSelectvalueField'key' // ioTPlatformApiSelectvalueField'key'
@ -582,16 +590,6 @@ async function onEdit(record: any) {
formValues.ioTPlatform = String(formValues.ioTPlatform); formValues.ioTPlatform = String(formValues.ioTPlatform);
} }
if (record.ioTPlatform === 2 || record.ioTPlatform === '2') {
// OneNET
formValues.oneNETAccountId = record.ioTPlatformAccountId;
formValues.oneNETProductId = record.ioTPlatformProductId;
} else if (record.ioTPlatform === 1 || record.ioTPlatform === '1') {
// CTWing
formValues.ctWingAccountId = record.ioTPlatformAccountId;
formValues.ctWingProductId = record.ioTPlatformProductId;
}
editFormApi.setValues(formValues); editFormApi.setValues(formValues);
} }
@ -955,15 +953,11 @@ async function submitBatchAdd() {
return; return;
} }
// // ID
let ioTPlatformProductId = ''; const ioTPlatformProductId =
if (formValues.ioTPlatform === 2 || formValues.ioTPlatform === '2') { formValues.ioTPlatformProductId ||
// OneNET formValues.oneNETProductId ||
ioTPlatformProductId = formValues.oneNETProductId; formValues.ctWingProductId;
} else if (formValues.ioTPlatform === 1 || formValues.ioTPlatform === '1') {
// CTWing
ioTPlatformProductId = formValues.ctWingProductId;
}
if (!ioTPlatformProductId) { if (!ioTPlatformProductId) {
Message.error('请选择产品'); Message.error('请选择产品');

File diff suppressed because it is too large Load Diff