| 1 | 1 | import { Options } from './type'; | 
|  | 2 | +import { getMeetTheConditionsDevice } from '/@/api/dataBoard'; | 
| 2 | 3 | import { queryDeviceProfileBy } from '/@/api/device/deviceManager'; | 
|  | 4 | +import { DeviceRecord, DeviceTypeEnum } from '/@/api/device/model/deviceModel'; | 
| 3 | 5 | import { findDictItemByCode } from '/@/api/system/dict'; | 
| 4 | 6 | import { getOrganizationList } from '/@/api/system/system'; | 
| 5 | 7 | import { FormSchema } from '/@/components/Form'; | 
| 6 | 8 | import { BasicColumn } from '/@/components/Table'; | 
| 7 | 9 | import { copyTransFun } from '/@/utils/fnUtils'; | 
|  | 10 | +import { TransportTypeEnum } from '/@/views/device/profiles/components/TransportDescript/const'; | 
| 8 | 11 |  | 
| 9 | 12 | export enum FieldsEnum { | 
| 10 | 13 | ORGANIZATION_ID = 'organizationId', | 
| ... | ... | @@ -14,6 +17,9 @@ export enum FieldsEnum { | 
| 14 | 17 | DELIMITER = 'delimiter', | 
| 15 | 18 | HEADER = 'header', | 
| 16 | 19 | UPDATE = 'update', | 
|  | 20 | +  GATEWAY_TB_DEVICE_ID = 'gateWayTbDeviceId', | 
|  | 21 | +  TB_DEVICE_PROFILE_ID = 'tbDeviceProfileId', | 
|  | 22 | +  IS_TCP_DEVICE_PROFILE = 'isTcpDeviceProfile', | 
| 17 | 23 | } | 
| 18 | 24 |  | 
| 19 | 25 | export enum DelimiterEnum { | 
| ... | ... | @@ -39,7 +45,7 @@ export enum ColumnFileEnum { | 
| 39 | 45 |  | 
| 40 | 46 | export enum ColumTypeEnum { | 
| 41 | 47 | NAME = 'NAME', | 
| 42 |  | -  // TYPE = 'TYPE', | 
|  | 48 | +  TYPE = 'TYPE', | 
| 43 | 49 | LABEL = 'LABEL', | 
| 44 | 50 | DESCRIPTION = 'DESCRIPTION', | 
| 45 | 51 | SHARED_ATTRIBUTE = 'SHARED_ATTRIBUTE', | 
| ... | ... | @@ -48,6 +54,17 @@ export enum ColumTypeEnum { | 
| 48 | 54 | IS_GATEWAY = 'IS_GATEWAY', | 
| 49 | 55 | } | 
| 50 | 56 |  | 
|  | 57 | +export enum ColumnTypeNameEnum { | 
|  | 58 | +  NAME = '名称', | 
|  | 59 | +  TYPE = '类型', | 
|  | 60 | +  LABEL = '标签', | 
|  | 61 | +  DESCRIPTION = '说明', | 
|  | 62 | +  SHARED_ATTRIBUTE = '共享属性', | 
|  | 63 | +  SERVER_ATTRIBUTE = '服务器属性', | 
|  | 64 | +  TIMESERIES = 'Timeseries', | 
|  | 65 | +  IS_GATEWAY = 'Is网关', | 
|  | 66 | +} | 
|  | 67 | + | 
| 51 | 68 | export enum CredentialsEnum { | 
| 52 | 69 | ACCESS_TOKEN = 'ACCESS_TOKEN', | 
| 53 | 70 | X509 = 'X509', | 
| ... | ... | @@ -67,17 +84,6 @@ export enum CredentialsEnum { | 
| 67 | 84 | // LWM2M_SERVER_CLIENT_SECRET_KEY = 'LWM2M_SERVER_CLIENT_SECRET_KEY', | 
| 68 | 85 | } | 
| 69 | 86 |  | 
| 70 |  | -export enum ColumnTypeNameEnum { | 
| 71 |  | -  NAME = '名称', | 
| 72 |  | -  // TYPE = '类型', | 
| 73 |  | -  // LABEL = '标签', | 
| 74 |  | -  // DESCRIPTION = '说明', | 
| 75 |  | -  SHARED_ATTRIBUTE = '共享属性', | 
| 76 |  | -  SERVER_ATTRIBUTE = '服务器属性', | 
| 77 |  | -  TIMESERIES = 'Timeseries', | 
| 78 |  | -  IS_GATEWAY = 'Is网关', | 
| 79 |  | -} | 
| 80 |  | - | 
| 81 | 87 | export enum CredentialsNameEnum { | 
| 82 | 88 | ACCESS_TOKEN = '访问令牌', | 
| 83 | 89 | X509 = 'X.509', | 
| ... | ... | @@ -103,8 +109,7 @@ export const basicInfoForm: FormSchema[] = [ | 
| 103 | 109 | label: '所属组织', | 
| 104 | 110 | component: 'ApiTreeSelect', | 
| 105 | 111 | rules: [{ required: true, message: '所属组织为必填项' }], | 
| 106 |  | -    componentProps: ({ formActionType }) => { | 
| 107 |  | -      const { submit } = formActionType; | 
|  | 112 | +    componentProps: () => { | 
| 108 | 113 | return { | 
| 109 | 114 | maxLength: 250, | 
| 110 | 115 | placeholder: '请选择所属组织', | 
| ... | ... | @@ -114,7 +119,6 @@ export const basicInfoForm: FormSchema[] = [ | 
| 114 | 119 | return data; | 
| 115 | 120 | }, | 
| 116 | 121 | getPopupContainer: () => document.body, | 
| 117 |  | -        onChange: () => submit(), | 
| 118 | 122 | }; | 
| 119 | 123 | }, | 
| 120 | 124 | }, | 
| ... | ... | @@ -124,7 +128,7 @@ export const basicInfoForm: FormSchema[] = [ | 
| 124 | 128 | component: 'ApiSelect', | 
| 125 | 129 | rules: [{ required: true, message: '设备类型为必填项' }], | 
| 126 | 130 | componentProps: ({ formActionType }) => { | 
| 127 |  | -      const { setFieldsValue, submit, clearValidate } = formActionType; | 
|  | 131 | +      const { setFieldsValue, clearValidate } = formActionType; | 
| 128 | 132 | return { | 
| 129 | 133 | api: findDictItemByCode, | 
| 130 | 134 | params: { | 
| ... | ... | @@ -136,8 +140,8 @@ export const basicInfoForm: FormSchema[] = [ | 
| 136 | 140 | setFieldsValue({ | 
| 137 | 141 | [FieldsEnum.DEVICE_TYPE_NAME]: value ? options.label : null, | 
| 138 | 142 | [FieldsEnum.TK_DEVICE_PROFILE_ID]: null, | 
|  | 143 | +            [FieldsEnum.GATEWAY_TB_DEVICE_ID]: null, | 
| 139 | 144 | }); | 
| 140 |  | -          submit(); | 
| 141 | 145 | clearValidate(); | 
| 142 | 146 | }, | 
| 143 | 147 | }; | 
| ... | ... | @@ -149,7 +153,7 @@ export const basicInfoForm: FormSchema[] = [ | 
| 149 | 153 | label: '产品', | 
| 150 | 154 | rules: [{ required: true, message: '产品为必填项' }], | 
| 151 | 155 | componentProps: ({ formActionType, formModel }) => { | 
| 152 |  | -      const { submit } = formActionType; | 
|  | 156 | +      const { setFieldsValue } = formActionType; | 
| 153 | 157 | const deviceType = Reflect.get(formModel, FieldsEnum.DEVICE_TYPE); | 
| 154 | 158 | return { | 
| 155 | 159 | api: queryDeviceProfileBy, | 
| ... | ... | @@ -158,7 +162,14 @@ export const basicInfoForm: FormSchema[] = [ | 
| 158 | 162 | placeholder: '请选择产品', | 
| 159 | 163 | params: { deviceType }, | 
| 160 | 164 | getPopupContainer: () => document.body, | 
| 161 |  | -        onChange: () => submit(), | 
|  | 165 | +        onChange(value: string, options: DeviceRecord) { | 
|  | 166 | +          setFieldsValue({ | 
|  | 167 | +            [FieldsEnum.IS_TCP_DEVICE_PROFILE]: value | 
|  | 168 | +              ? options.transportType === TransportTypeEnum.TCP | 
|  | 169 | +              : false, | 
|  | 170 | +            [FieldsEnum.TB_DEVICE_PROFILE_ID]: value ? options.tbProfileId : null, | 
|  | 171 | +          }); | 
|  | 172 | +        }, | 
| 162 | 173 | showSearch: true, | 
| 163 | 174 | filterOption: (inputValue: string, options: Record<'label', string>) => { | 
| 164 | 175 | return options.label.includes(inputValue); | 
| ... | ... | @@ -167,6 +178,51 @@ export const basicInfoForm: FormSchema[] = [ | 
| 167 | 178 | }, | 
| 168 | 179 | }, | 
| 169 | 180 | { | 
|  | 181 | +    field: FieldsEnum.GATEWAY_TB_DEVICE_ID, | 
|  | 182 | +    component: 'ApiSelect', | 
|  | 183 | +    label: '网关设备', | 
|  | 184 | +    ifShow: ({ model }) => model[FieldsEnum.DEVICE_TYPE] === DeviceTypeEnum.SENSOR, | 
|  | 185 | +    required: true, | 
|  | 186 | +    componentProps: ({ formModel }) => { | 
|  | 187 | +      const organizationId = formModel[FieldsEnum.ORGANIZATION_ID]; | 
|  | 188 | +      return { | 
|  | 189 | +        api: async () => { | 
|  | 190 | +          try { | 
|  | 191 | +            if (!organizationId) return; | 
|  | 192 | +            const result = await getMeetTheConditionsDevice({ | 
|  | 193 | +              deviceType: DeviceTypeEnum.GATEWAY, | 
|  | 194 | +              organizationId, | 
|  | 195 | +            }); | 
|  | 196 | +            return result; | 
|  | 197 | +          } catch (error) { | 
|  | 198 | +            return []; | 
|  | 199 | +          } | 
|  | 200 | +        }, | 
|  | 201 | +        labelField: 'name', | 
|  | 202 | +        valueField: 'tbDeviceId', | 
|  | 203 | +        getPopupContainer: () => document.body, | 
|  | 204 | +      }; | 
|  | 205 | +    }, | 
|  | 206 | +  }, | 
|  | 207 | +  { | 
|  | 208 | +    field: FieldsEnum.IS_TCP_DEVICE_PROFILE, | 
|  | 209 | +    component: 'Checkbox', | 
|  | 210 | +    label: 'tcp产品标志', | 
|  | 211 | +    show: false, | 
|  | 212 | +  }, | 
|  | 213 | +  { | 
|  | 214 | +    field: FieldsEnum.TB_DEVICE_PROFILE_ID, | 
|  | 215 | +    component: 'Input', | 
|  | 216 | +    label: 'tb设备配置id', | 
|  | 217 | +    show: false, | 
|  | 218 | +  }, | 
|  | 219 | +  { | 
|  | 220 | +    field: FieldsEnum.GATEWAY_TB_DEVICE_ID, | 
|  | 221 | +    component: 'Input', | 
|  | 222 | +    label: 'tb网关设备ID', | 
|  | 223 | +    show: false, | 
|  | 224 | +  }, | 
|  | 225 | +  { | 
| 170 | 226 | field: FieldsEnum.DEVICE_TYPE_NAME, | 
| 171 | 227 | component: 'Input', | 
| 172 | 228 | label: '设备名称', | 
| ... | ... | @@ -205,14 +261,16 @@ export const importConfigurationSchema: FormSchema[] = [ | 
| 205 | 261 | ]; | 
| 206 | 262 |  | 
| 207 | 263 | export const generateColumnTypeOptions = () => { | 
| 208 |  | -  const valueOptions = Object.keys(ColumTypeEnum); | 
| 209 |  | -  const labelOptions = Object.values(ColumnTypeNameEnum); | 
|  | 264 | +  // const valueOptions = Object.keys(ColumTypeEnum); | 
|  | 265 | +  // const labelOptions = Object.values(ColumnTypeNameEnum); | 
| 210 | 266 | const credentialsValueOptions = Object.keys(CredentialsEnum); | 
| 211 | 267 | const credentialsNameOptions = Object.values(CredentialsNameEnum); | 
| 212 |  | -  const options: Options[] = valueOptions.map((value, index) => ({ | 
| 213 |  | -    label: labelOptions[index], | 
| 214 |  | -    value, | 
| 215 |  | -  })); | 
|  | 268 | +  // const options: Options[] = valueOptions.map((value, index) => ({ | 
|  | 269 | +  //   label: labelOptions[index], | 
|  | 270 | +  //   value, | 
|  | 271 | +  // })); | 
|  | 272 | + | 
|  | 273 | +  const options: Options[] = []; | 
| 216 | 274 |  | 
| 217 | 275 | const credentialsOption: Options = { | 
| 218 | 276 | label: 'credentials', | 
| ... | ... | @@ -245,9 +303,8 @@ export const columnTypeSchema: BasicColumn[] = [ | 
| 245 | 303 | }, | 
| 246 | 304 | ]; | 
| 247 | 305 |  | 
| 248 |  | -export const csvTemplate = `name,username,password | 
| 249 |  | -Device 11,admin,password | 
| 250 |  | -Device 22,admin1,password1 | 
|  | 306 | +export const csvTemplate = `设备名称,凭证账号,凭证密码 | 
|  | 307 | +温湿度设备,admin,123456 | 
| 251 | 308 | `; | 
| 252 | 309 |  | 
| 253 | 310 | export const downloadFile = (data: string, fileName: string, type: string, ext: string) => { | 
... | ... |  |