@jdlinker/linker
Version:
jdLinker 系统模块
202 lines (199 loc) • 4.33 kB
text/typescript
import { BasicColumn, FormSchema, render } from '@jdlinker/ui';
const isScript = (type) => type === 'script';
const isJar = (type) => type === 'jar';
const isLocal = (type) => type === 'local';
const isEncode = (type) => type === '1';
const isDecode = (type) => type === '2';
//列表数据
export const columns: BasicColumn[] = [
{
title: 'ID',
align: 'center',
dataIndex: 'id',
width: 180
},
{
title: '协议名称',
align: 'center',
dataIndex: 'name',
width: 160
},
{
title: '类型',
align: 'center',
dataIndex: 'type',
width: 80,
customRender: ({ text }) => {
return render.renderDict(text, 'protocol_type');
}
},
{
title: '说明',
align: 'center',
dataIndex: 'description'
}
];
//查询数据
export const searchFormSchema: FormSchema[] = [
{
label: '协议名称',
field: 'name',
component: 'Input'
},
{
label: '协议类型',
field: 'type',
component: 'JDictSelectTag',
componentProps: {
dictCode: 'protocol_type'
}
}
];
//表单数据
export const formSchema: FormSchema[] = [
{
label: '协议名称',
field: 'name',
component: 'Input'
},
{
label: '类型',
field: 'type',
component: 'JDictSelectTag',
componentProps: {
dictCode: 'protocol_type'
}
},
{
label: '上传协议',
field: 'location',
component: 'JUpload',
componentProps: { maxCount: 1 },
ifShow: ({ values }) => isJar(values.type) || isLocal(values.type)
},
{
label: '协议标识',
field: 'protocol',
component: 'Input',
ifShow: ({ values }) => isScript(values.type)
},
{
label: '连接协议',
field: 'transport',
component: 'JDictSelectTag',
componentProps: {
dictCode: 'connect_protocol'
},
ifShow: ({ values }) => isScript(values.type)
},
{
label: '脚本',
field: 'script',
component: 'JCodeEditor',
defaultValue:
'//解码,收到设备上行消息时\n' +
'codec.decoder(function (context) {\n' +
' var message = context.getMessage();\n' +
' return {\n' +
' messageType:"REPORT_PROPERTY"//消息类型\n' +
' };\n' +
'});\n' +
'\n' +
'//编码读取设备属性消息\n' +
'codec.encoder("READ_PROPERTY",function(context){\n' +
' var message = context.getMessage();\n' +
' var properties = message.properties;\n' +
' alert(properties);\n' +
'})',
ifShow: ({ values }) => isScript(values.type)
},
{
label: '描述',
field: 'description',
component: 'InputTextArea',
colProps: {
span: 24
}
},
{
label: '',
field: 'id',
component: 'Input',
show: false
}
];
//调试参数
export const debugSchema: FormSchema[] = [
{
label: '',
field: 'debugType',
component: 'RadioGroup',
defaultValue: '1',
componentProps: ({ formActionType }) => {
return {
options: [
{ label: '编码', value: '1' },
{ label: '解码', value: '2' }
],
onChange: (e) => {
const { updateSchema } = formActionType;
updateSchema([
{
field: 'encodeScript',
ifShow: isEncode(e.target.value)
},
{
field: 'decodeScript',
ifShow: isDecode(e.target.value)
}
]);
}
};
},
colProps: {
span: 8
}
},
{
label: '连接类型',
field: 'transportType',
component: 'JDictSelectTag',
componentProps: {
dictCode: 'connect_protocol'
},
colProps: {
span: 8
}
},
{
label: '消息类型',
field: 'contentType',
component: 'JDictSelectTag',
componentProps: {
dictCode: 'content_type'
},
defaultValue: '1',
colProps: {
span: 8
}
},
{
label: '',
field: 'encodeScript',
component: 'JCodeEditor',
defaultValue: '{\n' + ' "messageType":"READ_PROPERTY",\n' + ' "properties":[\n' + ' \n' + ' ]\n' + '}'
},
{
label: '',
field: 'decodeScript',
component: 'JCodeEditor',
defaultValue: '',
ifShow: false
},
{
label: '',
field: 'debugResult',
component: 'JCodeEditor',
ifShow: false
}
];