device.data.ts
3.9 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
import { formatToDate } from '/@/utils/dateUtil';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { DeviceTypeEnum, DeviceState, DeviceRecord } from '/@/api/device/model/deviceModel';
import { deviceProfile } from '/@/api/device/deviceManager';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { handeleCopy } from '../../profiles/step/topic';
// 表格列数据
export const columns: BasicColumn[] = [
  {
    title: '状态',
    dataIndex: 'deviceState',
    width: 80,
    slots: { customRender: 'deviceState' },
  },
  {
    title: '设备图片',
    dataIndex: 'deviceInfo.avatar',
    width: 70,
    slots: { customRender: 'img' },
  },
  {
    dataIndex: 'name',
    title: '别名/设备名称',
    width: 210,
    slots: { customRender: 'name', title: 'deviceTitle' },
    customRender: ({ record }) => {
      return h('div', { style: 'display:flex;flex-direction:column' }, [
        h(
          'p',
          {
            class: 'cursor-pointer',
          },
          `${record.alias}`
        ),
        h(
          'p',
          {
            class: 'cursor-pointer text-blue-500',
            onClick: () => {
              handeleCopy(`${record.name}`);
            },
          },
          `${record.name}`
        ),
      ]);
    },
  },
  {
    title: '设备类型',
    dataIndex: 'deviceType',
    width: 100,
    slots: { customRender: 'deviceType' },
  },
  {
    title: '所属产品',
    dataIndex: 'deviceProfile.name',
    width: 180,
    slots: { customRender: 'deviceProfile' },
    ellipsis: true,
  },
  {
    title: '所属组织',
    dataIndex: 'organizationDTO.name',
    width: 100,
  },
  {
    title: '客户',
    dataIndex: 'customerName',
    width: 100,
  },
  {
    title: '公开',
    dataIndex: 'public',
    width: 100,
    customRender({ record }: { record: DeviceRecord }) {
      const flag = record?.customerAdditionalInfo?.isPublic;
      return h(Tag, { color: flag ? 'blue' : 'orange' }, () => (flag ? '公开' : '私有'));
    },
  },
  {
    title: '最后连接时间',
    dataIndex: 'lastOnlineTime',
    format: (text) => text && formatToDate(text, 'YYYY-MM-DD HH:mm:ss'),
    width: 160,
  },
  {
    title: '最后断开时间',
    dataIndex: 'lastOfflineTime',
    format: (text) => text && formatToDate(text, 'YYYY-MM-DD HH:mm:ss'),
    width: 160,
  },
];
// 查询字段
export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '设备名称',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 255,
      placeholder: '请输入设备名称',
    },
  },
  {
    field: 'deviceType',
    label: '设备类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '网关设备', value: DeviceTypeEnum.GATEWAY },
        { label: '直连设备', value: DeviceTypeEnum.DIRECT_CONNECTION },
        { label: '网关子设备', value: DeviceTypeEnum.SENSOR },
      ],
      placeholder: '请选择设备类型',
    },
    colProps: { span: 6 },
  },
  {
    field: 'deviceState',
    label: '设备状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '待激活', value: DeviceState.INACTIVE },
        { label: '在线', value: DeviceState.ONLINE },
        { label: '离线', value: DeviceState.OFFLINE },
      ],
      placeholder: '请选择设备状态',
    },
    colProps: { span: 6 },
  },
  {
    field: 'deviceProfileId',
    label: '产品',
    component: 'ApiSelect',
    colProps: { span: 6 },
    componentProps: () => {
      return {
        showSearch: true,
        labelField: 'name',
        valueField: 'tbProfileId',
        resultField: 'data',
        placeholder: '请选择产品',
        api: deviceProfile,
        filterOption: (inputValue: string, option: Record<'label' | 'value', string>) =>
          option.label.includes(inputValue),
      };
    },
  },
];