n20-common-lib 3.2.16 → 3.2.18

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": "n20-common-lib",
3
- "version": "3.2.16",
3
+ "version": "3.2.18",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -315,29 +315,32 @@ export default {
315
315
  const calcRangeWidth = (item, value, value2) => {
316
316
  let textMaxWidth = 426 - getWidth(item.label) - 16
317
317
  let textMinWidth = 160
318
+ // 日期区间:宽度按类型固定(与内部 el-range-editor 的 CSS 宽度对齐),
319
+ // 不随实际选中值变化、也不因是否选中而改变,避免选中后宽度变化
320
+ const rangeFixedWidthMap = {
321
+ daterange: 225,
322
+ datetimerange: 340,
323
+ monthrange: 200
324
+ }
325
+ if (rangeFixedWidthMap[item.type]) {
326
+ let widthMax = rangeFixedWidthMap[item.type]
327
+ if (widthMax > textMaxWidth) {
328
+ return textMaxWidth + 'px'
329
+ }
330
+ return widthMax + 'px'
331
+ }
332
+ // 数值区间(numberrange)无固定格式:未选中返回最小宽度,选中按实际值计算
318
333
  if (!value && !value2) {
319
334
  return textMinWidth + 'px'
320
- } else {
321
- if (!value || !value2) {
322
- let widthMax = (getWidth(value) + getWidth(value2) + 72) * 2
323
- if (widthMax < textMinWidth) {
324
- return textMinWidth + 'px'
325
- }
326
- if (widthMax > textMaxWidth) {
327
- return textMaxWidth + 'px'
328
- }
329
- return widthMax + 'px'
330
- } else {
331
- let widthMax = getWidth(value) + getWidth(value2) + 140
332
- if (widthMax < textMinWidth) {
333
- return textMinWidth + 'px'
334
- }
335
- if (widthMax > textMaxWidth) {
336
- return textMaxWidth + 'px'
337
- }
338
- return widthMax + 'px'
339
- }
340
335
  }
336
+ let widthMax = getWidth(value) + getWidth(value2) + 140
337
+ if (widthMax < textMinWidth) {
338
+ return textMinWidth + 'px'
339
+ }
340
+ if (widthMax > textMaxWidth) {
341
+ return textMaxWidth + 'px'
342
+ }
343
+ return widthMax + 'px'
341
344
  }
342
345
 
343
346
  const calcDateWidth = (item, value) => {
@@ -32,15 +32,11 @@
32
32
  :height="height"
33
33
  border
34
34
  @selection-change="(selection) => (selectionList = selection)"
35
+ @sort-change="onSortChange"
35
36
  >
36
37
  <slot name="selection-column">
37
38
  <el-table-column type="selection" width="50" align="center" />
38
39
  </slot>
39
- <el-table-column :label="'排序' | $lc" width="50" align="center">
40
- <template slot-scope="{ row }">
41
- <i class="n20-icon-tuodong file-upload-table__drag-handle" :data-row-key="row[keys.rowKey]"></i>
42
- </template>
43
- </el-table-column>
44
40
  <template v-if="dataPorp.slotHeader">
45
41
  <el-table-column
46
42
  v-for="item in dataPorp.slotHeader"
@@ -77,7 +73,7 @@
77
73
  </div>
78
74
  </slot>
79
75
  </el-table-column>
80
- <el-table-column :label="'附件名称' | $lc" :prop="keys.name">
76
+ <el-table-column :label="'附件名称' | $lc" :prop="keys.name" sortable="custom">
81
77
  <slot slot="header" slot-scope="scope" name="name-header" :column="scope.column">{{ '附件名称' | $lc }}</slot>
82
78
  <slot slot-scope="{ row }" name="name" :row="row">
83
79
  <span v-if="readonly">{{ row[keys.name] ? row[keys.name].replace(/\.[A-z0-9]+$/, '') : '' }}</span>
@@ -322,7 +318,6 @@ import aiCheckDialog from './aiCheckDialog.vue'
322
318
  import getJsonc from '../../assets/getJsonc.js'
323
319
  import _axios from 'axios'
324
320
  import dayjs from 'dayjs'
325
- import Sortable from 'sortablejs'
326
321
  import XEUtils from 'xe-utils'
327
322
 
328
323
  import 'viewerjs/dist/viewer.css'
@@ -502,8 +497,7 @@ export default {
502
497
  previewName: undefined,
503
498
  previewSameOrg: false,
504
499
  seeRow: {},
505
- officeStatus: false,
506
- sortable: null
500
+ officeStatus: false
507
501
  }
508
502
  },
509
503
  computed: {
@@ -546,63 +540,31 @@ export default {
546
540
  },
547
541
  immediate: true,
548
542
  deep: true
549
- },
550
- tableKey() {
551
- this.initSortable()
552
543
  }
553
544
  },
