DetectionTemplatePreview.vue
10.3 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
<template>
<div>
<div class="pageBox_title">
检测模板预览
<a-button style="float: right" @click="handleBack()"
>返回列表</a-button
>
</div>
<div class="InformationBox">
<a-card class="tabs-card" :bordered="false">
<a-descriptions :column="3" size="small" layout="vertical">
<template #title>模板基本信息</template>
<a-descriptions-item label="模板名称">
{{ pageData.templateName || "-" }}
</a-descriptions-item>
<a-descriptions-item label="适配车型">
{{ templateTypeText }}
</a-descriptions-item>
<a-descriptions-item label="备注说明">
{{ pageData.description || "-" }}
</a-descriptions-item>
</a-descriptions>
</a-card>
</div>
<div class="optionBox" v-if="nodeList.length">
<div
v-for="item in nodeList"
@click="handleNodeList(item)"
:key="item.id"
:class="{ optionBut_active: item.id == activeNodeId }"
class="optionBut"
>
{{ item.nodeName }}
</div>
</div>
<div class="customizeFormBox">
<a-form layout="vertical">
<div v-for="group in activeColumns" :key="group.id">
<title-divider :title="group.nodeName"></title-divider>
<a-row>
<a-col
v-for="item in group.childrenNodes || []"
:key="item.id"
:span="8"
>
<a-form-item :label="item.nodeName" class="calc_24">
<div class="preview-text-line">
类型:{{
interactionTypeText(
item.interactionType,
)
}}
</div>
<div
v-if="hasOptions(item)"
class="preview-text-line preview-options-line"
>
<span class="preview-options-label"
>可选项:</span
>
<a-popover
trigger="hover"
placement="topLeft"
:overlay-class-name="'preview-options-popover'"
>
<template #content>
<div class="options-tag-list-full">
<a-tag
v-for="(
opt, i
) in parseOptions(
item.options,
)"
:key="i"
class="options-tag"
>{{ opt }}</a-tag
>
</div>
</template>
<div class="options-tag-list-inline">
<a-tag
v-for="(opt, i) in parseOptions(
item.options,
)"
:key="i"
class="options-tag"
>{{ opt }}</a-tag
>
</div>
</a-popover>
</div>
</a-form-item>
</a-col>
</a-row>
</div>
</a-form>
</div>
</div>
</template>
<script lang="ts">
import { Component, Vue } from "vue-facing-decorator";
import TitleDivider from "@/components/TitleDivider.vue";
import { DetectionController } from "@/api/DetectionController";
@Component({
components: { TitleDivider },
})
export default class DetectionTemplatePreview extends Vue {
pageData: any = {};
nodeList: any[] = [];
activeNodeId: number | string = null;
created(): void {
this.getDetailData();
}
getDetailData() {
const routeData = this.$route.query || {};
if (!routeData.id) return;
DetectionController.inspectionTemplateDetail(this.axios, {
id: routeData.id,
}).then((response) => {
const data = response?.data?.data || {};
this.pageData = data;
const roots =
data.nodes ||
data.rootNodes ||
data.nodeList ||
data.childrenNodes ||
[];
this.nodeList = roots;
this.activeNodeId = roots[0]?.id ?? null;
});
}
handleNodeList(item: any) {
this.activeNodeId = item.id;
}
handleBack() {
this.$router.back();
}
interactionTypeMap: Record<string, string> = {
text_input: "文字输入",
textarea_input: "长文本输入",
number_input: "数字输入",
date_picker: "日期选择",
dropdown: "下拉",
cascade: "级联选项",
button_select: "按钮选择(可多选)",
radio_button_select: "单选按钮",
image_upload: "图片上传",
video_upload: "视频上传",
image_upload_and_button_select: "图片和按钮选择",
};
interactionTypeText(type: string): string {
if (!type) return "-";
return this.interactionTypeMap[type] || type;
}
hasOptions(item: any): boolean {
return this.parseOptions(item?.options).length > 0;
}
parseOptions(raw: any): string[] {
if (raw == null) return [];
if (Array.isArray(raw)) return raw.map((x) => String(x));
if (typeof raw === "string") {
const trimmed = raw.trim();
if (trimmed === "" || trimmed === "[]") return [];
try {
const parsed = JSON.parse(trimmed);
if (Array.isArray(parsed)) return parsed.map((x) => String(x));
return [String(parsed)];
} catch (e) {
return [trimmed];
}
}
return [];
}
get templateTypeText(): string {
const map: Record<number, string> = {
1: "燃油车",
2: "新能源车",
};
const t = Number(this.pageData?.templateType);
return map[t] || "-";
}
/**
* 当前选中根节点下的分区数据
* - 如果子节点本身还有 childrenNodes(三层结构),原样返回作为分区
* - 如果子节点已经是叶子(两层结构),就用当前根节点本身包一层作为分区
*/
get activeColumns(): any[] {
const active = this.nodeList.find((n) => n.id == this.activeNodeId);
if (!active) return [];
const children = active.childrenNodes || [];
if (children.length === 0) return [];
const firstHasChildren =
Array.isArray(children[0]?.childrenNodes) &&
children[0].childrenNodes.length > 0;
if (firstHasChildren) {
return children;
}
return [
{
id: active.id,
nodeName: active.nodeName,
childrenNodes: children,
},
];
}
}
</script>
<style scoped lang="less">
.pageBox_title {
width: 100%;
height: 24px;
float: left;
color: #202020;
font-size: 16px;
font-weight: 700;
line-height: 24px;
margin-top: 16px;
margin-bottom: 16px;
}
.InformationBox {
width: 100%;
padding: 0 24px;
float: left;
border-radius: 8px;
background: linear-gradient(
56.9deg,
#e6f6ff 0%,
#f0f6ff 28.999999999999996%,
#f0f6ff 60%,
#e3f1ff 100%
);
}
.tabs-card {
background: linear-gradient(
56.9deg,
#e6f6ff 0%,
#f0f6ff 28.999999999999996%,
#f0f6ff 60%,
#e3f1ff 100%
);
}
.optionBox {
width: 100%;
float: left;
margin-top: 24px;
margin-bottom: 4px;
}
.optionBut {
min-width: 76px;
padding: 0 24px;
height: 36px;
float: left;
line-height: 36px;
border-radius: 6px;
background: #f7f8f9;
color: #565d6b;
font-size: 14px;
font-weight: 400;
text-align: center;
margin-right: 12px;
margin-bottom: 12px;
cursor: pointer;
}
.optionBut_active {
background: #e8f0ff !important;
color: #1956fe !important;
}
.customizeFormBox {
width: 100%;
float: left;
}
.calc_24 {
width: -webkit-calc(100% - 24px);
width: -moz-calc(100% - 24px);
width: calc(100% - 24px);
position: relative;
}
.calc_24 :deep(.ant-form-item-label > label) {
font-weight: 700;
}
.preview-text-line {
color: #2f3133;
font-size: 14px;
line-height: 22px;
word-break: break-all;
}
.preview-options-line {
display: flex;
align-items: center;
overflow: hidden;
}
.preview-options-label {
flex-shrink: 0;
white-space: nowrap;
}
.options-tag-list-inline {
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}
.options-tag-list-inline :deep(.options-tag) {
margin-right: 4px;
margin-bottom: 0;
}
.options-tag-list-full {
max-width: 360px;
display: flex;
flex-wrap: wrap;
gap: 4px;
}
.options-tag-list-full :deep(.options-tag) {
margin: 0;
}
</style>