265 lines
6.0 KiB
TypeScript
265 lines
6.0 KiB
TypeScript
import type { FormSchemaGetter } from '#/adapter/form';
|
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
|
|
import { networkList } from '#/api/operations/network';
|
|
import { protocolList } from '#/api/operations/protocol';
|
|
|
|
import { enabledOptions, networkTypeOptions } from '../user.data';
|
|
|
|
export const providerOptions = [
|
|
...networkTypeOptions,
|
|
{
|
|
label: '网关子设备接入',
|
|
value: 'child-device',
|
|
channel: 'child-device',
|
|
transport: 'Gateway',
|
|
description:
|
|
'需要通过网关与平台进行数据通信的设备,将作为网关子设备接入到平台。',
|
|
},
|
|
];
|
|
|
|
// 存储网络组件更新回调函数
|
|
let networkOptionsUpdateCallback: ((provider: string) => Promise<void>) | null =
|
|
null;
|
|
|
|
// 注册网络组件更新回调
|
|
export const registerNetworkOptionsUpdate = (
|
|
callback: (provider: string) => Promise<void>,
|
|
) => {
|
|
networkOptionsUpdateCallback = callback;
|
|
};
|
|
|
|
// 获取网络组件选项
|
|
export const getNetworkOptions = async (networkType?: string) => {
|
|
try {
|
|
const params: any = { enabled: '1' };
|
|
if (networkType) {
|
|
params.networkType = networkType;
|
|
}
|
|
const response = await networkList(params);
|
|
return response.rows.map((item: any) => ({
|
|
label: item.name,
|
|
value: item.id,
|
|
}));
|
|
} catch (error) {
|
|
console.error('获取网络组件失败:', error);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
// 获取消息协议选项
|
|
export const getProtocolOptions = async () => {
|
|
try {
|
|
const response = await protocolList({ enabled: '1' });
|
|
return response.rows.map((item: any) => ({
|
|
label: item.name,
|
|
value: item.id,
|
|
}));
|
|
} catch (error) {
|
|
console.error('获取消息协议失败:', error);
|
|
return [];
|
|
}
|
|
};
|
|
|
|
export const querySchema: FormSchemaGetter = () => [
|
|
{
|
|
component: 'Input',
|
|
fieldName: 'name',
|
|
label: '网关名称',
|
|
},
|
|
{
|
|
component: 'Select',
|
|
componentProps: {
|
|
allowClear: true,
|
|
filterOption: true,
|
|
options: providerOptions,
|
|
placeholder: '请选择',
|
|
showSearch: true,
|
|
},
|
|
fieldName: 'provider',
|
|
label: '接入方式',
|
|
},
|
|
// {
|
|
// component: 'Select',
|
|
// componentProps: {
|
|
// allowClear: true,
|
|
// filterOption: true,
|
|
// placeholder: '请选择网络组件',
|
|
// showSearch: true,
|
|
// },
|
|
// fieldName: 'channelId',
|
|
// label: '网络组件',
|
|
// dependencies: {
|
|
// triggerFields: ['provider'],
|
|
// show: (values: any) =>
|
|
// values.provider && values.provider !== 'child-device',
|
|
// },
|
|
// },
|
|
{
|
|
component: 'Select',
|
|
componentProps: {
|
|
allowClear: true,
|
|
filterOption: true,
|
|
placeholder: '请选择消息协议',
|
|
showSearch: true,
|
|
},
|
|
fieldName: 'protocol',
|
|
label: '消息协议',
|
|
},
|
|
{
|
|
component: 'Select',
|
|
componentProps: {
|
|
allowClear: true,
|
|
filterOption: true,
|
|
options: enabledOptions,
|
|
placeholder: '请选择',
|
|
showSearch: true,
|
|
},
|
|
fieldName: 'enabled',
|
|
label: '启用状态',
|
|
},
|
|
];
|
|
|
|
// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
|
|
// export const columns: () => VxeGridProps['columns'] = () => [
|
|
export const columns: VxeGridProps['columns'] = [
|
|
{ type: 'checkbox', width: 60 },
|
|
{
|
|
title: '编号',
|
|
field: 'id',
|
|
},
|
|
{
|
|
title: '网关名称',
|
|
field: 'name',
|
|
},
|
|
{
|
|
title: '网络组件',
|
|
field: 'channelId',
|
|
},
|
|
{
|
|
title: '消息协议',
|
|
field: 'protocol',
|
|
},
|
|
{
|
|
title: '启用状态',
|
|
field: 'enabled',
|
|
slots: { default: 'enabled' },
|
|
},
|
|
{
|
|
field: 'action',
|
|
fixed: 'right',
|
|
slots: { default: 'action' },
|
|
title: '操作',
|
|
width: 180,
|
|
},
|
|
];
|
|
|
|
export const drawerSchema: FormSchemaGetter = () => [
|
|
{
|
|
label: '编号',
|
|
fieldName: 'id',
|
|
component: 'Input',
|
|
dependencies: {
|
|
show: () => false,
|
|
triggerFields: [''],
|
|
},
|
|
},
|
|
{
|
|
label: '网关名称',
|
|
fieldName: 'name',
|
|
component: 'Input',
|
|
rules: 'required',
|
|
},
|
|
{
|
|
label: '接入方式',
|
|
fieldName: 'provider',
|
|
component: 'Select',
|
|
componentProps: {
|
|
allowClear: true,
|
|
filterOption: true,
|
|
options: providerOptions,
|
|
placeholder: '请选择',
|
|
showSearch: true,
|
|
onChange: async (value: string) => {
|
|
console.log('抽屉表单接入方式变化:', value);
|
|
if (networkOptionsUpdateCallback) {
|
|
await networkOptionsUpdateCallback(value);
|
|
}
|
|
},
|
|
},
|
|
rules: 'required',
|
|
},
|
|
{
|
|
label: '网络组件',
|
|
fieldName: 'channelId',
|
|
component: 'Select',
|
|
componentProps: {
|
|
allowClear: true,
|
|
filterOption: true,
|
|
placeholder: '请选择网络组件',
|
|
showSearch: true,
|
|
},
|
|
rules: 'required',
|
|
dependencies: {
|
|
triggerFields: ['provider'],
|
|
show: (values: any) =>
|
|
values.provider && values.provider !== 'child-device',
|
|
},
|
|
},
|
|
{
|
|
label: '消息协议',
|
|
fieldName: 'protocol',
|
|
component: 'Select',
|
|
componentProps: {
|
|
allowClear: true,
|
|
filterOption: true,
|
|
placeholder: '请选择消息协议',
|
|
showSearch: true,
|
|
},
|
|
rules: 'required',
|
|
dependencies: {
|
|
triggerFields: ['provider'],
|
|
show: (values: any) => values.provider && values.provider !== '',
|
|
},
|
|
},
|
|
{
|
|
label: '启用状态',
|
|
fieldName: 'enabled',
|
|
component: 'RadioGroup',
|
|
componentProps: {
|
|
buttonStyle: 'solid',
|
|
options: enabledOptions,
|
|
optionType: 'button',
|
|
},
|
|
defaultValue: '1',
|
|
rules: 'required',
|
|
},
|
|
{
|
|
label: '描述',
|
|
fieldName: 'description',
|
|
component: 'Textarea',
|
|
componentProps: {
|
|
placeholder: '请输入描述',
|
|
rows: 3,
|
|
},
|
|
},
|
|
{
|
|
label: '接入通道(方式)',
|
|
fieldName: 'channel',
|
|
component: 'Input',
|
|
dependencies: {
|
|
show: () => false,
|
|
triggerFields: [''],
|
|
},
|
|
},
|
|
{
|
|
label: '传输协议',
|
|
fieldName: 'transport',
|
|
component: 'Input',
|
|
dependencies: {
|
|
show: () => false,
|
|
triggerFields: [''],
|
|
},
|
|
},
|
|
];
|