Commit 4a03bcbcc8e9ef9a0314195ec84018b3a89cf161

Authored by xp.Huang
2 parents bfe36787 85e57b2c

Merge branch 'fix/DEFECT-1388' into 'main_dev'

Fix/defect 1388

See merge request yunteng/thingskit-front!691
1   -import { FormSchema } from '/@/components/Form';
2   -import { findDictItemByCode } from '/@/api/system/dict';
3   -import { h, unref } from 'vue';
4   -import { getDeviceProfile } from '/@/api/alarm/position';
5   -import { BasicColumn, BasicTableProps } from '/@/components/Table';
6   -import { devicePage } from '/@/api/device/deviceManager';
7   -import { Tag } from 'ant-design-vue';
8   -import { DeviceRecord } from '/@/api/device/model/deviceModel';
9   -import { FETCH_SETTING } from '/@/components/Table/src/const';
10   -import { useMessage } from '/@/hooks/web/useMessage';
11   -import {
12   - BasicInfoFormField,
13   - DataSourceType,
14   - DeviceStatusEnum,
15   - DeviceStatusNameEnum,
16   - DeviceTypeNameEnum,
17   -} from '../enum';
18   -import { useClipboard } from '@vueuse/core';
19   -
20   -export const stepConfig = ['选择流转方式', '完善配置参数'];
21   -
22   -export const removeFieldByModeForm = ['name', 'description'];
23   -
24   -//表单通用配置
25   -export const modelFormPublicConfig = {
26   - labelWidth: 120,
27   - actionColOptions: {
28   - span: 14,
29   - },
30   - showResetButton: false,
31   - showSubmitButton: false,
32   -};
33   -
34   -const handleGroupDevice = (options: DeviceRecord[]) => {
35   - const map = new Map<string, string[]>();
36   - options.forEach((item) => {
37   - if (map.has(item.profileId)) {
38   - const deviceList = map.get(item.profileId)!;
39   - deviceList.push(item.tbDeviceId);
40   - } else {
41   - map.set(item.profileId, [item.tbDeviceId]);
42   - }
43   - });
44   - const value = Array.from(map.entries()).map(([product, devices]) => ({ product, devices }));
45   -
46   - return value;
47   -};
48   -
49   -const deviceTableFormSchema: FormSchema[] = [
50   - {
51   - field: 'name',
52   - label: '设备名称',
53   - component: 'Input',
54   - colProps: { span: 9 },
55   - componentProps: {
56   - placeholder: '请输入设备名称',
57   - },
58   - },
59   - {
60   - field: 'deviceType',
61   - label: '设备类型',
62   - component: 'ApiSelect',
63   - colProps: { span: 9 },
64   - componentProps: {
65   - placeholder: '请选择设备类型',
66   - api: findDictItemByCode,
67   - params: {
68   - dictCode: 'device_type',
69   - },
70   - labelField: 'itemText',
71   - valueField: 'itemValue',
72   - },
73   - },
74   -];
75   -
76   -const { copied, copy } = useClipboard({ legacy: true });
77   -
78   -const { createMessage } = useMessage();
79   -
80   -const deviceTableColumn: BasicColumn[] = [
81   - {
82   - title: '状态',
83   - dataIndex: 'deviceState',
84   - customRender: ({ text }) => {
85   - return h(
86   - Tag,
87   - {
88   - color:
89   - text === DeviceStatusEnum.INACTIVE
90   - ? 'warning'
91   - : text === DeviceStatusEnum.OFFLINE
92   - ? 'error'
93   - : 'success',
94   - },
95   - () => DeviceStatusNameEnum[text]
96   - );
97   - },
98   - },
99   - {
100   - title: '别名/设备名称',
101   - dataIndex: 'name',
102   - customRender: ({ record }) => {
103   - return h('div', [
104   - h(
105   - 'div',
106   - {
107   - class: 'cursor-pointer',
108   - onClick: async () => {
109   - await copy(record.name);
110   - if (unref(copied)) createMessage.success('复制成功~');
111   - },
112   - },
113   - [
114   - record.alias && h('div', { class: 'truncate' }, record.alias),
115   - h('div', { class: 'text-blue-400 truncate' }, record.name),
116   - ]
117   - ),
118   - ]);
119   - },
120   - },
121   - {
122   - title: '设备类型',
123   - dataIndex: 'deviceType',
124   - customRender: ({ text }) => {
125   - return h(Tag, { color: 'success' }, () => DeviceTypeNameEnum[text]);
126   - },
127   - },
128   - {
129   - title: '所属产品',
130   - dataIndex: 'deviceProfile.name',
131   - },
132   - {
133   - title: '所属组织',
134   - dataIndex: 'organizationDTO.name',
135   - },
136   -];
137   -
138   -const TransferTableProps: BasicTableProps = {
139   - formConfig: {
140   - layout: 'inline',
141   - labelWidth: 80,
142   - schemas: deviceTableFormSchema,
143   - actionColOptions: { span: 6 },
144   - },
145   - size: 'small',
146   - maxHeight: 240,
147   - useSearchForm: true,
148   - columns: deviceTableColumn,
149   - showIndexColumn: false,
150   - fetchSetting: FETCH_SETTING,
151   -} as BasicTableProps;
152   -
153   -export const modeForm = (submitFn?: Function): FormSchema[] => {
154   - return [
155   - {
156   - field: BasicInfoFormField.CONVERT_CONFIG_ID,
157   - label: '',
158   - component: 'Input',
159   - show: false,
160   - },
161   - {
162   - field: BasicInfoFormField.DATA_SOURCE_TYPE,
163   - label: '数据源',
164   - component: 'RadioGroup',
165   - defaultValue: DataSourceType.ALL,
166   - componentProps: {
167   - options: [
168   - { label: '全部', value: DataSourceType.ALL },
169   - { label: '产品', value: DataSourceType.PRODUCT },
170   - { label: '设备', value: DataSourceType.DEVICE },
171   - ],
172   - },
173   - },
174   - {
175   - field: BasicInfoFormField.DATA_SOURCE_PRODUCT,
176   - label: '数据源产品',
177   - component: 'TransferModal',
178   - ifShow: ({ model }) => {
179   - return model[BasicInfoFormField.DATA_SOURCE_TYPE] !== DataSourceType.ALL;
180   - },
181   - valueField: 'value',
182   - changeEvent: 'update:value',
183   - componentProps: ({ formActionType }) => {
184   - const { setFieldsValue } = formActionType;
185   - return {
186   - api: getDeviceProfile,
187   - labelField: 'name',
188   - valueField: 'tbProfileId',
189   - transferProps: {
190   - listStyle: { height: '400px' },
191   - showSearch: true,
192   - filterOption: (inputValue: string, option: Recordable) => {
193   - const upperCaseInputValue = inputValue.toUpperCase();
194   - const upperCaseOptionValue = option.name.toUpperCase();
195   - return upperCaseOptionValue.includes(upperCaseInputValue);
196   - },
197   - },
198   - onChange: () => {
199   - setFieldsValue({ [BasicInfoFormField.DATA_SOURCE_DEVICE]: [] });
200   - },
201   - };
202   - },
203   - },
204   - {
205   - field: BasicInfoFormField.DATA_SOURCE_DEVICE,
206   - label: '数据源设备',
207   - component: 'TransferTableModal',
208   - ifShow: ({ model }) => {
209   - return model[BasicInfoFormField.DATA_SOURCE_TYPE] === DataSourceType.DEVICE;
210   - },
211   - valueField: 'value',
212   - changeEvent: 'update:value',
213   - componentProps: ({ formActionType }) => {
214   - const { getFieldsValue } = formActionType;
215   - const values = getFieldsValue();
216   - const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
217   - const devices = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_DEVICE);
218   -
219   - return {
220   - labelField: 'name',
221   - valueField: 'tbDeviceId',
222   - primaryKey: 'tbDeviceId',
223   - pendingTableProps: {
224   - ...TransferTableProps,
225   - api: devicePage,
226   - beforeFetch: (params) => {
227   - const values = getFieldsValue();
228   - const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
229   - const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
230   - if (convertConfigId) {
231   - Object.assign(params, { convertConfigId, selected: false });
232   - }
233   - return { ...params, deviceProfileIds };
234   - },
235   - } as BasicTableProps,
236   - selectedTableProps: {
237   - ...TransferTableProps,
238   - // api
239   - api: !!(convertConfigId && devices) ? devicePage : undefined,
240   - beforeFetch: (params) => {
241   - const values = getFieldsValue();
242   - const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
243   - const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
244   - if (convertConfigId) {
245   - Object.assign(params, { convertConfigId, selected: true });
246   - }
247   - return { ...params, deviceProfileIds };
248   - },
249   - } as BasicTableProps,
250   - initSelectedOptions: async ({ setSelectedTotal }) => {
251   - const values = getFieldsValue();
252   - const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
253   - const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
254   - const devices = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_DEVICE);
255   - if (convertConfigId && devices) {
256   - const { items, total } = await devicePage({
257   - page: 1,
258   - pageSize: 10,
259   - convertConfigId: values[BasicInfoFormField.CONVERT_CONFIG_ID],
260   - deviceProfileIds,
261   - selected: true,
262   - });
263   - setSelectedTotal(total);
264   - return items;
265   - }
266   - return [];
267   - },
268   - onSelectedAfter: async () => {
269   - submitFn && (await submitFn(false));
270   - },
271   - onRemoveAfter: async ({ reloadSelected }) => {
272   - submitFn && (await submitFn(false));
273   - reloadSelected();
274   - },
275   - transformValue: (_selectedRowKeys: string[], selectedRows: DeviceRecord[]) => {
276   - return handleGroupDevice(selectedRows);
277   - },
278   - };
279   - },
280   - },
281   - {
282   - field: 'type',
283   - label: '转换方式',
284   - component: 'ApiSelect',
285   - required: true,
286   - colProps: {
287   - span: 24,
288   - },
289   - componentProps({}) {
290   - return {
291   - api: findDictItemByCode,
292   - params: {
293   - dictCode: 'convert_data_to',
294   - },
295   - labelField: 'itemText',
296   - valueField: 'itemValue',
297   - };
298   - },
299   - },
300   - {
301   - field: 'remark',
302   - label: '描述',
303   - colProps: { span: 24 },
304   - component: 'Input',
305   - componentProps: {
306   - maxLength: 255,
307   - placeholder: '请输入描述',
308   - },
309   - },
310   - ];
311   -};
  1 +import { FormSchema } from '/@/components/Form';
  2 +import { findDictItemByCode } from '/@/api/system/dict';
  3 +import { h, unref } from 'vue';
  4 +import { getDeviceProfile } from '/@/api/alarm/position';
  5 +import { BasicColumn, BasicTableProps } from '/@/components/Table';
  6 +import { devicePage } from '/@/api/device/deviceManager';
  7 +import { Tag } from 'ant-design-vue';
  8 +import { DeviceRecord } from '/@/api/device/model/deviceModel';
  9 +import { FETCH_SETTING } from '/@/components/Table/src/const';
  10 +import { useMessage } from '/@/hooks/web/useMessage';
  11 +import {
  12 + BasicInfoFormField,
  13 + DataSourceType,
  14 + DeviceStatusEnum,
  15 + DeviceStatusNameEnum,
  16 + DeviceTypeNameEnum,
  17 +} from '../enum';
  18 +import { useClipboard } from '@vueuse/core';
  19 +
  20 +export const stepConfig = ['选择流转方式', '完善配置参数'];
  21 +
  22 +export const removeFieldByModeForm = ['name', 'description'];
  23 +
  24 +//表单通用配置
  25 +export const modelFormPublicConfig = {
  26 + labelWidth: 120,
  27 + actionColOptions: {
  28 + span: 14,
  29 + },
  30 + showResetButton: false,
  31 + showSubmitButton: false,
  32 +};
  33 +
  34 +const handleGroupDevice = (options: DeviceRecord[]) => {
  35 + const map = new Map<string, string[]>();
  36 + options.forEach((item) => {
  37 + if (map.has(item.profileId)) {
  38 + const deviceList = map.get(item.profileId)!;
  39 + deviceList.push(item.tbDeviceId);
  40 + } else {
  41 + map.set(item.profileId, [item.tbDeviceId]);
  42 + }
  43 + });
  44 + const value = Array.from(map.entries()).map(([product, devices]) => ({ product, devices }));
  45 +
  46 + return value;
  47 +};
  48 +
  49 +const deviceTableFormSchema: FormSchema[] = [
  50 + {
  51 + field: 'name',
  52 + label: '设备名称',
  53 + component: 'Input',
  54 + colProps: { span: 9 },
  55 + componentProps: {
  56 + placeholder: '请输入设备名称',
  57 + },
  58 + },
  59 + {
  60 + field: 'deviceType',
  61 + label: '设备类型',
  62 + component: 'ApiSelect',
  63 + colProps: { span: 9 },
  64 + componentProps: {
  65 + placeholder: '请选择设备类型',
  66 + api: findDictItemByCode,
  67 + params: {
  68 + dictCode: 'device_type',
  69 + },
  70 + labelField: 'itemText',
  71 + valueField: 'itemValue',
  72 + },
  73 + },
  74 +];
  75 +
  76 +const { copied, copy } = useClipboard({ legacy: true });
  77 +
  78 +const { createMessage } = useMessage();
  79 +
  80 +const deviceTableColumn: BasicColumn[] = [
  81 + {
  82 + title: '状态',
  83 + dataIndex: 'deviceState',
  84 + customRender: ({ text }) => {
  85 + return h(
  86 + Tag,
  87 + {
  88 + color:
  89 + text === DeviceStatusEnum.INACTIVE
  90 + ? 'warning'
  91 + : text === DeviceStatusEnum.OFFLINE
  92 + ? 'error'
  93 + : 'success',
  94 + },
  95 + () => DeviceStatusNameEnum[text]
  96 + );
  97 + },
  98 + },
  99 + {
  100 + title: '别名/设备名称',
  101 + dataIndex: 'name',
  102 + customRender: ({ record }) => {
  103 + return h('div', [
  104 + h(
  105 + 'div',
  106 + {
  107 + class: 'cursor-pointer',
  108 + onClick: async () => {
  109 + await copy(record.name);
  110 + if (unref(copied)) createMessage.success('复制成功~');
  111 + },
  112 + },
  113 + [
  114 + record.alias && h('div', { class: 'truncate' }, record.alias),
  115 + h('div', { class: 'text-blue-400 truncate' }, record.name),
  116 + ]
  117 + ),
  118 + ]);
  119 + },
  120 + },
  121 + {
  122 + title: '设备类型',
  123 + dataIndex: 'deviceType',
  124 + customRender: ({ text }) => {
  125 + return h(Tag, { color: 'success' }, () => DeviceTypeNameEnum[text]);
  126 + },
  127 + },
  128 + {
  129 + title: '所属产品',
  130 + dataIndex: 'deviceProfile.name',
  131 + },
  132 + {
  133 + title: '所属组织',
  134 + dataIndex: 'organizationDTO.name',
  135 + },
  136 +];
  137 +
  138 +const TransferTableProps: BasicTableProps = {
  139 + formConfig: {
  140 + layout: 'inline',
  141 + labelWidth: 80,
  142 + schemas: deviceTableFormSchema,
  143 + actionColOptions: { span: 6 },
  144 + },
  145 + size: 'small',
  146 + maxHeight: 240,
  147 + useSearchForm: true,
  148 + columns: deviceTableColumn,
  149 + showIndexColumn: false,
  150 + fetchSetting: FETCH_SETTING,
  151 +} as BasicTableProps;
  152 +
  153 +export const modeForm = (submitFn?: Function): FormSchema[] => {
  154 + return [
  155 + {
  156 + field: BasicInfoFormField.CONVERT_CONFIG_ID,
  157 + label: '',
  158 + component: 'Input',
  159 + show: false,
  160 + },
  161 + {
  162 + field: BasicInfoFormField.DATA_SOURCE_TYPE,
  163 + label: '数据源',
  164 + component: 'RadioGroup',
  165 + defaultValue: DataSourceType.ALL,
  166 + componentProps: {
  167 + options: [
  168 + { label: '全部', value: DataSourceType.ALL },
  169 + { label: '产品', value: DataSourceType.PRODUCT },
  170 + { label: '设备', value: DataSourceType.DEVICE },
  171 + ],
  172 + },
  173 + },
  174 + {
  175 + field: BasicInfoFormField.DATA_SOURCE_PRODUCT,
  176 + label: '数据源产品',
  177 + component: 'TransferModal',
  178 + rules: [{ required: true, message: '数据源产品为必选项', type: 'array' }],
  179 + ifShow: ({ model }) => {
  180 + return model[BasicInfoFormField.DATA_SOURCE_TYPE] !== DataSourceType.ALL;
  181 + },
  182 + valueField: 'value',
  183 + changeEvent: 'update:value',
  184 + componentProps: ({ formActionType }) => {
  185 + const { setFieldsValue } = formActionType;
  186 + return {
  187 + api: getDeviceProfile,
  188 + labelField: 'name',
  189 + valueField: 'tbProfileId',
  190 + transferProps: {
  191 + listStyle: { height: '400px' },
  192 + showSearch: true,
  193 + filterOption: (inputValue: string, option: Recordable) => {
  194 + const upperCaseInputValue = inputValue.toUpperCase();
  195 + const upperCaseOptionValue = option.name.toUpperCase();
  196 + return upperCaseOptionValue.includes(upperCaseInputValue);
  197 + },
  198 + },
  199 + onChange: () => {
  200 + setFieldsValue({ [BasicInfoFormField.DATA_SOURCE_DEVICE]: [] });
  201 + },
  202 + };
  203 + },
  204 + },
  205 + {
  206 + field: BasicInfoFormField.DATA_SOURCE_DEVICE,
  207 + label: '数据源设备',
  208 + component: 'TransferTableModal',
  209 + ifShow: ({ model }) => {
  210 + return model[BasicInfoFormField.DATA_SOURCE_TYPE] === DataSourceType.DEVICE;
  211 + },
  212 + valueField: 'value',
  213 + changeEvent: 'update:value',
  214 + rules: [{ required: true, message: '数据源设备为必选项', type: 'array' }],
  215 + componentProps: ({ formActionType }) => {
  216 + const { getFieldsValue } = formActionType;
  217 + const values = getFieldsValue();
  218 + const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
  219 + const devices = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_DEVICE);
  220 +
  221 + return {
  222 + labelField: 'name',
  223 + valueField: 'tbDeviceId',
  224 + primaryKey: 'tbDeviceId',
  225 + pendingTableProps: {
  226 + ...TransferTableProps,
  227 + api: devicePage,
  228 + beforeFetch: (params) => {
  229 + const values = getFieldsValue();
  230 + const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
  231 + const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
  232 + if (convertConfigId) {
  233 + Object.assign(params, { convertConfigId, selected: false });
  234 + }
  235 + return { ...params, deviceProfileIds };
  236 + },
  237 + } as BasicTableProps,
  238 + selectedTableProps: {
  239 + ...TransferTableProps,
  240 + // api
  241 + api: !!(convertConfigId && devices) ? devicePage : undefined,
  242 + beforeFetch: (params) => {
  243 + const values = getFieldsValue();
  244 + const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
  245 + const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
  246 + if (convertConfigId) {
  247 + Object.assign(params, { convertConfigId, selected: true });
  248 + }
  249 + return { ...params, deviceProfileIds };
  250 + },
  251 + } as BasicTableProps,
  252 + initSelectedOptions: async ({ setSelectedTotal }) => {
  253 + const values = getFieldsValue();
  254 + const convertConfigId = Reflect.get(values, BasicInfoFormField.CONVERT_CONFIG_ID);
  255 + const deviceProfileIds = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_PRODUCT);
  256 + const devices = Reflect.get(values, BasicInfoFormField.DATA_SOURCE_DEVICE);
  257 + if (convertConfigId && devices) {
  258 + const { items, total } = await devicePage({
  259 + page: 1,
  260 + pageSize: 10,
  261 + convertConfigId: values[BasicInfoFormField.CONVERT_CONFIG_ID],
  262 + deviceProfileIds,
  263 + selected: true,
  264 + });
  265 + setSelectedTotal(total);
  266 + return items;
  267 + }
  268 + return [];
  269 + },
  270 + onSelectedAfter: async () => {
  271 + submitFn && (await submitFn(false));
  272 + },
  273 + onRemoveAfter: async ({ reloadSelected }) => {
  274 + submitFn && (await submitFn(false));
  275 + reloadSelected();
  276 + },
  277 + transformValue: (_selectedRowKeys: string[], selectedRows: DeviceRecord[]) => {
  278 + return handleGroupDevice(selectedRows);
  279 + },
  280 + };
  281 + },
  282 + },
  283 + {
  284 + field: 'type',
  285 + label: '转换方式',
  286 + component: 'ApiSelect',
  287 + required: true,
  288 + colProps: {
  289 + span: 24,
  290 + },
  291 + componentProps({}) {
  292 + return {
  293 + api: findDictItemByCode,
  294 + params: {
  295 + dictCode: 'convert_data_to',
  296 + },
  297 + labelField: 'itemText',
  298 + valueField: 'itemValue',
  299 + };
  300 + },
  301 + },
  302 + {
  303 + field: 'remark',
  304 + label: '描述',
  305 + colProps: { span: 24 },
  306 + component: 'Input',
  307 + componentProps: {
  308 + maxLength: 255,
  309 + placeholder: '请输入描述',
  310 + },
  311 + },
  312 + ];
  313 +};
... ...