feat: 添加新功能

This commit is contained in:
陈益 2025-07-30 23:44:47 +08:00
parent a894b1d510
commit 4185ad0d10
2 changed files with 114 additions and 87 deletions

View File

@ -12,11 +12,10 @@ import { message as Message, Modal, Tag } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form'; import { useVbenForm } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
postDeviceInfoArchivesDown,
postAggregationDeviceCreateAsync, postAggregationDeviceCreateAsync,
postAggregationDeviceDeleteAsync, postAggregationDeviceDeleteAsync,
postDeviceInfoArchivesDown,
postDeviceInfoPage, postDeviceInfoPage,
postAggregationDeviceFindByIdAsync,
} from '#/api-client'; } from '#/api-client';
import { TableAction } from '#/components/table-action'; import { TableAction } from '#/components/table-action';
import { $t } from '#/locales'; import { $t } from '#/locales';
@ -123,11 +122,11 @@ async function submit() {
if (!valid) return; if (!valid) return;
const formValues = await formApi.getValues(); const formValues = await formApi.getValues();
// //
let processedFormValues = { ...formValues }; const processedFormValues = { ...formValues };
if (formValues.ioTPlatform === '2') { if (formValues.ioTPlatform === 2 || formValues.ioTPlatform === '2') {
// OneNET // OneNET
processedFormValues.ioTPlatformAccountId = formValues.oneNETAccountId; processedFormValues.ioTPlatformAccountId = formValues.oneNETAccountId;
processedFormValues.ioTPlatformProductId = formValues.oneNETProductId; processedFormValues.ioTPlatformProductId = formValues.oneNETProductId;
@ -136,7 +135,7 @@ async function submit() {
delete processedFormValues.oneNETProductId; delete processedFormValues.oneNETProductId;
delete processedFormValues.ctWingAccountId; delete processedFormValues.ctWingAccountId;
delete processedFormValues.ctWingProductId; delete processedFormValues.ctWingProductId;
} else if (formValues.ioTPlatform === '1') { } else if (formValues.ioTPlatform === 1 || formValues.ioTPlatform === '1') {
// CTWing // CTWing
processedFormValues.ioTPlatformAccountId = formValues.ctWingAccountId; processedFormValues.ioTPlatformAccountId = formValues.ctWingAccountId;
processedFormValues.ioTPlatformProductId = formValues.ctWingProductId; processedFormValues.ioTPlatformProductId = formValues.ctWingProductId;
@ -184,10 +183,10 @@ async function submit() {
async function onEdit(record: any) { async function onEdit(record: any) {
editRow.value = record; editRow.value = record;
userModalApi.open(); userModalApi.open();
// //
const formValues = { ...record }; const formValues = { ...record };
if (record.ioTPlatform === 2 || record.ioTPlatform === '2') { if (record.ioTPlatform === 2 || record.ioTPlatform === '2') {
// OneNET // OneNET
formValues.oneNETAccountId = record.ioTPlatformAccountId; formValues.oneNETAccountId = record.ioTPlatformAccountId;
@ -197,7 +196,7 @@ async function onEdit(record: any) {
formValues.ctWingAccountId = record.ioTPlatformAccountId; formValues.ctWingAccountId = record.ioTPlatformAccountId;
formValues.ctWingProductId = record.ioTPlatformProductId; formValues.ctWingProductId = record.ioTPlatformProductId;
} }
editFormApi.setValues(formValues); editFormApi.setValues(formValues);
} }
@ -206,7 +205,9 @@ function onDel(row: any) {
title: `${$t('common.confirmDelete')}${row.deviceName || row.deviceAddress} ?`, title: `${$t('common.confirmDelete')}${row.deviceName || row.deviceAddress} ?`,
onOk: async () => { onOk: async () => {
try { try {
const result = await postAggregationDeviceDeleteAsync({ body: { id: row.id } }); const result = await postAggregationDeviceDeleteAsync({
body: { id: row.id },
});
if (result.data) { if (result.data) {
gridApi.reload(); gridApi.reload();
Message.success($t('common.deleteSuccess')); Message.success($t('common.deleteSuccess'));
@ -262,23 +263,19 @@ const openAddModal = async () => {
<Page auto-content-height> <Page auto-content-height>
<Grid> <Grid>
<template #toolbar-actions> <template #toolbar-actions>
<TableAction :actions="[ <TableAction
{ :actions="[
label: $t('common.add'), {
type: 'primary', label: $t('common.add'),
icon: 'ant-design:plus-outlined', type: 'primary',
onClick: openAddModal.bind(null), icon: 'ant-design:plus-outlined',
auth: ['AbpIdentity.Users.Create'], onClick: openAddModal.bind(null),
}, auth: ['AbpIdentity.Users.Create'],
]" /> },
]"
/>
</template> </template>
<template #isMeterType="{ row }">
{{ meterTypeOptions[row.meterType - 1]?.label }}
</template>
<template #isSingleRate="{ row }">
{{rateOptions.find((item) => item.value === row.singleRate)?.label}}
</template>
<template #isArchiveStatus="{ row }"> <template #isArchiveStatus="{ row }">
{{ {{
row.archiveStatus ? $t('common.Issued') : $t('common.Undistributed') row.archiveStatus ? $t('common.Issued') : $t('common.Undistributed')
@ -288,40 +285,54 @@ const openAddModal = async () => {
{{ row.tripState ? $t('common.SwitchOff') : $t('common.Closing') }} {{ row.tripState ? $t('common.SwitchOff') : $t('common.Closing') }}
</template> </template>
<template #isHaveValve="{ row }"> <template #isHaveValve="{ row }">
<component :is="h(Tag, { color: row.haveValve ? 'green' : 'red' }, () => <component
row.haveValve ? $t('common.yes') : $t('common.no'), :is="
) h(Tag, { color: row.haveValve ? 'green' : 'red' }, () =>
" /> row.haveValve ? $t('common.yes') : $t('common.no'),
)
"
/>
</template> </template>
<template #isSelfDevelop="{ row }"> <template #isSelfDevelop="{ row }">
<component :is="h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () => <component
row.selfDevelop ? $t('common.yes') : $t('common.no'), :is="
) h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () =>
" /> row.selfDevelop ? $t('common.yes') : $t('common.no'),
)
"
/>
</template> </template>
<template #isDynamicPassword="{ row }"> <template #isDynamicPassword="{ row }">
<component :is="h(Tag, { color: row.dynamicPassword ? 'green' : 'red' }, () => <component
row.dynamicPassword ? $t('common.yes') : $t('common.no'), :is="
) h(Tag, { color: row.dynamicPassword ? 'green' : 'red' }, () =>
" /> row.dynamicPassword ? $t('common.yes') : $t('common.no'),
)
"
/>
</template> </template>
<template #isEnable="{ row }"> <template #isEnable="{ row }">
<component :is="h(Tag, { color: row.enabled ? 'green' : 'red' }, () => <component
row.enabled ? $t('common.yes') : $t('common.no'), :is="
) h(Tag, { color: row.enabled ? 'green' : 'red' }, () =>
" /> row.enabled ? $t('common.yes') : $t('common.no'),
)
"
/>
</template> </template>
<template #action="{ row }"> <template #action="{ row }">
<TableAction :actions="[ <TableAction
{ :actions="[
label: $t('common.edit'), {
type: 'link', label: $t('common.edit'),
size: 'small', type: 'link',
auth: ['AbpIdentity.Users.Update'], size: 'small',
onClick: onEdit.bind(null, row), auth: ['AbpIdentity.Users.Update'],
}, onClick: onEdit.bind(null, row),
]" :drop-down-actions="[ },
]"
:drop-down-actions="[
{ {
label: $t('common.delete'), label: $t('common.delete'),
icon: 'ant-design:delete-outlined', icon: 'ant-design:delete-outlined',
@ -346,10 +357,14 @@ const openAddModal = async () => {
auth: ['AbpIdentity.Users.Delete'], auth: ['AbpIdentity.Users.Delete'],
onClick: archivesIssued.bind(null, row), onClick: archivesIssued.bind(null, row),
}, },
]" /> ]"
/>
</template> </template>
</Grid> </Grid>
<UserModal :title="editRow.id ? $t('common.edit') : $t('common.add')" class="w-[800px]"> <UserModal
:title="editRow.id ? $t('common.edit') : $t('common.add')"
class="w-[800px]"
>
<component :is="editRow.id ? EditForm : AddForm" /> <component :is="editRow.id ? EditForm : AddForm" />
</UserModal> </UserModal>
</Page> </Page>

View File

@ -21,20 +21,6 @@ export const querySchema = computed(() => [
}, },
]); ]);
export const ioTPlatformOptions = [
{
label: 'OneNET',
value: 1,
},
{
label: 'CTWing',
value: 2,
},
{
label: 'Other',
value: 0,
},
];
export const tableSchema: any = computed((): VxeGridProps['columns'] => [ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 }, { title: $t('common.seq'), type: 'seq', width: 50 },
{ {
@ -134,10 +120,10 @@ export const addDeviceFormSchema: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformAccountName'), label: $t('abp.deviceInfos.ioTPlatformAccountName'),
dependencies: { dependencies: {
show(values: any) { show(values: any) {
return values.ioTPlatform === '2'; // OneNET平台 return values.ioTPlatform === 2 || values.ioTPlatform === '2'; // OneNET平台
}, },
rules(values: any) { rules(values: any) {
if (values.ioTPlatform === '2') { if (values.ioTPlatform === 2 || values.ioTPlatform === '2') {
return 'required'; return 'required';
} }
return null; return null;
@ -187,15 +173,15 @@ export const addDeviceFormSchema: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformAccountName'), label: $t('abp.deviceInfos.ioTPlatformAccountName'),
dependencies: { dependencies: {
show(values: any) { show(values: any) {
return values.ioTPlatform === '1'; // CTWing平台 return values.ioTPlatform === 1 || values.ioTPlatform === '1'; // CTWing平台
}, },
rules(values: any) { rules(values: any) {
if (values.ioTPlatform === '1') { if (values.ioTPlatform === 1 || values.ioTPlatform === '1') {
return 'required'; return 'required';
} }
return null; return null;
}, },
triggerFields: ['ioTPlatform'], triggerFields: ['ioTPlatform'], // 添加这一行,使其能够响应平台切换
}, },
componentProps: { componentProps: {
api: postCtWingAccountListAsync, api: postCtWingAccountListAsync,
@ -206,7 +192,7 @@ export const addDeviceFormSchema: any = computed(() => [
}, },
}, },
labelField: 'accountName', labelField: 'accountName',
valueField: 'ctWingAccountId', valueField: 'accountId',
immediate: true, immediate: true,
afterFetch: (res: any) => { afterFetch: (res: any) => {
// 如果是 Axios 响应对象,提取 data // 如果是 Axios 响应对象,提取 data
@ -240,10 +226,16 @@ export const addDeviceFormSchema: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformProductName'), label: $t('abp.deviceInfos.ioTPlatformProductName'),
dependencies: { dependencies: {
show(values: any) { show(values: any) {
return values.ioTPlatform === '2' && values.oneNETAccountId; // OneNET平台且已选择账号 return (
(values.ioTPlatform === 2 || values.ioTPlatform === '2') &&
values.oneNETAccountId
); // OneNET平台且已选择账号
}, },
rules(values: any) { rules(values: any) {
if (values.ioTPlatform === '2' && values.oneNETAccountId) { if (
(values.ioTPlatform === 2 || values.ioTPlatform === '2') &&
values.oneNETAccountId
) {
return 'required'; return 'required';
} }
return null; return null;
@ -297,10 +289,16 @@ export const addDeviceFormSchema: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformProductName'), label: $t('abp.deviceInfos.ioTPlatformProductName'),
dependencies: { dependencies: {
show(values: any) { show(values: any) {
return values.ioTPlatform === '1' && values.ctWingAccountId; // CTWing平台且已选择账号 return (
(values.ioTPlatform === 1 || values.ioTPlatform === '1') &&
values.ctWingAccountId
); // CTWing平台且已选择账号
}, },
rules(values: any) { rules(values: any) {
if (values.ioTPlatform === '1' && values.ctWingAccountId) { if (
(values.ioTPlatform === 1 || values.ioTPlatform === '1') &&
values.ctWingAccountId
) {
return 'required'; return 'required';
} }
return null; return null;
@ -334,9 +332,10 @@ export const addDeviceFormSchema: any = computed(() => [
items = data.data; items = data.data;
} }
// 为每个产品项添加组合标签 // 为每个产品项添加组合标签并确保产品ID是字符串类型
return items.map((item: any) => ({ return items.map((item: any) => ({
...item, ...item,
ioTPlatformProductId: String(item.ioTPlatformProductId || ''),
label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`,
})); }));
} }
@ -401,10 +400,10 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformAccountName'), label: $t('abp.deviceInfos.ioTPlatformAccountName'),
dependencies: { dependencies: {
show(values: any) { show(values: any) {
return values.ioTPlatform === '2'; // OneNET平台 return values.ioTPlatform === 2 || values.ioTPlatform === '2'; // OneNET平台
}, },
rules(values: any) { rules(values: any) {
if (values.ioTPlatform === '2') { if (values.ioTPlatform === 2 || values.ioTPlatform === '2') {
return 'required'; return 'required';
} }
return null; return null;
@ -454,10 +453,10 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformAccountName'), label: $t('abp.deviceInfos.ioTPlatformAccountName'),
dependencies: { dependencies: {
show(values: any) { show(values: any) {
return values.ioTPlatform === '1'; // CTWing平台 return values.ioTPlatform === 1 || values.ioTPlatform === '1'; // CTWing平台
}, },
rules(values: any) { rules(values: any) {
if (values.ioTPlatform === '1') { if (values.ioTPlatform === 1 || values.ioTPlatform === '1') {
return 'required'; return 'required';
} }
return null; return null;
@ -507,10 +506,16 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformProductName'), label: $t('abp.deviceInfos.ioTPlatformProductName'),
dependencies: { dependencies: {
show(values: any) { show(values: any) {
return values.ioTPlatform === '2' && values.oneNETAccountId; // OneNET平台且已选择账号 return (
(values.ioTPlatform === 2 || values.ioTPlatform === '2') &&
values.oneNETAccountId
); // OneNET平台且已选择账号
}, },
rules(values: any) { rules(values: any) {
if (values.ioTPlatform === '2' && values.oneNETAccountId) { if (
(values.ioTPlatform === 2 || values.ioTPlatform === '2') &&
values.oneNETAccountId
) {
return 'required'; return 'required';
} }
return null; return null;
@ -564,10 +569,16 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
label: $t('abp.deviceInfos.ioTPlatformProductName'), label: $t('abp.deviceInfos.ioTPlatformProductName'),
dependencies: { dependencies: {
show(values: any) { show(values: any) {
return values.ioTPlatform === '1' && values.ctWingAccountId; // CTWing平台且已选择账号 return (
(values.ioTPlatform === 1 || values.ioTPlatform === '1') &&
values.ctWingAccountId
); // CTWing平台且已选择账号
}, },
rules(values: any) { rules(values: any) {
if (values.ioTPlatform === '1' && values.ctWingAccountId) { if (
(values.ioTPlatform === 1 || values.ioTPlatform === '1') &&
values.ctWingAccountId
) {
return 'required'; return 'required';
} }
return null; return null;
@ -601,9 +612,10 @@ export const editDeviceFormSchemaEdit: any = computed(() => [
items = data.data; items = data.data;
} }
// 为每个产品项添加组合标签 // 为每个产品项添加组合标签并确保产品ID是字符串类型
return items.map((item: any) => ({ return items.map((item: any) => ({
...item, ...item,
ioTPlatformProductId: String(item.ioTPlatformProductId || ''),
label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`, label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`,
})); }));
} }