cover2Descriptions.js
5.15 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
import dayjs from "dayjs";
import customParseFormat from "dayjs/plugin/customParseFormat";
import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
import DescriptionImageList from "@/components/descriptions/components/imageList.vue";
import { statusOptions } from "@/views/residentManage/taskCenter/constant";
import "dayjs/locale/zh-cn";
if (typeof dayjs === "undefined") {
console.error("[cover2Descriptions] dayjs 未加载,请检查 CDN 顺序");
}
dayjs.extend(isSameOrBefore);
dayjs.extend(isSameOrAfter);
dayjs.extend(customParseFormat);
function parseDatetime(value) {
if (!value) {
return "-";
}
const formats = [
"YYYY-MM-DDTHH:mm:ss",
"YYYY-MM-DD HH:mm:ss",
"YYYY-MM-DDTHH:mm",
"YYYY-MM-DD",
];
for (const format of formats) {
const parsed = dayjs(value, format, true);
if (parsed.isValid()) {
return parsed.format("YYYY-MM-DD HH:mm:ss");
}
}
return "-";
}
// tooltip: true,
// parentProps: {
// style: {
// display: "inline-block",
// height: "32px",
// width: "auto",
// maxWidth: "100%",
// verticalAlign: "top",
// },
// },
// // tooltipProps: el-tooltip 的传参
// render: (h, { data, schemaItem, schema }) => {
// return h("div", { class: "text-hide" }, data.description || "-");
// },
function renderText() {
return {
render: (h, { data, schemaItem, schema }) => {
return h("div", {
style: {
whiteSpace: "normal",
wordBreak: "break-all",
wordWrap: "break-word",
overflowWrap: "break-word",
textAlign: "left",
},
}, schemaItem.meta.fieldValue || "-");
},
};
}
function renderEnum() {
return {
render: (h, { data, schemaItem, schema }) => {
const { fieldValue } = schemaItem.meta;
if (!fieldValue) {
return h("span", "-");
}
// 统一处理:字符串转数组
const values = Array.isArray(fieldValue) ? fieldValue : [fieldValue];
// 循环渲染为 el-tag
const tagChildren = values.map((item, index) => {
return h("el-tag", {
attrs: {
type: "info",
},
style: {
marginRight: index < values.length - 1 ? "8px" : "0",
marginBottom: "4px",
},
}, item);
});
return h("div", {
style: {
display: "flex",
flexWrap: "wrap",
alignItems: "center",
},
}, tagChildren);
},
};
}
function renderDatetime() {
return {
render: (h, { data, schemaItem, schema }) => {
const formatted = parseDatetime(schemaItem.meta.fieldValue);
return h("span", formatted);
},
};
}
function renderLink() {
return {
tooltip: true,
tooltipProps: {
render: (h, { data, schemaItem, schema }) => {
return h("div", schemaItem.meta.fieldValue || "-");
},
},
parentProps: {
style: {
display: "inline-block",
width: "auto",
maxWidth: "100%",
verticalAlign: "top",
},
},
render: (h, { data, schemaItem, schema }) => {
const { fieldValue, linkAlias } = schemaItem.meta;
if (!fieldValue) {
return h("span", "-");
}
const linkProps = {
class: "link-type",
style: {
width: "100%",
whiteSpace: "normal",
wordBreak: "break-all",
wordWrap: "break-word",
overflowWrap: "break-word",
},
attrs: {
href: fieldValue,
target: "_blank",
type: "primary",
},
on: {
click: (e) => {
e.preventDefault();
window.open(fieldValue, "_blank");
},
},
};
return h("el-link", linkProps, linkAlias || fieldValue);
},
};
}
function renderImage() {
return {
render: (h, { data, schemaItem, schema }) => {
const { fieldValue } = schemaItem.meta;
if (!fieldValue || !Array.isArray(fieldValue) || fieldValue.length === 0) {
return h("span", "-");
}
return h(DescriptionImageList, { props: { list: fieldValue, size: 120 } });
},
};
}
function renderAttachment() {
return {
render: (h, { data, schemaItem, schema }) => {
const { fieldValue } = schemaItem.meta;
if (!fieldValue || !Array.isArray(fieldValue) || fieldValue.length === 0) {
return h("span", "-");
}
const containerChildren = fieldValue.map((item, index) => {
const fileName = item.name || item.fileName || item.url || `附件${index + 1}`;
const fileUrl = item.value || item.url || "";
const rowChildren = [
h("span", {
attrs: {
class: "file-name text-hide",
title: fileName,
style: "max-width: 50%",
},
}, fileName),
];
rowChildren.push(
h("el-link", {
attrs: { href: fileUrl, target: "_blank", title: fileUrl },
props: { type: "primary", underline: false },
style: { marginLeft: "8px", lineHeight: 1 },
on: {
click: (e) => {
if (!fileUrl) {
return;
}
e.preventDefault();
window.open(fileUrl, "_blank");
},
},
}, "下载"),
);
return h("div", { attrs: { class: "attachment-item" } }, rowChildren);
});
return h("div", { attrs: { class: "attachment-list" } }, containerChildren);
},
};
}
export default {
TEXT: renderText,
NUMBER: renderText,
ENUM: renderEnum,
DATETIME: renderDatetime,
LINK: renderLink,
IMAGE: renderImage,
ATTACHMENT: renderAttachment,
};