@sy-common/organize-select-help 1.0.0-beta.42 → 1.0.0-beta.43

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.vue +70 -39
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sy-common/organize-select-help",
3
- "version": "1.0.0-beta.42",
3
+ "version": "1.0.0-beta.43",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
package/src/index.vue CHANGED
@@ -1,5 +1,6 @@
1
1
  <template>
2
2
  <Modal
3
+ v-if="isNameValid"
3
4
  title=""
4
5
  v-model="modal"
5
6
  @on-ok="confirm"
@@ -297,30 +298,32 @@ export default {
297
298
  }
298
299
  },
299
300
  created() {
300
- console.log("this.name", this.name);
301
- this.activeTabName = this.computedTabName;
302
- console.log("this.activeTabName", this.activeTabName);
303
- // 新增:初始化时强制触发一次Tab更新,确保DOM渲染
304
- this.$nextTick(() => {
305
- this.$forceUpdate();
306
- });
301
+ if (this.isNameValid) {
302
+ console.log("this.name", this.name);
303
+ this.activeTabName = this.computedTabName;
304
+ console.log("this.activeTabName", this.activeTabName);
305
+ this.$nextTick(() => {
306
+ this.$forceUpdate();
307
+ });
308
+ }
307
309
  },
308
310
  mounted() {
309
- this.queryTagList()
310
- this.queryPositionList()
311
- this.initStaffOrgTree()
311
+ // 优化:仅当name有效时才执行初始化逻辑
312
+ if (this.isNameValid) {
313
+ this.queryTagList()
314
+ this.queryPositionList()
315
+ this.initStaffOrgTree()
312
316
 
313
- // 新增:mounted阶段再次确认activeTabName,确保Tab激活
314
- this.$nextTick(() => {
315
- this.activeTabName = this.computedTabName;
316
- // 如果是staff Tab,主动触发初始化
317
- if (this.activeTabName === 'staff') {
318
- this.handleTabChange('staff');
319
- }
320
- });
321
- console.log("传入的 name 数组:", this.name);
322
- console.log("是否包含 staff:", this.name.includes('staff'));
323
- console.log("最终激活的 Tab:", this.activeTabName);
317
+ this.$nextTick(() => {
318
+ this.activeTabName = this.computedTabName;
319
+ if (this.activeTabName === 'org' || this.activeTabName === 'post' || this.activeTabName === 'staff') {
320
+ this.handleTabChange(this.activeTabName);
321
+ }
322
+ });
323
+ console.log("传入的 name 数组:", this.name);
324
+ console.log("是否包含 staff:", this.name.includes('staff'));
325
+ console.log("最终激活的 Tab:", this.activeTabName);
326
+ }
324
327
  },
325
328
  methods:{
326
329
  async initStaffOrgTree() {
@@ -954,22 +957,26 @@ export default {
954
957
  this.staffList.splice(index,1)
955
958
  },
956
959
  confirm(){
957
- const v = {
958
- orgList:this.orgList,
959
- postList:this.postList,
960
- staffList:this.staffList
960
+ if (this.isNameValid) {
961
+ const v = {
962
+ orgList:this.orgList,
963
+ postList:this.postList,
964
+ staffList:this.staffList
965
+ }
966
+ this.$emit('confirm',deepCopy(v))
961
967
  }
962
- this.$emit('confirm',deepCopy(v))
963
968
  },
964
969
  visibleChange(val) {
965
- this.$emit('input', val);
966
- if (val) {
967
- this.initStaffList()
968
- } else {
969
- this.staffEnding = false;
970
- this.offset = 0;
971
- this.staffAllList = [];
972
- this.$set(this, 'selectedStaffOrgId', '');
970
+ if (this.isNameValid) {
971
+ this.$emit('input', val);
972
+ if (val) {
973
+ this.initStaffList()
974
+ } else {
975
+ this.staffEnding = false;
976
+ this.offset = 0;
977
+ this.staffAllList = [];
978
+ this.$set(this, 'selectedStaffOrgId', '');
979
+ }
973
980
  }
974
981
  },
975
982
  initStaffList() {
@@ -1527,8 +1534,13 @@ export default {
1527
1534
 
1528
1535
  },
1529
1536
  computed:{
1537
+ isNameValid() {
1538
+ return Array.isArray(this.name) && this.name.length > 0;
1539
+ },
1530
1540
  computedTabName() {
1531
- const validTabNames = Array.isArray(this.name) ? this.name : [];
1541
+ // 优化:基于isNameValid做边界判断
1542
+ if (!this.isNameValid) return '';
1543
+ const validTabNames = this.name.filter(name => ['org', 'post', 'staff'].includes(name));
1532
1544
  return validTabNames.length > 0 ? validTabNames[0] : '';
1533
1545
  },
1534
1546
  getCheckedStaff(){
@@ -1543,10 +1555,10 @@ export default {
1543
1555
  },
1544
1556
  watch:{
1545
1557
  computedTabName(newVal) {
1546
- if (newVal && this.name.includes(newVal)) {
1558
+ // 优化:增加name有效性判断
1559
+ if (this.isNameValid && newVal && this.name.includes(newVal)) {
1547
1560
  this.activeTabName = newVal;
1548
1561
  this.$nextTick(() => {
1549
- // 确保 Tab 组件已渲染后再强制更新
1550
1562
  if (this.$refs.tabs) {
1551
1563
  this.$refs.tabs.$forceUpdate();
1552
1564
  }
@@ -1556,12 +1568,31 @@ export default {
1556
1568
  });
1557
1569
  }
1558
1570
  },
1571
+ name: {
1572
+ handler(newVal) {
1573
+ if (this.isNameValid) {
1574
+ this.activeTabName = this.computedTabName;
1575
+ this.$nextTick(() => {
1576
+ this.$forceUpdate();
1577
+ if (newVal === 'org' || newVal === 'post' || newVal === 'staff') {
1578
+ this.handleTabChange(newVal);
1579
+ }
1580
+ });
1581
+ }
1582
+ },
1583
+ deep: true,
1584
+ immediate: true
1585
+ },
1559
1586
  value(val){
1560
- this.modal = val
1587
+ if (this.isNameValid) {
1588
+ this.modal = val
1589
+ }
1561
1590
  },
1562
1591
  data:{
1563
1592
  handler(val){
1564
- if(!val) return
1593
+ // 优化:增加边界判断
1594
+ if(!this.isNameValid || !val) return
1595
+ // 原有逻辑保持不变
1565
1596
  let map = deepCopy(val)
1566
1597
  let orgList = map.orgList || []
1567
1598
  orgList.forEach(item=>{