data.ts 11.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
import { FormSchema } from '/@/components/Form';
import { deviceConfigGetRuleChain } from '/@/api/device/deviceConfigApi';
import { findDictItemByCode } from '/@/api/system/dict';

enum EnumMQTT {
  IS_DEFAULT = 'DEFAULT',
  IS_MQTT = 'MQTT',
  IS_PROTOBUF = 'PROTOBUF',
  IS_COAP = 'COAP',
  IS_LWM2M = 'LWM2M',
  IS_SNMP = 'SNMP',
  IS_PSM = 'PSM',
  IS_DRX = 'E_DRX',
  IS_EFENTO_NBIOT = 'EFENTO',
}

const isMqtt = (type: string) => {
  return type === EnumMQTT.IS_MQTT;
};
const isProtobuf = (type: string) => {
  return type === EnumMQTT.IS_PROTOBUF;
};

const isNBIOt = (type: string) => {
  return type === EnumMQTT.IS_COAP;
};

const isPsm = (type: string) => {
  return type === EnumMQTT.IS_PSM;
};

const isDrx = (type: string) => {
  return type === EnumMQTT.IS_DRX;
};

const isEfentoNb = (type: string) => {
  return type === EnumMQTT.IS_EFENTO_NBIOT;
};

export const step1Schemas: FormSchema[] = [
  {
    field: 'name',
    label: '上传图片',
    component: 'Input',
    slot: 'imageSelect',
  },
  {
    field: 'name',
    label: '配置名称',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入配置名称',
    },
  },
  {
    field: 'defaultRuleChainId',
    label: '规则链',
    component: 'ApiSelect',
    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',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'queen_execute_sequence',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
      resultField: 'items',
    },
  },

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

