n20-common-lib 3.0.56 → 3.0.57

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.0.56",
3
+ "version": "3.0.57",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -40,7 +40,7 @@
40
40
  <el-input v-model="keyword" clearable class="input-w m-b-s" :placeholder="$lc('搜索筛选条件')" />
41
41
  <div class="flex-box flex-lr">
42
42
  <el-button type="text" @click="allCheck">{{
43
- checkList.length === filterListS.length ? $lc('取消全选') : $lc('全选')
43
+ isAllNonFixedChecked ? $lc('取消全选') : $lc('全选')
44
44
  }}</el-button>
45
45
  <el-button v-if="filterId" type="text" @click="defaultCheck">{{ $lc('恢复默认') }}</el-button>
46
46
  </div>
@@ -210,6 +210,14 @@ export default {
210
210
  set(v) {
211
211
  return v
212
212
  }
213
+ },
214
+ // 判断所有非固定(非static、非isNotClose)项目是否都已选中
215
+ isAllNonFixedChecked() {
216
+ const nonFixedItems = this.filterListS.filter((res) => !res.static && !res.isNotClose)
217
+ if (nonFixedItems.length === 0) return false
218
+
219
+ const nonFixedItemIds = nonFixedItems.map((item) => item[this.onlyKey])
220
+ return nonFixedItemIds.every((id) => this.checkList.includes(id))
213
221
  }
214
222
  },
215
223
  watch: {
@@ -393,15 +401,23 @@ export default {
393
401
  }
394
402
  },
395
403
  allCheck() {
396
- if (this.checkList.length === this.filterListS.length) {
397
- this.checkList = this.filterListS
398
- ?.filter((res) => {
399
- if (res.static || res.isNotClose) {
400
- return res[this.onlyKey]
401
- }
402
- })
403
- ?.map((item) => item[this.onlyKey])
404
+ // 获取非固定(非static、非isNotClose)的项目
405
+ const nonFixedItems = this.filterListS.filter((res) => !res.static && !res.isNotClose)
406
+ const nonFixedItemIds = nonFixedItems.map((item) => item[this.onlyKey])
407
+
408
+ // 检查所有非固定项目是否都已选中
409
+ const allNonFixedChecked = nonFixedItemIds.length > 0 && nonFixedItemIds.every((id) => this.checkList.includes(id))
410
+
411
+ // 获取固定项目的ID
412
+ const fixedItemIds = this.filterListS
413
+ .filter((res) => res.static || res.isNotClose)
414
+ .map((item) => item[this.onlyKey])
415
+
416
+ if (allNonFixedChecked) {
417
+ // 取消全选:只保留固定项目
418
+ this.checkList = [...fixedItemIds]
404
419
  } else {
420
+ // 全选:选中所有项目
405
421
  if (this.maxLength) {
406
422
  this.checkList = this.filterListS.slice(0, this.maxLength)?.map((res) => res[this.onlyKey])
407
423
  } else {
@@ -516,24 +532,34 @@ export default {
516
532
  mackData(data) {
517
533
  let _data = data
518
534
  if (_data && _data.length > 0) {
519
- this.GroupData = _data.map((item) => {
520
- for (let i = 0; i < this.filterList.length; i++) {
521
- const originItem = this.filterList[i]
522
- if (originItem[this.onlyKey] === item[this.onlyKey]) {
535
+ // 先过滤出在 filterList 中存在的项目,避免使用已删除的筛选条件
536
+ _data = _data.filter((item) => {
537
+ return this.filterList.some((filterItem) => filterItem[this.onlyKey] === item[this.onlyKey])
538
+ })
539
+
540
+ // 如果过滤后没有有效数据,使用默认逻辑
541
+ if (_data.length === 0) {
542
+ if (this.removeLoad) {
543
+ this.GroupData = this.filterList.filter((item) => {
544
+ if (item.isDefault) {
545
+ return item
546
+ }
547
+ })
548
+ } else {
549
+ this.GroupData = []
550
+ }
551
+ } else {
552
+ // 更新有效数据的 label 和 options
553
+ this.GroupData = _data.map((item) => {
554
+ const originItem = this.filterList.find((filter) => filter[this.onlyKey] === item[this.onlyKey])
555
+ if (originItem) {
523
556
  item.label = originItem.label
524
- if (item.options && originItem.options) {
557
+ if (originItem.options) {
525
558
  item.options = originItem.options
526
559
  }
527
560
  }
528
- }
529
- return item
530
- })
531
-
532
- // ✨ 强制将 static: true 的项目移到最前面
533
- if (this.GroupData && this.GroupData.length > 0) {
534
- const staticItems = this.GroupData.filter((item) => item.static)
535
- const otherItems = this.GroupData.filter((item) => !item.static)
536
- this.GroupData = [...staticItems, ...otherItems]
561
+ return item
562
+ })
537
563
  }
538
564
  } else {
539
565
  if (this.removeLoad) {
@@ -546,6 +572,27 @@ export default {
546
572
  this.GroupData = []
547
573
  }
548
574
  }
575
+
576
+ // ✨ 确保 static: true 的项目自动添加并勾选
577
+ const staticItemsInFilterList = this.filterList.filter((item) => item.static)
578
+ const existingIds = this.GroupData.map((item) => item[this.onlyKey])
579
+
580
+ // 找出不在 GroupData 中的 static 项目
581
+ const missingStaticItems = staticItemsInFilterList.filter((item) => !existingIds.includes(item[this.onlyKey]))
582
+
583
+ // 将缺失的 static 项目添加到 GroupData 开头
584
+ if (missingStaticItems.length > 0) {
585
+ const staticItemsToAdd = missingStaticItems.map((item) => ({ ...item }))
586
+ this.GroupData = [...staticItemsToAdd, ...this.GroupData]
587
+ }
588
+
589
+ // ✨ 强制将所有 static: true 的项目移到最前面
590
+ if (this.GroupData && this.GroupData.length > 0) {
591
+ const staticItems = this.GroupData.filter((item) => item.static)
592
+ const otherItems = this.GroupData.filter((item) => !item.static)
593
+ this.GroupData = [...staticItems, ...otherItems]
594
+ }
595
+
549
596
  this.checkList = this.GroupData.map((res) => res.id)
550
597
  console.log(this.checkList)
551
598
  this.cancelCheck = XEUtils.clone(this.checkList, true)