@hbdlzy/ui-core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -2
- package/components.manifest.json +185 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1140 -12
- package/dist/style.css +1 -0
- package/package.json +4 -3
- package/src/components/BaseCard/BaseCard.types.ts +38 -0
- package/src/components/BaseCard/BaseCard.vue +250 -0
- package/src/components/BaseCard/README.md +164 -0
- package/src/components/BaseCard/index.ts +5 -0
- package/src/components/BaseEChart/BaseEChart.types.ts +35 -0
- package/src/components/BaseEChart/BaseEChart.vue +327 -0
- package/src/components/BaseEChart/README.md +136 -0
- package/src/components/BaseEChart/index.ts +5 -0
- package/src/components/BaseExportButton/BaseExportButton.vue +1 -1
- package/src/components/BaseExportButton/README.md +104 -8
- package/src/components/BaseTable/BaseTable.types.ts +174 -0
- package/src/components/BaseTable/BaseTable.vue +809 -0
- package/src/components/BaseTable/README.md +398 -0
- package/src/components/BaseTable/index.ts +25 -0
- package/src/echarts/index.ts +12 -0
- package/src/excel/exportExcel.ts +36 -10
- package/src/index.ts +15 -0
package/dist/index.js
CHANGED
|
@@ -1,9 +1,1122 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as echarts from "echarts";
|
|
2
|
+
export { echarts };
|
|
3
|
+
import { defineComponent, useSlots, computed, openBlock, createElementBlock, normalizeStyle, createElementVNode, createCommentVNode, renderSlot, toDisplayString, ref, reactive, watch, onMounted, resolveComponent, resolveDirective, createVNode, withDirectives, createBlock, withCtx, Fragment, renderList, createSlots, createTextVNode, mergeProps, shallowRef, nextTick, onUnmounted } from "vue";
|
|
2
4
|
import { ElMessage } from "element-plus";
|
|
3
|
-
import
|
|
5
|
+
import ExcelJS from "exceljs";
|
|
4
6
|
import { saveAs } from "file-saver";
|
|
7
|
+
var BaseCard_vue_vue_type_style_index_0_scoped_true_lang = "";
|
|
8
|
+
var _export_sfc = (sfc, props) => {
|
|
9
|
+
const target = sfc.__vccOpts || sfc;
|
|
10
|
+
for (const [key, val] of props) {
|
|
11
|
+
target[key] = val;
|
|
12
|
+
}
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
const _hoisted_1$1 = {
|
|
16
|
+
key: 0,
|
|
17
|
+
class: "base-card__header"
|
|
18
|
+
};
|
|
19
|
+
const _hoisted_2$1 = { class: "base-card__header-left" };
|
|
20
|
+
const _hoisted_3$1 = {
|
|
21
|
+
key: 0,
|
|
22
|
+
class: "base-card__title-wrap"
|
|
23
|
+
};
|
|
24
|
+
const _hoisted_4$1 = {
|
|
25
|
+
key: 0,
|
|
26
|
+
class: "base-card__title-marker"
|
|
27
|
+
};
|
|
28
|
+
const _hoisted_5$1 = {
|
|
29
|
+
key: 2,
|
|
30
|
+
class: "base-card__title"
|
|
31
|
+
};
|
|
32
|
+
const _hoisted_6$1 = {
|
|
33
|
+
key: 0,
|
|
34
|
+
class: "base-card__header-right"
|
|
35
|
+
};
|
|
36
|
+
const _hoisted_7$1 = {
|
|
37
|
+
key: 0,
|
|
38
|
+
class: "base-card__meta"
|
|
39
|
+
};
|
|
40
|
+
const _hoisted_8$1 = ["disabled"];
|
|
41
|
+
const _hoisted_9$1 = { class: "base-card__body" };
|
|
42
|
+
const _hoisted_10$1 = {
|
|
43
|
+
key: 0,
|
|
44
|
+
class: "base-card__tip"
|
|
45
|
+
};
|
|
46
|
+
const _hoisted_11 = { class: "base-card__content" };
|
|
47
|
+
const _sfc_main$3 = defineComponent({
|
|
48
|
+
...{
|
|
49
|
+
name: "BaseCard"
|
|
50
|
+
},
|
|
51
|
+
__name: "BaseCard",
|
|
52
|
+
props: {
|
|
53
|
+
title: { default: "" },
|
|
54
|
+
metaText: { default: "" },
|
|
55
|
+
showHeader: { type: Boolean, default: true },
|
|
56
|
+
showRight: { type: Boolean, default: true },
|
|
57
|
+
showTitleMarker: { type: Boolean, default: true },
|
|
58
|
+
showExport: { type: Boolean, default: false },
|
|
59
|
+
exportText: { default: "\u5BFC\u51FA" },
|
|
60
|
+
exportDisabled: { type: Boolean, default: false },
|
|
61
|
+
exportPayload: {},
|
|
62
|
+
padding: { default: 20 },
|
|
63
|
+
radius: { default: 8 },
|
|
64
|
+
borderColor: { default: "var(--border-color)" },
|
|
65
|
+
backgroundColor: { default: "var(--border-bg-color)" },
|
|
66
|
+
shadowColor: { default: "var(--border-projection)" },
|
|
67
|
+
headerGap: { default: 16 },
|
|
68
|
+
headerMarginBottom: { default: 20 },
|
|
69
|
+
leftGap: { default: 16 },
|
|
70
|
+
rightGap: { default: 16 },
|
|
71
|
+
titleColor: { default: "var(--el-text-color-primary)" },
|
|
72
|
+
titleSize: { default: 18 },
|
|
73
|
+
titleWeight: { default: 500 },
|
|
74
|
+
markerColor: { default: "var(--el-color-primary)" },
|
|
75
|
+
markerWidth: { default: 4 },
|
|
76
|
+
markerHeight: { default: 24 },
|
|
77
|
+
markerRadius: { default: "0 4px 4px 0" },
|
|
78
|
+
markerGap: { default: 10 },
|
|
79
|
+
metaColor: { default: "#808080" },
|
|
80
|
+
metaSize: { default: 16 },
|
|
81
|
+
exportColor: { default: "var(--el-color-primary)" }
|
|
82
|
+
},
|
|
83
|
+
emits: ["export"],
|
|
84
|
+
setup(__props, { emit: __emit }) {
|
|
85
|
+
const props = __props;
|
|
86
|
+
const emit = __emit;
|
|
87
|
+
const slots = useSlots();
|
|
88
|
+
const hasTitleBlock = computed(() => Boolean(props.title) || Boolean(slots["title-label"]));
|
|
89
|
+
const hasTitleExtra = computed(() => Boolean(slots.title));
|
|
90
|
+
const hasRightExtra = computed(() => Boolean(slots["header-right"]));
|
|
91
|
+
const hasRightSection = computed(
|
|
92
|
+
() => props.showRight && (hasRightExtra.value || Boolean(props.metaText) || props.showExport)
|
|
93
|
+
);
|
|
94
|
+
const shouldRenderHeader = computed(
|
|
95
|
+
() => props.showHeader && (hasTitleBlock.value || hasTitleExtra.value || hasRightSection.value)
|
|
96
|
+
);
|
|
97
|
+
const defaultExportPayload = computed(() => ({
|
|
98
|
+
title: props.title || void 0,
|
|
99
|
+
metaText: props.metaText || void 0
|
|
100
|
+
}));
|
|
101
|
+
const cardStyles = computed(() => ({
|
|
102
|
+
"--base-card-padding": toCssValue(props.padding),
|
|
103
|
+
"--base-card-radius": toCssValue(props.radius),
|
|
104
|
+
"--base-card-border-color": props.borderColor,
|
|
105
|
+
"--base-card-background-color": props.backgroundColor,
|
|
106
|
+
"--base-card-shadow-color": props.shadowColor,
|
|
107
|
+
"--base-card-header-gap": toCssValue(props.headerGap),
|
|
108
|
+
"--base-card-header-margin-bottom": toCssValue(props.headerMarginBottom),
|
|
109
|
+
"--base-card-left-gap": toCssValue(props.leftGap),
|
|
110
|
+
"--base-card-right-gap": toCssValue(props.rightGap),
|
|
111
|
+
"--base-card-title-color": props.titleColor,
|
|
112
|
+
"--base-card-title-size": toCssValue(props.titleSize),
|
|
113
|
+
"--base-card-title-weight": toTextValue(props.titleWeight),
|
|
114
|
+
"--base-card-marker-color": props.markerColor,
|
|
115
|
+
"--base-card-marker-width": toCssValue(props.markerWidth),
|
|
116
|
+
"--base-card-marker-height": toCssValue(props.markerHeight),
|
|
117
|
+
"--base-card-marker-radius": toCssValue(props.markerRadius),
|
|
118
|
+
"--base-card-marker-gap": toCssValue(props.markerGap),
|
|
119
|
+
"--base-card-meta-color": props.metaColor,
|
|
120
|
+
"--base-card-meta-size": toCssValue(props.metaSize),
|
|
121
|
+
"--base-card-export-color": props.exportColor
|
|
122
|
+
}));
|
|
123
|
+
const handleExport = () => {
|
|
124
|
+
emit("export", props.exportPayload === void 0 ? defaultExportPayload.value : props.exportPayload);
|
|
125
|
+
};
|
|
126
|
+
function toCssValue(value, unit = "px") {
|
|
127
|
+
if (value === void 0 || value === null || value === "") {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
return typeof value === "number" ? `${value}${unit}` : value;
|
|
131
|
+
}
|
|
132
|
+
function toTextValue(value) {
|
|
133
|
+
if (value === void 0 || value === null || value === "") {
|
|
134
|
+
return void 0;
|
|
135
|
+
}
|
|
136
|
+
return String(value);
|
|
137
|
+
}
|
|
138
|
+
return (_ctx, _cache) => {
|
|
139
|
+
return openBlock(), createElementBlock("div", {
|
|
140
|
+
class: "base-card",
|
|
141
|
+
style: normalizeStyle(cardStyles.value)
|
|
142
|
+
}, [
|
|
143
|
+
shouldRenderHeader.value ? (openBlock(), createElementBlock("div", _hoisted_1$1, [
|
|
144
|
+
createElementVNode("div", _hoisted_2$1, [
|
|
145
|
+
hasTitleBlock.value ? (openBlock(), createElementBlock("div", _hoisted_3$1, [
|
|
146
|
+
__props.showTitleMarker ? (openBlock(), createElementBlock("span", _hoisted_4$1)) : createCommentVNode("", true),
|
|
147
|
+
_ctx.$slots["title-label"] ? renderSlot(_ctx.$slots, "title-label", { key: 1 }, void 0, true) : (openBlock(), createElementBlock("h4", _hoisted_5$1, toDisplayString(__props.title), 1))
|
|
148
|
+
])) : createCommentVNode("", true),
|
|
149
|
+
renderSlot(_ctx.$slots, "title", {}, void 0, true)
|
|
150
|
+
]),
|
|
151
|
+
hasRightSection.value ? (openBlock(), createElementBlock("div", _hoisted_6$1, [
|
|
152
|
+
renderSlot(_ctx.$slots, "header-right", {}, void 0, true),
|
|
153
|
+
__props.metaText ? (openBlock(), createElementBlock("span", _hoisted_7$1, toDisplayString(__props.metaText), 1)) : createCommentVNode("", true),
|
|
154
|
+
__props.showExport ? (openBlock(), createElementBlock("button", {
|
|
155
|
+
key: 1,
|
|
156
|
+
class: "base-card__export",
|
|
157
|
+
type: "button",
|
|
158
|
+
disabled: __props.exportDisabled,
|
|
159
|
+
onClick: handleExport
|
|
160
|
+
}, toDisplayString(__props.exportText), 9, _hoisted_8$1)) : createCommentVNode("", true)
|
|
161
|
+
])) : createCommentVNode("", true)
|
|
162
|
+
])) : createCommentVNode("", true),
|
|
163
|
+
createElementVNode("div", _hoisted_9$1, [
|
|
164
|
+
_ctx.$slots.tip ? (openBlock(), createElementBlock("div", _hoisted_10$1, [
|
|
165
|
+
renderSlot(_ctx.$slots, "tip", {}, void 0, true)
|
|
166
|
+
])) : createCommentVNode("", true),
|
|
167
|
+
createElementVNode("div", _hoisted_11, [
|
|
168
|
+
renderSlot(_ctx.$slots, "default", {}, void 0, true)
|
|
169
|
+
])
|
|
170
|
+
])
|
|
171
|
+
], 4);
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
var BaseCard = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-6bfddf1c"]]);
|
|
176
|
+
var BaseTable_vue_vue_type_style_index_0_scoped_true_lang = "";
|
|
177
|
+
const _hoisted_1 = { class: "base-table" };
|
|
178
|
+
const _hoisted_2 = {
|
|
179
|
+
key: 0,
|
|
180
|
+
class: "base-table__toolbar"
|
|
181
|
+
};
|
|
182
|
+
const _hoisted_3 = { class: "base-table__toolbar-left" };
|
|
183
|
+
const _hoisted_4 = {
|
|
184
|
+
key: 0,
|
|
185
|
+
class: "base-table__toolbar-right"
|
|
186
|
+
};
|
|
187
|
+
const _hoisted_5 = {
|
|
188
|
+
key: 0,
|
|
189
|
+
class: "base-table__actions"
|
|
190
|
+
};
|
|
191
|
+
const _hoisted_6 = {
|
|
192
|
+
key: 2,
|
|
193
|
+
class: "base-table__tags"
|
|
194
|
+
};
|
|
195
|
+
const _hoisted_7 = { key: 1 };
|
|
196
|
+
const _hoisted_8 = ["innerHTML"];
|
|
197
|
+
const _hoisted_9 = ["onClick"];
|
|
198
|
+
const _hoisted_10 = {
|
|
199
|
+
key: 6,
|
|
200
|
+
class: "base-table__text"
|
|
201
|
+
};
|
|
202
|
+
const _sfc_main$2 = defineComponent({
|
|
203
|
+
...{
|
|
204
|
+
name: "BaseTable"
|
|
205
|
+
},
|
|
206
|
+
__name: "BaseTable",
|
|
207
|
+
props: {
|
|
208
|
+
columns: {},
|
|
209
|
+
data: { default: () => [] },
|
|
210
|
+
request: {},
|
|
211
|
+
requestParams: { default: () => ({}) },
|
|
212
|
+
resultAdapter: {},
|
|
213
|
+
autoLoad: { type: Boolean, default: true },
|
|
214
|
+
reloadOnParamsChange: { type: Boolean, default: true },
|
|
215
|
+
reloadOnSortChange: { type: Boolean, default: true },
|
|
216
|
+
rowKey: { default: "id" },
|
|
217
|
+
height: { default: "100%" },
|
|
218
|
+
border: { type: Boolean, default: false },
|
|
219
|
+
stripe: { type: Boolean, default: false },
|
|
220
|
+
showToolbar: { type: Boolean, default: true },
|
|
221
|
+
showPagination: { type: Boolean, default: true },
|
|
222
|
+
hasSelection: { type: Boolean, default: false },
|
|
223
|
+
hasIndex: { type: Boolean, default: false },
|
|
224
|
+
indexLabel: { default: "\u5E8F\u53F7" },
|
|
225
|
+
indexWidth: { default: 60 },
|
|
226
|
+
selectionWidth: { default: 50 },
|
|
227
|
+
rowSelectable: {},
|
|
228
|
+
pagination: { default: () => ({}) },
|
|
229
|
+
currentPageKey: { default: "pageNum" },
|
|
230
|
+
pageSizeKey: { default: "pageSize" },
|
|
231
|
+
defaultSort: { default: () => ({
|
|
232
|
+
prop: void 0,
|
|
233
|
+
order: null
|
|
234
|
+
}) },
|
|
235
|
+
sortFieldKey: { default: "sortField" },
|
|
236
|
+
sortOrderKey: { default: "sortOrder" },
|
|
237
|
+
sortOrderMap: { default: () => ({
|
|
238
|
+
ascending: "asc",
|
|
239
|
+
descending: "desc"
|
|
240
|
+
}) },
|
|
241
|
+
sortMapper: {},
|
|
242
|
+
emptyText: { default: "\u6682\u65E0\u6570\u636E" },
|
|
243
|
+
loadingText: { default: "\u52A0\u8F7D\u4E2D..." }
|
|
244
|
+
},
|
|
245
|
+
emits: ["selection-change", "sort-change", "row-action", "cell-click", "cell-input", "page-change", "size-change", "update:pagination", "loaded", "request-error"],
|
|
246
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
247
|
+
var _a, _b;
|
|
248
|
+
const props = __props;
|
|
249
|
+
const emit = __emit;
|
|
250
|
+
const slots = useSlots();
|
|
251
|
+
const tableRef = ref();
|
|
252
|
+
const loading = ref(false);
|
|
253
|
+
const rows = ref(normalizeRows(props.data));
|
|
254
|
+
const selectionRows = ref([]);
|
|
255
|
+
const sortState = reactive({
|
|
256
|
+
prop: (_a = props.defaultSort) == null ? void 0 : _a.prop,
|
|
257
|
+
order: ((_b = props.defaultSort) == null ? void 0 : _b.order) || null
|
|
258
|
+
});
|
|
259
|
+
const paginationState = reactive({
|
|
260
|
+
currentPage: 1,
|
|
261
|
+
pageSize: 20,
|
|
262
|
+
total: 0,
|
|
263
|
+
pageSizes: [10, 20, 50, 100]
|
|
264
|
+
});
|
|
265
|
+
syncPagination(props.pagination);
|
|
266
|
+
const normalizedHeight = computed(() => toCssValue(props.height));
|
|
267
|
+
const shouldRenderToolbar = computed(() => props.showToolbar && (Boolean(slots.toolbar) || props.showPagination));
|
|
268
|
+
const normalizedDefaultSort = computed(() => {
|
|
269
|
+
if (!sortState.prop || !sortState.order) {
|
|
270
|
+
return void 0;
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
prop: sortState.prop,
|
|
274
|
+
order: sortState.order
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
watch(
|
|
278
|
+
() => props.data,
|
|
279
|
+
(value) => {
|
|
280
|
+
if (!props.request) {
|
|
281
|
+
setData(value || []);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
{ deep: true }
|
|
285
|
+
);
|
|
286
|
+
watch(
|
|
287
|
+
() => props.pagination,
|
|
288
|
+
(value) => {
|
|
289
|
+
syncPagination(value);
|
|
290
|
+
},
|
|
291
|
+
{ deep: true }
|
|
292
|
+
);
|
|
293
|
+
watch(
|
|
294
|
+
() => props.requestParams,
|
|
295
|
+
() => {
|
|
296
|
+
if (props.request && props.reloadOnParamsChange && props.autoLoad) {
|
|
297
|
+
paginationState.currentPage = 1;
|
|
298
|
+
void load();
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
{ deep: true }
|
|
302
|
+
);
|
|
303
|
+
watch(
|
|
304
|
+
() => props.defaultSort,
|
|
305
|
+
(value) => {
|
|
306
|
+
sortState.prop = value == null ? void 0 : value.prop;
|
|
307
|
+
sortState.order = (value == null ? void 0 : value.order) || null;
|
|
308
|
+
},
|
|
309
|
+
{ deep: true }
|
|
310
|
+
);
|
|
311
|
+
onMounted(() => {
|
|
312
|
+
var _a2;
|
|
313
|
+
if (props.request && props.autoLoad) {
|
|
314
|
+
void load();
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (!props.request) {
|
|
318
|
+
rows.value = normalizeRows(props.data);
|
|
319
|
+
if (!((_a2 = props.pagination) == null ? void 0 : _a2.total)) {
|
|
320
|
+
paginationState.total = rows.value.length;
|
|
321
|
+
emitPagination();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
function syncPagination(value) {
|
|
326
|
+
paginationState.currentPage = Number((value == null ? void 0 : value.currentPage) || paginationState.currentPage || 1);
|
|
327
|
+
paginationState.pageSize = Number((value == null ? void 0 : value.pageSize) || paginationState.pageSize || 20);
|
|
328
|
+
paginationState.total = Number((value == null ? void 0 : value.total) || (value == null ? void 0 : value.total) === 0 ? value.total : paginationState.total || rows.value.length);
|
|
329
|
+
paginationState.pageSizes = Array.isArray(value == null ? void 0 : value.pageSizes) && value.pageSizes.length ? [...value.pageSizes] : [...paginationState.pageSizes.length ? paginationState.pageSizes : [10, 20, 50, 100]];
|
|
330
|
+
}
|
|
331
|
+
function emitPagination() {
|
|
332
|
+
emit("update:pagination", {
|
|
333
|
+
currentPage: paginationState.currentPage,
|
|
334
|
+
pageSize: paginationState.pageSize,
|
|
335
|
+
total: paginationState.total,
|
|
336
|
+
pageSizes: [...paginationState.pageSizes]
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async function load(data) {
|
|
340
|
+
if (Array.isArray(data)) {
|
|
341
|
+
setData(data);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (!props.request) {
|
|
345
|
+
setData(props.data || []);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
loading.value = true;
|
|
349
|
+
const requestParams = buildRequestParams();
|
|
350
|
+
try {
|
|
351
|
+
const result = await props.request(requestParams);
|
|
352
|
+
const normalized = normalizeRequestResult(result, requestParams);
|
|
353
|
+
rows.value = normalized.rows;
|
|
354
|
+
paginationState.total = normalized.total;
|
|
355
|
+
emitPagination();
|
|
356
|
+
emit("loaded", {
|
|
357
|
+
rows: [...rows.value],
|
|
358
|
+
total: paginationState.total,
|
|
359
|
+
params: requestParams
|
|
360
|
+
});
|
|
361
|
+
} catch (error) {
|
|
362
|
+
rows.value = [];
|
|
363
|
+
paginationState.total = 0;
|
|
364
|
+
emitPagination();
|
|
365
|
+
emit("request-error", error);
|
|
366
|
+
} finally {
|
|
367
|
+
loading.value = false;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
async function refresh() {
|
|
371
|
+
await load();
|
|
372
|
+
}
|
|
373
|
+
async function resetPage() {
|
|
374
|
+
paginationState.currentPage = 1;
|
|
375
|
+
emitPagination();
|
|
376
|
+
await load();
|
|
377
|
+
}
|
|
378
|
+
function setData(data) {
|
|
379
|
+
var _a2, _b2;
|
|
380
|
+
rows.value = normalizeRows(data);
|
|
381
|
+
if (!props.request) {
|
|
382
|
+
paginationState.total = Number((_b2 = (_a2 = props.pagination) == null ? void 0 : _a2.total) != null ? _b2 : rows.value.length);
|
|
383
|
+
emitPagination();
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function clearSelection() {
|
|
387
|
+
var _a2;
|
|
388
|
+
(_a2 = tableRef.value) == null ? void 0 : _a2.clearSelection();
|
|
389
|
+
selectionRows.value = [];
|
|
390
|
+
}
|
|
391
|
+
function toggleRowSelection(row, selected) {
|
|
392
|
+
var _a2;
|
|
393
|
+
(_a2 = tableRef.value) == null ? void 0 : _a2.toggleRowSelection(row, selected);
|
|
394
|
+
}
|
|
395
|
+
function getSelectionRows() {
|
|
396
|
+
return [...selectionRows.value];
|
|
397
|
+
}
|
|
398
|
+
function getRows() {
|
|
399
|
+
return [...rows.value];
|
|
400
|
+
}
|
|
401
|
+
function handleSelectionChange(value) {
|
|
402
|
+
selectionRows.value = value;
|
|
403
|
+
emit("selection-change", value);
|
|
404
|
+
}
|
|
405
|
+
function handleSortChange(payload) {
|
|
406
|
+
const column = props.columns.find((item) => String(item.prop || "") === String(payload.prop || ""));
|
|
407
|
+
sortState.prop = payload.prop;
|
|
408
|
+
sortState.order = payload.order;
|
|
409
|
+
const sortPayload = buildSortPayload(column, payload.prop, payload.order);
|
|
410
|
+
emit("sort-change", sortPayload);
|
|
411
|
+
if (props.request && props.reloadOnSortChange) {
|
|
412
|
+
paginationState.currentPage = 1;
|
|
413
|
+
emitPagination();
|
|
414
|
+
void load();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function handleCurrentChange(value) {
|
|
418
|
+
paginationState.currentPage = value;
|
|
419
|
+
emitPagination();
|
|
420
|
+
emit("page-change", value);
|
|
421
|
+
if (props.request) {
|
|
422
|
+
void load();
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function handleSizeChange(value) {
|
|
426
|
+
paginationState.pageSize = value;
|
|
427
|
+
paginationState.currentPage = 1;
|
|
428
|
+
emitPagination();
|
|
429
|
+
emit("size-change", value);
|
|
430
|
+
if (props.request) {
|
|
431
|
+
void load();
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function handleRowAction(row, action, column) {
|
|
435
|
+
emit("row-action", {
|
|
436
|
+
row,
|
|
437
|
+
action,
|
|
438
|
+
column
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
function handleCellClick(row, column) {
|
|
442
|
+
var _a2;
|
|
443
|
+
(_a2 = column.clickHandler) == null ? void 0 : _a2.call(column, row, column);
|
|
444
|
+
emit("cell-click", {
|
|
445
|
+
row,
|
|
446
|
+
column,
|
|
447
|
+
value: getCellValue2(row, column)
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
function handleInputChange(value, row, column) {
|
|
451
|
+
var _a2;
|
|
452
|
+
if (!column.prop) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
row[column.prop] = value;
|
|
456
|
+
(_a2 = column.inputHandler) == null ? void 0 : _a2.call(column, value, row, column);
|
|
457
|
+
emit("cell-input", {
|
|
458
|
+
row,
|
|
459
|
+
column,
|
|
460
|
+
value
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
function buildRequestParams() {
|
|
464
|
+
const params = {
|
|
465
|
+
...props.requestParams,
|
|
466
|
+
currentPage: paginationState.currentPage,
|
|
467
|
+
pageSize: paginationState.pageSize,
|
|
468
|
+
[props.currentPageKey]: paginationState.currentPage,
|
|
469
|
+
[props.pageSizeKey]: paginationState.pageSize
|
|
470
|
+
};
|
|
471
|
+
const currentColumn = props.columns.find((item) => String(item.prop || "") === String(sortState.prop || ""));
|
|
472
|
+
const sortPayload = buildSortPayload(currentColumn, sortState.prop, sortState.order);
|
|
473
|
+
const sortParams = buildSortParams(sortPayload);
|
|
474
|
+
return {
|
|
475
|
+
...params,
|
|
476
|
+
...sortParams
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function normalizeRequestResult(result, requestParams) {
|
|
480
|
+
var _a2, _b2;
|
|
481
|
+
if (props.resultAdapter) {
|
|
482
|
+
const adaptedResult = props.resultAdapter(result, requestParams);
|
|
483
|
+
const adaptedRows = normalizeRows(adaptedResult == null ? void 0 : adaptedResult.rows);
|
|
484
|
+
return {
|
|
485
|
+
rows: adaptedRows,
|
|
486
|
+
total: Number((_a2 = adaptedResult == null ? void 0 : adaptedResult.total) != null ? _a2 : adaptedRows.length)
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
if (Array.isArray(result)) {
|
|
490
|
+
return {
|
|
491
|
+
rows: normalizeRows(result),
|
|
492
|
+
total: result.length
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
const payload = result || {};
|
|
496
|
+
const container = payload.data && typeof payload.data === "object" ? payload.data : payload;
|
|
497
|
+
const list = container.records || container.list || container.items || [];
|
|
498
|
+
const normalizedRows = normalizeRows(list);
|
|
499
|
+
return {
|
|
500
|
+
rows: normalizedRows,
|
|
501
|
+
total: Number((_b2 = container.total) != null ? _b2 : normalizedRows.length)
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
function normalizeRows(data) {
|
|
505
|
+
return Array.isArray(data) ? [...data] : [];
|
|
506
|
+
}
|
|
507
|
+
function getColumnKey(column) {
|
|
508
|
+
return String(column.prop || column.label);
|
|
509
|
+
}
|
|
510
|
+
function getColumnProp(column) {
|
|
511
|
+
return column.prop ? String(column.prop) : void 0;
|
|
512
|
+
}
|
|
513
|
+
function getCellValue2(row, column) {
|
|
514
|
+
if (!column.prop) {
|
|
515
|
+
return void 0;
|
|
516
|
+
}
|
|
517
|
+
return row[column.prop];
|
|
518
|
+
}
|
|
519
|
+
function formatCellDisplay(row, column) {
|
|
520
|
+
if (column.formatter) {
|
|
521
|
+
const formatted = column.formatter(row, column);
|
|
522
|
+
return toDisplayValue(formatted, resolveEmptyText(column));
|
|
523
|
+
}
|
|
524
|
+
return toDisplayValue(getCellValue2(row, column), resolveEmptyText(column));
|
|
525
|
+
}
|
|
526
|
+
function getHtmlContent(row, column) {
|
|
527
|
+
if (column.html) {
|
|
528
|
+
return column.html(row, column);
|
|
529
|
+
}
|
|
530
|
+
const value = getCellValue2(row, column);
|
|
531
|
+
return value === void 0 || value === null ? "" : String(value);
|
|
532
|
+
}
|
|
533
|
+
function isActionColumn(column) {
|
|
534
|
+
var _a2;
|
|
535
|
+
return column.kind === "actions" || Boolean((_a2 = column.actions) == null ? void 0 : _a2.length);
|
|
536
|
+
}
|
|
537
|
+
function isLinkColumn(column) {
|
|
538
|
+
return column.kind === "link" || Boolean(column.clickable);
|
|
539
|
+
}
|
|
540
|
+
function getVisibleActions(column, row) {
|
|
541
|
+
return (column.actions || []).filter((action) => {
|
|
542
|
+
if (typeof action.visible === "function") {
|
|
543
|
+
return action.visible(row);
|
|
544
|
+
}
|
|
545
|
+
return action.visible !== false;
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
function isActionDisabled(action, row) {
|
|
549
|
+
if (typeof action.disabled === "function") {
|
|
550
|
+
return action.disabled(row);
|
|
551
|
+
}
|
|
552
|
+
return Boolean(action.disabled);
|
|
553
|
+
}
|
|
554
|
+
function resolveCellSlotName(column) {
|
|
555
|
+
return column.slotName || (column.prop ? `cell-${String(column.prop)}` : "");
|
|
556
|
+
}
|
|
557
|
+
function resolveHeaderSlotName(column) {
|
|
558
|
+
return column.headerSlotName || (column.prop ? `header-${String(column.prop)}` : "");
|
|
559
|
+
}
|
|
560
|
+
function hasCellSlot(column) {
|
|
561
|
+
const slotName = resolveCellSlotName(column);
|
|
562
|
+
return Boolean(slotName && slots[slotName]);
|
|
563
|
+
}
|
|
564
|
+
function hasHeaderSlot(column) {
|
|
565
|
+
const slotName = resolveHeaderSlotName(column);
|
|
566
|
+
return Boolean(slotName && slots[slotName]);
|
|
567
|
+
}
|
|
568
|
+
function getMatchedOptions(row, column) {
|
|
569
|
+
const value = getCellValue2(row, column);
|
|
570
|
+
const values = Array.isArray(value) ? value : [value];
|
|
571
|
+
const valueKey = column.optionValueKey || "value";
|
|
572
|
+
const labelKey = column.optionLabelKey || "label";
|
|
573
|
+
const tagTypeKey = column.optionTagTypeKey || "tagType";
|
|
574
|
+
return values.filter((item) => item !== void 0 && item !== null && item !== "").map((item) => {
|
|
575
|
+
const matched = (column.options || []).find((option) => option[valueKey] === item);
|
|
576
|
+
if (!matched) {
|
|
577
|
+
return {
|
|
578
|
+
label: String(item),
|
|
579
|
+
value: item,
|
|
580
|
+
tagType: "info"
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
return {
|
|
584
|
+
label: String(matched[labelKey]),
|
|
585
|
+
value: matched[valueKey],
|
|
586
|
+
tagType: matched[tagTypeKey],
|
|
587
|
+
color: matched.color
|
|
588
|
+
};
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
function getImageStyle(column) {
|
|
592
|
+
return {
|
|
593
|
+
width: toCssValue(column.imageWidth || 50),
|
|
594
|
+
height: toCssValue(column.imageHeight || 50)
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function toImageSrc(value) {
|
|
598
|
+
if (typeof value === "string") {
|
|
599
|
+
return value;
|
|
600
|
+
}
|
|
601
|
+
if (value && typeof value === "object" && "url" in value) {
|
|
602
|
+
return String(value.url || "");
|
|
603
|
+
}
|
|
604
|
+
return "";
|
|
605
|
+
}
|
|
606
|
+
function getPreviewSrcList(row, column) {
|
|
607
|
+
const src = toImageSrc(getCellValue2(row, column));
|
|
608
|
+
return src ? [src] : [];
|
|
609
|
+
}
|
|
610
|
+
function resolveEmptyText(column) {
|
|
611
|
+
return column.emptyText || "--";
|
|
612
|
+
}
|
|
613
|
+
function resolveColumnSortable(column) {
|
|
614
|
+
if (!props.request) {
|
|
615
|
+
return column.sortable || false;
|
|
616
|
+
}
|
|
617
|
+
if (column.sortable === true) {
|
|
618
|
+
return "custom";
|
|
619
|
+
}
|
|
620
|
+
return column.sortable || false;
|
|
621
|
+
}
|
|
622
|
+
function buildSortPayload(column, prop, order = null) {
|
|
623
|
+
return {
|
|
624
|
+
column,
|
|
625
|
+
prop,
|
|
626
|
+
order,
|
|
627
|
+
field: resolveSortField(column, prop),
|
|
628
|
+
direction: resolveSortDirection(order)
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
function buildSortParams(payload) {
|
|
632
|
+
var _a2;
|
|
633
|
+
if (!payload.field || !payload.direction) {
|
|
634
|
+
return {};
|
|
635
|
+
}
|
|
636
|
+
const mappedParams = (_a2 = props.sortMapper) == null ? void 0 : _a2.call(props, payload);
|
|
637
|
+
if (mappedParams && typeof mappedParams === "object") {
|
|
638
|
+
return mappedParams;
|
|
639
|
+
}
|
|
640
|
+
return {
|
|
641
|
+
[props.sortFieldKey]: payload.field,
|
|
642
|
+
[props.sortOrderKey]: payload.direction
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
function resolveSortField(column, prop) {
|
|
646
|
+
return (column == null ? void 0 : column.sortField) || prop;
|
|
647
|
+
}
|
|
648
|
+
function resolveSortDirection(order) {
|
|
649
|
+
if (order === "ascending") {
|
|
650
|
+
return props.sortOrderMap.ascending;
|
|
651
|
+
}
|
|
652
|
+
if (order === "descending") {
|
|
653
|
+
return props.sortOrderMap.descending;
|
|
654
|
+
}
|
|
655
|
+
return null;
|
|
656
|
+
}
|
|
657
|
+
function toDisplayValue(value, emptyText = "--") {
|
|
658
|
+
if (value === 0) {
|
|
659
|
+
return "0";
|
|
660
|
+
}
|
|
661
|
+
if (value === void 0 || value === null || value === "") {
|
|
662
|
+
return emptyText;
|
|
663
|
+
}
|
|
664
|
+
return String(value);
|
|
665
|
+
}
|
|
666
|
+
function toCssValue(value) {
|
|
667
|
+
if (value === void 0 || value === null || value === "") {
|
|
668
|
+
return void 0;
|
|
669
|
+
}
|
|
670
|
+
return typeof value === "number" ? `${value}px` : value;
|
|
671
|
+
}
|
|
672
|
+
__expose({
|
|
673
|
+
load,
|
|
674
|
+
refresh,
|
|
675
|
+
setData,
|
|
676
|
+
resetPage,
|
|
677
|
+
clearSelection,
|
|
678
|
+
toggleRowSelection,
|
|
679
|
+
getSelectionRows,
|
|
680
|
+
getRows
|
|
681
|
+
});
|
|
682
|
+
return (_ctx, _cache) => {
|
|
683
|
+
const _component_el_pagination = resolveComponent("el-pagination");
|
|
684
|
+
const _component_el_empty = resolveComponent("el-empty");
|
|
685
|
+
const _component_el_table_column = resolveComponent("el-table-column");
|
|
686
|
+
const _component_el_button = resolveComponent("el-button");
|
|
687
|
+
const _component_el_image = resolveComponent("el-image");
|
|
688
|
+
const _component_el_tag = resolveComponent("el-tag");
|
|
689
|
+
const _component_el_input = resolveComponent("el-input");
|
|
690
|
+
const _component_el_table = resolveComponent("el-table");
|
|
691
|
+
const _directive_loading = resolveDirective("loading");
|
|
692
|
+
return openBlock(), createElementBlock("div", _hoisted_1, [
|
|
693
|
+
shouldRenderToolbar.value ? (openBlock(), createElementBlock("div", _hoisted_2, [
|
|
694
|
+
createElementVNode("div", _hoisted_3, [
|
|
695
|
+
renderSlot(_ctx.$slots, "toolbar", {}, void 0, true)
|
|
696
|
+
]),
|
|
697
|
+
__props.showPagination ? (openBlock(), createElementBlock("div", _hoisted_4, [
|
|
698
|
+
createVNode(_component_el_pagination, {
|
|
699
|
+
small: "",
|
|
700
|
+
background: "",
|
|
701
|
+
layout: "total, prev, pager, next, sizes, jumper",
|
|
702
|
+
total: paginationState.total,
|
|
703
|
+
"current-page": paginationState.currentPage,
|
|
704
|
+
"page-size": paginationState.pageSize,
|
|
705
|
+
"page-sizes": paginationState.pageSizes,
|
|
706
|
+
"pager-count": 5,
|
|
707
|
+
"popper-append-to-body": false,
|
|
708
|
+
onSizeChange: handleSizeChange,
|
|
709
|
+
onCurrentChange: handleCurrentChange
|
|
710
|
+
}, null, 8, ["total", "current-page", "page-size", "page-sizes"])
|
|
711
|
+
])) : createCommentVNode("", true)
|
|
712
|
+
])) : createCommentVNode("", true),
|
|
713
|
+
withDirectives((openBlock(), createBlock(_component_el_table, {
|
|
714
|
+
ref_key: "tableRef",
|
|
715
|
+
ref: tableRef,
|
|
716
|
+
data: rows.value,
|
|
717
|
+
"row-key": __props.rowKey,
|
|
718
|
+
height: normalizedHeight.value,
|
|
719
|
+
border: __props.border,
|
|
720
|
+
stripe: __props.stripe,
|
|
721
|
+
"default-sort": normalizedDefaultSort.value,
|
|
722
|
+
"highlight-current-row": "",
|
|
723
|
+
onSelectionChange: handleSelectionChange,
|
|
724
|
+
onSortChange: handleSortChange
|
|
725
|
+
}, {
|
|
726
|
+
empty: withCtx(() => [
|
|
727
|
+
createVNode(_component_el_empty, { description: __props.emptyText }, null, 8, ["description"])
|
|
728
|
+
]),
|
|
729
|
+
default: withCtx(() => [
|
|
730
|
+
__props.hasSelection ? (openBlock(), createBlock(_component_el_table_column, {
|
|
731
|
+
key: 0,
|
|
732
|
+
type: "selection",
|
|
733
|
+
width: __props.selectionWidth,
|
|
734
|
+
align: "center",
|
|
735
|
+
selectable: __props.rowSelectable
|
|
736
|
+
}, null, 8, ["width", "selectable"])) : createCommentVNode("", true),
|
|
737
|
+
__props.hasIndex ? (openBlock(), createBlock(_component_el_table_column, {
|
|
738
|
+
key: 1,
|
|
739
|
+
type: "index",
|
|
740
|
+
label: __props.indexLabel,
|
|
741
|
+
width: __props.indexWidth,
|
|
742
|
+
fixed: "left",
|
|
743
|
+
align: "center"
|
|
744
|
+
}, null, 8, ["label", "width"])) : createCommentVNode("", true),
|
|
745
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.columns, (column) => {
|
|
746
|
+
return openBlock(), createBlock(_component_el_table_column, {
|
|
747
|
+
key: getColumnKey(column),
|
|
748
|
+
prop: getColumnProp(column),
|
|
749
|
+
label: column.label,
|
|
750
|
+
type: column.type || void 0,
|
|
751
|
+
width: toCssValue(column.width),
|
|
752
|
+
"min-width": toCssValue(column.minWidth),
|
|
753
|
+
fixed: column.fixed,
|
|
754
|
+
align: column.align || "left",
|
|
755
|
+
"header-align": column.headerAlign || column.align || "left",
|
|
756
|
+
sortable: resolveColumnSortable(column),
|
|
757
|
+
"show-overflow-tooltip": column.showOverflowTooltip !== false,
|
|
758
|
+
"class-name": column.className,
|
|
759
|
+
"label-class-name": column.headerClassName
|
|
760
|
+
}, createSlots({
|
|
761
|
+
default: withCtx((scope) => [
|
|
762
|
+
hasCellSlot(column) ? renderSlot(_ctx.$slots, resolveCellSlotName(column), {
|
|
763
|
+
key: 0,
|
|
764
|
+
row: scope.row,
|
|
765
|
+
columnConfig: column,
|
|
766
|
+
columnIndex: scope.$index,
|
|
767
|
+
value: getCellValue2(scope.row, column)
|
|
768
|
+
}, void 0, true) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
769
|
+
isActionColumn(column) ? (openBlock(), createElementBlock("div", _hoisted_5, [
|
|
770
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(getVisibleActions(column, scope.row), (action) => {
|
|
771
|
+
return openBlock(), createBlock(_component_el_button, {
|
|
772
|
+
key: `${action.type}-${action.label}`,
|
|
773
|
+
link: "",
|
|
774
|
+
type: action.buttonType || (action.type === "delete" ? "danger" : "primary"),
|
|
775
|
+
disabled: isActionDisabled(action, scope.row),
|
|
776
|
+
onClick: ($event) => handleRowAction(scope.row, action, column)
|
|
777
|
+
}, {
|
|
778
|
+
default: withCtx(() => [
|
|
779
|
+
createTextVNode(toDisplayString(action.label), 1)
|
|
780
|
+
]),
|
|
781
|
+
_: 2
|
|
782
|
+
}, 1032, ["type", "disabled", "onClick"]);
|
|
783
|
+
}), 128))
|
|
784
|
+
])) : column.kind === "image" ? (openBlock(), createBlock(_component_el_image, {
|
|
785
|
+
key: 1,
|
|
786
|
+
class: "base-table__image",
|
|
787
|
+
style: normalizeStyle(getImageStyle(column)),
|
|
788
|
+
src: toImageSrc(getCellValue2(scope.row, column)),
|
|
789
|
+
"preview-src-list": getPreviewSrcList(scope.row, column),
|
|
790
|
+
fit: column.imageFit || "cover"
|
|
791
|
+
}, null, 8, ["style", "src", "preview-src-list", "fit"])) : column.kind === "tag" ? (openBlock(), createElementBlock("div", _hoisted_6, [
|
|
792
|
+
getMatchedOptions(scope.row, column).length ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(getMatchedOptions(scope.row, column), (option) => {
|
|
793
|
+
return openBlock(), createBlock(_component_el_tag, {
|
|
794
|
+
key: String(option.value),
|
|
795
|
+
type: option.tagType || "info",
|
|
796
|
+
style: normalizeStyle(option.color ? { color: option.color, borderColor: `${option.color}33`, backgroundColor: `${option.color}1a` } : void 0),
|
|
797
|
+
size: "small"
|
|
798
|
+
}, {
|
|
799
|
+
default: withCtx(() => [
|
|
800
|
+
createTextVNode(toDisplayString(option.label), 1)
|
|
801
|
+
]),
|
|
802
|
+
_: 2
|
|
803
|
+
}, 1032, ["type", "style"]);
|
|
804
|
+
}), 128)) : (openBlock(), createElementBlock("span", _hoisted_7, toDisplayString(resolveEmptyText(column)), 1))
|
|
805
|
+
])) : column.kind === "html" ? (openBlock(), createElementBlock("div", {
|
|
806
|
+
key: 3,
|
|
807
|
+
innerHTML: getHtmlContent(scope.row, column)
|
|
808
|
+
}, null, 8, _hoisted_8)) : column.kind === "input" ? (openBlock(), createBlock(_component_el_input, {
|
|
809
|
+
key: 4,
|
|
810
|
+
"model-value": toDisplayValue(getCellValue2(scope.row, column), ""),
|
|
811
|
+
type: column.inputType || "text",
|
|
812
|
+
"onUpdate:modelValue": ($event) => handleInputChange($event, scope.row, column)
|
|
813
|
+
}, null, 8, ["model-value", "type", "onUpdate:modelValue"])) : isLinkColumn(column) ? (openBlock(), createElementBlock("button", {
|
|
814
|
+
key: 5,
|
|
815
|
+
class: "base-table__link",
|
|
816
|
+
type: "button",
|
|
817
|
+
onClick: ($event) => handleCellClick(scope.row, column)
|
|
818
|
+
}, toDisplayString(formatCellDisplay(scope.row, column)), 9, _hoisted_9)) : (openBlock(), createElementBlock("div", _hoisted_10, toDisplayString(formatCellDisplay(scope.row, column)), 1))
|
|
819
|
+
], 64))
|
|
820
|
+
]),
|
|
821
|
+
_: 2
|
|
822
|
+
}, [
|
|
823
|
+
hasHeaderSlot(column) ? {
|
|
824
|
+
name: "header",
|
|
825
|
+
fn: withCtx((headerScope) => [
|
|
826
|
+
renderSlot(_ctx.$slots, resolveHeaderSlotName(column), mergeProps({ ref_for: true }, headerScope, { columnConfig: column }), void 0, true)
|
|
827
|
+
]),
|
|
828
|
+
key: "0"
|
|
829
|
+
} : void 0
|
|
830
|
+
]), 1032, ["prop", "label", "type", "width", "min-width", "fixed", "align", "header-align", "sortable", "show-overflow-tooltip", "class-name", "label-class-name"]);
|
|
831
|
+
}), 128))
|
|
832
|
+
]),
|
|
833
|
+
_: 3
|
|
834
|
+
}, 8, ["data", "row-key", "height", "border", "stripe", "default-sort"])), [
|
|
835
|
+
[_directive_loading, loading.value]
|
|
836
|
+
])
|
|
837
|
+
]);
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
var BaseTable = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-429ba785"]]);
|
|
842
|
+
var BaseEChart_vue_vue_type_style_index_0_scoped_true_lang = "";
|
|
843
|
+
const _sfc_main$1 = defineComponent({
|
|
844
|
+
__name: "BaseEChart",
|
|
845
|
+
props: {
|
|
846
|
+
option: { default: () => ({}) },
|
|
847
|
+
theme: {},
|
|
848
|
+
initOptions: { default: () => ({ renderer: "canvas" }) },
|
|
849
|
+
setOptionOptions: { type: Boolean, default: () => ({ notMerge: false, lazyUpdate: true }) },
|
|
850
|
+
loading: { type: Boolean, default: false },
|
|
851
|
+
loadingOptions: {},
|
|
852
|
+
autoResize: { type: Boolean, default: true },
|
|
853
|
+
useDefaultColors: { type: Boolean, default: true },
|
|
854
|
+
colorStorageKey: { default: "echartsColor" },
|
|
855
|
+
defaultColors: { default: () => [] },
|
|
856
|
+
group: { default: void 0 }
|
|
857
|
+
},
|
|
858
|
+
emits: ["ready"],
|
|
859
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
860
|
+
const props = __props;
|
|
861
|
+
const emit = __emit;
|
|
862
|
+
const containerRef = ref(null);
|
|
863
|
+
const chartRef = ref(null);
|
|
864
|
+
const chartInstance = shallowRef(null);
|
|
865
|
+
let resizeObserver = null;
|
|
866
|
+
let resizeFrameId = null;
|
|
867
|
+
let pendingResizeOptions;
|
|
868
|
+
const cancelResizeFrame = () => {
|
|
869
|
+
if (resizeFrameId !== null) {
|
|
870
|
+
cancelAnimationFrame(resizeFrameId);
|
|
871
|
+
resizeFrameId = null;
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
const getDefaultColors = () => {
|
|
875
|
+
if (!props.useDefaultColors || typeof window === "undefined") {
|
|
876
|
+
return props.defaultColors;
|
|
877
|
+
}
|
|
878
|
+
try {
|
|
879
|
+
const raw = window.sessionStorage.getItem(props.colorStorageKey);
|
|
880
|
+
const colors = raw ? JSON.parse(raw) : [];
|
|
881
|
+
return colors.length > 0 ? colors : props.defaultColors;
|
|
882
|
+
} catch {
|
|
883
|
+
return props.defaultColors;
|
|
884
|
+
}
|
|
885
|
+
};
|
|
886
|
+
const normalizeOption = (option = {}) => {
|
|
887
|
+
if (option.color) {
|
|
888
|
+
return option;
|
|
889
|
+
}
|
|
890
|
+
const colors = getDefaultColors();
|
|
891
|
+
if (!colors || colors.length === 0) {
|
|
892
|
+
return option;
|
|
893
|
+
}
|
|
894
|
+
return {
|
|
895
|
+
...option,
|
|
896
|
+
color: colors
|
|
897
|
+
};
|
|
898
|
+
};
|
|
899
|
+
const createChart = () => {
|
|
900
|
+
if (!chartRef.value) {
|
|
901
|
+
return null;
|
|
902
|
+
}
|
|
903
|
+
const existingChart = echarts.getInstanceByDom(chartRef.value);
|
|
904
|
+
existingChart == null ? void 0 : existingChart.dispose();
|
|
905
|
+
const instance = echarts.init(chartRef.value, props.theme, props.initOptions);
|
|
906
|
+
if (props.group) {
|
|
907
|
+
instance.group = props.group;
|
|
908
|
+
}
|
|
909
|
+
chartInstance.value = instance;
|
|
910
|
+
emit("ready", instance);
|
|
911
|
+
return instance;
|
|
912
|
+
};
|
|
913
|
+
const getInstance = () => chartInstance.value;
|
|
914
|
+
const ensureChart = () => {
|
|
915
|
+
var _a;
|
|
916
|
+
return (_a = chartInstance.value) != null ? _a : createChart();
|
|
917
|
+
};
|
|
918
|
+
const setOption = (option, setOptionOptions = props.setOptionOptions) => {
|
|
919
|
+
const chart = ensureChart();
|
|
920
|
+
if (!chart) {
|
|
921
|
+
return null;
|
|
922
|
+
}
|
|
923
|
+
const nextOption = normalizeOption(option);
|
|
924
|
+
if (typeof setOptionOptions === "boolean") {
|
|
925
|
+
chart.setOption(nextOption, setOptionOptions);
|
|
926
|
+
} else {
|
|
927
|
+
chart.setOption(nextOption, setOptionOptions);
|
|
928
|
+
}
|
|
929
|
+
return chart;
|
|
930
|
+
};
|
|
931
|
+
const showLoading = (type = "default", loadingOptions) => {
|
|
932
|
+
const chart = ensureChart();
|
|
933
|
+
if (!chart) {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
chart.showLoading(type, loadingOptions);
|
|
937
|
+
};
|
|
938
|
+
const hideLoading = () => {
|
|
939
|
+
var _a;
|
|
940
|
+
(_a = chartInstance.value) == null ? void 0 : _a.hideLoading();
|
|
941
|
+
};
|
|
942
|
+
const syncLoading = () => {
|
|
943
|
+
if (props.loading) {
|
|
944
|
+
showLoading("default", props.loadingOptions);
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
hideLoading();
|
|
948
|
+
};
|
|
949
|
+
const resize = (resizeOptions) => {
|
|
950
|
+
pendingResizeOptions = resizeOptions;
|
|
951
|
+
cancelResizeFrame();
|
|
952
|
+
resizeFrameId = requestAnimationFrame(() => {
|
|
953
|
+
var _a;
|
|
954
|
+
(_a = chartInstance.value) == null ? void 0 : _a.resize(pendingResizeOptions);
|
|
955
|
+
pendingResizeOptions = void 0;
|
|
956
|
+
resizeFrameId = null;
|
|
957
|
+
});
|
|
958
|
+
};
|
|
959
|
+
const handleWindowResize = () => {
|
|
960
|
+
resize();
|
|
961
|
+
};
|
|
962
|
+
const stopAutoResize = () => {
|
|
963
|
+
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
964
|
+
resizeObserver = null;
|
|
965
|
+
window.removeEventListener("resize", handleWindowResize);
|
|
966
|
+
};
|
|
967
|
+
const startAutoResize = () => {
|
|
968
|
+
stopAutoResize();
|
|
969
|
+
if (!props.autoResize || !containerRef.value) {
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
resizeObserver = new ResizeObserver(() => {
|
|
973
|
+
resize();
|
|
974
|
+
});
|
|
975
|
+
resizeObserver.observe(containerRef.value);
|
|
976
|
+
window.addEventListener("resize", handleWindowResize);
|
|
977
|
+
};
|
|
978
|
+
const clear = () => {
|
|
979
|
+
var _a;
|
|
980
|
+
(_a = chartInstance.value) == null ? void 0 : _a.clear();
|
|
981
|
+
};
|
|
982
|
+
const disposeChart = () => {
|
|
983
|
+
var _a;
|
|
984
|
+
(_a = chartInstance.value) == null ? void 0 : _a.dispose();
|
|
985
|
+
chartInstance.value = null;
|
|
986
|
+
};
|
|
987
|
+
const dispose = () => {
|
|
988
|
+
disposeChart();
|
|
989
|
+
};
|
|
990
|
+
const dispatchAction = (payload) => {
|
|
991
|
+
var _a;
|
|
992
|
+
(_a = chartInstance.value) == null ? void 0 : _a.dispatchAction(payload);
|
|
993
|
+
};
|
|
994
|
+
const on = (eventName, handler, context) => {
|
|
995
|
+
const chart = ensureChart();
|
|
996
|
+
chart == null ? void 0 : chart.on(eventName, handler, context);
|
|
997
|
+
};
|
|
998
|
+
const off = (eventName, handler) => {
|
|
999
|
+
if (!chartInstance.value) {
|
|
1000
|
+
return;
|
|
1001
|
+
}
|
|
1002
|
+
if (!eventName) {
|
|
1003
|
+
chartInstance.value.off();
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
if (handler) {
|
|
1007
|
+
chartInstance.value.off(eventName, handler);
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
chartInstance.value.off(eventName);
|
|
1011
|
+
};
|
|
1012
|
+
const reinitChart = async () => {
|
|
1013
|
+
disposeChart();
|
|
1014
|
+
await nextTick();
|
|
1015
|
+
createChart();
|
|
1016
|
+
setOption(props.option);
|
|
1017
|
+
syncLoading();
|
|
1018
|
+
resize();
|
|
1019
|
+
};
|
|
1020
|
+
watch(
|
|
1021
|
+
() => props.option,
|
|
1022
|
+
(option) => {
|
|
1023
|
+
setOption(option);
|
|
1024
|
+
},
|
|
1025
|
+
{ deep: true }
|
|
1026
|
+
);
|
|
1027
|
+
watch(
|
|
1028
|
+
() => props.loading,
|
|
1029
|
+
() => {
|
|
1030
|
+
syncLoading();
|
|
1031
|
+
}
|
|
1032
|
+
);
|
|
1033
|
+
watch(
|
|
1034
|
+
() => props.loadingOptions,
|
|
1035
|
+
() => {
|
|
1036
|
+
if (props.loading) {
|
|
1037
|
+
syncLoading();
|
|
1038
|
+
}
|
|
1039
|
+
},
|
|
1040
|
+
{ deep: true }
|
|
1041
|
+
);
|
|
1042
|
+
watch(
|
|
1043
|
+
() => props.group,
|
|
1044
|
+
(group) => {
|
|
1045
|
+
if (!chartInstance.value) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
chartInstance.value.group = group != null ? group : "";
|
|
1049
|
+
}
|
|
1050
|
+
);
|
|
1051
|
+
watch(
|
|
1052
|
+
() => props.autoResize,
|
|
1053
|
+
async (enabled) => {
|
|
1054
|
+
stopAutoResize();
|
|
1055
|
+
if (enabled) {
|
|
1056
|
+
await nextTick();
|
|
1057
|
+
startAutoResize();
|
|
1058
|
+
resize();
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
);
|
|
1062
|
+
watch(
|
|
1063
|
+
() => props.theme,
|
|
1064
|
+
() => {
|
|
1065
|
+
reinitChart();
|
|
1066
|
+
},
|
|
1067
|
+
{ deep: true }
|
|
1068
|
+
);
|
|
1069
|
+
watch(
|
|
1070
|
+
() => props.initOptions,
|
|
1071
|
+
() => {
|
|
1072
|
+
reinitChart();
|
|
1073
|
+
},
|
|
1074
|
+
{ deep: true }
|
|
1075
|
+
);
|
|
1076
|
+
onMounted(async () => {
|
|
1077
|
+
await nextTick();
|
|
1078
|
+
createChart();
|
|
1079
|
+
setOption(props.option);
|
|
1080
|
+
syncLoading();
|
|
1081
|
+
startAutoResize();
|
|
1082
|
+
resize();
|
|
1083
|
+
});
|
|
1084
|
+
onUnmounted(() => {
|
|
1085
|
+
stopAutoResize();
|
|
1086
|
+
cancelResizeFrame();
|
|
1087
|
+
disposeChart();
|
|
1088
|
+
});
|
|
1089
|
+
__expose({
|
|
1090
|
+
getInstance,
|
|
1091
|
+
setOption,
|
|
1092
|
+
resize,
|
|
1093
|
+
dispatchAction,
|
|
1094
|
+
showLoading,
|
|
1095
|
+
hideLoading,
|
|
1096
|
+
clear,
|
|
1097
|
+
dispose,
|
|
1098
|
+
on,
|
|
1099
|
+
off
|
|
1100
|
+
});
|
|
1101
|
+
return (_ctx, _cache) => {
|
|
1102
|
+
return openBlock(), createElementBlock("div", {
|
|
1103
|
+
ref_key: "containerRef",
|
|
1104
|
+
ref: containerRef,
|
|
1105
|
+
class: "base-echart"
|
|
1106
|
+
}, [
|
|
1107
|
+
createElementVNode("div", {
|
|
1108
|
+
ref_key: "chartRef",
|
|
1109
|
+
ref: chartRef,
|
|
1110
|
+
class: "base-echart__inner"
|
|
1111
|
+
}, null, 512)
|
|
1112
|
+
], 512);
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
var BaseEChart = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-51bc4772"]]);
|
|
5
1117
|
const DEFAULT_SHEET_NAME = "Sheet1";
|
|
6
1118
|
const DEFAULT_COLUMN_WIDTH = 16;
|
|
1119
|
+
const EXCEL_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
7
1120
|
function getLeafCount(column) {
|
|
8
1121
|
var _a;
|
|
9
1122
|
if (!((_a = column.children) == null ? void 0 : _a.length)) {
|
|
@@ -89,13 +1202,23 @@ function buildColumnWidths(leafColumns, dataRows, defaultColumnWidth, autoWidth)
|
|
|
89
1202
|
return Math.max(maxWidth, getDisplayLength(row[columnIndex]));
|
|
90
1203
|
}, 0);
|
|
91
1204
|
const targetWidth = (_a = column.width) != null ? _a : autoWidth ? Math.max(defaultColumnWidth, headerWidth, dataWidth) : defaultColumnWidth;
|
|
92
|
-
return
|
|
1205
|
+
return targetWidth;
|
|
93
1206
|
});
|
|
94
1207
|
}
|
|
95
1208
|
function normalizeFileName(fileName) {
|
|
96
1209
|
return fileName.endsWith(".xlsx") ? fileName : `${fileName}.xlsx`;
|
|
97
1210
|
}
|
|
98
|
-
function
|
|
1211
|
+
function applyColumnWidths(worksheet, columnWidths) {
|
|
1212
|
+
columnWidths.forEach((width, index) => {
|
|
1213
|
+
worksheet.getColumn(index + 1).width = width;
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
function applyMerges(worksheet, merges) {
|
|
1217
|
+
merges.forEach((range) => {
|
|
1218
|
+
worksheet.mergeCells(range.s.r + 1, range.s.c + 1, range.e.r + 1, range.e.c + 1);
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
async function exportExcel(options) {
|
|
99
1222
|
const {
|
|
100
1223
|
fileName,
|
|
101
1224
|
sheetName = DEFAULT_SHEET_NAME,
|
|
@@ -109,12 +1232,17 @@ function exportExcel(options) {
|
|
|
109
1232
|
}
|
|
110
1233
|
const { headerRows, leafColumns, merges } = buildHeaderMatrix(columns);
|
|
111
1234
|
const dataRows = data.map((row, rowIndex) => leafColumns.map((column) => getCellValue(row, rowIndex, column)));
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
worksheet
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
1235
|
+
const columnWidths = buildColumnWidths(leafColumns, dataRows, defaultColumnWidth, autoWidth);
|
|
1236
|
+
const workbook = new ExcelJS.Workbook();
|
|
1237
|
+
const worksheet = workbook.addWorksheet(sheetName);
|
|
1238
|
+
[...headerRows, ...dataRows].forEach((row) => {
|
|
1239
|
+
worksheet.addRow(row);
|
|
1240
|
+
});
|
|
1241
|
+
applyMerges(worksheet, merges);
|
|
1242
|
+
applyColumnWidths(worksheet, columnWidths);
|
|
1243
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
1244
|
+
const blob = new Blob([buffer], { type: EXCEL_MIME_TYPE });
|
|
1245
|
+
saveAs(blob, normalizeFileName(fileName));
|
|
118
1246
|
}
|
|
119
1247
|
const DEFAULT_EXPORT_FILE_NAME = "export-file";
|
|
120
1248
|
function getHeaderValue(headers, headerName) {
|
|
@@ -251,7 +1379,7 @@ const _sfc_main = defineComponent({
|
|
|
251
1379
|
emit("start");
|
|
252
1380
|
try {
|
|
253
1381
|
if (exportMode.value === "excel" && props.excelOptions) {
|
|
254
|
-
exportExcel(props.excelOptions);
|
|
1382
|
+
await exportExcel(props.excelOptions);
|
|
255
1383
|
if (props.autoMessage) {
|
|
256
1384
|
ElMessage.success(props.successMessage);
|
|
257
1385
|
}
|
|
@@ -305,4 +1433,4 @@ const _sfc_main = defineComponent({
|
|
|
305
1433
|
};
|
|
306
1434
|
}
|
|
307
1435
|
});
|
|
308
|
-
export { _sfc_main as BaseExportButton, downloadExportResponse, exportExcel, extractFileNameFromDisposition, normalizeExportFileName };
|
|
1436
|
+
export { BaseCard, BaseEChart, _sfc_main as BaseExportButton, BaseTable, downloadExportResponse, exportExcel, extractFileNameFromDisposition, normalizeExportFileName };
|