@infly/ui 1.0.27 → 1.0.29

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.
@@ -1,926 +1,926 @@
1
- <template>
2
- <!-- packages\infly-ui\src\Business\InflyList\ListPanel.vue 列表组件 -->
3
- <div :class="['comp-InflyList']">
4
- <el-tabs
5
- v-model="activityTab"
6
- :class="{
7
- 'list__tabs--top': isTopList,
8
- 'list__tabs--hide': !tabList.length || hideTab,
9
- 'list__tabs--hide-header': tabList.length == 1 && !tabList[0].name,
10
- 'list__tabs--inner': isInnerList
11
- }"
12
- lazy
13
- v-bind="tabsProps"
14
- @tab-click="handleClickTab"
15
- >
16
- <slot name="pretop"></slot>
17
- <el-tab-pane v-for="item in visibleTabList" :key="item.name" v-bind="item">
18
- <slot name="prepend"></slot>
19
- <slot name="replace">
20
- <InflyForm
21
- :formData="formData"
22
- :filterList="filterList"
23
- :btnList="btnList"
24
- :reqParams="reqParams"
25
- v-bind="formProps"
26
- @initData="handleFormInitData"
27
- @reset-form="handleResetForm"
28
- @secTabChange="handleFormSecTabChange"
29
- >
30
- <template #customRender="{ item }">
31
- <slot name="customRender" :item="item"></slot>
32
- </template>
33
- </InflyForm>
34
- <el-divider v-if="!hideDivider" />
35
- <slot name="replaceTable">
36
- <el-table
37
- :class="['main-table', tableProps.tableClass]"
38
- :data="tableDataList"
39
- :tree-props="tableProps.treeProps || { children: 'lists', hasChildren: 'hasChildren' }"
40
- :size="tableProps.size || 'mini'"
41
- :indent="tableProps.indent || 0"
42
- v-loading="showTableLoading"
43
- v-bind="tableProps"
44
- >
45
- <template v-for="(defaultColumn, colIndex) in columnGroups.defaultColumns">
46
- <el-table-column
47
- v-if="defaultColumn.type !== 'expand'"
48
- :key="`default_${colIndex}`"
49
- v-bind="defaultColumn"
50
- />
51
- <el-table-column v-else :key="`default_expand_${colIndex}`" v-bind="defaultColumn">
52
- <template slot-scope="scope">
53
- <slot name="expand" :column="defaultColumn" :row="scope.row" :rowIndex="scope.$index"></slot>
54
- </template>
55
- </el-table-column>
56
- </template>
57
- <InflyListTableColumn
58
- v-for="(column, columnIndex) in columnGroups.customColumns"
59
- :key="getColumnKey(column, columnIndex)"
60
- :column="column"
61
- :list-vm="listContext"
62
- />
63
- </el-table>
64
- <div class="pagination-wrap" v-if="formData.total > 0">
65
- <el-pagination
66
- class="standard-list__pagination"
67
- layout="total, sizes, prev, pager, next, jumper"
68
- :current-page.sync="formData.page"
69
- :page-sizes="[10, 20, 50, 100]"
70
- :page-size.sync="formData.pagesize"
71
- :total="formData.total"
72
- background
73
- @size-change="handleSizeChange"
74
- @current-change="handleCurrentChange"
75
- >
76
- </el-pagination>
77
- <el-button
78
- v-if="!hideJumpPageButton"
79
- @click="handleCurrentChange(formData.page)"
80
- type="primary"
81
- style="margin-left: 10px"
82
- size="mini"
83
- >
84
- 跳 转
85
- </el-button>
86
- </div>
87
- </slot>
88
- </slot>
89
- </el-tab-pane>
90
- </el-tabs>
91
- </div>
92
- </template>
93
-
94
- <script>
95
- import Uts from "../../utils/Uts.js";
96
- import InflyForm from "../InflyForm/InflyForm.vue";
97
-
98
- // 模块级常量,避免每次渲染返回新对象引用
99
- const EMPTY_EVENTS = Object.freeze({});
100
- const REQUEST_TIMEOUT = 60000;
101
- const DEFAULT_COLUMN_TYPES = new Set(["selection", "index", "expand"]);
102
- const TABLE_COLUMN_INTERNAL_KEYS = Object.freeze([
103
- "children",
104
- "columns",
105
- "type",
106
- "buttonList",
107
- "className",
108
- "isHide",
109
- "isShow",
110
- "click",
111
- "options",
112
- "optionKeyField",
113
- "optionValueField",
114
- "propValueField",
115
- "mapField",
116
- "render"
117
- ]);
118
- const CELL_CONFIG_EXCLUDED_KEYS = Object.freeze(["width", "fixed", "showOverflowTooltip", "children", "columns"]);
119
- const BUTTON_INTERNAL_KEYS = Object.freeze(["name", "label", "className", "isShow", "isHide", "click", "btnEvent"]);
120
- const IMAGE_PROP_KEYS = Object.freeze(["fit", "lazy", "scrollContainer", "zIndex"]);
121
-
122
- // 组件类型映射,避免每次 getCompType 调用创建新对象
123
- const COMP_TYPE_MAP = Object.freeze({
124
- "el-tag": "el-tag",
125
- "el-popover": "el-popover",
126
- "el-button": "div",
127
- custom: "div",
128
- render: "div"
129
- });
130
-
131
- // 用 WeakMap 按 options 数组对象缓存 pluckMap 结果,options 引用不变时直接命中
132
- const optionMapCache = new WeakMap();
133
- function getOrBuildOptionMap(options, optionValueField, optionKeyField) {
134
- if (!optionMapCache.has(options)) {
135
- optionMapCache.set(options, Uts.pluckMap(options, optionValueField, optionKeyField));
136
- }
137
- return optionMapCache.get(options);
138
- }
139
-
140
- function getColumnChildren(column = {}) {
141
- if (Array.isArray(column.children)) {
142
- return column.children;
143
- }
144
- if (Array.isArray(column.columns)) {
145
- return column.columns;
146
- }
147
- return [];
148
- }
149
-
150
- function getTableColumnProps(column = {}) {
151
- const columnProps = { ...(column || {}) };
152
- TABLE_COLUMN_INTERNAL_KEYS.forEach((key) => {
153
- delete columnProps[key];
154
- });
155
-
156
- return {
157
- align: "center",
158
- ...columnProps
159
- };
160
- }
161
-
162
- const InflyListTableColumn = {
163
- name: "InflyListTableColumn",
164
- props: {
165
- column: { type: Object, required: true },
166
- listVm: { type: Object, required: true }
167
- },
168
- methods: {
169
- getCellConfig() {
170
- const { label, prop, type, buttonList, className, click = () => {}, ...otherAttrs } = this.column || {};
171
-
172
- CELL_CONFIG_EXCLUDED_KEYS.forEach((key) => {
173
- delete otherAttrs[key];
174
- });
175
-
176
- return {
177
- label,
178
- prop,
179
- type,
180
- buttonList,
181
- className,
182
- click,
183
- otherAttrs
184
- };
185
- },
186
- renderCustomCell(createElement, { row, prop, label, click, data = {} }) {
187
- const result = this.listVm.customRender(row, prop, { label });
188
- const cellData = { ...data };
189
-
190
- if (click) {
191
- cellData.on = {
192
- ...(cellData.on || {}),
193
- click: () => click(row, prop)
194
- };
195
- }
196
-
197
- if (typeof result === "string") {
198
- cellData.domProps = { innerHTML: result };
199
- return createElement("div", cellData);
200
- }
201
-
202
- if (click || Object.keys(cellData).length) {
203
- return createElement("div", cellData, [result || createElement("span")]);
204
- }
205
-
206
- return result || createElement("span");
207
- },
208
- renderLeafCell(createElement, row) {
209
- const { label, prop, type, buttonList, className, click, otherAttrs } = this.getCellConfig();
210
- const cellAttrs = { type, ...otherAttrs };
211
-
212
- if (!this.listVm.shouldShowByConfig(this.column, row)) {
213
- return createElement("span");
214
- }
215
-
216
- if (this.listVm.hasColumnSlot(prop)) {
217
- return this.listVm.$scopedSlots[prop]({ row, prop });
218
- }
219
-
220
- if (type === "slot") {
221
- return createElement("span", [this.listVm.getValue(row, prop, cellAttrs)]);
222
- }
223
-
224
- const componentType = this.listVm.getCompType(row, { type, prop }, otherAttrs);
225
- const children = [];
226
-
227
- if (type === "el-tag") {
228
- children.push(this.listVm.getValue(row, prop, cellAttrs));
229
- } else if (type === "el-popover") {
230
- children.push(
231
- this.renderCustomCell(createElement, { row, prop, label }),
232
- this.renderCustomCell(createElement, {
233
- row,
234
- prop,
235
- label,
236
- data: {
237
- slot: "reference",
238
- class: ["infly-list__popover-text", "el-popover__text", className]
239
- }
240
- })
241
- );
242
- } else if (type === "custom" || type === "render") {
243
- children.push(this.renderCustomCell(createElement, { row, prop, label, click }));
244
- } else if (type === "el-button" || Uts.notEmptyArray(buttonList)) {
245
- children.push(
246
- ...this.listVm
247
- .normalizeButtonList(buttonList)
248
- .map((btnItem, btnIndex) => {
249
- if (!this.listVm.shouldShowByConfig(btnItem, row)) {
250
- return null;
251
- }
252
- return createElement(
253
- "el-button",
254
- {
255
- key: this.listVm.getButtonKey(btnItem, btnIndex),
256
- props: this.listVm.getButtonProps(btnItem),
257
- on: { click: () => this.listVm.handleColumnButtonClick(btnItem, row) }
258
- },
259
- [
260
- createElement(
261
- "span",
262
- { class: ["infly-list__button-text", "btn__text", this.listVm.getButtonClassName(btnItem, row)] },
263
- [this.listVm.getButtonText(btnItem, row)]
264
- )
265
- ]
266
- );
267
- })
268
- .filter(Boolean)
269
- );
270
- } else if (type === "el-image") {
271
- children.push(this.renderImageCell(createElement, row, prop, cellAttrs, otherAttrs));
272
- } else if (row.level !== 0) {
273
- children.push(
274
- createElement("div", {
275
- domProps: { innerHTML: this.listVm.getValue(row, prop, cellAttrs) }
276
- })
277
- );
278
- }
279
-
280
- return createElement(
281
- componentType,
282
- {
283
- props: this.listVm.getCompProps(row, { type, prop, ...otherAttrs }),
284
- on: this.listVm.getCompEvents(row)
285
- },
286
- children
287
- );
288
- },
289
- renderImageCell(createElement, row, prop, cellAttrs = {}, otherAttrs = {}) {
290
- const { style, class: className, ...restAttrs } = otherAttrs;
291
- const imageProps = {
292
- src: this.listVm.getValue(row, prop, cellAttrs),
293
- previewSrcList: this.listVm.getImagePreviewList(row, prop, cellAttrs)
294
- };
295
- const imageAttrs = {};
296
-
297
- Object.keys(restAttrs).forEach((key) => {
298
- if (IMAGE_PROP_KEYS.includes(key)) {
299
- imageProps[key] = restAttrs[key];
300
- } else {
301
- imageAttrs[key] = restAttrs[key];
302
- }
303
- });
304
-
305
- return createElement("el-image", {
306
- props: imageProps,
307
- attrs: imageAttrs,
308
- class: className,
309
- style
310
- });
311
- }
312
- },
313
- render(createElement) {
314
- const columnChildren = getColumnChildren(this.column).filter((column) =>
315
- this.listVm.shouldShowByConfig(column, column)
316
- );
317
- const columnData = { props: getTableColumnProps(this.column) };
318
-
319
- if (columnChildren.length) {
320
- return createElement(
321
- "el-table-column",
322
- columnData,
323
- columnChildren.map((column, columnIndex) =>
324
- createElement(InflyListTableColumn, {
325
- key: this.listVm.getColumnKey(column, columnIndex),
326
- props: {
327
- column,
328
- listVm: this.listVm
329
- }
330
- })
331
- )
332
- );
333
- }
334
-
335
- return createElement("el-table-column", {
336
- ...columnData,
337
- scopedSlots: {
338
- default: ({ row }) => this.renderLeafCell(createElement, row)
339
- }
340
- });
341
- }
342
- };
343
-
344
- export default {
345
- name: "InflyList",
346
- inheritAttrs: false,
347
- components: {
348
- InflyListTableColumn,
349
- InflyForm
350
- },
351
- props: {
352
- // 数据 / 配置
353
- formData: { type: Object, required: true, default: () => ({}) },
354
- defaultTabName: { type: String, default: "" },
355
- hideTab: { type: Boolean, default: false },
356
- tabList: { type: Array, default: () => [{}] },
357
- filterList: { type: Array, default: () => [] },
358
- columns: { type: Array, required: true, default: () => [] },
359
- btnList: { type: Array, default: () => [] },
360
- outSideReqParams: { type: Object, default: () => ({}) },
361
-
362
- // 请求配置及数据请求/返回处理
363
- reqUrl: { type: String, default: "" },
364
- reqMethod: { type: String, default: "get" },
365
- defaultInit: { type: Boolean, default: true },
366
- dealParams: { type: Function, default: null },
367
- dealRes: { type: Function, default: null },
368
- initEventName: { type: String, default: "initData" },
369
-
370
- hideDivider: { type: Boolean, default: false },
371
- isInnerList: { type: Boolean, default: false }, // 是否为内嵌列表
372
- isTopList: { type: Boolean, default: true }, // 是否为页面顶部列表,影响样式
373
- hideEmptyTag: { type: Boolean, default: false }, // 是否隐藏 el-tag 组件的空值标签
374
- hideJumpPageButton: { type: Boolean, default: false },
375
-
376
- // 自定义渲染函数
377
- customRender: {
378
- type: Function,
379
- default: (row, prop) => {
380
- return Uts.getNestedValue(row, prop);
381
- }
382
- },
383
-
384
- // UI 配置
385
- tableProps: { type: Object, default: () => ({}) },
386
- formProps: { type: Object, default: () => ({ "label-width": "80px" }) },
387
- emptyText: { type: String, default: "" },
388
- tabsProps: { type: Object, default: () => ({ type: "border-card" }) }
389
- },
390
-
391
- data() {
392
- const [firstTab] = this.tabList || [];
393
- const { name: firstTabName } = firstTab || {};
394
- return {
395
- dataList: [],
396
- showTableLoading: false,
397
- activityTab: this.defaultTabName || firstTabName,
398
- reqParams: {},
399
- activitySecTab: "",
400
- latestRequestId: 0
401
- };
402
- },
403
- created() {
404
- if (this.defaultInit) {
405
- this.initData();
406
- }
407
- },
408
- computed: {
409
- tableDataList() {
410
- const { dataList } = this.tableProps || {};
411
- if (dataList !== undefined && dataList !== null) {
412
- return dataList;
413
- }
414
- return this.dataList;
415
- },
416
- listContext() {
417
- return this;
418
- },
419
- /**
420
- * 将列过滤结果缓存为计算属性,避免模板中多次调用 filerColumns() 重复计算。
421
- * 只有 columns 数组引用变化时才重新计算。
422
- */
423
- columnGroups() {
424
- const defaultColumns = [];
425
- const customColumns = [];
426
-
427
- (this.columns || []).forEach((column) => {
428
- const { type } = column || {};
429
- if (!this.shouldShowByConfig(column)) {
430
- return;
431
- }
432
- if (DEFAULT_COLUMN_TYPES.has(type)) {
433
- defaultColumns.push(column);
434
- } else {
435
- customColumns.push(column);
436
- }
437
- });
438
-
439
- return { defaultColumns, customColumns, columns: this.columns };
440
- },
441
- /**
442
- * 根据 isShow / isHide 过滤后的可见 tab 列表
443
- * 优先判断 isShow,其次判断 isHide,未设置则默认显示
444
- */
445
- visibleTabList() {
446
- return (this.tabList || []).filter((item) => this.shouldShowByConfig(item));
447
- }
448
- },
449
- methods: {
450
- /**
451
- * 通用显示判断
452
- * @param {Boolean|Function} condition - 显示/隐藏条件
453
- * @param {Object} row - 数据行
454
- * @param {Boolean} isShowCondition - true 表示 isShow,false 表示 isHide
455
- * @returns {Boolean}
456
- */
457
- shouldShow(condition, row = {}, isShowCondition = false) {
458
- if (condition === undefined) {
459
- return true;
460
- }
461
-
462
- const result = Uts.isFunction(condition) ? condition(row) : condition;
463
- return isShowCondition ? result : !result;
464
- },
465
-
466
- /**
467
- * 根据配置对象的 isShow / isHide 判断是否显示
468
- * isShow 优先级高于 isHide,两者均未设置则默认显示
469
- * @param {Object} config - 配置对象 { isShow, isHide }
470
- * @param {Object} row - 数据行
471
- * @returns {Boolean}
472
- */
473
- shouldShowByConfig(config = {}, row = {}) {
474
- const { isShow, isHide } = config;
475
-
476
- if (isShow !== undefined) {
477
- return this.shouldShow(isShow, row, true);
478
- }
479
- if (isHide !== undefined) {
480
- return this.shouldShow(isHide, row, false);
481
- }
482
- return true;
483
- },
484
-
485
- initData(options = {}) {
486
- const { page, pagesize, resetPage } = this.normalizeInitOptions(options);
487
- const nextPage = page || (resetPage ? 1 : this.formData.page || 1);
488
- const nextPageSize = pagesize || this.formData.pagesize || 10;
489
-
490
- this.setFormField("page", nextPage);
491
- this.setFormField("pagesize", nextPageSize);
492
- this.getList(nextPage, nextPageSize);
493
- this.$emit(this.initEventName);
494
- },
495
- handleFormInitData() {
496
- this.initData({ resetPage: true });
497
- },
498
- normalizeInitOptions(options = {}) {
499
- const optionKeys = ["page", "pagesize", "resetPage"];
500
- if (!options || typeof options !== "object") {
501
- return {};
502
- }
503
- return optionKeys.some((key) => Object.prototype.hasOwnProperty.call(options, key)) ? options : {};
504
- },
505
- setFormField(key, value) {
506
- if (!this.formData || !key) {
507
- return;
508
- }
509
- this.$set(this.formData, key, value);
510
- },
511
- replaceFormData(nextData = {}) {
512
- if (!this.formData) {
513
- return;
514
- }
515
-
516
- Object.keys(this.formData).forEach((key) => {
517
- if (!Object.prototype.hasOwnProperty.call(nextData, key)) {
518
- this.$delete(this.formData, key);
519
- }
520
- });
521
-
522
- Object.keys(nextData).forEach((key) => {
523
- this.$set(this.formData, key, nextData[key]);
524
- });
525
- },
526
- /**
527
- * 获取组件类型
528
- * @param {Object} row - 表格行数据
529
- * @param {Object} column - 表格列配置
530
- * @param {Object} otherAttrs - 额外参数
531
- */
532
- getCompType(row, column = {}, otherAttrs = {}) {
533
- const { type, prop } = column;
534
-
535
- // level 为 0 或未传 type 时,统一返回 div
536
- if ((row || {}).level === 0 || !type) {
537
- return "div";
538
- }
539
-
540
- // el-tag 类型且开启隐藏空值时,检查是否为空
541
- if (type === "el-tag" && this.hideEmptyTag && !this.getValue(row, prop, otherAttrs)) {
542
- return "div";
543
- }
544
-
545
- return COMP_TYPE_MAP[type] || "div";
546
- },
547
- /**
548
- * 获取组件属性配置
549
- * @param {Object} row - 表格行数据
550
- * @param {Object} column - 表格列配置
551
- */
552
- getCompProps(row = {}, column = {}) {
553
- const {
554
- type,
555
- options = [],
556
- prop = "",
557
- propValueField = prop.replace("_str", ""),
558
- mapField = "value"
559
- } = column || {};
560
- const [option] = Uts.filterObjByCondition(options, { [mapField]: Uts.getNestedValue(row, propValueField) }) || [];
561
- const { tagType = "" } = option || {};
562
-
563
- switch (type) {
564
- case "el-tag":
565
- return {
566
- type: tagType
567
- };
568
- case "el-popover":
569
- return {
570
- placement: "top",
571
- width: 200,
572
- trigger: "hover"
573
- };
574
- default:
575
- return {};
576
- }
577
- },
578
- /**
579
- * 处理默认显示值
580
- * @param {Object} row - 行数据
581
- * @param {String} prop - 属性名
582
- * @param {Object} otherAttrs - 额外参数
583
- * @returns {String} - 显示值
584
- */
585
- getValue(row = {}, prop, otherAttrs = {}) {
586
- const { type, options = [], optionKeyField = "name", optionValueField = "value", render } = otherAttrs;
587
- const displayValue = Uts.getNestedValue(row, prop);
588
-
589
- // 优先使用 render 函数
590
- if (Uts.isFunction(render)) {
591
- return render(row, prop);
592
- }
593
-
594
- // 其次使用 options 映射(WeakMap 缓存,同一 options 引用只构建一次)
595
- if (Uts.notEmptyArray(options) && type === "el-tag" && Uts.isNumber(Number(displayValue))) {
596
- const optionMap = getOrBuildOptionMap(options, optionValueField, optionKeyField);
597
- if (Uts.notEmptyObject(optionMap)) {
598
- return optionMap[displayValue] || this.emptyText;
599
- }
600
- }
601
-
602
- if (Uts.isNumber(displayValue)) {
603
- return displayValue;
604
- }
605
-
606
- // 最后返回原值或空文本
607
- return displayValue || this.emptyText;
608
- },
609
- /**
610
- * 组件事件(当前无需动态事件,返回模块级常量避免每次渲染产生新对象引用)
611
- */
612
- getCompEvents(row) {
613
- return EMPTY_EVENTS;
614
- },
615
- getColumnKey(column = {}, columnIndex) {
616
- const { prop, type, label } = column || {};
617
- return `${prop || type || label || "column"}_${columnIndex}`;
618
- },
619
- hasColumnSlot(prop) {
620
- return Boolean(prop && this.$scopedSlots[prop]);
621
- },
622
- normalizeButtonList(buttonList) {
623
- return Uts.notEmptyArray(buttonList) ? buttonList : [];
624
- },
625
- getButtonKey(btnItem = {}, btnIndex) {
626
- return `btn_${btnIndex}_${btnItem.name || btnItem.label || btnIndex}`;
627
- },
628
- getButtonText(btnItem = {}, row = {}) {
629
- const { name, label = "" } = btnItem;
630
- if (Uts.isFunction(name)) {
631
- return name(row);
632
- }
633
- if (name === undefined || name === null || name === "") {
634
- return label;
635
- }
636
- return name;
637
- },
638
- getButtonClassName(btnItem = {}, row = {}) {
639
- const { className } = btnItem;
640
- return Uts.isFunction(className) ? className(row) : className;
641
- },
642
- getButtonProps(btnItem = {}) {
643
- const buttonProps = { ...(btnItem || {}) };
644
- BUTTON_INTERNAL_KEYS.forEach((key) => {
645
- delete buttonProps[key];
646
- });
647
- return buttonProps;
648
- },
649
- handleColumnButtonClick(btnItem = {}, row = {}) {
650
- if (Uts.isFunction(btnItem.click)) {
651
- btnItem.click(row);
652
- }
653
- },
654
- getImagePreviewList(row = {}, prop, otherAttrs = {}) {
655
- const value = this.getValue(row, prop, otherAttrs);
656
- return value ? [value] : [];
657
- },
658
- getRequestUrl() {
659
- let tempReqUrl = this.reqUrl;
660
-
661
- if (!tempReqUrl && Uts.notEmptyArray(this.tabList)) {
662
- const currentTabConfig = this.tabList.find((item) => item && item.name === this.activityTab) || {};
663
- tempReqUrl = currentTabConfig.reqUrl || "";
664
- }
665
-
666
- return tempReqUrl;
667
- },
668
- getRequestMethod() {
669
- return (this.reqMethod || "get").toLowerCase();
670
- },
671
- buildRequestParams(page, pagesize, otherParams = {}) {
672
- const { total, ...params } = this.formData || {};
673
- let reqParams = {
674
- ...params,
675
- page,
676
- pagesize,
677
- ...otherParams,
678
- ...this.outSideReqParams
679
- };
680
-
681
- if (Uts.isFunction(this.dealParams)) {
682
- const nextReqParams = this.dealParams(reqParams);
683
- if (nextReqParams && typeof nextReqParams === "object") {
684
- reqParams = nextReqParams;
685
- }
686
- }
687
-
688
- return Uts.filterCommaFields(reqParams);
689
- },
690
- buildAxiosParams(reqParams = {}) {
691
- if (this.getRequestMethod() !== "get") {
692
- return reqParams;
693
- }
694
-
695
- const params = { ...reqParams };
696
- Object.keys(params).forEach((key) => {
697
- const value = params[key];
698
- if (Uts.isArray(value)) {
699
- params[key] = value.join(",");
700
- }
701
- });
702
-
703
- return { params };
704
- },
705
- isLatestRequest(requestId) {
706
- return requestId === this.latestRequestId;
707
- },
708
- applyListResponse(res = {}, page, pagesize) {
709
- const { total, counts = total || 0, page: resPage, pagesize: resPageSize, data, lists = data } = res || {};
710
-
711
- this.setFormField("total", counts);
712
- this.setFormField("page", resPage || page);
713
- this.setFormField("pagesize", resPageSize || pagesize);
714
- this.dataList = lists || [];
715
- },
716
- getList(page = this.formData.page || 1, pagesize = this.formData.pagesize || 10, otherParams = {}, config = {}) {
717
- const { onlyReturnData } = config || {};
718
- const tempReqUrl = this.getRequestUrl();
719
-
720
- if (!tempReqUrl) {
721
- // console.warn("InflyList 组件缺少 reqUrl 属性");
722
- return Promise.resolve();
723
- }
724
-
725
- const reqParams = this.buildRequestParams(page, pagesize, otherParams);
726
- const axiosParams = this.buildAxiosParams(reqParams);
727
- const reqMethod = this.getRequestMethod();
728
- const requestFn = this.$axios && this.$axios[reqMethod];
729
-
730
- this.reqParams = axiosParams;
731
-
732
- if (!Uts.isFunction(requestFn)) {
733
- const err = new Error(`InflyList 不支持的请求方法:${reqMethod}`);
734
- console.error("InflyList getList error:", err);
735
- this.$emit("request-error", err);
736
- return Promise.resolve();
737
- }
738
-
739
- const requestId = this.latestRequestId + 1;
740
- this.latestRequestId = requestId;
741
- this.showTableLoading = true;
742
-
743
- const loadingTimer = setTimeout(() => {
744
- if (this.isLatestRequest(requestId)) {
745
- this.showTableLoading = false;
746
- this.$emit("request-timeout", { reqUrl: tempReqUrl, reqMethod, reqParams: axiosParams });
747
- }
748
- }, REQUEST_TIMEOUT);
749
-
750
- return requestFn
751
- .call(this.$axios, tempReqUrl, axiosParams)
752
- .then((res) => {
753
- clearTimeout(loadingTimer);
754
-
755
- if (!this.isLatestRequest(requestId)) {
756
- return onlyReturnData ? res : undefined;
757
- }
758
-
759
- this.showTableLoading = false;
760
-
761
- let finalRes = res;
762
- if (Uts.isFunction(this.dealRes)) {
763
- const nextRes = this.dealRes(res);
764
- if (nextRes && typeof nextRes === "object") {
765
- finalRes = nextRes;
766
- }
767
- }
768
-
769
- if (onlyReturnData) {
770
- return finalRes;
771
- }
772
-
773
- this.applyListResponse(finalRes, page, pagesize);
774
- return finalRes;
775
- })
776
- .catch((err) => {
777
- clearTimeout(loadingTimer);
778
- if (this.isLatestRequest(requestId)) {
779
- this.showTableLoading = false;
780
- this.$emit("request-error", err);
781
- console.error("InflyList getList error:", err);
782
- }
783
- return undefined;
784
- });
785
- },
786
- /**
787
- * 处理标签点击事件
788
- * @param {Object} tab - 切换的标签对象(Element UI TabPane 实例)
789
- * @param {Event} event - 事件对象
790
- * @description 切换活动标签时,更新查询条件并重新加载数据
791
- */
792
- handleClickTab(tab, event) {
793
- const { name: tabName } = tab;
794
- this.activityTab = tabName;
795
- this.setFormField("page", 1);
796
-
797
- // 查找原始 tabList 配置,保留自定义属性
798
- const originalTabConfig = this.tabList.find((item) => item.name === tabName) || {};
799
-
800
- const emitParams = {
801
- ...originalTabConfig,
802
- tabName,
803
- name: tabName,
804
- activityTab: this.activityTab
805
- };
806
-
807
- // 推荐使用 tab-change(kebab-case),tabChange 保留向后兼容
808
- this.$emit("tab-change", emitParams);
809
- this.$emit("tabChange", emitParams);
810
- this.$emit(this.initEventName, emitParams);
811
- },
812
- handleFormSecTabChange(emitParams = {}) {
813
- const { activitySecTab, name } = emitParams;
814
- const nextActivitySecTab = activitySecTab || name || "";
815
- const nextEmitParams = {
816
- ...emitParams,
817
- activitySecTab: nextActivitySecTab,
818
- name: name || nextActivitySecTab
819
- };
820
-
821
- this.activitySecTab = nextActivitySecTab;
822
- this.setFormField("page", 1);
823
- this.$emit("secTabChange", nextEmitParams);
824
- this.$emit("sec-tab-change", nextEmitParams);
825
- },
826
- handleCurrentChange(page) {
827
- this.initData({ page: page || 1 });
828
- },
829
- /**
830
- * 处理表单重置事件
831
- */
832
- handleResetForm(resetData) {
833
- const { pagesize } = this.formData || {};
834
- const nextFormData = {
835
- ...(resetData || {}),
836
- page: (resetData && resetData.page) || 1,
837
- pagesize: (resetData && resetData.pagesize) || pagesize || 10
838
- };
839
-
840
- this.replaceFormData(nextFormData);
841
- // 重置后重新加载数据
842
- this.initData({ page: nextFormData.page, pagesize: nextFormData.pagesize });
843
- },
844
- handleSizeChange(pagesize) {
845
- this.initData({ page: 1, pagesize });
846
- }
847
- }
848
- };
849
- </script>
850
-
851
- <style lang="scss" scoped>
852
- // 简化:合并重复的 tabs header 隐藏样式
853
- .list__tabs--hide,
854
- .list__tabs--hide-header {
855
- &::v-deep > .el-tabs__header {
856
- display: none;
857
- }
858
- }
859
-
860
- // 只有 hide 样式需要的额外样式
861
- .list__tabs--hide,
862
- .list__tabs--inner {
863
- &::v-deep {
864
- box-shadow: none;
865
- border: none;
866
-
867
- .el-tabs__content {
868
- padding: 0;
869
- }
870
- }
871
- }
872
-
873
- .el-popover__text {
874
- display: -webkit-box;
875
- -webkit-line-clamp: 2;
876
- line-clamp: 2;
877
- -webkit-box-orient: vertical;
878
- overflow: hidden;
879
- text-overflow: ellipsis;
880
- word-break: break-all;
881
- font-weight: bold;
882
- }
883
-
884
- .btn__text {
885
- font-size: 12px;
886
- font-weight: normal;
887
- }
888
-
889
- .pagination-wrap {
890
- display: flex;
891
- justify-content: center;
892
- align-items: center;
893
- text-align: center;
894
- margin-top: 20px;
895
-
896
- &::v-deep {
897
- .el-pagination {
898
- width: 100%;
899
- }
900
-
901
- .el-pagination__jump {
902
- float: right;
903
- }
904
- }
905
- }
906
- </style>
907
-
908
- <style lang="scss">
909
- .infly-list {
910
- &__popover-text.el-popover__text {
911
- display: -webkit-box;
912
- -webkit-line-clamp: 2;
913
- line-clamp: 2;
914
- -webkit-box-orient: vertical;
915
- overflow: hidden;
916
- text-overflow: ellipsis;
917
- word-break: break-all;
918
- font-weight: normal;
919
- }
920
-
921
- &__button-text.btn__text {
922
- font-size: 12px;
923
- font-weight: normal;
924
- }
925
- }
926
- </style>
1
+ <template>
2
+ <!-- packages\infly-ui\src\Business\InflyList\ListPanel.vue 列表组件 -->
3
+ <div :class="['comp-InflyList']">
4
+ <el-tabs
5
+ v-model="activityTab"
6
+ :class="{
7
+ 'list__tabs--top': isTopList,
8
+ 'list__tabs--hide': !tabList.length || hideTab,
9
+ 'list__tabs--hide-header': tabList.length == 1 && !tabList[0].name,
10
+ 'list__tabs--inner': isInnerList
11
+ }"
12
+ lazy
13
+ v-bind="tabsProps"
14
+ @tab-click="handleClickTab"
15
+ >
16
+ <slot name="pretop"></slot>
17
+ <el-tab-pane v-for="item in visibleTabList" :key="item.name" v-bind="item">
18
+ <slot name="prepend"></slot>
19
+ <slot name="replace">
20
+ <InflyForm
21
+ :formData="formData"
22
+ :filterList="filterList"
23
+ :btnList="btnList"
24
+ :reqParams="reqParams"
25
+ v-bind="formProps"
26
+ @initData="handleFormInitData"
27
+ @reset-form="handleResetForm"
28
+ @secTabChange="handleFormSecTabChange"
29
+ >
30
+ <template #customRender="{ item }">
31
+ <slot name="customRender" :item="item"></slot>
32
+ </template>
33
+ </InflyForm>
34
+ <el-divider v-if="!hideDivider" />
35
+ <slot name="replaceTable">
36
+ <el-table
37
+ :class="['main-table', tableProps.tableClass]"
38
+ :data="tableDataList"
39
+ :tree-props="tableProps.treeProps || { children: 'lists', hasChildren: 'hasChildren' }"
40
+ :size="tableProps.size || 'mini'"
41
+ :indent="tableProps.indent || 0"
42
+ v-loading="showTableLoading"
43
+ v-bind="tableProps"
44
+ >
45
+ <template v-for="(defaultColumn, colIndex) in columnGroups.defaultColumns">
46
+ <el-table-column
47
+ v-if="defaultColumn.type !== 'expand'"
48
+ :key="`default_${colIndex}`"
49
+ v-bind="defaultColumn"
50
+ />
51
+ <el-table-column v-else :key="`default_expand_${colIndex}`" v-bind="defaultColumn">
52
+ <template slot-scope="scope">
53
+ <slot name="expand" :column="defaultColumn" :row="scope.row" :rowIndex="scope.$index"></slot>
54
+ </template>
55
+ </el-table-column>
56
+ </template>
57
+ <InflyListTableColumn
58
+ v-for="(column, columnIndex) in columnGroups.customColumns"
59
+ :key="getColumnKey(column, columnIndex)"
60
+ :column="column"
61
+ :list-vm="listContext"
62
+ />
63
+ </el-table>
64
+ <div class="pagination-wrap" v-if="formData.total > 0">
65
+ <el-pagination
66
+ class="standard-list__pagination"
67
+ layout="total, sizes, prev, pager, next, jumper"
68
+ :current-page.sync="formData.page"
69
+ :page-sizes="[10, 20, 50, 100]"
70
+ :page-size.sync="formData.pagesize"
71
+ :total="formData.total"
72
+ background
73
+ @size-change="handleSizeChange"
74
+ @current-change="handleCurrentChange"
75
+ >
76
+ </el-pagination>
77
+ <el-button
78
+ v-if="!hideJumpPageButton"
79
+ @click="handleCurrentChange(formData.page)"
80
+ type="primary"
81
+ style="margin-left: 10px"
82
+ size="mini"
83
+ >
84
+ 跳 转
85
+ </el-button>
86
+ </div>
87
+ </slot>
88
+ </slot>
89
+ </el-tab-pane>
90
+ </el-tabs>
91
+ </div>
92
+ </template>
93
+
94
+ <script>
95
+ import Uts from "../../utils/Uts.js";
96
+ import InflyForm from "../InflyForm/InflyForm.vue";
97
+
98
+ // 模块级常量,避免每次渲染返回新对象引用
99
+ const EMPTY_EVENTS = Object.freeze({});
100
+ const REQUEST_TIMEOUT = 60000;
101
+ const DEFAULT_COLUMN_TYPES = new Set(["selection", "index", "expand"]);
102
+ const TABLE_COLUMN_INTERNAL_KEYS = Object.freeze([
103
+ "children",
104
+ "columns",
105
+ "type",
106
+ "buttonList",
107
+ "className",
108
+ "isHide",
109
+ "isShow",
110
+ "click",
111
+ "options",
112
+ "optionKeyField",
113
+ "optionValueField",
114
+ "propValueField",
115
+ "mapField",
116
+ "render"
117
+ ]);
118
+ const CELL_CONFIG_EXCLUDED_KEYS = Object.freeze(["width", "fixed", "showOverflowTooltip", "children", "columns"]);
119
+ const BUTTON_INTERNAL_KEYS = Object.freeze(["name", "label", "className", "isShow", "isHide", "click", "btnEvent"]);
120
+ const IMAGE_PROP_KEYS = Object.freeze(["fit", "lazy", "scrollContainer", "zIndex"]);
121
+
122
+ // 组件类型映射,避免每次 getCompType 调用创建新对象
123
+ const COMP_TYPE_MAP = Object.freeze({
124
+ "el-tag": "el-tag",
125
+ "el-popover": "el-popover",
126
+ "el-button": "div",
127
+ custom: "div",
128
+ render: "div"
129
+ });
130
+
131
+ // 用 WeakMap 按 options 数组对象缓存 pluckMap 结果,options 引用不变时直接命中
132
+ const optionMapCache = new WeakMap();
133
+ function getOrBuildOptionMap(options, optionValueField, optionKeyField) {
134
+ if (!optionMapCache.has(options)) {
135
+ optionMapCache.set(options, Uts.pluckMap(options, optionValueField, optionKeyField));
136
+ }
137
+ return optionMapCache.get(options);
138
+ }
139
+
140
+ function getColumnChildren(column = {}) {
141
+ if (Array.isArray(column.children)) {
142
+ return column.children;
143
+ }
144
+ if (Array.isArray(column.columns)) {
145
+ return column.columns;
146
+ }
147
+ return [];
148
+ }
149
+
150
+ function getTableColumnProps(column = {}) {
151
+ const columnProps = { ...(column || {}) };
152
+ TABLE_COLUMN_INTERNAL_KEYS.forEach((key) => {
153
+ delete columnProps[key];
154
+ });
155
+
156
+ return {
157
+ align: "center",
158
+ ...columnProps
159
+ };
160
+ }
161
+
162
+ const InflyListTableColumn = {
163
+ name: "InflyListTableColumn",
164
+ props: {
165
+ column: { type: Object, required: true },
166
+ listVm: { type: Object, required: true }
167
+ },
168
+ methods: {
169
+ getCellConfig() {
170
+ const { label, prop, type, buttonList, className, click = () => {}, ...otherAttrs } = this.column || {};
171
+
172
+ CELL_CONFIG_EXCLUDED_KEYS.forEach((key) => {
173
+ delete otherAttrs[key];
174
+ });
175
+
176
+ return {
177
+ label,
178
+ prop,
179
+ type,
180
+ buttonList,
181
+ className,
182
+ click,
183
+ otherAttrs
184
+ };
185
+ },
186
+ renderCustomCell(createElement, { row, prop, label, click, data = {} }) {
187
+ const result = this.listVm.customRender(row, prop, { label });
188
+ const cellData = { ...data };
189
+
190
+ if (click) {
191
+ cellData.on = {
192
+ ...(cellData.on || {}),
193
+ click: () => click(row, prop)
194
+ };
195
+ }
196
+
197
+ if (typeof result === "string") {
198
+ cellData.domProps = { innerHTML: result };
199
+ return createElement("div", cellData);
200
+ }
201
+
202
+ if (click || Object.keys(cellData).length) {
203
+ return createElement("div", cellData, [result || createElement("span")]);
204
+ }
205
+
206
+ return result || createElement("span");
207
+ },
208
+ renderLeafCell(createElement, row) {
209
+ const { label, prop, type, buttonList, className, click, otherAttrs } = this.getCellConfig();
210
+ const cellAttrs = { type, ...otherAttrs };
211
+
212
+ if (!this.listVm.shouldShowByConfig(this.column, row)) {
213
+ return createElement("span");
214
+ }
215
+
216
+ if (this.listVm.hasColumnSlot(prop)) {
217
+ return this.listVm.$scopedSlots[prop]({ row, prop });
218
+ }
219
+
220
+ if (type === "slot") {
221
+ return createElement("span", [this.listVm.getValue(row, prop, cellAttrs)]);
222
+ }
223
+
224
+ const componentType = this.listVm.getCompType(row, { type, prop }, otherAttrs);
225
+ const children = [];
226
+
227
+ if (type === "el-tag") {
228
+ children.push(this.listVm.getValue(row, prop, cellAttrs));
229
+ } else if (type === "el-popover") {
230
+ children.push(
231
+ this.renderCustomCell(createElement, { row, prop, label }),
232
+ this.renderCustomCell(createElement, {
233
+ row,
234
+ prop,
235
+ label,
236
+ data: {
237
+ slot: "reference",
238
+ class: ["infly-list__popover-text", "el-popover__text", className]
239
+ }
240
+ })
241
+ );
242
+ } else if (type === "custom" || type === "render") {
243
+ children.push(this.renderCustomCell(createElement, { row, prop, label, click }));
244
+ } else if (type === "el-button" || Uts.notEmptyArray(buttonList)) {
245
+ children.push(
246
+ ...this.listVm
247
+ .normalizeButtonList(buttonList)
248
+ .map((btnItem, btnIndex) => {
249
+ if (!this.listVm.shouldShowByConfig(btnItem, row)) {
250
+ return null;
251
+ }
252
+ return createElement(
253
+ "el-button",
254
+ {
255
+ key: this.listVm.getButtonKey(btnItem, btnIndex),
256
+ props: this.listVm.getButtonProps(btnItem),
257
+ on: { click: () => this.listVm.handleColumnButtonClick(btnItem, row) }
258
+ },
259
+ [
260
+ createElement(
261
+ "span",
262
+ { class: ["infly-list__button-text", "btn__text", this.listVm.getButtonClassName(btnItem, row)] },
263
+ [this.listVm.getButtonText(btnItem, row)]
264
+ )
265
+ ]
266
+ );
267
+ })
268
+ .filter(Boolean)
269
+ );
270
+ } else if (type === "el-image") {
271
+ children.push(this.renderImageCell(createElement, row, prop, cellAttrs, otherAttrs));
272
+ } else if (row.level !== 0) {
273
+ children.push(
274
+ createElement("div", {
275
+ domProps: { innerHTML: this.listVm.getValue(row, prop, cellAttrs) }
276
+ })
277
+ );
278
+ }
279
+
280
+ return createElement(
281
+ componentType,
282
+ {
283
+ props: this.listVm.getCompProps(row, { type, prop, ...otherAttrs }),
284
+ on: this.listVm.getCompEvents(row)
285
+ },
286
+ children
287
+ );
288
+ },
289
+ renderImageCell(createElement, row, prop, cellAttrs = {}, otherAttrs = {}) {
290
+ const { style, class: className, ...restAttrs } = otherAttrs;
291
+ const imageProps = {
292
+ src: this.listVm.getValue(row, prop, cellAttrs),
293
+ previewSrcList: this.listVm.getImagePreviewList(row, prop, cellAttrs)
294
+ };
295
+ const imageAttrs = {};
296
+
297
+ Object.keys(restAttrs).forEach((key) => {
298
+ if (IMAGE_PROP_KEYS.includes(key)) {
299
+ imageProps[key] = restAttrs[key];
300
+ } else {
301
+ imageAttrs[key] = restAttrs[key];
302
+ }
303
+ });
304
+
305
+ return createElement("el-image", {
306
+ props: imageProps,
307
+ attrs: imageAttrs,
308
+ class: className,
309
+ style
310
+ });
311
+ }
312
+ },
313
+ render(createElement) {
314
+ const columnChildren = getColumnChildren(this.column).filter((column) =>
315
+ this.listVm.shouldShowByConfig(column, column)
316
+ );
317
+ const columnData = { props: getTableColumnProps(this.column) };
318
+
319
+ if (columnChildren.length) {
320
+ return createElement(
321
+ "el-table-column",
322
+ columnData,
323
+ columnChildren.map((column, columnIndex) =>
324
+ createElement(InflyListTableColumn, {
325
+ key: this.listVm.getColumnKey(column, columnIndex),
326
+ props: {
327
+ column,
328
+ listVm: this.listVm
329
+ }
330
+ })
331
+ )
332
+ );
333
+ }
334
+
335
+ return createElement("el-table-column", {
336
+ ...columnData,
337
+ scopedSlots: {
338
+ default: ({ row }) => this.renderLeafCell(createElement, row)
339
+ }
340
+ });
341
+ }
342
+ };
343
+
344
+ export default {
345
+ name: "InflyList",
346
+ inheritAttrs: false,
347
+ components: {
348
+ InflyListTableColumn,
349
+ InflyForm
350
+ },
351
+ props: {
352
+ // 数据 / 配置
353
+ formData: { type: Object, required: true, default: () => ({}) },
354
+ defaultTabName: { type: String, default: "" },
355
+ hideTab: { type: Boolean, default: false },
356
+ tabList: { type: Array, default: () => [{}] },
357
+ filterList: { type: Array, default: () => [] },
358
+ columns: { type: Array, required: true, default: () => [] },
359
+ btnList: { type: Array, default: () => [] },
360
+ outSideReqParams: { type: Object, default: () => ({}) },
361
+
362
+ // 请求配置及数据请求/返回处理
363
+ reqUrl: { type: String, default: "" },
364
+ reqMethod: { type: String, default: "get" },
365
+ defaultInit: { type: Boolean, default: true },
366
+ dealParams: { type: Function, default: null },
367
+ dealRes: { type: Function, default: null },
368
+ initEventName: { type: String, default: "initData" },
369
+
370
+ hideDivider: { type: Boolean, default: false },
371
+ isInnerList: { type: Boolean, default: false }, // 是否为内嵌列表
372
+ isTopList: { type: Boolean, default: true }, // 是否为页面顶部列表,影响样式
373
+ hideEmptyTag: { type: Boolean, default: false }, // 是否隐藏 el-tag 组件的空值标签
374
+ hideJumpPageButton: { type: Boolean, default: false },
375
+
376
+ // 自定义渲染函数
377
+ customRender: {
378
+ type: Function,
379
+ default: (row, prop) => {
380
+ return Uts.getNestedValue(row, prop);
381
+ }
382
+ },
383
+
384
+ // UI 配置
385
+ tableProps: { type: Object, default: () => ({}) },
386
+ formProps: { type: Object, default: () => ({ "label-width": "80px" }) },
387
+ emptyText: { type: String, default: "" },
388
+ tabsProps: { type: Object, default: () => ({ type: "border-card" }) }
389
+ },
390
+
391
+ data() {
392
+ const [firstTab] = this.tabList || [];
393
+ const { name: firstTabName } = firstTab || {};
394
+ return {
395
+ dataList: [],
396
+ showTableLoading: false,
397
+ activityTab: this.defaultTabName || firstTabName,
398
+ reqParams: {},
399
+ activitySecTab: "",
400
+ latestRequestId: 0
401
+ };
402
+ },
403
+ created() {
404
+ if (this.defaultInit) {
405
+ this.initData();
406
+ }
407
+ },
408
+ computed: {
409
+ tableDataList() {
410
+ const { dataList } = this.tableProps || {};
411
+ if (dataList !== undefined && dataList !== null) {
412
+ return dataList;
413
+ }
414
+ return this.dataList;
415
+ },
416
+ listContext() {
417
+ return this;
418
+ },
419
+ /**
420
+ * 将列过滤结果缓存为计算属性,避免模板中多次调用 filerColumns() 重复计算。
421
+ * 只有 columns 数组引用变化时才重新计算。
422
+ */
423
+ columnGroups() {
424
+ const defaultColumns = [];
425
+ const customColumns = [];
426
+
427
+ (this.columns || []).forEach((column) => {
428
+ const { type } = column || {};
429
+ if (!this.shouldShowByConfig(column)) {
430
+ return;
431
+ }
432
+ if (DEFAULT_COLUMN_TYPES.has(type)) {
433
+ defaultColumns.push(column);
434
+ } else {
435
+ customColumns.push(column);
436
+ }
437
+ });
438
+
439
+ return { defaultColumns, customColumns, columns: this.columns };
440
+ },
441
+ /**
442
+ * 根据 isShow / isHide 过滤后的可见 tab 列表
443
+ * 优先判断 isShow,其次判断 isHide,未设置则默认显示
444
+ */
445
+ visibleTabList() {
446
+ return (this.tabList || []).filter((item) => this.shouldShowByConfig(item));
447
+ }
448
+ },
449
+ methods: {
450
+ /**
451
+ * 通用显示判断
452
+ * @param {Boolean|Function} condition - 显示/隐藏条件
453
+ * @param {Object} row - 数据行
454
+ * @param {Boolean} isShowCondition - true 表示 isShow,false 表示 isHide
455
+ * @returns {Boolean}
456
+ */
457
+ shouldShow(condition, row = {}, isShowCondition = false) {
458
+ if (condition === undefined) {
459
+ return true;
460
+ }
461
+
462
+ const result = Uts.isFunction(condition) ? condition(row) : condition;
463
+ return isShowCondition ? result : !result;
464
+ },
465
+
466
+ /**
467
+ * 根据配置对象的 isShow / isHide 判断是否显示
468
+ * isShow 优先级高于 isHide,两者均未设置则默认显示
469
+ * @param {Object} config - 配置对象 { isShow, isHide }
470
+ * @param {Object} row - 数据行
471
+ * @returns {Boolean}
472
+ */
473
+ shouldShowByConfig(config = {}, row = {}) {
474
+ const { isShow, isHide } = config;
475
+
476
+ if (isShow !== undefined) {
477
+ return this.shouldShow(isShow, row, true);
478
+ }
479
+ if (isHide !== undefined) {
480
+ return this.shouldShow(isHide, row, false);
481
+ }
482
+ return true;
483
+ },
484
+
485
+ initData(options = {}) {
486
+ const { page, pagesize, resetPage } = this.normalizeInitOptions(options);
487
+ const nextPage = page || (resetPage ? 1 : this.formData.page || 1);
488
+ const nextPageSize = pagesize || this.formData.pagesize || 10;
489
+
490
+ this.setFormField("page", nextPage);
491
+ this.setFormField("pagesize", nextPageSize);
492
+ this.getList(nextPage, nextPageSize);
493
+ this.$emit(this.initEventName);
494
+ },
495
+ handleFormInitData() {
496
+ this.initData({ resetPage: true });
497
+ },
498
+ normalizeInitOptions(options = {}) {
499
+ const optionKeys = ["page", "pagesize", "resetPage"];
500
+ if (!options || typeof options !== "object") {
501
+ return {};
502
+ }
503
+ return optionKeys.some((key) => Object.prototype.hasOwnProperty.call(options, key)) ? options : {};
504
+ },
505
+ setFormField(key, value) {
506
+ if (!this.formData || !key) {
507
+ return;
508
+ }
509
+ this.$set(this.formData, key, value);
510
+ },
511
+ replaceFormData(nextData = {}) {
512
+ if (!this.formData) {
513
+ return;
514
+ }
515
+
516
+ Object.keys(this.formData).forEach((key) => {
517
+ if (!Object.prototype.hasOwnProperty.call(nextData, key)) {
518
+ this.$delete(this.formData, key);
519
+ }
520
+ });
521
+
522
+ Object.keys(nextData).forEach((key) => {
523
+ this.$set(this.formData, key, nextData[key]);
524
+ });
525
+ },
526
+ /**
527
+ * 获取组件类型
528
+ * @param {Object} row - 表格行数据
529
+ * @param {Object} column - 表格列配置
530
+ * @param {Object} otherAttrs - 额外参数
531
+ */
532
+ getCompType(row, column = {}, otherAttrs = {}) {
533
+ const { type, prop } = column;
534
+
535
+ // level 为 0 或未传 type 时,统一返回 div
536
+ if ((row || {}).level === 0 || !type) {
537
+ return "div";
538
+ }
539
+
540
+ // el-tag 类型且开启隐藏空值时,检查是否为空
541
+ if (type === "el-tag" && this.hideEmptyTag && !this.getValue(row, prop, otherAttrs)) {
542
+ return "div";
543
+ }
544
+
545
+ return COMP_TYPE_MAP[type] || "div";
546
+ },
547
+ /**
548
+ * 获取组件属性配置
549
+ * @param {Object} row - 表格行数据
550
+ * @param {Object} column - 表格列配置
551
+ */
552
+ getCompProps(row = {}, column = {}) {
553
+ const {
554
+ type,
555
+ options = [],
556
+ prop = "",
557
+ propValueField = prop.replace("_str", ""),
558
+ mapField = "value"
559
+ } = column || {};
560
+ const [option] = Uts.filterObjByCondition(options, { [mapField]: Uts.getNestedValue(row, propValueField) }) || [];
561
+ const { tagType = "" } = option || {};
562
+
563
+ switch (type) {
564
+ case "el-tag":
565
+ return {
566
+ type: tagType
567
+ };
568
+ case "el-popover":
569
+ return {
570
+ placement: "top",
571
+ width: 200,
572
+ trigger: "hover"
573
+ };
574
+ default:
575
+ return {};
576
+ }
577
+ },
578
+ /**
579
+ * 处理默认显示值
580
+ * @param {Object} row - 行数据
581
+ * @param {String} prop - 属性名
582
+ * @param {Object} otherAttrs - 额外参数
583
+ * @returns {String} - 显示值
584
+ */
585
+ getValue(row = {}, prop, otherAttrs = {}) {
586
+ const { type, options = [], optionKeyField = "name", optionValueField = "value", render } = otherAttrs;
587
+ const displayValue = Uts.getNestedValue(row, prop);
588
+
589
+ // 优先使用 render 函数
590
+ if (Uts.isFunction(render)) {
591
+ return render(row, prop);
592
+ }
593
+
594
+ // 其次使用 options 映射(WeakMap 缓存,同一 options 引用只构建一次)
595
+ if (Uts.notEmptyArray(options) && type === "el-tag" && Uts.isNumber(Number(displayValue))) {
596
+ const optionMap = getOrBuildOptionMap(options, optionValueField, optionKeyField);
597
+ if (Uts.notEmptyObject(optionMap)) {
598
+ return optionMap[displayValue] || this.emptyText;
599
+ }
600
+ }
601
+
602
+ if (Uts.isNumber(displayValue)) {
603
+ return displayValue;
604
+ }
605
+
606
+ // 最后返回原值或空文本
607
+ return displayValue || this.emptyText;
608
+ },
609
+ /**
610
+ * 组件事件(当前无需动态事件,返回模块级常量避免每次渲染产生新对象引用)
611
+ */
612
+ getCompEvents(row) {
613
+ return EMPTY_EVENTS;
614
+ },
615
+ getColumnKey(column = {}, columnIndex) {
616
+ const { prop, type, label } = column || {};
617
+ return `${prop || type || label || "column"}_${columnIndex}`;
618
+ },
619
+ hasColumnSlot(prop) {
620
+ return Boolean(prop && this.$scopedSlots[prop]);
621
+ },
622
+ normalizeButtonList(buttonList) {
623
+ return Uts.notEmptyArray(buttonList) ? buttonList : [];
624
+ },
625
+ getButtonKey(btnItem = {}, btnIndex) {
626
+ return `btn_${btnIndex}_${btnItem.name || btnItem.label || btnIndex}`;
627
+ },
628
+ getButtonText(btnItem = {}, row = {}) {
629
+ const { name, label = "" } = btnItem;
630
+ if (Uts.isFunction(name)) {
631
+ return name(row);
632
+ }
633
+ if (name === undefined || name === null || name === "") {
634
+ return label;
635
+ }
636
+ return name;
637
+ },
638
+ getButtonClassName(btnItem = {}, row = {}) {
639
+ const { className } = btnItem;
640
+ return Uts.isFunction(className) ? className(row) : className;
641
+ },
642
+ getButtonProps(btnItem = {}) {
643
+ const buttonProps = { ...(btnItem || {}) };
644
+ BUTTON_INTERNAL_KEYS.forEach((key) => {
645
+ delete buttonProps[key];
646
+ });
647
+ return buttonProps;
648
+ },
649
+ handleColumnButtonClick(btnItem = {}, row = {}) {
650
+ if (Uts.isFunction(btnItem.click)) {
651
+ btnItem.click(row);
652
+ }
653
+ },
654
+ getImagePreviewList(row = {}, prop, otherAttrs = {}) {
655
+ const value = this.getValue(row, prop, otherAttrs);
656
+ return value ? [value] : [];
657
+ },
658
+ getRequestUrl() {
659
+ let tempReqUrl = this.reqUrl;
660
+
661
+ if (!tempReqUrl && Uts.notEmptyArray(this.tabList)) {
662
+ const currentTabConfig = this.tabList.find((item) => item && item.name === this.activityTab) || {};
663
+ tempReqUrl = currentTabConfig.reqUrl || "";
664
+ }
665
+
666
+ return tempReqUrl;
667
+ },
668
+ getRequestMethod() {
669
+ return (this.reqMethod || "get").toLowerCase();
670
+ },
671
+ buildRequestParams(page, pagesize, otherParams = {}) {
672
+ const { total, ...params } = this.formData || {};
673
+ let reqParams = {
674
+ ...params,
675
+ page,
676
+ pagesize,
677
+ ...otherParams,
678
+ ...this.outSideReqParams
679
+ };
680
+
681
+ if (Uts.isFunction(this.dealParams)) {
682
+ const nextReqParams = this.dealParams(reqParams);
683
+ if (nextReqParams && typeof nextReqParams === "object") {
684
+ reqParams = nextReqParams;
685
+ }
686
+ }
687
+
688
+ return Uts.filterCommaFields(reqParams);
689
+ },
690
+ buildAxiosParams(reqParams = {}) {
691
+ if (this.getRequestMethod() !== "get") {
692
+ return reqParams;
693
+ }
694
+
695
+ const params = { ...reqParams };
696
+ Object.keys(params).forEach((key) => {
697
+ const value = params[key];
698
+ if (Uts.isArray(value)) {
699
+ params[key] = value.join(",");
700
+ }
701
+ });
702
+
703
+ return { params };
704
+ },
705
+ isLatestRequest(requestId) {
706
+ return requestId === this.latestRequestId;
707
+ },
708
+ applyListResponse(res = {}, page, pagesize) {
709
+ const { total, counts = total || 0, page: resPage, pagesize: resPageSize, data, lists = data } = res || {};
710
+
711
+ this.setFormField("total", counts);
712
+ this.setFormField("page", resPage || page);
713
+ this.setFormField("pagesize", resPageSize || pagesize);
714
+ this.dataList = lists || [];
715
+ },
716
+ getList(page = this.formData.page || 1, pagesize = this.formData.pagesize || 10, otherParams = {}, config = {}) {
717
+ const { onlyReturnData } = config || {};
718
+ const tempReqUrl = this.getRequestUrl();
719
+
720
+ if (!tempReqUrl) {
721
+ // console.warn("InflyList 组件缺少 reqUrl 属性");
722
+ return Promise.resolve();
723
+ }
724
+
725
+ const reqParams = this.buildRequestParams(page, pagesize, otherParams);
726
+ const axiosParams = this.buildAxiosParams(reqParams);
727
+ const reqMethod = this.getRequestMethod();
728
+ const requestFn = this.$axios && this.$axios[reqMethod];
729
+
730
+ this.reqParams = axiosParams;
731
+
732
+ if (!Uts.isFunction(requestFn)) {
733
+ const err = new Error(`InflyList 不支持的请求方法:${reqMethod}`);
734
+ console.error("InflyList getList error:", err);
735
+ this.$emit("request-error", err);
736
+ return Promise.resolve();
737
+ }
738
+
739
+ const requestId = this.latestRequestId + 1;
740
+ this.latestRequestId = requestId;
741
+ this.showTableLoading = true;
742
+
743
+ const loadingTimer = setTimeout(() => {
744
+ if (this.isLatestRequest(requestId)) {
745
+ this.showTableLoading = false;
746
+ this.$emit("request-timeout", { reqUrl: tempReqUrl, reqMethod, reqParams: axiosParams });
747
+ }
748
+ }, REQUEST_TIMEOUT);
749
+
750
+ return requestFn
751
+ .call(this.$axios, tempReqUrl, axiosParams)
752
+ .then((res) => {
753
+ clearTimeout(loadingTimer);
754
+
755
+ if (!this.isLatestRequest(requestId)) {
756
+ return onlyReturnData ? res : undefined;
757
+ }
758
+
759
+ this.showTableLoading = false;
760
+
761
+ let finalRes = res;
762
+ if (Uts.isFunction(this.dealRes)) {
763
+ const nextRes = this.dealRes(res);
764
+ if (nextRes && typeof nextRes === "object") {
765
+ finalRes = nextRes;
766
+ }
767
+ }
768
+
769
+ if (onlyReturnData) {
770
+ return finalRes;
771
+ }
772
+
773
+ this.applyListResponse(finalRes, page, pagesize);
774
+ return finalRes;
775
+ })
776
+ .catch((err) => {
777
+ clearTimeout(loadingTimer);
778
+ if (this.isLatestRequest(requestId)) {
779
+ this.showTableLoading = false;
780
+ this.$emit("request-error", err);
781
+ console.error("InflyList getList error:", err);
782
+ }
783
+ return undefined;
784
+ });
785
+ },
786
+ /**
787
+ * 处理标签点击事件
788
+ * @param {Object} tab - 切换的标签对象(Element UI TabPane 实例)
789
+ * @param {Event} event - 事件对象
790
+ * @description 切换活动标签时,更新查询条件并重新加载数据
791
+ */
792
+ handleClickTab(tab, event) {
793
+ const { name: tabName } = tab;
794
+ this.activityTab = tabName;
795
+ this.setFormField("page", 1);
796
+
797
+ // 查找原始 tabList 配置,保留自定义属性
798
+ const originalTabConfig = this.tabList.find((item) => item.name === tabName) || {};
799
+
800
+ const emitParams = {
801
+ ...originalTabConfig,
802
+ tabName,
803
+ name: tabName,
804
+ activityTab: this.activityTab
805
+ };
806
+
807
+ // 推荐使用 tab-change(kebab-case),tabChange 保留向后兼容
808
+ this.$emit("tab-change", emitParams);
809
+ this.$emit("tabChange", emitParams);
810
+ this.$emit(this.initEventName, emitParams);
811
+ },
812
+ handleFormSecTabChange(emitParams = {}) {
813
+ const { activitySecTab, name } = emitParams;
814
+ const nextActivitySecTab = activitySecTab || name || "";
815
+ const nextEmitParams = {
816
+ ...emitParams,
817
+ activitySecTab: nextActivitySecTab,
818
+ name: name || nextActivitySecTab
819
+ };
820
+
821
+ this.activitySecTab = nextActivitySecTab;
822
+ this.setFormField("page", 1);
823
+ this.$emit("secTabChange", nextEmitParams);
824
+ this.$emit("sec-tab-change", nextEmitParams);
825
+ },
826
+ handleCurrentChange(page) {
827
+ this.initData({ page: page || 1 });
828
+ },
829
+ /**
830
+ * 处理表单重置事件
831
+ */
832
+ handleResetForm(resetData) {
833
+ const { pagesize } = this.formData || {};
834
+ const nextFormData = {
835
+ ...(resetData || {}),
836
+ page: (resetData && resetData.page) || 1,
837
+ pagesize: (resetData && resetData.pagesize) || pagesize || 10
838
+ };
839
+
840
+ this.replaceFormData(nextFormData);
841
+ // 重置后重新加载数据
842
+ this.initData({ page: nextFormData.page, pagesize: nextFormData.pagesize });
843
+ },
844
+ handleSizeChange(pagesize) {
845
+ this.initData({ page: 1, pagesize });
846
+ }
847
+ }
848
+ };
849
+ </script>
850
+
851
+ <style lang="scss" scoped>
852
+ // 简化:合并重复的 tabs header 隐藏样式
853
+ .list__tabs--hide,
854
+ .list__tabs--hide-header {
855
+ &::v-deep > .el-tabs__header {
856
+ display: none;
857
+ }
858
+ }
859
+
860
+ // 只有 hide 样式需要的额外样式
861
+ .list__tabs--hide,
862
+ .list__tabs--inner {
863
+ &::v-deep {
864
+ box-shadow: none;
865
+ border: none;
866
+
867
+ .el-tabs__content {
868
+ padding: 0;
869
+ }
870
+ }
871
+ }
872
+
873
+ .el-popover__text {
874
+ display: -webkit-box;
875
+ -webkit-line-clamp: 2;
876
+ line-clamp: 2;
877
+ -webkit-box-orient: vertical;
878
+ overflow: hidden;
879
+ text-overflow: ellipsis;
880
+ word-break: break-all;
881
+ font-weight: bold;
882
+ }
883
+
884
+ .btn__text {
885
+ font-size: 12px;
886
+ font-weight: normal;
887
+ }
888
+
889
+ .pagination-wrap {
890
+ display: flex;
891
+ justify-content: center;
892
+ align-items: center;
893
+ text-align: center;
894
+ margin-top: 20px;
895
+
896
+ &::v-deep {
897
+ .el-pagination {
898
+ width: 100%;
899
+ }
900
+
901
+ .el-pagination__jump {
902
+ float: right;
903
+ }
904
+ }
905
+ }
906
+ </style>
907
+
908
+ <style lang="scss">
909
+ .infly-list {
910
+ &__popover-text.el-popover__text {
911
+ display: -webkit-box;
912
+ -webkit-line-clamp: 2;
913
+ line-clamp: 2;
914
+ -webkit-box-orient: vertical;
915
+ overflow: hidden;
916
+ text-overflow: ellipsis;
917
+ word-break: break-all;
918
+ font-weight: normal;
919
+ }
920
+
921
+ &__button-text.btn__text {
922
+ font-size: 12px;
923
+ font-weight: normal;
924
+ }
925
+ }
926
+ </style>