export const step2Schemas: FormSchema[] = [
  {
    field: 'transportType',
    component: 'Select',
    label: '传输方式',
    defaultValue: 'DEFAULT',
    componentProps: {
      options: [
        { label: '默认', value: 'DEFAULT' },
        { label: 'MQTT', value: 'MQTT' },
        { label: 'CoAP', value: 'COAP' },
      ],
    },
    colProps: { span: 11 },
  },
  {
    field: 'deviceTelemetryTopic',
    component: 'Input',
    label: '筛选器',
    required: true,
    defaultValue: 'v1/devices/me/telemetry',
    componentProps: {
      placeholder: '请输入遥测数据 topic 筛选器',
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isMqtt(values.transportType),
  },
  {
    field: 'deviceAttributesTopic',
    component: 'Input',
    required: true,
    label: 'topic filter',
    defaultValue: 'v1/devices/me/attributes',
    componentProps: {
      placeholder: '请输入Attributes topic 筛选器',
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isMqtt(values.transportType),
  },
  {
    field: 'desc',
    component: 'InputTextArea',
    label: '描述',
    defaultValue: `支持单[+]和多级[#]通配符。[+] is suitable for any topic filter level。例如:v1/devices/+/telemetry or +/devices/+/attributes。[#]可以替换 topic filter 本身,并且必须是 topic 的最后一个符号。例如:# or v1/devices/me/#。
    `,
    componentProps: {
      autoSize: {
        maxRows: 10,
      },
      placeholder: '请输入Attributes topic 筛选器',
    },
    colProps: { span: 24 },
    ifShow: ({ values }) => isMqtt(values.transportType),
  },
  {
    field: 'transportPayloadType',
    component: 'Select',
    label: '设备Payload',
    defaultValue: 'JSON',
    componentProps: {
      options: [
        { label: 'JSON', value: 'JSON' },
        { label: 'PROTOBUF', value: 'PROTOBUF' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isMqtt(values.transportType),
  },
  {
    field: 'useJsonPayloadFormatForDefaultDownlinkTopics',
    label: '',
    colProps: { span: 14 },
    defaultValue: false,
    component: 'Checkbox',
    renderComponentContent: `启用后,平台将默认使用Protobuf有效载荷格式。如果解析失败,平台将尝试使用JSON有效负载格式。用于固件更新期间的向后兼容性。例如,固件的初始版本使用Json,而新版本使用Protobuf。在设备组的固件更新过程中,需要同时支持Protobuf和JSON。兼容性模式会导致性能轻微下降,因此建议在所有设备更新后禁用此模式。`,
    ifShow: ({ values }) =>
      isProtobuf(values.transportPayloadType) && !isNBIOt(values.transportType),
  },
  {
    field: 'enableCompatibilityWithJsonPayloadFormat',
    label: '',
    colProps: { span: 14 },
    defaultValue: false,
    component: 'Checkbox',
    renderComponentContent: `启用后,平台将使用Json有效负载格式通过以下主题推送属性和RPC:v1/devices/me/attributes/response/$request_id、v1/devices/me/attributes、v1/devices/me/RPC/request/$request_id、,v1/devices/me/rpc/response/$request id。此设置不影响使用新(v2)主题发送的属性和rpc订阅:v2/a/res/$request id、v2/a、v2/r/req/$request id、v2/r/res/$request id。其中,$request id是整数请求标识符。`,
    ifShow: ({ values }) =>
      isProtobuf(values.transportPayloadType) &&
      !!values.useJsonPayloadFormatForDefaultDownlinkTopics &&
      !isNBIOt(values.transportType),
  },
  {
    field: 'coapDeviceType',
    component: 'Select',
    label: 'CoAP类型',
    defaultValue: 'DEFAULT',
    componentProps: {
      options: [
        { label: '默认', value: 'DEFAULT' },
        { label: 'Efento NB-IoT', value: 'EFENTO' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType),
  },
  {
    field: 'transportPayloadType',
    component: 'Select',
    label: 'Payload',
    defaultValue: 'JSON',
    componentProps: {
      options: [
        { label: 'JSON', value: 'JSON' },
        { label: 'PROTOBUF', value: 'PROTOBUF' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType) && !isEfentoNb(values.coapDeviceType),
  },
  {
    field: 'powerMode',
    component: 'Select',
    label: 'Power Mode',
    defaultValue: 'DRX',
    componentProps: {
      options: [
        { label: 'Power Saving Mode', value: 'PSM' },
        { label: 'Discontinuous Reception', value: 'DRX' },
        {
          label: 'Extended Discontinuous Reception',
          value: 'E_DRX',
        },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType),
  },
  {
    field: 'psmActivityTimer',
    component: 'InputNumber',
    label: 'Timer',
    required: true,
    defaultValue: '10',
    componentProps: {
      placeholder: '请输入PSM Activity Timer',
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType) && isPsm(values.powerMode),
  },
  {
    field: 'unit',
    component: 'Select',
    label: '时间单位',
    defaultValue: 'second',
    componentProps: {
      options: [
        { label: 'Milliseconds', value: 'Milliseconds' },
        { label: '秒', value: 'second' },
        { label: '分钟', value: 'minute' },
        { label: '小时', value: 'hour' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType) && isPsm(values.powerMode),
  },
  {
    field: 'edrxCycle',
    component: 'InputNumber',
    label: 'eDRX cycle',
    required: true,
    defaultValue: '81',
    componentProps: {
      placeholder: '请输入PSM Activity Timer',
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType) && isDrx(values.powerMode),
  },
  {
    field: 'unit',
    component: 'Select',
    label: '时间单位',
    defaultValue: 'second',
    componentProps: {
      options: [
        { label: 'Milliseconds', value: 'Milliseconds' },
        { label: '秒', value: 'second' },
        { label: '分钟', value: 'minute' },
        { label: '小时', value: 'hour' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType) && isDrx(values.powerMode),
  },
  {
    field: 'pagingTransmissionWindow',
    component: 'InputNumber',
    label: 'Paging',
    required: true,
    defaultValue: '10',
    componentProps: {
      placeholder: '请输入Paging Transmission Window',
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType) && isDrx(values.powerMode),
  },
  {
    field: 'unit',
    component: 'Select',
    label: '时间单位',
    defaultValue: 'second',
    componentProps: {
      options: [
        { label: 'Milliseconds', value: 'Milliseconds' },
        { label: '秒', value: 'second' },
        { label: '分钟', value: 'minute' },
        { label: '小时', value: 'hour' },
      ],
    },
    colProps: { span: 11 },
    ifShow: ({ values }) => isNBIOt(values.transportType) && isDrx(values.powerMode),
  },
  {
    field: 'deviceTelemetryProtoSchema',
    label: '遥测数据',
    colProps: { span: 22 },
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        maxRows: 10,
      },
    },
    defaultValue: `
    syntax ="proto3";
    package telemetry;

    message SensorDataReading {
      optional double temperature = 1;
      optional double humidity = 2;
      InnerObject innerObject = 3;
      message InnerObject {
        optional string key1 = 1;
        optional bool key2 = 2;
        optional double key3 = 3;
        optional int32 key4 = 4;
        optional string key5 = 5;
      }
    }
    `,
    ifShow: ({ values }) => isProtobuf(values.transportPayloadType),
  },
  {
    field: 'deviceAttributesProtoSchema',
    label: 'Attributes',
    colProps: { span: 22 },
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        maxRows: 10,
      },
    },
    defaultValue: `
    syntax ="proto3";
    package attributes;

    message SensorConfiguration {
      optional string firmwareVersion = 1;
      optional string serialNumber = 2;
    }
    `,
    ifShow: ({ values }) => isProtobuf(values.transportPayloadType),
  },
  {
    field: 'deviceRpcRequestProtoSchema',
    label: 'RPC 请求 ',
    colProps: { span: 22 },
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        maxRows: 10,
      },
    },
    defaultValue: `
    syntax ="proto3";
    package rpc;
    
    message RpcRequestMsg {
      optional string method = 1;
      optional int32 requestId = 2;
      optional string params = 3;
    }
    `,
    ifShow: ({ values }) => isProtobuf(values.transportPayloadType),
  },
  {
    field: 'deviceRpcResponseProtoSchema',
    label: 'RPC 响应',
    colProps: { span: 22 },
    component: 'InputTextArea',
    componentProps: {
      autoSize: {
        maxRows: 10,
      },
    },
    defaultValue: `
    syntax ="proto3";
    package rpc;
    
    message RpcResponseMsg {
      optional string payload = 1;
    }
    `,
    ifShow: ({ values }) => isProtobuf(values.transportPayloadType),
  },
];