657 lines
18 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,
2025-07-30 15:05:32 +08:00
postCtWingAccountListAsync,
postCtWingProductListAsync,
postOneNetAccountListAsync,
2025-07-28 16:50:59 +08:00
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',
2025-07-30 15:05:32 +08:00
fieldName: 'ioTPlatform',
label: $t('abp.deviceInfos.ioTPlatform'),
2025-07-28 16:50:59 +08:00
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-30 15:05:32 +08:00
message: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatform')}`,
2025-07-28 16:50:59 +08:00
}),
},
{
component: 'ApiSelect',
2025-07-30 15:05:32 +08:00
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: postOneNetAccountListAsync,
params: {
body: {
pageIndex: 1,
pageSize: 1000,
},
},
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'],
},
2025-07-28 16:50:59 +08:00
componentProps: {
api: postOneNetProductListAsync,
params: {
body: {
pageIndex: 1,
pageSize: 1000,
2025-07-30 15:05:32 +08:00
oneNETAccountId: '{{oneNETAccountId}}', // 动态参数
},
},
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: '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}}', // 动态参数
2025-07-28 16:50:59 +08:00
},
},
2025-07-30 15:05:32 +08:00
labelField: 'productName',
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,
2025-07-30 15:05:32 +08:00
label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`,
2025-07-29 17:32:30 +08:00
}));
2025-07-28 16:50:59 +08:00
}
// 如果都不是,返回空数组
return [];
},
2025-07-30 15:05:32 +08:00
placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`,
2025-07-28 16:50:59 +08:00
},
2025-07-30 15:05:32 +08:00
rules: z.string().optional(),
},
{
component: 'Input',
fieldName: 'deviceName',
label: $t('abp.deviceInfos.deviceName'),
2025-07-28 16:50:59 +08:00
rules: z.string().min(1, {
2025-07-30 15:05:32 +08:00
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceName')}`,
}),
},
{
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-30 15:05:32 +08:00
{
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')}`,
}),
},
2025-07-28 16:50:59 +08:00
]);
export const editDeviceFormSchemaEdit: any = computed(() => [
{
2025-07-28 16:50:59 +08:00
component: 'ApiSelect',
2025-07-30 15:05:32 +08:00
fieldName: 'ioTPlatform',
label: $t('abp.deviceInfos.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-30 15:05:32 +08:00
rules: z.string().min(1, {
message: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatform')}`,
}),
},
{
component: 'ApiSelect',
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: postOneNetAccountListAsync,
params: {
body: {
pageIndex: 1,
pageSize: 1000,
},
},
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(),
},
{
2025-07-28 16:50:59 +08:00
component: 'ApiSelect',
2025-07-30 15:05:32 +08:00
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: {
2025-07-28 16:50:59 +08:00
api: postOneNetProductListAsync,
params: {
body: {
pageIndex: 1,
pageSize: 1000,
2025-07-30 15:05:32 +08:00
oneNETAccountId: '{{oneNETAccountId}}', // 动态参数
2025-07-28 16:50:59 +08:00
},
},
2025-07-30 15:05:32 +08:00
labelField: 'productName',
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,
2025-07-30 15:05:32 +08:00
label: `${item.productName || ''} (${item.ioTPlatformProductId || ''})`,
2025-07-29 17:32:30 +08:00
}));
2025-07-28 16:50:59 +08:00
}
// 如果都不是,返回空数组
return [];
},
2025-07-30 15:05:32 +08:00
placeholder: `${$t('common.pleaseSelect')}${$t('abp.deviceInfos.ioTPlatformProductName')}`,
},
2025-07-30 15:05:32 +08:00
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',
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')}`,
}),
},
]);