hookehuyr

组织结构组件-搜索单选功能完善

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 18:23:40 4 + * @LastEditTime: 2024-08-05 19:27:33
5 * @FilePath: /data-table/src/components/OrgPickerField/MyComponent.vue 5 * @FilePath: /data-table/src/components/OrgPickerField/MyComponent.vue
6 * @Description: 树形组件 6 * @Description: 树形组件
7 --> 7 -->
...@@ -183,7 +183,10 @@ ...@@ -183,7 +183,10 @@
183 :text="dept.name" 183 :text="dept.name"
184 :key="dept.id" 184 :key="dept.id"
185 :name="dept.id" 185 :name="dept.id"
186 - shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.5rem;"> 186 + shape="square" icon-size="13px"
187 + :checked-color="styleColor.baseColor"
188 + :disabled="dept.disabled"
189 + style="margin-bottom: 0.5rem;">
187 {{ dept.name }} 190 {{ dept.name }}
188 </van-checkbox> 191 </van-checkbox>
189 <div v-if="!user_dept_role.dept.length" style="color: #999;">暂无数据</div> 192 <div v-if="!user_dept_role.dept.length" style="color: #999;">暂无数据</div>
...@@ -201,7 +204,11 @@ ...@@ -201,7 +204,11 @@
201 :text="role.name" 204 :text="role.name"
202 :key="role.id" 205 :key="role.id"
203 :name="role.id" 206 :name="role.id"
204 - shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.8rem;"> 207 + shape="square"
208 + icon-size="13px"
209 + :checked-color="styleColor.baseColor"
210 + :disabled="role.disabled"
211 + style="margin-bottom: 0.8rem;">
205 {{ role.name }} 212 {{ role.name }}
206 </van-checkbox> 213 </van-checkbox>
207 <div v-if="!user_dept_role.role.length" style="color: #999;">暂无数据</div> 214 <div v-if="!user_dept_role.role.length" style="color: #999;">暂无数据</div>
...@@ -219,7 +226,11 @@ ...@@ -219,7 +226,11 @@
219 :text="user.name" 226 :text="user.name"
220 :key="user.id" 227 :key="user.id"
221 :name="user.id" 228 :name="user.id"
222 - shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.5rem;"> 229 + shape="square"
230 + icon-size="13px"
231 + :checked-color="styleColor.baseColor"
232 + :disabled="user.disabled"
233 + style="margin-bottom: 0.5rem;">
223 <div class="van-ellipsis" :style="{ maxWidth: maxWidth + 'px' }"> 234 <div class="van-ellipsis" :style="{ maxWidth: maxWidth + 'px' }">
224 <span>{{ user.name }}</span> 235 <span>{{ user.name }}</span>
225 <span v-if="user.role_list.length">/ 236 <span v-if="user.role_list.length">/
...@@ -326,7 +337,7 @@ onMounted(async () => { ...@@ -326,7 +337,7 @@ onMounted(async () => {
326 // 如果有默认值处理 337 // 如果有默认值处理
327 props.value = props.component_props.default; 338 props.value = props.component_props.default;
328 // TEST 339 // TEST
329 - check_type.value = 'single'; // 默认单选 340 + check_type.value = ''; // 默认单选
330 if (props.value) { 341 if (props.value) {
331 props.value.forEach(item => { 342 props.value.forEach(item => {
332 if (item.type === 'dept') { 343 if (item.type === 'dept') {
...@@ -425,6 +436,22 @@ const search_result_checked = ref([]); ...@@ -425,6 +436,22 @@ const search_result_checked = ref([]);
425 const onSearchBlur = async () => { // 搜索框失去焦点 436 const onSearchBlur = async () => { // 搜索框失去焦点
426 const { code, data } = await searchUserDeptRoleAPI({ form_code: $route.query.code, word: searchValue.value }) 437 const { code, data } = await searchUserDeptRoleAPI({ form_code: $route.query.code, word: searchValue.value })
427 if (code) { 438 if (code) {
439 + // 单选模式
440 + if (check_type.value === 'single') {
441 + if (treeCheckedCount.value) {
442 + let arr = [...checkedGroup.value.dept, ...checkedGroup.value.role, ...checkedGroup.value.user]
443 + for (const key in data) {
444 + const element = data[key];
445 + element.forEach(item => {
446 + if (item.id === arr[0].id) { // 禁用其他
447 + item.disabled = false;
448 + } else {
449 + item.disabled = true;
450 + }
451 + });
452 + }
453 + }
454 + }
428 user_dept_role.value = data; 455 user_dept_role.value = data;
429 } 456 }
430 } 457 }
...@@ -498,6 +525,22 @@ const resetUserDisabled = () => { ...@@ -498,6 +525,22 @@ const resetUserDisabled = () => {
498 } 525 }
499 } 526 }
500 527
528 +const resetSearchDisable = () => {
529 + for (const key in user_dept_role.value) {
530 + const element = user_dept_role.value[key];
531 + element.forEach(item => {
532 + item.disabled = false;
533 + // search_result_checked.value.forEach(val => {
534 + // if (item.id === val) { // 禁用其他
535 + // item.disabled = false;
536 + // } else {
537 + // item.disabled = true;
538 + // }
539 + // })
540 + });
541 + }
542 +}
543 +
501 const onRemoveDeptTag = (dept) => { // 移除部门标签 544 const onRemoveDeptTag = (dept) => { // 移除部门标签
502 // 移除选中框显示 545 // 移除选中框显示
503 const index = checkedGroup.value.dept.findIndex(item => JSON.stringify(item) === JSON.stringify(dept)); 546 const index = checkedGroup.value.dept.findIndex(item => JSON.stringify(item) === JSON.stringify(dept));
...@@ -511,6 +554,7 @@ const onRemoveDeptTag = (dept) => { // 移除部门标签 ...@@ -511,6 +554,7 @@ const onRemoveDeptTag = (dept) => { // 移除部门标签
511 if (check_type.value === 'single') { 554 if (check_type.value === 'single') {
512 resetRoleDisabled();// 重置角色禁用状态 555 resetRoleDisabled();// 重置角色禁用状态
513 resetUserDisabled(); // 重置成员禁用状态 556 resetUserDisabled(); // 重置成员禁用状态
557 + resetSearchDisable(); // 重置搜索结果禁用状态
514 } 558 }
515 } 559 }
516 560
...@@ -527,6 +571,7 @@ const onRemoveRoleTag = (role) => { // 移除角色标签 ...@@ -527,6 +571,7 @@ const onRemoveRoleTag = (role) => { // 移除角色标签
527 if (check_type.value === 'single') { 571 if (check_type.value === 'single') {
528 resetRoleDisabled();// 重置角色禁用状态 572 resetRoleDisabled();// 重置角色禁用状态
529 resetUserDisabled(); // 重置成员禁用状态 573 resetUserDisabled(); // 重置成员禁用状态
574 + resetSearchDisable(); // 重置搜索结果禁用状态
530 } 575 }
531 } 576 }
532 577
...@@ -543,6 +588,7 @@ const onRemoveUserTag = (user) => { // 移除成员标签 ...@@ -543,6 +588,7 @@ const onRemoveUserTag = (user) => { // 移除成员标签
543 if (check_type.value === 'single') { 588 if (check_type.value === 'single') {
544 resetRoleDisabled(); // 重置角色禁用状态 589 resetRoleDisabled(); // 重置角色禁用状态
545 resetUserDisabled(); // 重置成员禁用状态 590 resetUserDisabled(); // 重置成员禁用状态
591 + resetSearchDisable(); // 重置搜索结果禁用状态
546 } 592 }
547 } 593 }
548 594
...@@ -817,7 +863,7 @@ const user_dept_role = ref({ ...@@ -817,7 +863,7 @@ const user_dept_role = ref({
817 863
818 const onSearchResultChange = (val) => { // 监听搜索结果集点击回调,结果集为选中项 864 const onSearchResultChange = (val) => { // 监听搜索结果集点击回调,结果集为选中项
819 } 865 }
820 - 866 +const deptCheckboxRef = ref(null);
821 const onSearchResultClick = (val, evt) => { // 搜索结果集项点击回调 867 const onSearchResultClick = (val, evt) => { // 搜索结果集项点击回调
822 nextTick(() => { 868 nextTick(() => {
823 let checked = false; 869 let checked = false;
...@@ -859,6 +905,29 @@ const onSearchResultClick = (val, evt) => { // 搜索结果集项点击回调 ...@@ -859,6 +905,29 @@ const onSearchResultClick = (val, evt) => { // 搜索结果集项点击回调
859 deptTreeRef.value?.setChecked(obj.id, false); 905 deptTreeRef.value?.setChecked(obj.id, false);
860 } 906 }
861 } 907 }
908 +
909 +
910 + // 单选模式
911 + if (check_type.value === 'single') {
912 + if (val.disabled) { // 节点禁用时不能操作
913 + showToast('单选模式下,只能勾选一个')
914 + return;
915 + }
916 + if (treeCheckedCount.value) {
917 + for (const key in user_dept_role.value) {
918 + const element = user_dept_role.value[key];
919 + element.forEach(item => {
920 + if (item.id === val.id) { // 禁用其他
921 + item.disabled = false;
922 + } else {
923 + item.disabled = true;
924 + }
925 + });
926 + }
927 + } else {
928 + resetSearchDisable();
929 + }
930 + }
862 }); 931 });
863 } 932 }
864 933
......