testEditBodyCellTable.vue
9.12 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
<!-- eslint-disable vue/valid-v-model -->
<template>
<div class="table-content">
<!-- TODO: 待优化测试表格 -->
<table align="center">
<thead>
<tr>
<th v-for="item in editTestCellTableTHeadConfig" :key="item">
<a-tooltip v-if="item === '参数值'">
<template #title>当自定义为entityType,应输入DEVICE</template>
<QuestionCircleOutlined :style="{ fontSize: '14px', marginLeft: '5px' }" />
</a-tooltip>
{{ item }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in tableTestArray.content" :key="index">
<td style="width: 7.5vw">
<Select
:getPopupContainer="
(triggerNode) => {
return triggerNode.parentNode;
}
"
:disabled="true"
v-model:value="item.key"
placeholder="请选择"
:options="selectOptions"
/>
</td>
<td style="width: 6.5vw">
<a-input v-if="item.key === 'scope'" placeholder="请输入" v-model:value="item.value" />
<a-tree-select
:getPopupContainer="
(triggerNode) => {
return triggerNode.parentNode;
}
"
v-else-if="item.key === 'organizationId'"
v-model:value="item.value"
show-search
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
placeholder="请选择组织"
allow-clear
tree-default-expand-all
:tree-data="treeData"
@change="handleOrgnationChange(item)"
/>
<Select
:getPopupContainer="
(triggerNode) => {
return triggerNode.parentNode;
}
"
v-else-if="item.key === 'entityId'"
v-model:value="item.value"
placeholder="请选择"
notFoundContent="请选择"
:options="entityOptions"
allowClear
/>
<Select
:getPopupContainer="
(triggerNode) => {
return triggerNode.parentNode;
}
"
v-else-if="item.key === 'keys'"
v-model:value="item.value"
placeholder="请选择"
notFoundContent="请选择"
:options="attributeOptions"
mode="multiple"
allowClear
/>
<div v-else-if="item.key === 'date_range'">
<a-button disabled type="primary">{{ item.value?.split(',').at(-2) }}</a-button>
<span>~</span>
<a-button disabled type="primary">{{ item.value?.split(',').at(-1) }}</a-button>
</div>
<div v-else-if="item.key === 'fixed_date'">
<a-button disabled type="primary">{{ item.value }}</a-button>
</div>
<Select
:getPopupContainer="
(triggerNode) => {
return triggerNode.parentNode;
}
"
v-else
v-model:value="item.value"
placeholder="请选择"
notFoundContent="请选择"
:options="valueOptions"
allowClear
@change="handleValueChange(item)"
/>
</td>
<td style="width: 6.5vw">
<a-input
v-if="item.key === 'scope'"
placeholder="请输入"
v-model:value="item.keyValue"
/>
<a-date-picker
v-else-if="item.key === 'fixed_date'"
style="width: 6.5vw"
v-model:value="item.keyValue"
:show-time="{ format: 'HH:mm' }"
format="YYYY-MM-DD HH:mm:ss"
placeholder="日期时间"
/>
<a-range-picker
v-else-if="item.key == 'date_range'"
style="width: 6.5vw"
v-model:value="item.dateValue"
:show-time="{ format: 'HH:mm' }"
format="YYYY-MM-DD HH:mm"
:placeholder="['开始', '结束']"
/>
<a-input v-else disabled placeholder="请输入" v-model:value="item.keyValue" />
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script lang="ts" setup name="editCellTable">
import { reactive, ref, onMounted } from 'vue';
import { Select } from 'ant-design-vue';
import { findDictItemByCode } from '/@/api/system/dict';
import { getAllDeviceByOrg } from '/@/api/dataBoard';
import { getDeviceAttributes } from '/@/api/dataBoard';
import { useApi } from '../../../hooks/useApi';
import { cloneDeep } from 'lodash-es';
import { tableItems, selectType } from '../../../types';
import { editTestCellTableTHeadConfig } from '../../../config';
import { QuestionCircleOutlined } from '@ant-design/icons-vue';
const props = defineProps({
method: {
type: String,
},
});
onMounted(async () => {
const res = await findDictItemByCode({ dictCode: 'dataview_builtin_params' });
selectOptions.value = res.map((m) => ({ label: m.itemText, value: m.itemValue }));
selectOptions.value.push({
label: '自定义',
value: 'scope',
});
if (props.method === '2')
selectOptions.value = selectOptions.value.filter((f) => f.value !== 'scope');
});
const selectOptions = ref<selectType[]>([]);
const valueOptions = ref<selectType[]>([]);
const entityOptions = ref<selectType[]>([]);
const attributeOptions = ref<selectType[]>([]);
const treeData = ref([]);
const tableTestArray = reactive<{
content: tableItems[];
}>({
content: [
{
key: undefined,
value: undefined,
keyValue: null,
editDisabled: false,
dateValue: null,
},
],
});
//设置数据
const setTableArray = (data) => {
const list = cloneDeep(data);
list?.forEach((it) => {
if (it.key === 'keys') it.value = [];
});
if (Array.isArray(list)) (tableTestArray.content = list) && getApi(list);
if (list.hasOwnProperty('form-data') && Array.isArray(list['form-data']))
(tableTestArray.content = list['form-data']) && getApi(list['form-data']);
if (
list.hasOwnProperty('x-www-form-urlencoded') &&
Array.isArray(list['x-www-form-urlencoded'])
)
(tableTestArray.content = list['x-www-form-urlencoded']) &&
getApi(list['x-www-form-urlencoded']);
};
const getApi = (list) => {
list?.forEach(async (it) => {
if (it.key === 'deviceProfileId') {
const { options } = await useApi(it.key);
valueOptions.value = options;
} else if (it.key === 'organizationId') {
const { options } = await useApi(it.key);
treeData.value = options as any;
}
});
};
const handleOrgnationChange = async (e) => {
let deviceProfileId = '';
tableTestArray.content.forEach((f: any) => {
if (f.key === 'entityId') {
f.value = null;
}
if (f.key === 'deviceProfileId') deviceProfileId = f.value;
});
getEntityOptions(e.value, deviceProfileId);
};
const getEntityOptions = async (organizationId: string, deviceProfileId?: string) => {
const res = await getAllDeviceByOrg(organizationId, deviceProfileId);
entityOptions.value = res.map((item) => ({
label: item.name,
value: item.tbDeviceId,
}));
};
const getAttributeOptions = async (params) => {
const res = await getDeviceAttributes(params);
if (Object.keys(res).length === 0) return (attributeOptions.value.length = 0);
attributeOptions.value = res?.map((item) => ({ label: item.name, value: item.identifier }));
};
const handleValueChange = (e) => {
let organizationId = '';
if (e.key === 'deviceProfileId') {
tableTestArray.content.forEach((f: any) => {
if (f.key === 'keys') {
f.value = [];
}
if (f.key === 'organizationId') organizationId = f.value;
if (f.key === 'entityId') f.value = null;
});
getAttributeOptions({ deviceProfileId: e.value });
if (organizationId !== '') {
getEntityOptions(organizationId, e.value);
}
}
};
//获取数据
const getValue = () => {
return tableTestArray.content;
};
defineExpose({
getValue,
setTableArray,
});
</script>
<style scoped lang="less">
@table-color: #e5e7eb;
.table-border-color {
border: 1px solid #e5e7eb;
text-align: center;
}
.table-content {
table {
width: 31vw;
&:extend(.table-border-color);
}
table td {
padding: 5px;
white-space: nowrap;
&:extend(.table-border-color);
}
table th {
padding: 5px;
&:extend(.table-border-color);
}
}
</style>