device.profile.data.ts 7.82 KB
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { findDictItemByCode } from '/@/api/system/dict';
import { MessageEnum } from '/@/enums/messageEnum';
import { numberRule } from '/@/utils/rules';
import { Tag } from 'ant-design-vue';
import { h } from 'vue';

import { deviceConfigGetRuleChain } from '/@/api/device/deviceConfigApi';

export const physicalColumn: BasicColumn[] = [
  {
    title: '功能名称',
    dataIndex: 'name',
    width: 80,
  },
  {
    title: '标识符',
    dataIndex: 'type',
    width: 80,
  },
  {
    title: '数据类型',
    dataIndex: 'transportType',
    width: 80,
  },
  {
    title: '单位',
    dataIndex: 'description1',
    width: 70,
  },
  {
    title: '读写类型',
    dataIndex: 'default',
    width: 70,
    customRender: ({ record }) => {
      const status = record.actionStatus;
      const enable = status === 'SUCCESS' ? '读写' : '只读';
      const color = enable === '读写' ? 'blue' : 'blue';
      const text = enable === '读写' ? '读写' : '只读';
      return h(Tag, { color }, () => text);
    },
  },
  {
    title: '创建人',
    dataIndex: 'description',
    width: 90,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 140,
  },
];

export const step1Schemas: FormSchema[] = [
  {
    field: 'image',
    label: '上传图片',
    component: 'Input',
    slot: 'imageSelect',
  },
  {
    field: 'name',
    label: '配置名称',
    required: true,
    component: 'Input',
    colProps: { span: 14 },
    componentProps() {
      return {
        disabled: false,
        ength: 255,
        placeholder: '请输入配置名称',
      };
    },
  },
  {
    field: 'defaultRuleChainId',
    label: '规则链',
    component: 'ApiSelect',
    colProps: { span: 14 },

    componentProps: {
      api: async () => {
        const data = await deviceConfigGetRuleChain();
        const returnData = data.map((m) => {
          return {
            getValueField: m.name,
            getKeyField: m.id.id,
          };
        });
        return returnData;
      },
      labelField: 'getValueField',
      valueField: 'getKeyField',
      immediate: true,
    },
  },
  {
    field: 'defaultQueueName',
    label: '处理队列',
    component: 'ApiSelect',
    colProps: { span: 14 },

    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'queen_execute_sequence',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
      resultField: 'items',
    },
  },

  {
    label: '描述',
    field: 'description',
    colProps: { span: 14 },
    component: 'InputTextArea',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入描述',
      rows: 6,
    },
  },
];

export const step2Schemas: FormSchema[] = [
  {
    field: 'transportType',
    component: 'Select',
    label: '接入协议',
    defaultValue: 'DEFAULT',
    componentProps() {
      return {
        options: [
          { label: '默认', value: 'DEFAULT' },
          { label: 'MQTT', value: 'MQTT' },
          { label: 'CoAP', value: 'COAP' },
          { label: 'LWM2M', value: 'LWM2M' },
          { label: 'SNMP', value: 'SNMP' },
        ],
      };
    },
    colProps: { span: 10 },
  },
];

export const columns: BasicColumn[] = [
  {
    title: '配置图片', //图标
    dataIndex: 'image',
    width: 80,
    slots: { customRender: 'img' },
  },
  {
    title: '名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '配置类型',
    dataIndex: 'type',
    width: 90,
  },
  {
    title: '接入协议',
    dataIndex: 'transportType',
    width: 90,
  },
  {
    title: '默认配置',
    dataIndex: 'default',
    width: 80,
    format: (text) => (text ? '是' : '否'),
  },
  {
    title: '描述',
    dataIndex: 'description',
    width: 90,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 120,
  },
];

export const defaultObj = {
  headers: {
    normalizedNames: {},
    lazyUpdate: null,
  },
  params: {
    updates: null,
    cloneFrom: null,
    encoder: {},
    map: null,
    interceptorConfig: {
      ignoreLoading: false,
      ignoreErrors: false,
      resendRequest: false,
    },
  },
};

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '配置名称',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 255,
      placeholder: '请输入配置名称',
    },
  },
];

export const isMessage = (type: string) => {
  return type === MessageEnum.IS_SMS;
};
export const isEmail = (type: string) => {
  return type === MessageEnum.IS_EMAIL;
};

export const formSchema: FormSchema[] = [
  {
    field: 'configName',
    label: '配置名称',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入配置名称',
    },
  },
  {
    field: 'messageType',
    label: '消息类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'message_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'platformType',
    label: '平台类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'platform_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'accessKeyId',
    label: 'accessKeyId',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeyId',
    },

    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'accessKeySecret',
    label: 'accessKeySecret',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeySecret',
    },

    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'host',
    label: '服务器地址',
    defaultValue: 'smtp.163.com',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeySecret',
    },

    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'port',
    label: '端口',
    defaultValue: 25,
    required: true,
    component: 'InputNumber',
    rules: numberRule,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入端口',
    },

    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'username',
    label: '用户名',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入用户名',
    },

    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'password',
    label: '密码',
    required: true,
    component: 'InputPassword',
    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'config',
    label: '消息配置',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 255,
      placeholder: '请输入消息配置',
    },
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入主键',
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '启用', value: 1 },
        { label: '停用', value: 0 },
      ],
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入备注',
    },
  },
];