From b16a495cf1e7c5b257b7c63227d9cdd8333f646f Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Mon, 28 Jul 2025 16:50:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-antd/src/locales/langs/en-US/abp.json | 4 +- .../src/locales/langs/en-US/common.json | 3 +- .../web-antd/src/locales/langs/zh-CN/abp.json | 4 +- .../src/locales/langs/zh-CN/common.json | 3 +- .../devicemanagement/deviceinfo/index.vue | 76 ++-- .../devicemanagement/deviceinfo/schema.ts | 351 +++++++++--------- .../iotdbdatamanagement/deviceData/schema.ts | 4 +- .../onenetmanagement/privateProduct/schema.ts | 105 +++++- 8 files changed, 333 insertions(+), 217 deletions(-) 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 ef4b306..ffcd85e 100644 --- a/apps/web-antd/src/locales/langs/en-US/abp.json +++ b/apps/web-antd/src/locales/langs/en-US/abp.json @@ -264,6 +264,7 @@ "OneNETManagement": { "AccountName": "AccountName", "PhoneNumber": "PhoneNumber", + "BelongingAccountName": "BelongingAccountName", "AccountAccesskey": "AccountAccesskey", "ProductCount": "ProductCount", "OneNETAccountId": "OneNETAccountId", @@ -273,6 +274,7 @@ "IoTPlatformProductId": "IoTPlatformProductId", "ProductName": "ProductName", "ProductAccesskey": "ProductAccesskey", - "IsEncrypted": "IsEncrypted" + "IsEncrypted": "IsEncrypted", + "BelongingProductName": "BelongingProductName" } } 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 cd388ac..147f4d0 100644 --- a/apps/web-antd/src/locales/langs/en-US/common.json +++ b/apps/web-antd/src/locales/langs/en-US/common.json @@ -53,5 +53,6 @@ "exportSuccess": "Data exported successfully", "exportFailed": "Data export failed", "getDataFailed": "Failed to get data", - "PhoneNumberFormatError": "PhoneNumber Format Error" + "PhoneNumberFormatError": "PhoneNumber Format Error", + "IoTPlatform": "IoTPlatform" } 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 fd8b286..d38d59d 100644 --- a/apps/web-antd/src/locales/langs/zh-CN/abp.json +++ b/apps/web-antd/src/locales/langs/zh-CN/abp.json @@ -265,6 +265,7 @@ }, "OneNETManagement": { "AccountName": "账号名称", + "BelongingAccountName": "所属账号", "PhoneNumber": "手机号码", "AccountAccesskey": "账户通信密钥", "ProductCount": "产品数量", @@ -275,6 +276,7 @@ "IoTPlatformProductId": "物联网平台对应的产品Id", "ProductName": "产品名称", "ProductAccesskey": "产品访问密钥", - "IsEncrypted": "是否加密" + "IsEncrypted": "是否加密", + "BelongingProductName": "所属产品" } } 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 feeea72..ba04083 100644 --- a/apps/web-antd/src/locales/langs/zh-CN/common.json +++ b/apps/web-antd/src/locales/langs/zh-CN/common.json @@ -54,5 +54,6 @@ "exportFailed": "数据导出失败", "getDataFailed": "获取数据失败", "IsEnabled": "是否启用", - "PhoneNumberFormatError": "手机号码格式错误" + "PhoneNumberFormatError": "手机号码格式错误", + "IoTPlatform": "物联网平台" } diff --git a/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue b/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue index aee9f5a..b44373d 100644 --- a/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue +++ b/apps/web-antd/src/views/devicemanagement/deviceinfo/index.vue @@ -24,9 +24,7 @@ import { $t } from '#/locales'; import { addDeviceFormSchema, editDeviceFormSchemaEdit, - meterTypeOptions, querySchema, - rateOptions, tableSchema, } from './schema'; @@ -120,22 +118,19 @@ const [EditForm, editFormApi] = useVbenForm({ async function submit() { const isEdit = !!editRow.value.id; const formApi = isEdit ? editFormApi : addFormApi; - // TODO: 需要确认设备更新接口,暂时使用创建接口 - const api = postAggregationDeviceCreateAsync; + const api = postAggregationDeviceCreateAsync; // 目前只有创建接口,编辑也使用创建接口 const { valid } = await formApi.validate(); if (!valid) return; const formValues = await formApi.getValues(); const fetchParams: any = isEdit ? { - id: editRow.value.id, - ...formValues, - password: formValues.password || '000000', - } + id: editRow.value.id, + ...formValues, + } : { - ...formValues, - password: formValues.password || '000000', - }; + ...formValues, + }; try { userModalApi.setState({ loading: true, confirmLoading: true }); @@ -145,12 +140,18 @@ async function submit() { editRow.value.id ? $t('common.editSuccess') : $t('common.addSuccess'), ); userModalApi.close(); + editRow.value = {}; gridApi.reload(); } else { Message.error( editRow.value.id ? $t('common.editFail') : $t('common.addFail'), ); } + } catch (error) { + console.error('设备操作失败:', error); + Message.error( + editRow.value.id ? $t('common.editFail') : $t('common.addFail'), + ); } finally { userModalApi.setState({ loading: false, confirmLoading: false }); } @@ -164,13 +165,18 @@ async function onEdit(record: any) { function onDel(row: any) { Modal.confirm({ - title: `${$t('common.confirmDelete')}${row.meterName} ?`, + title: `${$t('common.confirmDelete')}${row.deviceName || row.deviceAddress} ?`, onOk: async () => { - const result = await postAggregationDeviceDeleteAsync({ body: { id: row.id } }); - if (result) { - gridApi.reload(); - Message.success($t('common.deleteSuccess')); - } else { + try { + const result = await postAggregationDeviceDeleteAsync({ body: { id: row.id } }); + if (result.data) { + gridApi.reload(); + Message.success($t('common.deleteSuccess')); + } else { + Message.error($t('common.deleteFail')); + } + } catch (error) { + console.error('删除设备失败:', error); Message.error($t('common.deleteFail')); } }, @@ -181,27 +187,31 @@ const toStatusData = (row: Record) => { router.push({ path: '/iotdb/deviceData', query: { - DeviceType: row.meterType, - DeviceId: row.meterId, - FocusAddress: row.focusAddress, - DataBaseName: row.businessSystemName, + DeviceType: row.ioTPlatform, + DeviceId: row.deviceAddress, + FocusAddress: row.ioTPlatformDeviceOpenInfo, + DataBaseName: row.deviceName, }, }); }; // 档案下发 const archivesIssued = async (row: Record) => { - const result = await postDeviceInfoArchivesDown({ - body: { - meterAddress: row.meterAddress, - meterType: row.meterType, - focusAddress: row.focusAddress, - }, - }); - if (result) { - gridApi.reload(); - Message.success($t('common.success')); - } else { - Message.error($t('common.error')); + try { + const result = await postDeviceInfoArchivesDown({ + body: { + meterAddress: row.deviceAddress, + meterType: row.ioTPlatform, + focusAddress: row.ioTPlatformDeviceOpenInfo, + }, + }); + if (result.data) { + Message.success($t('common.operationSuccess')); + } else { + Message.error($t('common.operationFail')); + } + } catch (error) { + console.error('档案下发失败:', error); + Message.error($t('common.operationFail')); } }; const openAddModal = async () => { diff --git a/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts b/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts index 29b6e43..f81bb9c 100644 --- a/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts +++ b/apps/web-antd/src/views/devicemanagement/deviceinfo/schema.ts @@ -4,6 +4,10 @@ import { computed } from 'vue'; import { z } from '@vben/common-ui'; +import { + getCommonGetSelectList, + postOneNetProductListAsync, +} from '#/api-client'; import { $t } from '#/locales'; export const querySchema = computed(() => [ @@ -13,40 +17,19 @@ export const querySchema = computed(() => [ label: $t('abp.deviceInfos.deviceAddress'), }, ]); -export const meterTypeOptions = [ + +export const ioTPlatformOptions = [ { - label: $t('abp.deviceInfos.ElectricityMeter'), + label: 'OneNET', value: 1, }, { - label: $t('abp.deviceInfos.waterMeter'), + label: 'CTWing', value: 2, }, { - label: $t('abp.deviceInfos.GasMeter'), - value: 3, - }, - { - label: $t('abp.deviceInfos.HeatMeter'), - value: 4, - }, - { - label: $t('abp.deviceInfos.WaterMeterFlowmeter'), - value: 5, - }, - { - label: $t('abp.deviceInfos.GasMeterFlowmeter'), - value: 6, - }, -]; -export const rateOptions = [ - { - label: $t('abp.deviceInfos.MultipleRate'), - value: false, - }, - { - label: $t('abp.deviceInfos.SingleRate'), - value: true, + label: 'Other', + value: 0, }, ]; export const tableSchema: any = computed((): VxeGridProps['columns'] => [ @@ -106,6 +89,93 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ ]); export const addDeviceFormSchema: any = computed(() => [ + { + component: 'ApiSelect', + fieldName: 'IoTPlatform', + label: $t('common.IoTPlatform'), + componentProps: { + api: getCommonGetSelectList, + params: { + query: { + typeName: 'IoTPlatformTypeEnum', + }, + }, + labelField: 'value', + valueField: 'key', + optionsPropName: 'options', + immediate: true, + afterFetch: (res: any) => { + // 确保返回的是数组格式 + if (Array.isArray(res)) { + return res; + } + // 如果是包装在 items 中的,提取出来 + if (res && Array.isArray(res.items)) { + return res.items; + } + // 如果是包装在 data 中的,提取出来 + if (res && Array.isArray(res.data)) { + return res.data; + } + // 如果都不是,返回空数组 + return []; + }, + }, + rules: z.string().min(1, { + message: `${$t('common.pleaseSelect')}${$t('common.IoTPlatform')}`, + }), + }, + { + component: 'ApiSelect', + fieldName: 'ioTPlatformProductId', + label: $t('abp.OneNETManagement.BelongingProductName'), + 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; + + // 确保返回的是数组格式 + 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.OneNETManagement.BelongingAccountName')}`, + }, + rules: z.string().min(1, { + message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`, + }), + }, + { + component: 'Input', + fieldName: 'deviceName', + label: $t('abp.deviceInfos.deviceName'), + rules: z.string().min(1, { + message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceName')}`, + }), + }, { component: 'Input', fieldName: 'deviceAddress', @@ -119,19 +189,101 @@ export const addDeviceFormSchema: any = computed(() => [ fieldName: 'platformPassword', label: $t('abp.deviceInfos.platformPassword'), rules: z.string().min(1, { - message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.platformPassword')}`, + message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.deviceInfos.platformPassword')}`, }), }, ]); export const editDeviceFormSchemaEdit: any = computed(() => [ + { + component: 'ApiSelect', + fieldName: 'IoTPlatform', + label: $t('common.IoTPlatform'), + componentProps: { + api: getCommonGetSelectList, + params: { + query: { + typeName: 'IoTPlatformTypeEnum', + }, + }, + labelField: 'value', + valueField: 'key', + optionsPropName: 'options', + immediate: true, + afterFetch: (res: any) => { + // 确保返回的是数组格式 + if (Array.isArray(res)) { + return res; + } + // 如果是包装在 items 中的,提取出来 + if (res && Array.isArray(res.items)) { + return res.items; + } + // 如果是包装在 data 中的,提取出来 + if (res && Array.isArray(res.data)) { + return res.data; + } + // 如果都不是,返回空数组 + return []; + }, + }, + }, + { + component: 'ApiSelect', + fieldName: 'ioTPlatformProductId', + label: $t('abp.OneNETManagement.BelongingProductName'), + 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; + + // 确保返回的是数组格式 + 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.OneNETManagement.BelongingAccountName')}`, + }, + rules: z.string().min(1, { + message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`, + }), + }, + { + component: 'Input', + fieldName: 'deviceName', + label: $t('abp.deviceInfos.deviceName'), + rules: z.string().min(1, { + message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceName')}`, + }), + }, { component: 'Input', fieldName: 'deviceAddress', label: $t('abp.deviceInfos.deviceAddress'), - rules: z.string().min(1, { - message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.deviceInfos.deviceAddress')}`, - }), + disabled: true, }, { component: 'Input', @@ -141,141 +293,4 @@ export const editDeviceFormSchemaEdit: any = computed(() => [ message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.deviceInfos.platformPassword')}`, }), }, - { - component: 'Select', - componentProps: { - allowClear: true, - options: meterTypeOptions, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.meterType')}`, - }, - fieldName: 'meterType', - label: $t('abp.deviceInfos.meterType'), - rules: z - .number() - .min(1, { - message: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.meterType')}`, - }) - .default(1), - }, - { - component: 'Select', - componentProps: { - allowClear: true, - options: rateOptions, - placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.singleRate')}`, - }, - dependencies: { - show(values: any) { - return values.meterType === 1; - }, - rules(values: any) { - if (values.meterType === 1) { - return 'required'; - } - return null; - }, - triggerFields: ['meterType'], - }, - fieldName: 'singleRate', - label: $t('abp.deviceInfos.singleRate'), - }, - { - component: 'Switch', - componentProps: { - class: 'w-auto', - }, - fieldName: 'selfDevelop', - label: $t('abp.deviceInfos.selfDevelop'), - }, - { - component: 'Input', - fieldName: 'brandType', - label: $t('abp.deviceInfos.brandType'), - rules: z.string().optional(), - }, - { - component: 'Switch', - componentProps: { - class: 'w-auto', - }, - fieldName: 'dynamicPassword', - label: $t('abp.deviceInfos.dynamicPassword'), - }, - { - component: 'Input', - fieldName: 'password', - label: $t('abp.deviceInfos.password'), - rules: z.string().optional(), - }, - { - component: 'Switch', - componentProps: { - class: 'w-auto', - }, - dependencies: { - show(values: any) { - return values.meterType === 2; - }, - triggerFields: ['meterType'], - }, - fieldName: 'haveValve', - label: $t('abp.deviceInfos.haveValve'), - }, - { - component: 'Input', - fieldName: 'timesA', - label: $t('abp.deviceInfos.timesA'), - componentProps: { - allowClear: true, - placeholder: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.timesA')}`, - }, - dependencies: { - show(values: any) { - return values.meterType === 1; - }, - triggerFields: ['meterType'], - }, - rules: z - .string({ - message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.timesA')}`, - }) - .default('1'), - }, - { - component: 'Input', - fieldName: 'timev', - label: $t('abp.deviceInfos.timev'), - componentProps: { - allowClear: true, - placeholder: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.timev')}`, - }, - dependencies: { - show(values: any) { - return values.meterType === 1; - }, - triggerFields: ['meterType'], - }, - rules: z - .string({ - message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.timev')}`, - }) - .default('1'), - }, - { - component: 'Input', - fieldName: 'meteringCode', - label: $t('abp.deviceInfos.meteringCode'), - componentProps: { - allowClear: true, - placeholder: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.meteringCode')}`, - }, - rules: z - .string({ - message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.meteringCode')}`, - }) - .min(1, { - message: `${$t('common.MustGreaterTthan0')}`, - }) - .default('1'), - }, ]); diff --git a/apps/web-antd/src/views/iotdbdatamanagement/deviceData/schema.ts b/apps/web-antd/src/views/iotdbdatamanagement/deviceData/schema.ts index 744162c..84ac55d 100644 --- a/apps/web-antd/src/views/iotdbdatamanagement/deviceData/schema.ts +++ b/apps/web-antd/src/views/iotdbdatamanagement/deviceData/schema.ts @@ -47,7 +47,7 @@ export const querySchema = computed(() => [ api: getCommonGetSelectList, params: { query: { - typeName: 'MeterTypeEnum' + typeName: 'MeterTypeEnum', }, }, labelField: 'value', @@ -80,7 +80,7 @@ export const querySchema = computed(() => [ api: getCommonGetSelectList, params: { query: { - typeName: 'IoTDBDataTypeConst' + typeName: 'IoTDBDataTypeConst', }, }, labelField: 'value', diff --git a/apps/web-antd/src/views/onenetmanagement/privateProduct/schema.ts b/apps/web-antd/src/views/onenetmanagement/privateProduct/schema.ts index db4734e..945301b 100644 --- a/apps/web-antd/src/views/onenetmanagement/privateProduct/schema.ts +++ b/apps/web-antd/src/views/onenetmanagement/privateProduct/schema.ts @@ -5,6 +5,7 @@ import { computed } from 'vue'; import { z } from '@vben/common-ui'; import { $t } from '#/locales'; +import { postOneNetAccountListAsync } from '#/api-client'; export const querySchema = computed(() => [ { @@ -57,6 +58,56 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [ ]); export const addProductFormSchema: any = computed(() => [ + { + component: 'ApiSelect', + fieldName: 'oneNETAccountId', + label: $t('abp.OneNETManagement.BelongingAccountName'), + componentProps: { + api: postOneNetAccountListAsync, + params: { + body: { + pageIndex: 1, + pageSize: 1000, + }, + }, + labelField: 'accountName', + valueField: 'oneNETAccountId', + immediate: true, + afterFetch: (res: any) => { + console.log('ApiSelect afterFetch res:', res); + + // 如果是 Axios 响应对象,提取 data + if (res && res.data) { + console.log('提取 res.data:', res.data); + const data = res.data; + + // 确保返回的是数组格式 + if (Array.isArray(data)) { + console.log('返回数组,长度:', data.length); + return data; + } + // 如果是包装在 items 中的,提取出来 + if (data && Array.isArray(data.items)) { + console.log('返回items数组,长度:', data.items.length); + return data.items; + } + // 如果是包装在 data 中的,提取出来 + if (data && Array.isArray(data.data)) { + console.log('返回data数组,长度:', data.data.length); + return data.data; + } + } + + // 如果都不是,返回空数组 + console.log('没有找到数组数据,返回空数组'); + return []; + }, + placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`, + }, + rules: z.string().min(1, { + message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`, + }), + }, { component: 'Input', fieldName: 'oneNETProductId', @@ -89,14 +140,6 @@ export const addProductFormSchema: any = computed(() => [ message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductSecret')}`, }), }, - { - component: 'Input', - fieldName: 'accountName', - label: $t('abp.OneNETManagement.AccountName'), - rules: z.string().min(1, { - message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.AccountName')}`, - }), - }, { component: 'Switch', componentProps: { @@ -139,11 +182,53 @@ export const editProductFormSchemaEdit: any = computed(() => [ }), }, { - component: 'Input', + component: 'ApiSelect', fieldName: 'accountName', label: $t('abp.OneNETManagement.AccountName'), + componentProps: { + api: postOneNetAccountListAsync, + params: { + body: { + pageIndex: 1, + pageSize: 1000, + }, + }, + labelField: 'accountName', + valueField: 'oneNETAccountId', + immediate: true, + afterFetch: (res: any) => { + console.log('ApiSelect afterFetch res:', res); + + // 如果是 Axios 响应对象,提取 data + if (res && res.data) { + console.log('提取 res.data:', res.data); + const data = res.data; + + // 确保返回的是数组格式 + if (Array.isArray(data)) { + console.log('返回数组,长度:', data.length); + return data; + } + // 如果是包装在 items 中的,提取出来 + if (data && Array.isArray(data.items)) { + console.log('返回items数组,长度:', data.items.length); + return data.items; + } + // 如果是包装在 data 中的,提取出来 + if (data && Array.isArray(data.data)) { + console.log('返回data数组,长度:', data.data.length); + return data.data; + } + } + + // 如果都不是,返回空数组 + console.log('没有找到数组数据,返回空数组'); + return []; + }, + placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.AccountName')}`, + }, rules: z.string().min(1, { - message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.AccountName')}`, + message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.AccountName')}`, }), }, {