diff --git a/apps/web-antd/src/locales/langs/en-US/abp.json b/apps/web-antd/src/locales/langs/en-US/abp.json index b480f81..47510c9 100644 --- a/apps/web-antd/src/locales/langs/en-US/abp.json +++ b/apps/web-antd/src/locales/langs/en-US/abp.json @@ -264,7 +264,6 @@ "OneNETManagement": { "AccountName": "AccountName", "PhoneNumber": "PhoneNumber", - "BelongingAccountName": "BelongingAccountName", "AccountAccesskey": "AccountAccesskey", "ProductCount": "ProductCount", "OneNETAccountId": "OneNETAccountId", @@ -273,7 +272,6 @@ "ProductName": "ProductName", "ProductAccesskey": "ProductAccesskey", "IsEncrypted": "IsEncrypted", - "BelongingProductName": "Belonging ProductName", "CommunicationAddress": "Communication Address", "CommunicationAddressTLS": "TLS Communication Address", "DeviceThingModelFileName": "DeviceThingModelFileName", @@ -285,16 +283,15 @@ "CTWingManagement": { "AccountName": "AccountName", "PhoneNumber": "PhoneNumber", - "BelongingAccountName": "BelongingAccountName", "AccountAccesskey": "AccountAccesskey", "ProductCount": "ProductCount", "CTWingAccountId": "CTWingAccountId", "CTWingProductId": "CTWingProductId", "IoTPlatformProductId": "IoTPlatformProductId", "ProductName": "ProductName", - "ProductAccesskey": "ProductAccesskey", + "FeatureAccesskey": "FeatureAccesskey", + "MasterKey": "MasterKey", "IsEncrypted": "IsEncrypted", - "BelongingProductName": "Belonging ProductName", "CommunicationAddress": "Communication Address", "CommunicationAddressTLS": "TLS Communication Address", "DeviceThingModelFileName": "DeviceThingModelFileName", diff --git a/apps/web-antd/src/locales/langs/en-US/common.json b/apps/web-antd/src/locales/langs/en-US/common.json index e7a15b3..fe10ee3 100644 --- a/apps/web-antd/src/locales/langs/en-US/common.json +++ b/apps/web-antd/src/locales/langs/en-US/common.json @@ -57,5 +57,10 @@ "IoTPlatform": "IoTPlatform", "note": "note", "creationTime": "CreationTime", - "lastModificationTime": "LastModificationTime" + "lastModificationTime": "LastModificationTime", + "BelongingProductName": "Belonging ProductName", + "BelongingAccountName": "BelongingAccountName", + "AppId": "AppId", + "AppKey": "AppKey", + "AppSecret": "AppSecret" } diff --git a/apps/web-antd/src/locales/langs/zh-CN/abp.json b/apps/web-antd/src/locales/langs/zh-CN/abp.json index 4ef19f8..0e8dd1f 100644 --- a/apps/web-antd/src/locales/langs/zh-CN/abp.json +++ b/apps/web-antd/src/locales/langs/zh-CN/abp.json @@ -265,7 +265,6 @@ }, "OneNETManagement": { "AccountName": "账号名称", - "BelongingAccountName": "所属账号", "PhoneNumber": "手机号码", "AccountAccesskey": "账户通信密钥", "ProductCount": "产品数量", @@ -275,7 +274,6 @@ "ProductName": "产品名称", "ProductAccesskey": "产品密钥", "IsEncrypted": "是否加密", - "BelongingProductName": "所属产品", "CommunicationAddress": "通讯地址", "CommunicationAddressTLS": "TLS通讯地址", "DeviceThingModelFileName": "物模型文件", @@ -286,7 +284,6 @@ }, "CTWingManagement": { "AccountName": "账号名称", - "BelongingAccountName": "所属账号", "PhoneNumber": "手机号码", "AccountAccesskey": "账户通信密钥", "ProductCount": "产品数量", @@ -294,9 +291,9 @@ "CTWingProductId": "CTWing产品Id", "IoTPlatformProductId": "物联网平台对应的产品Id", "ProductName": "产品名称", - "ProductAccesskey": "产品密钥", + "FeatureAccesskey": "设备访问密钥", + "MasterKey": "通信主密钥", "IsEncrypted": "是否加密", - "BelongingProductName": "所属产品", "CommunicationAddress": "通讯地址", "CommunicationAddressTLS": "TLS通讯地址", "DeviceThingModelFileName": "物模型文件", diff --git a/apps/web-antd/src/locales/langs/zh-CN/common.json b/apps/web-antd/src/locales/langs/zh-CN/common.json index ad7bf75..936ae3c 100644 --- a/apps/web-antd/src/locales/langs/zh-CN/common.json +++ b/apps/web-antd/src/locales/langs/zh-CN/common.json @@ -58,5 +58,10 @@ "IoTPlatform": "物联网平台", "note": "备注", "creationTime": "创建时间", - "lastModificationTime": "最后更新时间" + "lastModificationTime": "最后更新时间", + "BelongingProductName": "所属产品", + "BelongingAccountName": "所属账号", + "AppId": "应用Id", + "AppKey": "应用Key", + "AppSecret": "应用Secret" } diff --git a/apps/web-antd/src/views/ctwingmanagement/account/schema.ts b/apps/web-antd/src/views/ctwingmanagement/account/schema.ts index 814cf4e..a388222 100644 --- a/apps/web-antd/src/views/ctwingmanagement/account/schema.ts +++ b/apps/web-antd/src/views/ctwingmanagement/account/schema.ts @@ -17,7 +17,7 @@ export const querySchema = computed(() => [ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ { title: $t('common.seq'), type: 'seq', width: 50 }, { - field: 'ctWingAccountId', + field: 'accountId', title: $t('abp.CTWingManagement.CTWingAccountId'), minWidth: '150', }, @@ -32,8 +32,18 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ minWidth: '150', }, { - field: 'accountAccesskey', - title: $t('abp.CTWingManagement.AccountAccesskey'), + field: 'appId', + title: $t('common.AppId'), + minWidth: '150', + }, + { + field: 'appKey', + title: $t('common.AppKey'), + minWidth: '150', + }, + { + field: 'appSecret', + title: $t('common.AppSecret'), minWidth: '150', }, { diff --git a/apps/web-antd/src/views/ctwingmanagement/privateProduct/schema.ts b/apps/web-antd/src/views/ctwingmanagement/privateProduct/schema.ts index 9475ade..cad83ff 100644 --- a/apps/web-antd/src/views/ctwingmanagement/privateProduct/schema.ts +++ b/apps/web-antd/src/views/ctwingmanagement/privateProduct/schema.ts @@ -19,7 +19,7 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ { title: $t('common.seq'), type: 'seq', width: 50 }, { field: 'ctWingAccountName', - title: $t('abp.CTWingManagement.BelongingAccountName'), + title: $t('common.BelongingAccountName'), minWidth: '150', }, { @@ -33,8 +33,13 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ minWidth: '150', }, { - field: 'productAccesskey', - title: $t('abp.CTWingManagement.ProductAccesskey'), + field: 'masterKey', + title: $t('abp.CTWingManagement.MasterKey'), + minWidth: '150', + }, + { + field: 'featureAccesskey', + title: $t('abp.CTWingManagement.FeatureAccesskey'), minWidth: '150', }, { @@ -42,55 +47,12 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ title: $t('abp.CTWingManagement.CommunicationAddress'), minWidth: '150', }, - { - field: 'communicationAddressTLS', - title: $t('abp.CTWingManagement.CommunicationAddressTLS'), - minWidth: '150', - }, { field: 'deviceThingModelFileName', title: $t('abp.CTWingManagement.DeviceThingModelFileName'), minWidth: '150', slots: { default: 'deviceThingModelFileName' }, }, - { - field: 'productCreateTime', - title: $t('abp.CTWingManagement.IoTPlatformProductCreateTime'), - minWidth: '150', - formatter: ({ cellValue }: any) => { - if (!cellValue) return '-'; - const date = new Date(cellValue); - if (isNaN(date.getTime())) return '-'; - return date.toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }).replace(/\//g, '-'); - }, - }, - { - field: 'productUpdateTime', - title: $t('abp.CTWingManagement.IoTPlatformProductUpdateTime'), - minWidth: '150', - formatter: ({ cellValue }: any) => { - if (!cellValue) return '-'; - const date = new Date(cellValue); - if (isNaN(date.getTime())) return '-'; - return date.toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }).replace(/\//g, '-'); - }, - }, { field: 'creationTime', title: $t('abp.CTWingManagement.CreationTime'), @@ -99,15 +61,17 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ if (!cellValue) return '-'; const date = new Date(cellValue); if (isNaN(date.getTime())) return '-'; - return date.toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }).replace(/\//g, '-'); + return date + .toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, + }) + .replaceAll('/', '-'); }, }, { @@ -118,15 +82,17 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ if (!cellValue) return '-'; const date = new Date(cellValue); if (isNaN(date.getTime())) return '-'; - return date.toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }).replace(/\//g, '-'); + return date + .toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, + }) + .replaceAll('/', '-'); }, }, { diff --git a/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue b/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue index b44373d..40be5e9 100644 --- a/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue +++ b/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue @@ -123,13 +123,37 @@ async function submit() { if (!valid) return; const formValues = await formApi.getValues(); + + // 根据平台类型处理数据 + let processedFormValues = { ...formValues }; + + if (formValues.ioTPlatform === '1') { + // 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 === '2') { + // 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, - ...formValues, + ...processedFormValues, } : { - ...formValues, + ...processedFormValues, }; try { @@ -160,7 +184,21 @@ async function submit() { async function onEdit(record: any) { editRow.value = record; userModalApi.open(); - editFormApi.setValues({ ...record }); + + // 根据平台类型设置表单值 + const formValues = { ...record }; + + if (record.ioTPlatform === 1 || record.ioTPlatform === '1') { + // OneNET平台 + formValues.oneNETAccountId = record.ioTPlatformAccountId; + formValues.oneNETProductId = record.ioTPlatformProductId; + } else if (record.ioTPlatform === 2 || record.ioTPlatform === '2') { + // CTWing平台 + formValues.ctWingAccountId = record.ioTPlatformAccountId; + formValues.ctWingProductId = record.ioTPlatformProductId; + } + + editFormApi.setValues(formValues); } function onDel(row: any) { diff --git a/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts b/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts index fb411ca..e6e8dc8 100644 --- a/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts +++ b/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts @@ -6,6 +6,9 @@ import { z } from '@vben/common-ui'; import { getCommonGetSelectList, + postCtWingAccountListAsync, + postCtWingProductListAsync, + postOneNetAccountListAsync, postOneNetProductListAsync, } from '#/api-client'; import { $t } from '#/locales'; @@ -91,8 +94,8 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ export const addDeviceFormSchema: any = computed(() => [ { component: 'ApiSelect', - fieldName: 'IoTPlatform', - label: $t('common.IoTPlatform'), + fieldName: 'ioTPlatform', + label: $t('abp.deviceInfos.ioTPlatform'), componentProps: { api: getCommonGetSelectList, params: { @@ -122,22 +125,141 @@ export const addDeviceFormSchema: any = computed(() => [ }, }, rules: z.string().min(1, { - message: `${$t('common.pleaseSelect')}${$t('common.IoTPlatform')}`, + message: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatform')}`, }), }, { component: 'ApiSelect', - fieldName: 'ioTPlatformProductId', - label: $t('abp.OneNETManagement.BelongingProductName'), + fieldName: 'oneNETAccountId', + label: $t('abp.deviceInfos.ioTPlatformAccountName'), + dependencies: { + show(values: any) { + return values.ioTPlatform === '1'; // OneNET平台 + }, + rules(values: any) { + if (values.ioTPlatform === '1') { + return 'required'; + } + return null; + }, + triggerFields: ['ioTPlatform'], + }, componentProps: { - api: postOneNetProductListAsync, + api: postOneNetAccountListAsync, params: { body: { pageIndex: 1, pageSize: 1000, }, }, - labelField: 'label', + 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 === '2'; // CTWing平台 + }, + rules(values: any) { + if (values.ioTPlatform === '2') { + 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', + label: $t('abp.deviceInfos.ioTPlatformProductName'), + dependencies: { + show(values: any) { + return values.ioTPlatform === '1' && values.oneNETAccountId; // OneNET平台且已选择账号 + }, + rules(values: any) { + if (values.ioTPlatform === '1' && values.oneNETAccountId) { + return 'required'; + } + return null; + }, + triggerFields: ['ioTPlatform', 'oneNETAccountId'], + }, + componentProps: { + api: postOneNetProductListAsync, + params: { + body: { + pageIndex: 1, + pageSize: 1000, + oneNETAccountId: '{{oneNETAccountId}}', // 动态参数 + }, + }, + labelField: 'productName', valueField: 'ioTPlatformProductId', immediate: true, afterFetch: (res: any) => { @@ -158,17 +280,80 @@ export const addDeviceFormSchema: any = computed(() => [ // 为每个产品项添加组合标签 return items.map((item: any) => ({ ...item, - label: `${item.productName || item.ProductName || ''} (${item.ioTPlatformProductId || ''})`, + label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, })); } // 如果都不是,返回空数组 return []; }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingProductName')}`, + 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 === '2' && values.ctWingAccountId; // CTWing平台且已选择账号 + }, + rules(values: any) { + if (values.ioTPlatform === '2' && values.ctWingAccountId) { + return 'required'; + } + return null; + }, + triggerFields: ['ioTPlatform', 'ctWingAccountId'], + }, + componentProps: { + api: postCtWingProductListAsync, + params: { + body: { + pageIndex: 1, + pageSize: 1000, + ctWingAccountId: '{{ctWingAccountId}}', // 动态参数 + }, + }, + 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; + } + + // 为每个产品项添加组合标签 + 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: 'Input', + fieldName: 'deviceName', + label: $t('abp.deviceInfos.deviceName'), rules: z.string().min(1, { - message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingProductName')}`, + message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceName')}`, }), }, { @@ -179,13 +364,21 @@ export const addDeviceFormSchema: any = computed(() => [ message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceAddress')}`, }), }, + { + component: 'Input', + fieldName: 'platformPassword', + label: $t('abp.deviceInfos.platformPassword'), + rules: z.string().min(1, { + message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.deviceInfos.platformPassword')}`, + }), + }, ]); export const editDeviceFormSchemaEdit: any = computed(() => [ { component: 'ApiSelect', - fieldName: 'IoTPlatform', - label: $t('common.IoTPlatform'), + fieldName: 'ioTPlatform', + label: $t('abp.deviceInfos.ioTPlatform'), componentProps: { api: getCommonGetSelectList, params: { @@ -214,20 +407,142 @@ export const editDeviceFormSchemaEdit: any = computed(() => [ return []; }, }, + rules: z.string().min(1, { + message: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatform')}`, + }), }, { component: 'ApiSelect', - fieldName: 'ioTPlatformProductId', - label: $t('abp.OneNETManagement.BelongingProductName'), + fieldName: 'oneNETAccountId', + label: $t('abp.deviceInfos.ioTPlatformAccountName'), + dependencies: { + show(values: any) { + return values.ioTPlatform === '1'; // OneNET平台 + }, + rules(values: any) { + if (values.ioTPlatform === '1') { + return 'required'; + } + return null; + }, + triggerFields: ['ioTPlatform'], + }, componentProps: { - api: postOneNetProductListAsync, + api: postOneNetAccountListAsync, params: { body: { pageIndex: 1, pageSize: 1000, }, }, - labelField: 'label', + 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 === '2'; // CTWing平台 + }, + rules(values: any) { + if (values.ioTPlatform === '2') { + 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', + label: $t('abp.deviceInfos.ioTPlatformProductName'), + dependencies: { + show(values: any) { + return values.ioTPlatform === '1' && values.oneNETAccountId; // OneNET平台且已选择账号 + }, + rules(values: any) { + if (values.ioTPlatform === '1' && values.oneNETAccountId) { + return 'required'; + } + return null; + }, + triggerFields: ['ioTPlatform', 'oneNETAccountId'], + }, + componentProps: { + api: postOneNetProductListAsync, + params: { + body: { + pageIndex: 1, + pageSize: 1000, + oneNETAccountId: '{{oneNETAccountId}}', // 动态参数 + }, + }, + labelField: 'productName', valueField: 'ioTPlatformProductId', immediate: true, afterFetch: (res: any) => { @@ -248,18 +563,73 @@ export const editDeviceFormSchemaEdit: any = computed(() => [ // 为每个产品项添加组合标签 return items.map((item: any) => ({ ...item, - label: `${item.productName || item.ProductName || ''} (${item.ioTPlatformProductId || ''})`, + label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, })); } // 如果都不是,返回空数组 return []; }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingProductName')}`, + placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`, }, - rules: z.string().min(1, { - message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingProductName')}`, - }), + rules: z.string().optional(), + }, + { + component: 'ApiSelect', + fieldName: 'ctWingProductId', + label: $t('abp.deviceInfos.ioTPlatformProductName'), + dependencies: { + show(values: any) { + return values.ioTPlatform === '2' && values.ctWingAccountId; // CTWing平台且已选择账号 + }, + rules(values: any) { + if (values.ioTPlatform === '2' && values.ctWingAccountId) { + return 'required'; + } + return null; + }, + triggerFields: ['ioTPlatform', 'ctWingAccountId'], + }, + componentProps: { + api: postCtWingProductListAsync, + params: { + body: { + pageIndex: 1, + pageSize: 1000, + ctWingAccountId: '{{ctWingAccountId}}', // 动态参数 + }, + }, + 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; + } + + // 为每个产品项添加组合标签 + 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: 'Input', diff --git a/apps/web-antd/src/views/onenetmanagement/privateProduct/schema.ts b/apps/web-antd/src/views/onenetmanagement/privateProduct/schema.ts index a2e64e0..462323f 100644 --- a/apps/web-antd/src/views/onenetmanagement/privateProduct/schema.ts +++ b/apps/web-antd/src/views/onenetmanagement/privateProduct/schema.ts @@ -19,7 +19,7 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ { title: $t('common.seq'), type: 'seq', width: 50 }, { field: 'oneNETAccountName', - title: $t('abp.OneNETManagement.BelongingAccountName'), + title: $t('common.BelongingAccountName'), minWidth: '150', }, { @@ -61,15 +61,17 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ if (!cellValue) return '-'; const date = new Date(cellValue); if (isNaN(date.getTime())) return '-'; - return date.toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }).replace(/\//g, '-'); + return date + .toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, + }) + .replaceAll('/', '-'); }, }, { @@ -80,15 +82,17 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ if (!cellValue) return '-'; const date = new Date(cellValue); if (isNaN(date.getTime())) return '-'; - return date.toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }).replace(/\//g, '-'); + return date + .toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, + }) + .replaceAll('/', '-'); }, }, { @@ -99,15 +103,17 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ if (!cellValue) return '-'; const date = new Date(cellValue); if (isNaN(date.getTime())) return '-'; - return date.toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }).replace(/\//g, '-'); + return date + .toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, + }) + .replaceAll('/', '-'); }, }, { @@ -118,15 +124,17 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ if (!cellValue) return '-'; const date = new Date(cellValue); if (isNaN(date.getTime())) return '-'; - return date.toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }).replace(/\//g, '-'); + return date + .toLocaleString('zh-CN', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false, + }) + .replaceAll('/', '-'); }, }, { @@ -158,7 +166,7 @@ export const addProductFormSchema: any = computed(() => [ { component: 'ApiSelect', fieldName: 'oneNETAccountId', - label: $t('abp.OneNETManagement.BelongingAccountName'), + label: $t('common.BelongingAccountName'), componentProps: { api: postOneNetAccountListAsync, params: { @@ -192,10 +200,10 @@ export const addProductFormSchema: any = computed(() => [ // 如果都不是,返回空数组 return []; }, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`, + placeholder: `${$t('common.pleaseSelect')}${$t('common.BelongingAccountName')}`, }, rules: z.string().min(1, { - message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`, + message: `${$t('common.pleaseSelect')}${$t('common.BelongingAccountName')}`, }), }, {