Showing
1 changed file
with
84 additions
and
9 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-08-29 14:31:20 | 2 | * @Date: 2022-08-29 14:31:20 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-08-05 16:53:52 | 4 | + * @LastEditTime: 2024-08-05 18:23:40 |
| 5 | * @FilePath: /data-table/src/components/OrgPickerField/MyComponent.vue | 5 | * @FilePath: /data-table/src/components/OrgPickerField/MyComponent.vue |
| 6 | * @Description: 树形组件 | 6 | * @Description: 树形组件 |
| 7 | --> | 7 | --> |
| ... | @@ -145,7 +145,6 @@ | ... | @@ -145,7 +145,6 @@ |
| 145 | @change="onUserChange" | 145 | @change="onUserChange" |
| 146 | > | 146 | > |
| 147 | <van-checkbox | 147 | <van-checkbox |
| 148 | - | ||
| 149 | @click="onCheckUserChange(user, $event)" | 148 | @click="onCheckUserChange(user, $event)" |
| 150 | v-for="(user, index) in userList" | 149 | v-for="(user, index) in userList" |
| 151 | :id="user.id" | 150 | :id="user.id" |
| ... | @@ -155,7 +154,10 @@ | ... | @@ -155,7 +154,10 @@ |
| 155 | :name="user.id" | 154 | :name="user.id" |
| 156 | shape="square" | 155 | shape="square" |
| 157 | icon-size="13px" | 156 | icon-size="13px" |
| 158 | - :checked-color="styleColor.baseColor" style="margin-bottom: 0.5rem;">{{ user.name }}</van-checkbox> | 157 | + :checked-color="styleColor.baseColor" |
| 158 | + :disabled="user.disabled" | ||
| 159 | + style="margin-bottom: 0.5rem;" | ||
| 160 | + >{{ user.name }}</van-checkbox> | ||
| 159 | </van-checkbox-group> | 161 | </van-checkbox-group> |
| 160 | <div style="height: 10vh;"></div> | 162 | <div style="height: 10vh;"></div> |
| 161 | </van-col> | 163 | </van-col> |
| ... | @@ -487,6 +489,15 @@ const resetRoleDisabled = () => { | ... | @@ -487,6 +489,15 @@ const resetRoleDisabled = () => { |
| 487 | } | 489 | } |
| 488 | } | 490 | } |
| 489 | 491 | ||
| 492 | +const resetUserDisabled = () => { | ||
| 493 | + // 如果角色没有选中,解除禁用 | ||
| 494 | + if (!user_checked.value.length) { | ||
| 495 | + userList.value.forEach(item => { | ||
| 496 | + item.disabled = false; | ||
| 497 | + }); | ||
| 498 | + } | ||
| 499 | +} | ||
| 500 | + | ||
| 490 | const onRemoveDeptTag = (dept) => { // 移除部门标签 | 501 | const onRemoveDeptTag = (dept) => { // 移除部门标签 |
| 491 | // 移除选中框显示 | 502 | // 移除选中框显示 |
| 492 | const index = checkedGroup.value.dept.findIndex(item => JSON.stringify(item) === JSON.stringify(dept)); | 503 | const index = checkedGroup.value.dept.findIndex(item => JSON.stringify(item) === JSON.stringify(dept)); |
| ... | @@ -498,7 +509,8 @@ const onRemoveDeptTag = (dept) => { // 移除部门标签 | ... | @@ -498,7 +509,8 @@ const onRemoveDeptTag = (dept) => { // 移除部门标签 |
| 498 | search_result_checked.value.splice(idx, 1); | 509 | search_result_checked.value.splice(idx, 1); |
| 499 | // 单选模式 | 510 | // 单选模式 |
| 500 | if (check_type.value === 'single') { | 511 | if (check_type.value === 'single') { |
| 501 | - resetRoleDisabled(); | 512 | + resetRoleDisabled();// 重置角色禁用状态 |
| 513 | + resetUserDisabled(); // 重置成员禁用状态 | ||
| 502 | } | 514 | } |
| 503 | } | 515 | } |
| 504 | 516 | ||
| ... | @@ -513,7 +525,8 @@ const onRemoveRoleTag = (role) => { // 移除角色标签 | ... | @@ -513,7 +525,8 @@ const onRemoveRoleTag = (role) => { // 移除角色标签 |
| 513 | search_result_checked.value.splice(i, 1); | 525 | search_result_checked.value.splice(i, 1); |
| 514 | // 单选模式 | 526 | // 单选模式 |
| 515 | if (check_type.value === 'single') { | 527 | if (check_type.value === 'single') { |
| 516 | - resetRoleDisabled(); | 528 | + resetRoleDisabled();// 重置角色禁用状态 |
| 529 | + resetUserDisabled(); // 重置成员禁用状态 | ||
| 517 | } | 530 | } |
| 518 | } | 531 | } |
| 519 | 532 | ||
| ... | @@ -528,7 +541,8 @@ const onRemoveUserTag = (user) => { // 移除成员标签 | ... | @@ -528,7 +541,8 @@ const onRemoveUserTag = (user) => { // 移除成员标签 |
| 528 | search_result_checked.value.splice(i, 1); | 541 | search_result_checked.value.splice(i, 1); |
| 529 | // 单选模式 | 542 | // 单选模式 |
| 530 | if (check_type.value === 'single') { | 543 | if (check_type.value === 'single') { |
| 531 | - resetRoleDisabled(); | 544 | + resetRoleDisabled(); // 重置角色禁用状态 |
| 545 | + resetUserDisabled(); // 重置成员禁用状态 | ||
| 532 | } | 546 | } |
| 533 | } | 547 | } |
| 534 | 548 | ||
| ... | @@ -586,7 +600,26 @@ const roleListReset = () => { // 角色重置列表 | ... | @@ -586,7 +600,26 @@ const roleListReset = () => { // 角色重置列表 |
| 586 | 600 | ||
| 587 | const userListReset = () => { // 成员重置列表 | 601 | const userListReset = () => { // 成员重置列表 |
| 588 | userTreeRef.value.setData(role_list); | 602 | userTreeRef.value.setData(role_list); |
| 589 | - userTreeRef.value.setExpand(35697, true) | 603 | + userTreeRef.value.setExpand(35697, true); |
| 604 | + if (check_type.value === 'single') { | ||
| 605 | + if (treeCheckedCount.value) { // 已勾选值一个 | ||
| 606 | + if (checkedGroup.value.user.length) { | ||
| 607 | + checkedGroup.value.user.forEach(user => { | ||
| 608 | + userList.value.forEach(item => { | ||
| 609 | + if (user.id === item.id) { | ||
| 610 | + item.disabled = false; | ||
| 611 | + } else { | ||
| 612 | + item.disabled = true; | ||
| 613 | + } | ||
| 614 | + }); | ||
| 615 | + }) | ||
| 616 | + } else { | ||
| 617 | + userList.value.forEach(item => { | ||
| 618 | + item.disabled = true; | ||
| 619 | + }) | ||
| 620 | + } | ||
| 621 | + } | ||
| 622 | + } | ||
| 590 | } | 623 | } |
| 591 | /**************** END *****************/ | 624 | /**************** END *****************/ |
| 592 | 625 | ||
| ... | @@ -691,7 +724,28 @@ const user_checked = ref([]); // 成员多选选中值 | ... | @@ -691,7 +724,28 @@ const user_checked = ref([]); // 成员多选选中值 |
| 691 | 724 | ||
| 692 | const onUserTreeClick = (node) => { // 点击成员树形回调 | 725 | const onUserTreeClick = (node) => { // 点击成员树形回调 |
| 693 | userList.value = node.user; | 726 | userList.value = node.user; |
| 694 | - user_checked.value = checkedGroup.value.user.map(item => item.id) | 727 | + user_checked.value = checkedGroup.value.user.map(item => item.id); |
| 728 | + // 单选模式判断 | ||
| 729 | + if (check_type.value === 'single') { | ||
| 730 | + if (treeCheckedCount.value) { // 已勾选值一个 | ||
| 731 | + if (checkedGroup.value.user.length) { // 成员列表有勾选值 | ||
| 732 | + checkedGroup.value.user.forEach(user => { | ||
| 733 | + node.user.forEach(item => { | ||
| 734 | + if (user.id === item.id) { | ||
| 735 | + item.disabled = false; | ||
| 736 | + } else { | ||
| 737 | + item.disabled = true; | ||
| 738 | + } | ||
| 739 | + }); | ||
| 740 | + }) | ||
| 741 | + } else { // 成员列表没有勾选值 | ||
| 742 | + showToast('单选模式下,只能勾选一个') | ||
| 743 | + userList.value = [] | ||
| 744 | + } | ||
| 745 | + } else { | ||
| 746 | + resetUserDisabled(); | ||
| 747 | + } | ||
| 748 | + } | ||
| 695 | } | 749 | } |
| 696 | 750 | ||
| 697 | const onUserChange = (val) => { // 成员多选组点击回调 | 751 | const onUserChange = (val) => { // 成员多选组点击回调 |
| ... | @@ -729,7 +783,28 @@ const onCheckUserChange = (val, evt) => { | ... | @@ -729,7 +783,28 @@ const onCheckUserChange = (val, evt) => { |
| 729 | checkedGroup.value.user.splice(index, 1); | 783 | checkedGroup.value.user.splice(index, 1); |
| 730 | } | 784 | } |
| 731 | } | 785 | } |
| 732 | - }) | 786 | + }); |
| 787 | + if (val.disabled) { // 节点禁用时不能操作 | ||
| 788 | + showToast('单选模式下,只能勾选一个') | ||
| 789 | + return; | ||
| 790 | + } | ||
| 791 | + if (check_type.value === 'single') { | ||
| 792 | + // 移除选中框显示 | ||
| 793 | + const index = checkedGroup.value['user'].findIndex(item => item === val.id); | ||
| 794 | + checkedGroup.value['user'].splice(index, 1); | ||
| 795 | + // 超出选中1个,禁用其他选中 | ||
| 796 | + if (!treeCheckedCount.value) { | ||
| 797 | + userList.value.forEach(item => { | ||
| 798 | + if (item.id === val.id) { | ||
| 799 | + item.disabled = false; | ||
| 800 | + } else { | ||
| 801 | + item.disabled = true; | ||
| 802 | + } | ||
| 803 | + }); | ||
| 804 | + } | ||
| 805 | + // 如果没有选中,解除禁用 | ||
| 806 | + resetUserDisabled(); | ||
| 807 | + } | ||
| 733 | } | 808 | } |
| 734 | /**************** END *****************/ | 809 | /**************** END *****************/ |
| 735 | 810 | ... | ... |
-
Please register or login to post a comment