diff --git a/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue b/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue index 958e91d..a4d0a77 100644 --- a/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue +++ b/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue @@ -52,6 +52,23 @@ const router = useRouter(); const route = useRoute(); const formOptions: VbenFormProps = { 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 = { checkboxConfig: { @@ -71,11 +88,19 @@ const gridOptions: VxeGridProps = { proxyConfig: { ajax: { query: async ({ page }, formValues) => { + // 总是从表单API获取最新的表单值,确保参数完整(分页、刷新时formValues可能不完整) + const currentFormValues = gridApi?.formApi + ? await gridApi.formApi.getValues() + : formValues || {}; + + // 优先使用从表单API获取的值(最新的),如果没有则使用传入的formValues + const finalFormValues = { ...(formValues || {}), ...currentFormValues }; + const { data } = await postDeviceInfoPage({ body: { pageIndex: page.currentPage, pageSize: page.pageSize, - ...formValues, + ...finalFormValues, }, }); return data; @@ -180,12 +205,8 @@ watch( } if (newQuery.ioTPlatformDeviceOpenInfo) { - // 根据平台类型设置对应的产品ID字段 - if (newQuery.ioTPlatform === '2' || newQuery.ioTPlatform === 2) { - filterValues.oneNETProductId = newQuery.ioTPlatformDeviceOpenInfo; - } else if (newQuery.ioTPlatform === '1' || newQuery.ioTPlatform === 1) { - filterValues.ctWingProductId = newQuery.ioTPlatformDeviceOpenInfo; - } + // 设置产品ID字段 + filterValues.ioTPlatformProductId = newQuery.ioTPlatformDeviceOpenInfo; // 同时设置通用字段用于查询 filterValues.ioTPlatformDeviceOpenInfo = newQuery.ioTPlatformDeviceOpenInfo; } @@ -211,22 +232,14 @@ watch( () => gridApi?.formApi?.getValues, (formValues) => { if (formValues) { - const { oneNETProductId, ctWingProductId } = formValues; + const { ioTPlatformProductId } = formValues; - // 如果选择了OneNET产品,设置ioTPlatformDeviceOpenInfo - if (oneNETProductId) { - console.log('检测到OneNET产品选择变化:', oneNETProductId); - gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', oneNETProductId); - console.log('已设置ioTPlatformDeviceOpenInfo为:', oneNETProductId); - } - // 如果选择了CTWing产品,设置ioTPlatformDeviceOpenInfo - else if (ctWingProductId) { - console.log('检测到CTWing产品选择变化:', ctWingProductId); - gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', ctWingProductId); - console.log('已设置ioTPlatformDeviceOpenInfo为:', ctWingProductId); - } - // 如果都没有选择,清空ioTPlatformDeviceOpenInfo - else if (!oneNETProductId && !ctWingProductId) { + // 如果选择了产品,设置ioTPlatformDeviceOpenInfo + if (ioTPlatformProductId) { + console.log('检测到产品选择变化:', ioTPlatformProductId); + gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', ioTPlatformProductId); + console.log('已设置ioTPlatformDeviceOpenInfo为:', ioTPlatformProductId); + } else { console.log('清空产品选择'); gridApi?.formApi?.setFieldValue('ioTPlatformDeviceOpenInfo', ''); } @@ -379,6 +392,12 @@ const [AddForm, addFormApi] = useVbenForm({ showCollapseButton: false, showDefaultActions: false, wrapperClass: 'grid-cols-2', + handleValuesChange: async (values, changedFields) => { + // 当账号切换时,清空产品名称字段 + if (changedFields.includes('ioTPlatformAccountId')) { + await addFormApi.setFieldValue('ioTPlatformProductId', undefined); + } + }, }); const [EditForm, editFormApi] = useVbenForm({ @@ -397,6 +416,12 @@ const [EditForm, editFormApi] = useVbenForm({ showCollapseButton: false, showDefaultActions: false, wrapperClass: 'grid-cols-2', + handleValuesChange: async (values, changedFields) => { + // 当账号切换时,清空产品名称字段 + if (changedFields.includes('ioTPlatformAccountId')) { + await editFormApi.setFieldValue('ioTPlatformProductId', undefined); + } + }, }); const [CommandForm, commandFormApi] = useVbenForm({ @@ -477,6 +502,12 @@ const [BatchAddForm, batchAddFormApi] = useVbenForm({ wrapperClass: 'grid-cols-2', // 添加响应式监听 autoSubmitOnEnter: false, + handleValuesChange: async (values, changedFields) => { + // 当账号切换时,清空产品名称字段 + if (changedFields.includes('ioTPlatformAccountId')) { + await batchAddFormApi.setFieldValue('ioTPlatformProductId', undefined); + } + }, }); const [BatchAddModal, batchAddModalApi] = useVbenModal({ @@ -513,36 +544,13 @@ async function submit() { 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 ? { id: editRow.value.id, - ...processedFormValues, + ...formValues, } : { - ...processedFormValues, + ...formValues, }; try { @@ -574,7 +582,7 @@ async function onEdit(record: any) { editRow.value = record; userModalApi.open(); - // 根据平台类型设置表单值 + // 设置表单值 const formValues = { ...record }; // 确保ioTPlatform是字符串格式,因为ApiSelect组件的valueField是'key' @@ -582,16 +590,6 @@ async function onEdit(record: any) { 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); } @@ -955,15 +953,11 @@ async function submitBatchAdd() { return; } - // 根据平台类型处理数据 - let ioTPlatformProductId = ''; - if (formValues.ioTPlatform === 2 || formValues.ioTPlatform === '2') { - // OneNET平台 - ioTPlatformProductId = formValues.oneNETProductId; - } else if (formValues.ioTPlatform === 1 || formValues.ioTPlatform === '1') { - // CTWing平台 - ioTPlatformProductId = formValues.ctWingProductId; - } + // 获取产品ID(兼容新旧字段名) + const ioTPlatformProductId = + formValues.ioTPlatformProductId || + formValues.oneNETProductId || + formValues.ctWingProductId; if (!ioTPlatformProductId) { Message.error('请选择产品'); diff --git a/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts b/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts index 0de2cbf..dbac096 100644 --- a/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts +++ b/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts @@ -8,11 +8,9 @@ import dayjs from 'dayjs'; import { getCommonGetSelectList, - postCtWingAccountListAsync, - postCtWingProductListAsync, + postAggregationIoTplatformGetIoTplatformAccountInfoAsync, + postAggregationIoTplatformGetIoTplatformProductInfoAsync, postDeviceThingModelManagementFindByPlatformProductIdAsync, - postOneNetAccountListAsync, - postOneNetProductListAsync, } from '#/api-client'; import { $t } from '#/locales'; @@ -61,112 +59,54 @@ export const querySchema = computed(() => [ }, { component: 'ApiSelect', - fieldName: 'oneNETProductId', + fieldName: 'ioTPlatformProductId', label: $t('common.BelongingProductName'), dependencies: { show(values: any) { - const shouldShow = - values.ioTPlatform === 2 || values.ioTPlatform === '2'; - console.log( - 'OneNET产品选择器显示检查 - 平台类型:', - values.ioTPlatform, - '是否显示:', - shouldShow, - ); - return shouldShow; // OneNET平台 + return !!values.ioTPlatform; }, triggerFields: ['ioTPlatform'], }, - componentProps: { - api: postOneNetProductListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', - immediate: true, - afterFetch: (res: any) => { - console.log('OneNET产品选择器afterFetch调用 - 响应:', res); - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; - // 确保返回的是数组格式 - let items = []; - if (Array.isArray(data)) { - items = data; - } else if (data && Array.isArray(data.items)) { - items = data.items; - } else if (data && Array.isArray(data.data)) { - items = data.data; + return { + api: platform + ? postAggregationIoTplatformGetIoTplatformProductInfoAsync + : null, + params: platform + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + }, + } + : {}, + labelField: 'productName', + valueField: 'ioTPlatformProductId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + $t('common.BelongingProductName'), + afterFetch: (res: any) => { + if (Array.isArray(res)) { + return res; } - - console.log('OneNET产品列表处理后的数据:', items); - return items; - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('common.BelongingProductName')}`, - }, - }, - { - component: 'ApiSelect', - fieldName: 'ctWingProductId', - label: $t('common.BelongingProductName'), - dependencies: { - show(values: any) { - const shouldShow = - values.ioTPlatform === 1 || values.ioTPlatform === '1'; - console.log( - 'CTWing产品选择器显示检查 - 平台类型:', - values.ioTPlatform, - '是否显示:', - shouldShow, - ); - return shouldShow; // CTWing平台 - }, - triggerFields: ['ioTPlatform'], - }, - componentProps: { - api: postCtWingProductListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', - immediate: true, - afterFetch: (res: any) => { - console.log('CTWing产品选择器afterFetch调用 - 响应:', res); - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - let items = []; - if (Array.isArray(data)) { - items = data; - } else if (data && Array.isArray(data.items)) { - items = data.items; - } else if (data && Array.isArray(data.data)) { - items = data.data; + if (res && Array.isArray(res.items)) { + return res.items; } - - console.log('CTWing产品列表处理后的数据:', items); - return items; - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('common.BelongingProductName')}`, + if (res && Array.isArray(res.data)) { + return res.data; + } + if (res && res.data && Array.isArray(res.data.items)) { + return res.data.items; + } + return []; + }, + }; }, }, ]); @@ -308,233 +248,126 @@ export const addDeviceFormSchema: any = computed(() => [ }, { component: 'ApiSelect', - fieldName: 'oneNETAccountId', + fieldName: 'ioTPlatformAccountId', label: $t('abp.deviceInfos.ioTPlatformAccountName'), dependencies: { show(values: any) { - return values.ioTPlatform === 2 || values.ioTPlatform === '2'; // OneNET平台 + return !!values.ioTPlatform; }, rules(values: any) { - if (values.ioTPlatform === 2 || values.ioTPlatform === '2') { + if (values.ioTPlatform) { return 'required'; } return null; }, triggerFields: ['ioTPlatform'], }, - componentProps: { - api: postOneNetAccountListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + + return { + api: platform + ? postAggregationIoTplatformGetIoTplatformAccountInfoAsync + : null, + params: platform + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + }, + } + : {}, + labelField: 'ioTPlatformPhoneNumber', + valueField: 'ioTPlatformAccountId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + + $t('abp.deviceInfos.ioTPlatformAccountName'), + afterFetch: (res: any) => { + let items: any[] = []; + if (Array.isArray(res)) { + items = res; + } else if (res && Array.isArray(res.items)) { + items = res.items; + } else if (res && Array.isArray(res.data)) { + items = res.data; + } else if (res && res.data && Array.isArray(res.data.items)) { + items = res.data.items; + } + // 将 ioTPlatformAccount 映射到 ioTPlatformAccountId,以便表单字段名保持一致 + return items.map((item: any) => ({ + ...item, + ioTPlatformAccountId: item.ioTPlatformAccount, + label: item.ioTPlatformPhoneNumber || item.ioTPlatformAccount || '', + })); }, - }, - labelField: 'accountName', - valueField: 'oneNETAccountId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - if (Array.isArray(data)) { - return data; - } - // 如果是包装在 items 中的,提取出来 - if (data && Array.isArray(data.items)) { - return data.items; - } - // 如果是包装在 data 中的,提取出来 - if (data && Array.isArray(data.data)) { - return data.data; - } - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformAccountName')}`, + }; }, rules: z.string().optional(), }, { component: 'ApiSelect', - fieldName: 'ctWingAccountId', - label: $t('abp.deviceInfos.ioTPlatformAccountName'), - dependencies: { - show(values: any) { - return values.ioTPlatform === 1 || values.ioTPlatform === '1'; // CTWing平台 - }, - rules(values: any) { - if (values.ioTPlatform === 1 || values.ioTPlatform === '1') { - return 'required'; - } - return null; - }, - triggerFields: ['ioTPlatform'], // 添加这一行,使其能够响应平台切换 - }, - componentProps: { - api: postCtWingAccountListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'accountName', - valueField: 'accountId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - if (Array.isArray(data)) { - return data; - } - // 如果是包装在 items 中的,提取出来 - if (data && Array.isArray(data.items)) { - return data.items; - } - // 如果是包装在 data 中的,提取出来 - if (data && Array.isArray(data.data)) { - return data.data; - } - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformAccountName')}`, - }, - rules: z.string().optional(), - }, - { - component: 'ApiSelect', - fieldName: 'oneNETProductId', + fieldName: 'ioTPlatformProductId', label: $t('abp.deviceInfos.ioTPlatformProductName'), dependencies: { show(values: any) { - return ( - (values.ioTPlatform === 2 || values.ioTPlatform === '2') && - values.oneNETAccountId - ); // OneNET平台且已选择账号 + return !!values.ioTPlatform && !!values.ioTPlatformAccountId; }, rules(values: any) { - if ( - (values.ioTPlatform === 2 || values.ioTPlatform === '2') && - values.oneNETAccountId - ) { + if (values.ioTPlatform && values.ioTPlatformAccountId) { return 'required'; } return null; }, - triggerFields: ['ioTPlatform', 'oneNETAccountId'], + triggerFields: ['ioTPlatform', 'ioTPlatformAccountId'], }, - componentProps: (formValues: any) => ({ - api: postOneNetProductListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - oneNETAccountId: formValues?.oneNETAccountId, - }, - }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + const accountId = formValues?.ioTPlatformAccountId; - // 确保返回的是数组格式 - let items = []; - if (Array.isArray(data)) { - items = data; - } else if (data && Array.isArray(data.items)) { - items = data.items; - } else if (data && Array.isArray(data.data)) { - items = data.data; + return { + api: platform && accountId + ? postAggregationIoTplatformGetIoTplatformProductInfoAsync + : null, + params: platform && accountId + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + ioTPlatformAccount: accountId, + }, + } + : {}, + labelField: 'productName', + valueField: 'ioTPlatformProductId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + + $t('abp.deviceInfos.ioTPlatformProductName'), + afterFetch: (res: any) => { + if (Array.isArray(res)) { + return res; } - - // 为每个产品项添加组合标签 - return items.map((item: any) => ({ - ...item, - label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, - })); - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`, - rules: z.string().optional(), - }), - }, - { - component: 'ApiSelect', - fieldName: 'ctWingProductId', - label: $t('abp.deviceInfos.ioTPlatformProductName'), - dependencies: { - show(values: any) { - return ( - (values.ioTPlatform === 1 || values.ioTPlatform === '1') && - values.ctWingAccountId - ); // CTWing平台且已选择账号 - }, - rules(values: any) { - if ( - (values.ioTPlatform === 1 || values.ioTPlatform === '1') && - values.ctWingAccountId - ) { - return 'required'; - } - return null; - }, - triggerFields: ['ioTPlatform', 'ctWingAccountId'], - }, - componentProps: { - api: postCtWingProductListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - let items = []; - if (Array.isArray(data)) { - items = data; - } else if (data && Array.isArray(data.items)) { - items = data.items; - } else if (data && Array.isArray(data.data)) { - items = data.data; + if (res && Array.isArray(res.items)) { + return res.items; } - - // 为每个产品项添加组合标签,并确保产品ID是字符串类型 - return items.map((item: any) => ({ - ...item, - ioTPlatformProductId: String(item.ioTPlatformProductId || ''), - label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, - })); - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`, + if (res && Array.isArray(res.data)) { + return res.data; + } + if (res && res.data && Array.isArray(res.data.items)) { + return res.data.items; + } + return []; + }, + }; }, rules: z.string().optional(), }, @@ -671,232 +504,126 @@ export const editDeviceFormSchemaEdit: any = computed(() => [ }, { component: 'ApiSelect', - fieldName: 'oneNETAccountId', + fieldName: 'ioTPlatformAccountId', label: $t('abp.deviceInfos.ioTPlatformAccountName'), dependencies: { show(values: any) { - return values.ioTPlatform === 2 || values.ioTPlatform === '2'; // OneNET平台 + return !!values.ioTPlatform; }, rules(values: any) { - if (values.ioTPlatform === 2 || values.ioTPlatform === '2') { + if (values.ioTPlatform) { return 'required'; } return null; }, triggerFields: ['ioTPlatform'], }, - componentProps: { - api: postOneNetAccountListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + + return { + api: platform + ? postAggregationIoTplatformGetIoTplatformAccountInfoAsync + : null, + params: platform + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + }, + } + : {}, + labelField: 'ioTPlatformPhoneNumber', + valueField: 'ioTPlatformAccountId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + + $t('abp.deviceInfos.ioTPlatformAccountName'), + afterFetch: (res: any) => { + let items: any[] = []; + if (Array.isArray(res)) { + items = res; + } else if (res && Array.isArray(res.items)) { + items = res.items; + } else if (res && Array.isArray(res.data)) { + items = res.data; + } else if (res && res.data && Array.isArray(res.data.items)) { + items = res.data.items; + } + // 将 ioTPlatformAccount 映射到 ioTPlatformAccountId,以便表单字段名保持一致 + return items.map((item: any) => ({ + ...item, + ioTPlatformAccountId: item.ioTPlatformAccount, + label: item.ioTPlatformPhoneNumber || item.ioTPlatformAccount || '', + })); }, - }, - labelField: 'accountName', - valueField: 'oneNETAccountId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - if (Array.isArray(data)) { - return data; - } - // 如果是包装在 items 中的,提取出来 - if (data && Array.isArray(data.items)) { - return data.items; - } - // 如果是包装在 data 中的,提取出来 - if (data && Array.isArray(data.data)) { - return data.data; - } - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformAccountName')}`, + }; }, rules: z.string().optional(), }, { component: 'ApiSelect', - fieldName: 'ctWingAccountId', - label: $t('abp.deviceInfos.ioTPlatformAccountName'), - dependencies: { - show(values: any) { - return values.ioTPlatform === 1 || values.ioTPlatform === '1'; // CTWing平台 - }, - rules(values: any) { - if (values.ioTPlatform === 1 || values.ioTPlatform === '1') { - return 'required'; - } - return null; - }, - triggerFields: ['ioTPlatform'], - }, - componentProps: { - api: postCtWingAccountListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'accountName', - valueField: 'ctWingAccountId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - if (Array.isArray(data)) { - return data; - } - // 如果是包装在 items 中的,提取出来 - if (data && Array.isArray(data.items)) { - return data.items; - } - // 如果是包装在 data 中的,提取出来 - if (data && Array.isArray(data.data)) { - return data.data; - } - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformAccountName')}`, - }, - rules: z.string().optional(), - }, - { - component: 'ApiSelect', - fieldName: 'oneNETProductId', + fieldName: 'ioTPlatformProductId', label: $t('abp.deviceInfos.ioTPlatformProductName'), dependencies: { show(values: any) { - return ( - (values.ioTPlatform === 2 || values.ioTPlatform === '2') && - values.oneNETAccountId - ); // OneNET平台且已选择账号 + return !!values.ioTPlatform && !!values.ioTPlatformAccountId; }, rules(values: any) { - if ( - (values.ioTPlatform === 2 || values.ioTPlatform === '2') && - values.oneNETAccountId - ) { + if (values.ioTPlatform && values.ioTPlatformAccountId) { return 'required'; } return null; }, - triggerFields: ['ioTPlatform', 'oneNETAccountId'], + triggerFields: ['ioTPlatform', 'ioTPlatformAccountId'], }, - componentProps: { - api: postOneNetProductListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + const accountId = formValues?.ioTPlatformAccountId; - // 确保返回的是数组格式 - let items = []; - if (Array.isArray(data)) { - items = data; - } else if (data && Array.isArray(data.items)) { - items = data.items; - } else if (data && Array.isArray(data.data)) { - items = data.data; + return { + api: platform && accountId + ? postAggregationIoTplatformGetIoTplatformProductInfoAsync + : null, + params: platform && accountId + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + ioTPlatformAccount: accountId, + }, + } + : {}, + labelField: 'productName', + valueField: 'ioTPlatformProductId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + + $t('abp.deviceInfos.ioTPlatformProductName'), + afterFetch: (res: any) => { + if (Array.isArray(res)) { + return res; } - - // 为每个产品项添加组合标签 - return items.map((item: any) => ({ - ...item, - label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, - })); - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`, - }, - rules: z.string().optional(), - }, - { - component: 'ApiSelect', - fieldName: 'ctWingProductId', - label: $t('abp.deviceInfos.ioTPlatformProductName'), - dependencies: { - show(values: any) { - return ( - (values.ioTPlatform === 1 || values.ioTPlatform === '1') && - values.ctWingAccountId - ); // CTWing平台且已选择账号 - }, - rules(values: any) { - if ( - (values.ioTPlatform === 1 || values.ioTPlatform === '1') && - values.ctWingAccountId - ) { - return 'required'; - } - return null; - }, - triggerFields: ['ioTPlatform', 'ctWingAccountId'], - }, - componentProps: { - api: postCtWingProductListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - let items = []; - if (Array.isArray(data)) { - items = data; - } else if (data && Array.isArray(data.items)) { - items = data.items; - } else if (data && Array.isArray(data.data)) { - items = data.data; + if (res && Array.isArray(res.items)) { + return res.items; } - - // 为每个产品项添加组合标签,并确保产品ID是字符串类型 - return items.map((item: any) => ({ - ...item, - ioTPlatformProductId: String(item.ioTPlatformProductId || ''), - label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, - })); - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`, + if (res && Array.isArray(res.data)) { + return res.data; + } + if (res && res.data && Array.isArray(res.data.items)) { + return res.data.items; + } + return []; + }, + }; }, rules: z.string().optional(), }, @@ -975,232 +702,126 @@ export const batchAddDeviceFormSchema: any = computed(() => [ }, { component: 'ApiSelect', - fieldName: 'oneNETAccountId', + fieldName: 'ioTPlatformAccountId', label: $t('abp.deviceInfos.ioTPlatformAccountName'), dependencies: { show(values: any) { - return values.ioTPlatform === 2 || values.ioTPlatform === '2'; // OneNET平台 + return !!values.ioTPlatform; }, rules(values: any) { - if (values.ioTPlatform === 2 || values.ioTPlatform === '2') { + if (values.ioTPlatform) { return 'required'; } return null; }, triggerFields: ['ioTPlatform'], }, - componentProps: { - api: postOneNetAccountListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + + return { + api: platform + ? postAggregationIoTplatformGetIoTplatformAccountInfoAsync + : null, + params: platform + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + }, + } + : {}, + labelField: 'ioTPlatformPhoneNumber', + valueField: 'ioTPlatformAccountId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + + $t('abp.deviceInfos.ioTPlatformAccountName'), + afterFetch: (res: any) => { + let items: any[] = []; + if (Array.isArray(res)) { + items = res; + } else if (res && Array.isArray(res.items)) { + items = res.items; + } else if (res && Array.isArray(res.data)) { + items = res.data; + } else if (res && res.data && Array.isArray(res.data.items)) { + items = res.data.items; + } + // 将 ioTPlatformAccount 映射到 ioTPlatformAccountId,以便表单字段名保持一致 + return items.map((item: any) => ({ + ...item, + ioTPlatformAccountId: item.ioTPlatformAccount, + label: item.ioTPlatformPhoneNumber || item.ioTPlatformAccount || '', + })); }, - }, - labelField: 'accountName', - valueField: 'oneNETAccountId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - if (Array.isArray(data)) { - return data; - } - // 如果是包装在 items 中的,提取出来 - if (data && Array.isArray(data.items)) { - return data.items; - } - // 如果是包装在 data 中的,提取出来 - if (data && Array.isArray(data.data)) { - return data.data; - } - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformAccountName')}`, + }; }, rules: z.string().optional(), }, { component: 'ApiSelect', - fieldName: 'ctWingAccountId', - label: $t('abp.deviceInfos.ioTPlatformAccountName'), - dependencies: { - show(values: any) { - return values.ioTPlatform === 1 || values.ioTPlatform === '1'; // CTWing平台 - }, - rules(values: any) { - if (values.ioTPlatform === 1 || values.ioTPlatform === '1') { - return 'required'; - } - return null; - }, - triggerFields: ['ioTPlatform'], // 添加这一行,使其能够响应平台切换 - }, - componentProps: { - api: postCtWingAccountListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'accountName', - valueField: 'accountId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - if (Array.isArray(data)) { - return data; - } - // 如果是包装在 items 中的,提取出来 - if (data && Array.isArray(data.items)) { - return data.items; - } - // 如果是包装在 data 中的,提取出来 - if (data && Array.isArray(data.data)) { - return data.data; - } - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformAccountName')}`, - }, - rules: z.string().optional(), - }, - { - component: 'ApiSelect', - fieldName: 'oneNETProductId', + fieldName: 'ioTPlatformProductId', label: $t('abp.deviceInfos.ioTPlatformProductName'), dependencies: { show(values: any) { - return ( - (values.ioTPlatform === 2 || values.ioTPlatform === '2') && - values.oneNETAccountId - ); // OneNET平台且已选择账号 + return !!values.ioTPlatform && !!values.ioTPlatformAccountId; }, rules(values: any) { - if ( - (values.ioTPlatform === 2 || values.ioTPlatform === '2') && - values.oneNETAccountId - ) { + if (values.ioTPlatform && values.ioTPlatformAccountId) { return 'required'; } return null; }, - triggerFields: ['ioTPlatform', 'oneNETAccountId'], + triggerFields: ['ioTPlatform', 'ioTPlatformAccountId'], }, - componentProps: { - api: postOneNetProductListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; + componentProps: (formValues: any) => { + const platform = formValues?.ioTPlatform; + const accountId = formValues?.ioTPlatformAccountId; - // 确保返回的是数组格式 - let items = []; - if (Array.isArray(data)) { - items = data; - } else if (data && Array.isArray(data.items)) { - items = data.items; - } else if (data && Array.isArray(data.data)) { - items = data.data; + return { + api: platform && accountId + ? postAggregationIoTplatformGetIoTplatformProductInfoAsync + : null, + params: platform && accountId + ? { + body: { + ioTPlatformType: + typeof platform === 'string' + ? Number.parseInt(platform) + : platform, + ioTPlatformAccount: accountId, + }, + } + : {}, + labelField: 'productName', + valueField: 'ioTPlatformProductId', + optionsPropName: 'options', + immediate: false, + allowClear: true, + placeholder: + $t('common.pleaseSelect') + + $t('abp.deviceInfos.ioTPlatformProductName'), + afterFetch: (res: any) => { + if (Array.isArray(res)) { + return res; } - - // 为每个产品项添加组合标签 - return items.map((item: any) => ({ - ...item, - label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, - })); - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`, - }, - rules: z.string().optional(), - }, - { - component: 'ApiSelect', - fieldName: 'ctWingProductId', - label: $t('abp.deviceInfos.ioTPlatformProductName'), - dependencies: { - show(values: any) { - return ( - (values.ioTPlatform === 1 || values.ioTPlatform === '1') && - values.ctWingAccountId - ); // CTWing平台且已选择账号 - }, - rules(values: any) { - if ( - (values.ioTPlatform === 1 || values.ioTPlatform === '1') && - values.ctWingAccountId - ) { - return 'required'; - } - return null; - }, - triggerFields: ['ioTPlatform', 'ctWingAccountId'], - }, - componentProps: { - api: postCtWingProductListAsync, - params: { - body: { - pageIndex: 1, - pageSize: 1000, - }, - }, - labelField: 'productName', - valueField: 'ioTPlatformProductId', - immediate: true, - afterFetch: (res: any) => { - // 如果是 Axios 响应对象,提取 data - if (res && res.data) { - const data = res.data; - - // 确保返回的是数组格式 - let items = []; - if (Array.isArray(data)) { - items = data; - } else if (data && Array.isArray(data.items)) { - items = data.items; - } else if (data && Array.isArray(data.data)) { - items = data.data; + if (res && Array.isArray(res.items)) { + return res.items; } - - // 为每个产品项添加组合标签,并确保产品ID是字符串类型 - return items.map((item: any) => ({ - ...item, - ioTPlatformProductId: String(item.ioTPlatformProductId || ''), - label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, - })); - } - - // 如果都不是,返回空数组 - return []; - }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`, + if (res && Array.isArray(res.data)) { + return res.data; + } + if (res && res.data && Array.isArray(res.data.items)) { + return res.data.items; + } + return []; + }, + }; }, rules: z.string().optional(), },