ol-base-components 2.8.7 → 2.8.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol-base-components",
3
- "version": "2.8.7",
3
+ "version": "2.8.9",
4
4
  "private": false,
5
5
  "main": "src/package/index.js",
6
6
  "bin": {
@@ -48,7 +48,7 @@
48
48
  "name": "vue-page-generator",
49
49
  "displayName": "Vue 页面生成器",
50
50
  "description": "配合ol-base-components组件使用, 无需联调的CRUD页面",
51
- "version": "0.0.4",
51
+ "version": "0.0.4",
52
52
  "engines": {
53
53
  "vscode": "^1.60.0"
54
54
  },
@@ -168,7 +168,7 @@
168
168
  <template v-for="(item, index) in this.tableData.columns">
169
169
  <TableColumn
170
170
  :column="item"
171
- :key="`${item.prop || item.label}-${item.show}-${key}`"
171
+ :key="`${item.prop || item.label}-${item.show}-${index}`"
172
172
  :id="`${item.prop}-${item.show}-${index}`"
173
173
  >
174
174
  <template v-for="(slotFn, name) in $scopedSlots" v-slot:[name]="slotProps">
@@ -245,639 +245,656 @@
245
245
  </div>
246
246
  </template>
247
247
  <script>
248
- import { getData } from "../../index.js";
249
- import nodata from "./nodata.jpg";
250
- import printTemplate from "./printTable.vue";
251
- import TableColumn from "./TableColumn.vue";
252
- export default {
253
- name: "table",
254
- components: {
255
- printTemplate,
256
- TableColumn,
257
- // 函数式组件注册
258
- renderDom: {
259
- functional: true,
260
- props: {
261
- render: Function,
262
- },
263
- render(createElement, renDom) {
264
- return <div>{renDom.props.render()}</div>;
265
- },
248
+ import { getData } from "../../index.js";
249
+ import nodata from "./nodata.jpg";
250
+ import printTemplate from "./printTable.vue";
251
+ import TableColumn from "./TableColumn.vue";
252
+ export default {
253
+ name: "table",
254
+ components: {
255
+ printTemplate,
256
+ TableColumn,
257
+ // 函数式组件注册
258
+ renderDom: {
259
+ functional: true,
260
+ props: {
261
+ render: Function,
266
262
  },
267
- // myTableColumn: {
268
- // functional: true,
269
- // props: {
270
- // column: { type: Object, required: true }
271
- // },
272
- // render(h, ctx) {
273
- // const col = ctx.props.column;
274
-
275
- // // 多级表头处理
276
- // if (col.children && col.children.length) {
277
- // return h(
278
- // 'el-table-column',
279
- // {
280
- // props: {
281
- // label: col.label,
282
- // align: 'center',
283
- // ...col.attrs,
284
- // }
285
- // },
286
- // col.children.map((child, idx) =>
287
- // h(ctx.parent.$options.components.myTableColumn, {
288
- // props: { column: child },
289
- // key: idx
290
- // })
291
- // )
292
- // );
293
- // }
294
-
295
- // // 单列表头处理
296
- // return h(
297
- // 'el-table-column',
298
- // {
299
- // props: {
300
- // label: col.label,
301
- // prop: col.prop,
302
- // minWidth: col.minWidth || '150px',
303
- // showOverflowTooltip: col.overHidden || true,
304
- // type: col.type || 'normal',
305
- // align: 'center',
306
- // width: col.width,
307
- // fixed: col.fixed || false,
308
- // sortable: col.sortable || false,
309
- // ...col.attrs
310
- // }
311
- // },
312
- // [
313
- // // 表头插槽 - 添加 el-tooltip
314
- // h('template', { slot: 'header' }, [
315
- // h('el-tooltip', {
316
- // props: {
317
- // content: `${col.label} ${col.prop}`,
318
- // placement: 'top'
319
- // }
320
- // }, [
321
- // h('span', col.label)
322
- // ])
323
- // ]),
324
- // // 内容插槽 - 支持自定义渲染
325
- // col.render ? h('template', { slot: 'default' }, {
326
- // render: (scope) => h(ctx.parent.$options.components.renderDom, {
327
- // props: { render: () => col.render(scope.row) }
328
- // })
329
- // }) : null,
330
- // // 插槽渲染
331
- // col.renderSlot ? h('template', { slot: 'default' }, {
332
- // render: (scope) => ctx.parent.$scopedSlots[col.prop] ?
333
- // ctx.parent.$scopedSlots[col.prop](scope) : null
334
- // }) : null
335
- // ].filter(Boolean)
336
- // );
337
- // }
338
- // }
339
- },
340
- model: {
341
- prop: "multipleSelection",
342
- event: "SelectionChange",
343
- },
344
- props: {
345
- url: {
346
- type: String,
347
- default: "",
348
- }, // 接口地址
349
- printListObj: {
350
- type: Object,
351
- default: () => {
352
- return {
353
- title: "",
354
- tableHeader: "",
355
- tableData: "",
356
- };
357
- },
358
- }, // 打印参数
359
- btnlist: Array,
360
- outTable: {
361
- type: Object,
362
- default: () => {
363
- return {
364
- tableProp: {},
365
- };
366
- },
263
+ render(createElement, renDom) {
264
+ return <div>{renDom.props.render()}</div>;
367
265
  },
368
- // exportBut: {
369
- // type: Array,
370
- // default: [],
371
- // },
372
- // 表格传的形式
373
- tableData: {
374
- type: Object,
375
- default: () => {
376
- return {
377
- loading: false,
378
- options: {
379
- selection: null, // 多选框
380
- index: null, // 序号
381
- headTool: true, // 开启头部工具栏
382
- refreshBtn: true, // 开启表格头部刷新按钮
383
- downloadBtn: true, // 开启表格头部下载按钮
384
- }, // 序号和复选框
385
- rows: [], // 表数据
386
- columns: [], // 表头
387
- operates: [], // 表格里面的操作按钮
388
- // tableHeightDiff: 300,
389
- operatesAttrs: {},
390
- };
391
- },
392
- },
393
- tableDataShow: {
394
- type: Boolean,
395
- default: true,
266
+ },
267
+ // myTableColumn: {
268
+ // functional: true,
269
+ // props: {
270
+ // column: { type: Object, required: true }
271
+ // },
272
+ // render(h, ctx) {
273
+ // const col = ctx.props.column;
274
+
275
+ // // 多级表头处理
276
+ // if (col.children && col.children.length) {
277
+ // return h(
278
+ // 'el-table-column',
279
+ // {
280
+ // props: {
281
+ // label: col.label,
282
+ // align: 'center',
283
+ // ...col.attrs,
284
+ // }
285
+ // },
286
+ // col.children.map((child, idx) =>
287
+ // h(ctx.parent.$options.components.myTableColumn, {
288
+ // props: { column: child },
289
+ // key: idx
290
+ // })
291
+ // )
292
+ // );
293
+ // }
294
+
295
+ // // 单列表头处理
296
+ // return h(
297
+ // 'el-table-column',
298
+ // {
299
+ // props: {
300
+ // label: col.label,
301
+ // prop: col.prop,
302
+ // minWidth: col.minWidth || '150px',
303
+ // showOverflowTooltip: col.overHidden || true,
304
+ // type: col.type || 'normal',
305
+ // align: 'center',
306
+ // width: col.width,
307
+ // fixed: col.fixed || false,
308
+ // sortable: col.sortable || false,
309
+ // ...col.attrs
310
+ // }
311
+ // },
312
+ // [
313
+ // // 表头插槽 - 添加 el-tooltip
314
+ // h('template', { slot: 'header' }, [
315
+ // h('el-tooltip', {
316
+ // props: {
317
+ // content: `${col.label} ${col.prop}`,
318
+ // placement: 'top'
319
+ // }
320
+ // }, [
321
+ // h('span', col.label)
322
+ // ])
323
+ // ]),
324
+ // // 内容插槽 - 支持自定义渲染
325
+ // col.render ? h('template', { slot: 'default' }, {
326
+ // render: (scope) => h(ctx.parent.$options.components.renderDom, {
327
+ // props: { render: () => col.render(scope.row) }
328
+ // })
329
+ // }) : null,
330
+ // // 插槽渲染
331
+ // col.renderSlot ? h('template', { slot: 'default' }, {
332
+ // render: (scope) => ctx.parent.$scopedSlots[col.prop] ?
333
+ // ctx.parent.$scopedSlots[col.prop](scope) : null
334
+ // }) : null
335
+ // ].filter(Boolean)
336
+ // );
337
+ // }
338
+ // }
339
+ },
340
+ model: {
341
+ prop: "multipleSelection",
342
+ event: "SelectionChange",
343
+ },
344
+ props: {
345
+ url: {
346
+ type: String,
347
+ default: "",
348
+ }, // 接口地址
349
+ printListObj: {
350
+ type: Object,
351
+ default: () => {
352
+ return {
353
+ title: "",
354
+ tableHeader: "",
355
+ tableData: "",
356
+ };
396
357
  },
397
- pageSizes: {
398
- type: Array,
399
- default: () => {
400
- return [20, 30, 40, 60, 100, 200];
401
- },
358
+ }, // 打印参数
359
+ btnlist: Array,
360
+ outTable: {
361
+ type: Object,
362
+ default: () => {
363
+ return {
364
+ tableProp: {},
365
+ };
402
366
  },
403
- paginations: {
404
- // 显示复选框,
405
- type: Object,
406
- default: () => {
407
- return {
408
- page: 1, // 当前位于那页面
409
- total: 0, // 总数
410
- limit: 30, // 一页显示多少条
411
- pagetionShow: true,
412
- };
413
- },
367
+ },
368
+ // exportBut: {
369
+ // type: Array,
370
+ // default: [],
371
+ // },
372
+ // 表格传的形式
373
+ tableData: {
374
+ type: Object,
375
+ default: () => {
376
+ return {
377
+ loading: false,
378
+ options: {
379
+ selection: null, // 多选框
380
+ index: null, // 序号
381
+ headTool: true, // 开启头部工具栏
382
+ refreshBtn: true, // 开启表格头部刷新按钮
383
+ downloadBtn: true, // 开启表格头部下载按钮
384
+ }, // 序号和复选框
385
+ rows: [], // 表数据
386
+ columns: [], // 表头
387
+ operates: [], // 表格里面的操作按钮
388
+ // tableHeightDiff: 300,
389
+ operatesAttrs: {},
390
+ };
414
391
  },
415
- emptyImg: {
416
- // 显示复选框,
417
- type: Boolean,
418
- default: false,
392
+ },
393
+ tableDataShow: {
394
+ type: Boolean,
395
+ default: true,
396
+ },
397
+ pageSizes: {
398
+ type: Array,
399
+ default: () => {
400
+ return [20, 30, 40, 60, 100, 200];
419
401
  },
420
- tableEvents: Object,
421
- showBtnBox: {
422
- type: Boolean,
423
- default: true,
402
+ },
403
+ paginations: {
404
+ // 显示复选框,
405
+ type: Object,
406
+ default: () => {
407
+ return {
408
+ page: 1, // 当前位于那页面
409
+ total: 0, // 总数
410
+ limit: 30, // 一页显示多少条
411
+ pagetionShow: true,
412
+ };
424
413
  },
425
414
  },
426
-
427
- data() {
428
- return {
429
- nodata,
430
- tableRef: this.tableData.tableRef || "tableRef", // ref
431
- toggleRowFlage: this.tableData.toggleRowFlage || false, // 点击行高亮select标识
432
- // screenWidth: 0,
433
- // tableHeight:
434
- // document.documentElement.clientHeight - this.tableData.tableHeightDiff,
435
- pagetionShow: this.paginations.pagetionShow || true,
436
- twinPage: 1,
437
- columnsWatcher: null,
438
- key: 0,
439
- };
415
+ emptyImg: {
416
+ // 显示复选框,
417
+ type: Boolean,
418
+ default: false,
419
+ },
420
+ tableEvents: Object,
421
+ showBtnBox: {
422
+ type: Boolean,
423
+ default: true,
424
+ },
425
+ //获取swagger后的钩子,返回swagger结构数据
426
+ swaggerColumnsProcessor: {
427
+ type: Function,
428
+ default: null,
429
+ },
430
+ },
431
+
432
+ data() {
433
+ return {
434
+ nodata,
435
+ tableRef: this.tableData.tableRef || "tableRef", // ref
436
+ toggleRowFlage: this.tableData.toggleRowFlage || false, // 点击行高亮select标识
437
+ // screenWidth: 0,
438
+ // tableHeight:
439
+ // document.documentElement.clientHeight - this.tableData.tableHeightDiff,
440
+ pagetionShow: this.paginations.pagetionShow || true,
441
+ twinPage: 1,
442
+ columnsWatcher: null,
443
+ key: 0,
444
+ };
445
+ },
446
+ computed: {
447
+ bindTableColumns() {
448
+ return this.tableData.columns.filter(column =>
449
+ Object.keys(column).includes("show") ? column.show : true
450
+ );
440
451
  },
441
- computed: {
442
- bindTableColumns() {
443
- return this.tableData.columns.filter(column =>
444
- Object.keys(column).includes("show") ? column.show : true
445
- );
446
- },
447
452
 
448
- checkedTableList: {
449
- get() {
450
- // 返回选中的列名
451
- return this.getAllColumnsWithProp(this.tableData.columns);
452
- },
453
+ checkedTableList: {
454
+ get() {
455
+ // 返回选中的列名
456
+ return this.getAllColumnsWithProp(this.tableData.columns);
453
457
  },
454
- /* 这里使用了getter和setter,这样写的好处不用自己手动监听复选框的选中事件 */
455
- checkedTableColumns: {
456
- get() {
457
- // 返回选中的列名
458
- return this.getAllLabelsWithProp();
459
- },
460
- set(checked) {
461
- this.setColumnsShow(checked);
462
- this.$nextTick(() => {
463
- this.$refs.tableRef.doLayout();
464
- });
465
- },
466
- },
467
- },
468
- created() {
469
- // 通过swagger完善columns
470
- this.init();
471
458
  },
472
- // 组件销毁时清理监听器
473
- beforeDestroy() {
474
- this.stopColumnsWatching();
459
+ /* 这里使用了getter和setter,这样写的好处不用自己手动监听复选框的选中事件 */
460
+ checkedTableColumns: {
461
+ get() {
462
+ // 返回选中的列名
463
+ return this.getAllLabelsWithProp();
464
+ },
465
+ set(checked) {
466
+ this.setColumnsShow(checked);
467
+ this.$nextTick(() => {
468
+ this.$refs.tableRef.doLayout();
469
+ });
470
+ },
475
471
  },
476
- methods: {
477
- // init() {
478
- // // 从 IndexedDB 中获取 Swagger 数据
479
- // getData().then((swaggerData) => {
480
- // const swaggerColumns = swaggerData.paths[this.url].get.responses["200"].content['application/json'].schema.properties.items.items.properties;
481
-
482
- // Object.keys(swaggerColumns).forEach(key => {
483
- // const item = swaggerColumns[key];
484
- // let tempItem = this.tableData.columns.find((e) => e.prop == key);
485
- // if (tempItem) {
486
- // tempItem = { ...item, ...tempItem };
487
- // } else if (item.description) {
488
- // this.tableData.columns.push({
489
- // prop: key,
490
- // label: item.description,
491
- // show: true,
492
- // sortable: false,
493
- // attrs: {}
494
- // });
495
- // }
496
- // });
497
- // console.log(`\x1b[36m\x1b[4mol插件-表格`, this.tableData.columns)
498
- // }).catch((error) => {
499
- // console.error("获取 Swagger 数据失败:", error);
500
- // });
501
- // },
502
- // 支持多级表头 useSlotHeader: true,且支持排序,通过columns中的顺序实现
503
- // columns: [
504
- // {
505
- // label: '一级表头',
506
- // children: [{ prop: 'bindStateEnum', label: '112' }, { prop: 'tagNumber' }]
507
- // },
508
- // {
509
- // prop: "remark",
510
- // label: "备注123",
511
- // },
512
- // ],
513
- init() {
514
- // 从 IndexedDB 中获取 Swagger 数据
515
- getData()
516
- .then(swaggerData => {
517
- const swaggerColumns =
518
- swaggerData.paths[this.url].get.responses["200"].content["application/json"].schema
519
- .properties.items.items.properties;
520
-
521
- // 递归映射函数
522
- const mapSwaggerToColumns = columns => {
523
- columns.forEach(column => {
524
- if (column.children && column.children.length) {
525
- mapSwaggerToColumns(column.children);
526
- } else {
527
- if (column.prop && swaggerColumns[column.prop]) {
528
- const swaggerItem = swaggerColumns[column.prop];
529
- this.$set(column, "label", swaggerItem.description);
530
- if (!Object.keys(column).includes("show")) this.$set(column, "show", true);
531
- }
472
+ },
473
+ created() {
474
+ // 通过swagger完善columns
475
+ this.init();
476
+ },
477
+ // 组件销毁时清理监听器
478
+ beforeDestroy() {
479
+ this.stopColumnsWatching();
480
+ },
481
+ methods: {
482
+ // init() {
483
+ // // IndexedDB 中获取 Swagger 数据
484
+ // getData().then((swaggerData) => {
485
+ // const swaggerColumns = swaggerData.paths[this.url].get.responses["200"].content['application/json'].schema.properties.items.items.properties;
486
+
487
+ // Object.keys(swaggerColumns).forEach(key => {
488
+ // const item = swaggerColumns[key];
489
+ // let tempItem = this.tableData.columns.find((e) => e.prop == key);
490
+ // if (tempItem) {
491
+ // tempItem = { ...item, ...tempItem };
492
+ // } else if (item.description) {
493
+ // this.tableData.columns.push({
494
+ // prop: key,
495
+ // label: item.description,
496
+ // show: true,
497
+ // sortable: false,
498
+ // attrs: {}
499
+ // });
500
+ // }
501
+ // });
502
+ // console.log(`\x1b[36m\x1b[4mol插件-表格`, this.tableData.columns)
503
+ // }).catch((error) => {
504
+ // console.error("获取 Swagger 数据失败:", error);
505
+ // });
506
+ // },
507
+ // 支持多级表头 useSlotHeader: true,且支持排序,通过columns中的顺序实现
508
+ // columns: [
509
+ // {
510
+ // label: '一级表头',
511
+ // children: [{ prop: 'bindStateEnum', label: '112' }, { prop: 'tagNumber' }]
512
+ // },
513
+ // {
514
+ // prop: "remark",
515
+ // label: "备注123",
516
+ // },
517
+ // ],
518
+ init() {
519
+ // IndexedDB 中获取 Swagger 数据
520
+ getData()
521
+ .then(async swaggerData => {
522
+ const swaggerColumns =
523
+ swaggerData.paths[this.url].get.responses["200"].content["application/json"].schema
524
+ .properties.items.items.properties;
525
+
526
+ try {
527
+ const res = await this.swaggerColumnsProcessor(swaggerColumns);
528
+ swaggerColumns = res;
529
+ } catch (err) {}
530
+
531
+ // 递归映射函数
532
+ const mapSwaggerToColumns = columns => {
533
+ columns.forEach(column => {
534
+ if (column.children && column.children.length) {
535
+ mapSwaggerToColumns(column.children);
536
+ } else {
537
+ if (column.prop && swaggerColumns[column.prop]) {
538
+ const swaggerItem = swaggerColumns[column.prop];
539
+ this.$set(column, "label", swaggerItem.description);
540
+ if (!Object.keys(column).includes("show")) this.$set(column, "show", true);
532
541
  }
533
- });
534
- };
535
- // 自定义columns数据
536
- mapSwaggerToColumns(this.tableData.columns);
537
-
538
- Object.keys(swaggerColumns).forEach(key => {
539
- const item = swaggerColumns[key];
540
- const existingColumn = this.findColumnByProp(this.tableData.columns, key);
541
- if (!existingColumn && item.description) {
542
- this.tableData.columns.push({
543
- prop: key,
544
- label: item.description,
545
- show: true,
546
- sortable: false,
547
- attrs: {},
548
- });
549
542
  }
550
543
  });
551
- // 根据beforeProp排序
552
- this.sortColumns(this.tableData.columns);
553
-
554
- // 添加show, 最后添加show是为了后期swagger可能会增加show字段(扩展)
555
- // 递归根据当前是否有show键名,没有show就添加show:true
556
- const addShow = columns => {
557
- columns.forEach(column => {
558
- if (!column.hasOwnProperty("show")) this.$set(column, "show", true);
559
- if (column.children && column.children.length) {
560
- addShow(column.children);
561
- } else {
562
- if (!column.hasOwnProperty("show")) {
563
- // 用set修改
564
- this.$set(column, "show", true);
565
- }
566
- }
567
- });
568
- };
569
- // 添加show,这里的show只显示隐藏,通过checkbox能实现显示隐藏。如果不想checkbox中出现可添加hidden(这是区别于老框架的逻辑)
570
- addShow(this.tableData.columns);
571
- console.log(`\x1b[36m\x1b[4mol插件-表格`, this.tableData.columns);
572
-
573
- // init 执行完成后,添加深度监听
574
- this.startColumnsWatching();
575
- })
576
- .catch(error => {
577
- console.error("获取 Swagger 数据失败:", error);
578
- });
579
- },
580
- // 多级表头顺序调整,只争对有多级表头的且包含beforeProp字段的,规则:通过多级表头的beforeProp字段将整个多级表头移到这个字段位置之后。(只会一级出现beforeProp,多级中的排序都要手动实现)
581
- sortColumns(columns) {
582
- let index = 0;
583
- columns.forEach(column => {
584
- if (!column.beforeProp) {
585
- column.sort = index;
586
- index++;
587
- const tempItem = columns.find(e => e.beforeProp == column.prop);
588
- if (tempItem) {
589
- tempItem.sort = index;
590
- index++;
544
+ };
545
+ // 自定义columns数据
546
+ mapSwaggerToColumns(this.tableData.columns);
547
+
548
+ Object.keys(swaggerColumns).forEach(key => {
549
+ const item = swaggerColumns[key];
550
+ const existingColumn = this.findColumnByProp(this.tableData.columns, key);
551
+ if (!existingColumn && item.description) {
552
+ const obj = {
553
+ prop: key,
554
+ label: item.description,
555
+ show: true,
556
+ sortable: false,
557
+ attrs: {},
558
+ };
559
+ // 如果是枚举值直接转成Desc结尾的,swagger中没有Desc但是后端接口会返回带Desc的字段,用于前端展示枚举值的中文
560
+ if (item.enum && Array.isArray(item.enum)) {
561
+ obj.prop = `${key}Desc`;
562
+ obj.label = item.description.replace(/枚举/g, "");
563
+ }
564
+ this.tableData.columns.push(obj);
591
565
  }
592
- }
566
+ });
567
+ // 根据beforeProp排序
568
+ this.sortColumns(this.tableData.columns);
569
+
570
+ // 添加show, 最后添加show是为了后期swagger可能会增加show字段(扩展)
571
+ // 递归根据当前是否有show键名,没有show就添加show:true
572
+ const addShow = columns => {
573
+ columns.forEach(column => {
574
+ if (!column.hasOwnProperty("show")) this.$set(column, "show", true);
575
+ if (column.children && column.children.length) {
576
+ addShow(column.children);
577
+ } else {
578
+ if (!column.hasOwnProperty("show")) {
579
+ // 用set修改
580
+ this.$set(column, "show", true);
581
+ }
582
+ }
583
+ });
584
+ };
585
+ // 添加show,这里的show只显示隐藏,通过checkbox能实现显示隐藏。如果不想checkbox中出现可添加hidden(这是区别于老框架的逻辑)
586
+ addShow(this.tableData.columns);
587
+ console.log(`\x1b[36m\x1b[4mol插件-表格`, this.tableData.columns);
588
+
589
+ // init 执行完成后,添加深度监听
590
+ this.startColumnsWatching();
591
+ })
592
+ .catch(error => {
593
+ console.error("获取 Swagger 数据失败:", error);
593
594
  });
594
- columns.sort((a, b) => a.sort - b.sort);
595
- },
596
- // 递归查找列配置的辅助方法
597
- findColumnByProp(columns, prop) {
598
- for (const column of columns) {
599
- if (column.children && column.children.length) {
600
- const found = this.findColumnByProp(column.children, prop);
601
- if (found) return found;
602
- } else if (column.prop === prop) {
603
- return column;
595
+ },
596
+ // 多级表头顺序调整,只争对有多级表头的且包含beforeProp字段的,规则:通过多级表头的beforeProp字段将整个多级表头移到这个字段位置之后。(只会一级出现beforeProp,多级中的排序都要手动实现)
597
+ sortColumns(columns) {
598
+ let index = 0;
599
+ columns.forEach(column => {
600
+ if (!column.beforeProp) {
601
+ column.sort = index;
602
+ index++;
603
+ const tempItem = columns.find(e => e.beforeProp == column.prop);
604
+ if (tempItem) {
605
+ tempItem.sort = index;
606
+ index++;
604
607
  }
605
608
  }
606
- return null;
607
- },
608
- radioChange() {
609
- this.$emit("radioChange", this.twinPage);
610
- },
611
- // 刷新表格
612
- refreshTable() {
613
- const view = this.$router.history.current;
614
- this.$store.dispatch("tagsView/delCachedView", view).then(() => {
615
- const { fullPath } = view;
616
- this.$nextTick(() => {
617
- this.$router.replace({
618
- path: "/redirect" + fullPath,
619
- });
609
+ });
610
+ columns.sort((a, b) => a.sort - b.sort);
611
+ },
612
+ // 递归查找列配置的辅助方法
613
+ findColumnByProp(columns, prop) {
614
+ for (const column of columns) {
615
+ if (column.children && column.children.length) {
616
+ const found = this.findColumnByProp(column.children, prop);
617
+ if (found) return found;
618
+ } else if (column.prop === prop) {
619
+ return column;
620
+ }
621
+ }
622
+ return null;
623
+ },
624
+ radioChange() {
625
+ this.$emit("radioChange", this.twinPage);
626
+ },
627
+ // 刷新表格
628
+ refreshTable() {
629
+ const view = this.$router.history.current;
630
+ this.$store.dispatch("tagsView/delCachedView", view).then(() => {
631
+ const { fullPath } = view;
632
+ this.$nextTick(() => {
633
+ this.$router.replace({
634
+ path: "/redirect" + fullPath,
620
635
  });
621
636
  });
622
- this.$emit("refreshTable");
623
- },
624
- printTable() {
625
- console.log("printTable");
626
- if (this.tableData.rows.length <= 0) return;
627
- this.printListObj.title = this.$router.history.current.name;
628
- this.printListObj.tableHeader = this.tableData.columns;
629
- this.printListObj.tableData = this.tableData.rows;
630
- console.log(this.printListObj);
631
- setTimeout(() => {
632
- $(".printTemplate").show();
633
- $(".printTemplate").jqprint();
634
- $(".printTemplate").hide();
635
- }, 50);
636
- this.$emit("printTable");
637
- },
638
- selectAll(val) {
639
- this.$emit("selectAll", val);
640
- },
641
- select(val, row) {
642
- this.$emit("selectTab", val, row);
643
- },
644
- refreshTableBTN() {
645
- this.$emit("refreshTableBTN");
646
- },
647
- rowClick(row, column) {
648
- if (column.label === "操作") return; // 操作列不处罚行点击事件
649
- this.$emit("rowClick", row);
650
- if (
651
- this.tableData.columns.every(item => {
652
- return item.label !== "是否只出样件";
653
- })
654
- ) {
655
- // 为true时 点击行高亮select
656
- this.$refs.tableRef.toggleRowSelection(row);
657
- }
658
- },
659
- computeTableIndex(index) {
660
- return (this.paginations.page - 1) * this.paginations.limit + index + 1;
661
- },
662
- // 挑选的数据
663
- SelectionChange(val) {
664
- this.multipleSelection = val;
665
- this.$emit("SelectionChange", val);
666
- },
667
- // 分页选择
668
- handleSizeChange(val) {
669
- this.paginations.limit = val;
670
- this.$emit("handleSizeChange", val);
671
- },
672
- handleindexChange(val) {
673
- this.paginations.page = val;
674
- this.$emit("handleindexChange", val);
675
- },
676
- getCheckboxList() {
677
- return this.tableData.column;
678
- },
679
- setCheckboxList(val) {},
680
-
681
- getAllColumnsWithProp(columns) {
682
- const result = [];
683
- const propMap = new Map(); // 使用Map存储prop -> column的映射
684
-
685
- const traverse = cols => {
686
- cols.forEach(column => {
687
- if (column.children && column.children.length) {
688
- // 如果有子列,递归处理子列
689
- traverse(column.children);
690
- } else if (column.prop) {
691
- // 如果包含prop属性且未重复,添加到结果数组
692
- if (!propMap.has(column.prop)) {
693
- propMap.set(column.prop, column);
694
- result.push(column);
695
- }
637
+ });
638
+ this.$emit("refreshTable");
639
+ },
640
+ printTable() {
641
+ console.log("printTable");
642
+ if (this.tableData.rows.length <= 0) return;
643
+ this.printListObj.title = this.$router.history.current.name;
644
+ this.printListObj.tableHeader = this.tableData.columns;
645
+ this.printListObj.tableData = this.tableData.rows;
646
+ console.log(this.printListObj);
647
+ setTimeout(() => {
648
+ $(".printTemplate").show();
649
+ $(".printTemplate").jqprint();
650
+ $(".printTemplate").hide();
651
+ }, 50);
652
+ this.$emit("printTable");
653
+ },
654
+ selectAll(val) {
655
+ this.$emit("selectAll", val);
656
+ },
657
+ select(val, row) {
658
+ this.$emit("selectTab", val, row);
659
+ },
660
+ refreshTableBTN() {
661
+ this.$emit("refreshTableBTN");
662
+ },
663
+ rowClick(row, column) {
664
+ if (column.label === "操作") return; // 操作列不处罚行点击事件
665
+ this.$emit("rowClick", row);
666
+ if (
667
+ this.tableData.columns.every(item => {
668
+ return item.label !== "是否只出样件";
669
+ })
670
+ ) {
671
+ // 为true时 点击行高亮select
672
+ this.$refs.tableRef.toggleRowSelection(row);
673
+ }
674
+ },
675
+ computeTableIndex(index) {
676
+ return (this.paginations.page - 1) * this.paginations.limit + index + 1;
677
+ },
678
+ // 挑选的数据
679
+ SelectionChange(val) {
680
+ this.multipleSelection = val;
681
+ this.$emit("SelectionChange", val);
682
+ },
683
+ // 分页选择
684
+ handleSizeChange(val) {
685
+ this.paginations.limit = val;
686
+ this.$emit("handleSizeChange", val);
687
+ },
688
+ handleindexChange(val) {
689
+ this.paginations.page = val;
690
+ this.$emit("handleindexChange", val);
691
+ },
692
+ getCheckboxList() {
693
+ return this.tableData.column;
694
+ },
695
+ setCheckboxList(val) {},
696
+
697
+ getAllColumnsWithProp(columns) {
698
+ const result = [];
699
+ const propMap = new Map(); // 使用Map存储prop -> column的映射
700
+
701
+ const traverse = cols => {
702
+ cols.forEach(column => {
703
+ if (column.children && column.children.length) {
704
+ // 如果有子列,递归处理子列
705
+ traverse(column.children);
706
+ } else if (column.prop) {
707
+ // 如果包含prop属性且未重复,添加到结果数组
708
+ if (!propMap.has(column.prop)) {
709
+ propMap.set(column.prop, column);
710
+ result.push(column);
696
711
  }
697
- });
698
- };
712
+ }
713
+ });
714
+ };
699
715
 
700
- traverse(columns);
701
- return result;
702
- },
716
+ traverse(columns);
717
+ return result;
718
+ },
703
719
 
704
- // checkbox的显示隐藏
705
- getAllLabelsWithProp() {
706
- const result = [];
707
-
708
- const traverse = cols => {
709
- cols.forEach(column => {
710
- if (column.children && column.children.length) {
711
- // 如果有子列,递归处理子列
712
- traverse(column.children);
713
- } else if (column.prop && column.show) {
714
- // 如果包含prop属性且未重复,添加到结果数组
715
- if (!result.includes(column.prop) && column.show) {
716
- result.push(column.prop);
717
- }
720
+ // checkbox的显示隐藏
721
+ getAllLabelsWithProp() {
722
+ const result = [];
723
+
724
+ const traverse = cols => {
725
+ cols.forEach(column => {
726
+ if (column.children && column.children.length) {
727
+ // 如果有子列,递归处理子列
728
+ traverse(column.children);
729
+ } else if (column.prop && column.show) {
730
+ // 如果包含prop属性且未重复,添加到结果数组
731
+ if (!result.includes(column.prop) && column.show) {
732
+ result.push(column.prop);
718
733
  }
719
- });
720
- };
721
- traverse(this.tableData.columns);
722
- return result;
723
- },
724
- setColumnsShow(checkedList) {
725
- // 递归更新tableData.columns的show属性
726
- const traverse = cols => {
727
- cols.forEach(column => {
728
- if (column.children && column.children.length) {
729
- traverse(column.children);
730
- } else if (column.prop) {
731
- // 用set修改
732
- if (checkedList.includes(column.prop)) {
733
- this.$set(column, "show", true);
734
- } else {
735
- this.$set(column, "show", false);
736
- }
734
+ }
735
+ });
736
+ };
737
+ traverse(this.tableData.columns);
738
+ return result;
739
+ },
740
+ setColumnsShow(checkedList) {
741
+ // 递归更新tableData.columns的show属性
742
+ const traverse = cols => {
743
+ cols.forEach(column => {
744
+ if (column.children && column.children.length) {
745
+ traverse(column.children);
746
+ } else if (column.prop) {
747
+ // 用set修改
748
+ if (checkedList.includes(column.prop)) {
749
+ this.$set(column, "show", true);
750
+ } else {
751
+ this.$set(column, "show", false);
737
752
  }
738
- });
739
- };
740
- traverse(this.tableData.columns);
741
- },
742
-
743
- // 开启 columns 监听,(二级菜单是递归组件,数据变化dom没有发送变化,故监听直接更新dom)
744
- startColumnsWatching() {
745
- this.stopColumnsWatching();
746
- this.columnsWatcher = this.$watch("tableData.columns", () => (this.key += 1), {
747
- deep: true, // 深度监听
748
- immediate: false,
753
+ }
749
754
  });
750
- },
755
+ };
756
+ traverse(this.tableData.columns);
757
+ },
751
758
 
752
- // 停止 columns 监听
753
- stopColumnsWatching() {
754
- if (this.columnsWatcher) {
755
- this.columnsWatcher();
756
- this.columnsWatcher = null;
757
- }
758
- },
759
+ // 开启 columns 监听,(二级菜单是递归组件,数据变化dom没有发送变化,故监听直接更新dom)
760
+ startColumnsWatching() {
761
+ this.stopColumnsWatching();
762
+ this.columnsWatcher = this.$watch("tableData.columns", () => (this.key += 1), {
763
+ deep: true, // 深度监听
764
+ immediate: false,
765
+ });
759
766
  },
760
- };
761
- </script>
762
767
 
763
- <style lang="scss" scoped>
764
- .table_list_fix {
765
- overflow: auto;
766
- flex: 1;
767
- display: flex;
768
- flex-direction: column;
769
- justify-content: space-between;
770
- padding: 10px;
771
- gap: 10px;
772
-
773
- ::v-deep .el-table {
774
- td {
775
- padding: 0px;
776
-
777
- div {
778
- line-height: 28px;
779
- font-size: 12px;
780
- }
768
+ // 停止 columns 监听
769
+ stopColumnsWatching() {
770
+ if (this.columnsWatcher) {
771
+ this.columnsWatcher();
772
+ this.columnsWatcher = null;
781
773
  }
774
+ },
775
+ },
776
+ };
777
+ </script>
782
778
 
783
- th {
784
- padding: 0px;
785
- background: #f5f7fa;
786
- div {
787
- line-height: 28px;
788
- color: #909399;
789
- font-size: 12px;
790
- }
779
+ <style lang="scss" scoped>
780
+ .table_list_fix {
781
+ overflow: auto;
782
+ flex: 1;
783
+ display: flex;
784
+ flex-direction: column;
785
+ justify-content: space-between;
786
+ padding: 10px;
787
+ gap: 10px;
788
+
789
+ ::v-deep .el-table {
790
+ td {
791
+ padding: 0px;
792
+
793
+ div {
794
+ line-height: 28px;
795
+ font-size: 12px;
791
796
  }
792
797
  }
793
798
 
794
- .btn-operates {
795
- margin: 10px 0px 10px 15px;
796
-
797
- ::v-deep a {
798
- color: #fff;
799
- text-decoration: none;
800
- display: inline-block;
801
- margin: 0px 5px;
802
- ::v-deep .el-button {
803
- width: 100%;
804
- padding: 7px;
805
- font-size: 13px;
806
- }
799
+ th {
800
+ padding: 0px;
801
+ background: #f5f7fa;
802
+ div {
803
+ line-height: 28px;
804
+ color: #909399;
805
+ font-size: 12px;
807
806
  }
808
807
  }
809
808
  }
810
809
 
811
- .table-header {
812
- padding-top: 10px;
813
-
814
- .table-header_button {
815
- text-align: right;
816
- float: right;
817
- margin-bottom: 12px;
818
- line-height: 40px;
810
+ .btn-operates {
811
+ margin: 10px 0px 10px 15px;
812
+
813
+ ::v-deep a {
814
+ color: #fff;
815
+ text-decoration: none;
816
+ display: inline-block;
817
+ margin: 0px 5px;
818
+ ::v-deep .el-button {
819
+ width: 100%;
820
+ padding: 7px;
821
+ font-size: 13px;
822
+ }
819
823
  }
820
824
  }
825
+ }
821
826
 
822
- .newjump {
823
- text-decoration: none;
824
- color: dodgerblue;
825
- }
827
+ .table-header {
828
+ padding-top: 10px;
826
829
 
827
- .tablebox {
828
- box-sizing: border-box;
829
- flex: 1;
830
- overflow: auto;
830
+ .table-header_button {
831
+ text-align: right;
832
+ float: right;
833
+ margin-bottom: 12px;
834
+ line-height: 40px;
831
835
  }
832
-
833
- ::v-deep .el-table__body tr.current-row > td {
834
- background-color: rgb(24, 144, 255) !important;
835
- color: #fff;
836
+ }
837
+
838
+ .newjump {
839
+ text-decoration: none;
840
+ color: dodgerblue;
841
+ }
842
+
843
+ .tablebox {
844
+ box-sizing: border-box;
845
+ flex: 1;
846
+ overflow: auto;
847
+ }
848
+
849
+ ::v-deep .el-table__body tr.current-row > td {
850
+ background-color: rgb(24, 144, 255) !important;
851
+ color: #fff;
852
+ }
853
+
854
+ ::v-deep .redrow {
855
+ background: #fde6e6 !important;
856
+ }
857
+
858
+ .btnbox {
859
+ width: 100%;
860
+ display: flex;
861
+ align-items: center;
862
+ justify-content: space-between;
863
+
864
+ .upload-demo {
865
+ display: -webkit-inline-box;
866
+ margin-left: 10px;
836
867
  }
837
868
 
838
- ::v-deep .redrow {
839
- background: #fde6e6 !important;
840
- }
841
-
842
- .btnbox {
843
- width: 100%;
844
- display: flex;
845
- align-items: center;
846
- justify-content: space-between;
847
-
848
- .upload-demo {
849
- display: -webkit-inline-box;
850
- margin-left: 10px;
851
- }
852
-
853
- .el-form-item {
854
- margin-bottom: 0px;
855
- }
856
- }
857
-
858
- .layui-table-tool-self {
859
- display: block;
860
- width: 26px;
861
- height: 26px;
862
- padding: 5px;
863
- line-height: 16px;
864
- text-align: center;
865
- color: #333;
866
- border: 1px solid #ccc;
867
- cursor: pointer;
868
- }
869
-
870
- .checkbox {
871
- display: block;
872
- }
873
- // 操作列按钮布局
874
- .operate-group {
875
- display: flex;
876
- align-items: center;
877
- justify-content: space-around;
878
- }
879
- .toolbox {
880
- display: flex;
881
- gap: 10px;
869
+ .el-form-item {
870
+ margin-bottom: 0px;
882
871
  }
872
+ }
873
+
874
+ .layui-table-tool-self {
875
+ display: block;
876
+ width: 26px;
877
+ height: 26px;
878
+ padding: 5px;
879
+ line-height: 16px;
880
+ text-align: center;
881
+ color: #333;
882
+ border: 1px solid #ccc;
883
+ cursor: pointer;
884
+ }
885
+
886
+ .checkbox {
887
+ display: block;
888
+ }
889
+ // 操作列按钮布局
890
+ .operate-group {
891
+ display: flex;
892
+ align-items: center;
893
+ justify-content: space-around;
894
+ }
895
+ .toolbox {
896
+ display: flex;
897
+ gap: 10px;
898
+ }
883
899
  </style>
900
+