287 lines
7.4 KiB
TypeScript
Raw Normal View History

import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed } from 'vue';
import { z } from '@vben/common-ui';
2025-07-28 16:50:59 +08:00
import {
getCommonGetSelectList,
postOneNetProductListAsync,
} from '#/api-client';
import { $t } from '#/locales';
export const querySchema = computed(() => [
{
component: 'Input',
2025-07-25 17:27:41 +08:00
fieldName: 'deviceAddress',
label: $t('abp.deviceInfos.deviceAddress'),
},
]);
2025-07-28 16:50:59 +08:00
export const ioTPlatformOptions = [
{
2025-07-28 16:50:59 +08:00
label: 'OneNET',
value: 1,
},
{
2025-07-28 16:50:59 +08:00
label: 'CTWing',
value: 2,
},
{
2025-07-28 16:50:59 +08:00
label: 'Other',
value: 0,
},
];
export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 },
{
2025-07-25 17:27:41 +08:00
field: 'deviceName',
title: $t('abp.deviceInfos.deviceName'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'deviceAddress',
title: $t('abp.deviceInfos.deviceAddress'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatform',
title: $t('abp.deviceInfos.ioTPlatform'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformName',
title: $t('abp.deviceInfos.ioTPlatformName'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformDeviceOpenInfo',
title: $t('abp.deviceInfos.ioTPlatformDeviceOpenInfo'),
minWidth: '100',
},
{
2025-07-25 17:27:41 +08:00
field: 'platformPassword',
title: $t('abp.deviceInfos.platformPassword'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformProductName',
title: $t('abp.deviceInfos.ioTPlatformProductName'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformAccountName',
title: $t('abp.deviceInfos.ioTPlatformAccountName'),
minWidth: '150',
},
{
2025-07-25 17:27:41 +08:00
field: 'ioTPlatformResponse',
title: $t('abp.deviceInfos.ioTPlatformResponse'),
minWidth: '150',
},
{
title: $t('common.action'),
field: 'action',
fixed: 'right',
width: '150',
slots: { default: 'action' },
},
]);
2025-07-25 17:27:41 +08:00
export const addDeviceFormSchema: any = computed(() => [
{
2025-07-28 16:50:59 +08:00
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, {
2025-07-28 16:50:59 +08:00
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,
},
},
2025-07-29 17:32:30 +08:00
labelField: 'label',
2025-07-28 16:50:59 +08:00
valueField: 'ioTPlatformProductId',
immediate: true,
afterFetch: (res: any) => {
// 如果是 Axios 响应对象,提取 data
if (res && res.data) {
const data = res.data;
// 确保返回的是数组格式
2025-07-29 17:32:30 +08:00
let items = [];
2025-07-28 16:50:59 +08:00
if (Array.isArray(data)) {
2025-07-29 17:32:30 +08:00
items = data;
} else if (data && Array.isArray(data.items)) {
items = data.items;
} else if (data && Array.isArray(data.data)) {
items = data.data;
2025-07-28 16:50:59 +08:00
}
2025-07-29 17:32:30 +08:00
// 为每个产品项添加组合标签
return items.map((item: any) => ({
...item,
label: `${item.productName || item.ProductName || ''} (${item.ioTPlatformProductId || ''})`,
}));
2025-07-28 16:50:59 +08:00
}
// 如果都不是,返回空数组
return [];
},
2025-07-29 17:32:30 +08:00
placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingProductName')}`,
2025-07-28 16:50:59 +08:00
},
rules: z.string().min(1, {
2025-07-29 17:32:30 +08:00
message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingProductName')}`,
}),
},
{
component: 'Input',
2025-07-25 17:27:41 +08:00
fieldName: 'deviceAddress',
label: $t('abp.deviceInfos.deviceAddress'),
rules: z.string().min(1, {
2025-07-28 16:50:59 +08:00
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceAddress')}`,
}),
},
2025-07-28 16:50:59 +08:00
]);
export const editDeviceFormSchemaEdit: any = computed(() => [
{
2025-07-28 16:50:59 +08:00
component: 'ApiSelect',
fieldName: 'IoTPlatform',
label: $t('common.IoTPlatform'),
componentProps: {
2025-07-28 16:50:59 +08:00
api: getCommonGetSelectList,
params: {
query: {
typeName: 'IoTPlatformTypeEnum',
},
},
2025-07-28 16:50:59 +08:00
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
2025-07-28 16:50:59 +08:00
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果都不是,返回空数组
return [];
},
},
},
{
2025-07-28 16:50:59 +08:00
component: 'ApiSelect',
fieldName: 'ioTPlatformProductId',
label: $t('abp.OneNETManagement.BelongingProductName'),
componentProps: {
2025-07-28 16:50:59 +08:00
api: postOneNetProductListAsync,
params: {
body: {
pageIndex: 1,
pageSize: 1000,
},
},
2025-07-29 17:32:30 +08:00
labelField: 'label',
2025-07-28 16:50:59 +08:00
valueField: 'ioTPlatformProductId',
immediate: true,
afterFetch: (res: any) => {
// 如果是 Axios 响应对象,提取 data
if (res && res.data) {
const data = res.data;
// 确保返回的是数组格式
2025-07-29 17:32:30 +08:00
let items = [];
2025-07-28 16:50:59 +08:00
if (Array.isArray(data)) {
2025-07-29 17:32:30 +08:00
items = data;
} else if (data && Array.isArray(data.items)) {
items = data.items;
} else if (data && Array.isArray(data.data)) {
items = data.data;
2025-07-28 16:50:59 +08:00
}
2025-07-29 17:32:30 +08:00
// 为每个产品项添加组合标签
return items.map((item: any) => ({
...item,
label: `${item.productName || item.ProductName || ''} (${item.ioTPlatformProductId || ''})`,
}));
2025-07-28 16:50:59 +08:00
}
// 如果都不是,返回空数组
return [];
},
2025-07-29 17:32:30 +08:00
placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingProductName')}`,
},
2025-07-28 16:50:59 +08:00
rules: z.string().min(1, {
2025-07-29 17:32:30 +08:00
message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingProductName')}`,
2025-07-28 16:50:59 +08:00
}),
},
{
component: 'Input',
2025-07-28 16:50:59 +08:00
fieldName: 'deviceName',
label: $t('abp.deviceInfos.deviceName'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceName')}`,
}),
},
{
component: 'Input',
2025-07-28 16:50:59 +08:00
fieldName: 'deviceAddress',
label: $t('abp.deviceInfos.deviceAddress'),
disabled: true,
},
{
component: 'Input',
2025-07-28 16:50:59 +08:00
fieldName: 'platformPassword',
label: $t('abp.deviceInfos.platformPassword'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.deviceInfos.platformPassword')}`,
}),
},
]);