554
545
  mounted() {
555
546
  this.getConfiguration()
556
- this.initSortable()
557
- },
558
- beforeDestroy() {
559
- this.destroySortable()
560
547
  },
561
548
  methods: {
562
- initSortable() {
563
- this.$nextTick(() => {
564
- this.destroySortable()
565
-
566
- const $tbody = this.$refs.elTable?.$el?.querySelector('.el-table__body-wrapper > table > tbody')
567
- if (!$tbody) {
568
- return
569
- }
570
-
571
- this.sortable = Sortable.create($tbody, {
572
- handle: '.file-upload-table__drag-handle',
573
- ghostClass: 'file-upload-table__sortable-ghost',
574
- setData(dataTransfer) {
575
- dataTransfer.setData('Text', '')
576
- },
577
- onEnd: ({ oldIndex, newIndex }) => {
578
- if (
579
- oldIndex === newIndex ||
580
- oldIndex === undefined ||
581
- newIndex === undefined ||
582
- oldIndex < 0 ||
583
- newIndex < 0
584
- ) {
585
- return
586
- }
587
-
588
- const targetRow = this.tableData.splice(oldIndex, 1)[0]
589
- if (!targetRow) {
590
- return
591
- }
592
- this.tableData.splice(newIndex, 0, targetRow)
593
- this.$emit('sort', this.tableData.slice())
594
- this.saveFileSort().catch(() => {
595
- this.$message.error($lc('附件排序保存失败'))
596
- })
597
- }
598
- })
599
- })
600
- },
601
- destroySortable() {
602
- if (this.sortable) {
603
- this.sortable.destroy()
604
- this.sortable = null
549
+ // 点击附件名称表头排序(替代原拖动排序)
550
+ onSortChange({ prop, order }) {
551
+ // 仅处理附件名称列;order 为 null(取消排序)时不处理
552
+ if (prop !== this.keys.name || !order) {
553
+ return
605
554
  }
555
+ const nameKey = this.keys.name
556
+ // 与显示一致:去除扩展名后再比较
557
+ const stripName = (v) => (v == null ? '' : String(v).replace(/\.[A-z0-9]+$/, ''))
558
+ const dir = order === 'ascending' ? 1 : -1
559
+ const sorted = [...this.tableData].sort(
560
+ (a, b) => stripName(a[nameKey]).localeCompare(stripName(b[nameKey]), 'zh-CN', { numeric:true }) * dir
561
+ )
562
+ // 原地更新 tableData(沿用现有 splice 修改 prop 数组的模式)
563
+ this.tableData.splice(0, this.tableData.length, ...sorted)
564
+ this.$emit('sort', this.tableData.slice())
565
+ this.saveFileSort().catch(() => {
566
+ this.$message.error($lc('附件排序保存失败'))
567
+ })
606
568
  },
607
569
  async saveFileSort() {
608
570
  const sortList = this.tableData
@@ -1076,21 +1038,4 @@ export default {
1076
1038
  right: 46px;
1077
1039
  top: 10px;
1078
1040
  }
1079
-
1080
- .file-upload-table__drag-handle {
1081
- display: inline-block;
1082
- color: #909399;
1083
- font-size: 16px;
1084
- cursor: move;
1085
- }
1086
-
1087
- .file-upload-table__drag-handle:hover {
1088
- color: #606266;
1089
- }
1090
-
1091
- .file-upload-table__sortable-ghost {
1092
- opacity: 0.8;
1093
- color: #fff !important;
1094
- background: #42b983 !important;
1095
- }
1096
1041
  </style>