hookehuyr

搜索查询结果API联调

1 <!-- 1 <!--
2 * @Date: 2023-11-01 10:18:53 2 * @Date: 2023-11-01 10:18:53
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-11-23 10:24:27 4 + * @LastEditTime: 2023-11-23 16:00:07
5 * @FilePath: /vue-flow-editor/doc/selectUserView.vue 5 * @FilePath: /vue-flow-editor/doc/selectUserView.vue
6 * @Description: 成员列表选择控件 6 * @Description: 成员列表选择控件
7 --> 7 -->
...@@ -71,7 +71,6 @@ ...@@ -71,7 +71,6 @@
71 </template> 71 </template>
72 <template #append> 72 <template #append>
73 <div class="search-group"> 73 <div class="search-group">
74 - <!-- <div class="confirm-btn" @click="onSearch">搜索</div> -->
75 <div class="cancel-btn" @click="onClearSearch">关闭</div> 74 <div class="cancel-btn" @click="onClearSearch">关闭</div>
76 </div> 75 </div>
77 </template> 76 </template>
...@@ -193,25 +192,69 @@ ...@@ -193,25 +192,69 @@
193 </div> 192 </div>
194 </div> 193 </div>
195 <div v-else style="height: 300px; overflow: scroll;"> 194 <div v-else style="height: 300px; overflow: scroll;">
196 - <el-checkbox-group 195 + <div v-if="searchUserList.dept">
197 - class="flow-checkbox-group" 196 + <div style="margin-top: 5px;">部门</div>
198 - style="padding-left: 10px;" 197 + <template
199 - v-model="checkedSearchUserList" 198 + v-if="searchUserList.dept.length"
199 + v-for="(dept, idx) in searchUserList.dept"
200 + :key="idx"
201 + >
202 + <el-checkbox
203 + style="width: 98%; margin-left: 2%;"
204 + :model-value="dept.checked"
205 + :checked="dept.checked"
206 + :label="dept.id"
207 + @change="handleCheckedUserListChange(dept, $event)"
208 + >
209 + {{ dept.name }}
210 + </el-checkbox>
211 + </template>
212 + <template v-else>
213 + <div style="font-size: 12px; color: gray; margin-top: 5px; margin-left: 2%;">暂无相关部门</div>
214 + </template>
215 + </div>
216 + <div v-if="searchUserList.role">
217 + <div style="margin-top: 5px;">角色</div>
218 + <template
219 + v-if="searchUserList.role.length"
220 + v-for="(role, idx) in searchUserList.role"
221 + :key="idx"
222 + >
223 + <el-checkbox
224 + style="width: 98%; margin-left: 2%;"
225 + :label="role.id"
226 + :model-value="role.checked"
227 + :checked="role.checked"
228 + @change="handleCheckedUserListChange(role, $event)"
200 > 229 >
230 + {{ role.name }}
231 + </el-checkbox>
232 + </template>
233 + <template v-else>
234 + <div style="font-size: 12px; color: gray; margin-top: 5px; margin-left: 2%;">暂无相关角色</div>
235 + </template>
236 + </div>
237 + <div v-if="searchUserList.user">
238 + <div style="margin-top: 5px;">成员</div>
201 <template 239 <template
202 - v-for="(user, idx) in searchUserList" 240 + v-if="searchUserList.user.length"
241 + v-for="(user, idx) in searchUserList.user"
203 :key="idx" 242 :key="idx"
204 > 243 >
205 <el-checkbox 244 <el-checkbox
206 - v-if="user.show" 245 + style="width: 98%; margin-left: 2%;"
207 :label="user.id" 246 :label="user.id"
208 - :disabled="user.disabled" 247 + :model-value="user.checked"
248 + :checked="user.checked"
209 @change="handleCheckedUserListChange(user, $event)" 249 @change="handleCheckedUserListChange(user, $event)"
210 > 250 >
211 {{ user.name }} 251 {{ user.name }}
212 </el-checkbox> 252 </el-checkbox>
213 </template> 253 </template>
214 - </el-checkbox-group> 254 + <template v-else>
255 + <div style="font-size: 12px; color: gray; margin-top: 5px; margin-left: 2%;">暂无相关成员</div>
256 + </template>
257 + </div>
215 </div> 258 </div>
216 </div> 259 </div>
217 <template #footer> 260 <template #footer>
...@@ -269,6 +312,7 @@ const userTabs = ref([ ...@@ -269,6 +312,7 @@ const userTabs = ref([
269 } 312 }
270 ]); 313 ]);
271 const tabSelectData = ref([]); 314 const tabSelectData = ref([]);
315 +const tabCheckedData = ref({}); // 保存选中Tab的数据
272 const userTabType = ref("user-tree"); 316 const userTabType = ref("user-tree");
273 const tabOffset = ref("0px"); 317 const tabOffset = ref("0px");
274 const tabTextWidth = ref("76px"); // 文字宽度需要打开弹框时重新计算 318 const tabTextWidth = ref("76px"); // 文字宽度需要打开弹框时重新计算
...@@ -276,7 +320,7 @@ const is_active_search = ref(false); ...@@ -276,7 +320,7 @@ const is_active_search = ref(false);
276 const search_input = ref(""); 320 const search_input = ref("");
277 const userList = ref([]); 321 const userList = ref([]);
278 const checkedUserList = ref([]); 322 const checkedUserList = ref([]);
279 -const searchUserList = ref([]); // 搜索框 选中 用户ID 323 +const searchUserList = ref({}); // 搜索框 选中 用户ID
280 const checkedSearchUserList = ref([]); 324 const checkedSearchUserList = ref([]);
281 const defaultProps = ref({ 325 const defaultProps = ref({
282 children: "children", 326 children: "children",
...@@ -386,6 +430,7 @@ watch( ...@@ -386,6 +430,7 @@ watch(
386 */ 430 */
387 const handleTabClick = (tab, event, idx) => { 431 const handleTabClick = (tab, event, idx) => {
388 tabSelectData.value = tab.data; // tab选中数据提供给左右选择结构使用 432 tabSelectData.value = tab.data; // tab选中数据提供给左右选择结构使用
433 + tabCheckedData.value = tab; // tab选中数据
389 userList.value = []; // 清空用户列表 434 userList.value = []; // 清空用户列表
390 checkedUserList.value = []; // 清空选中用户列表 435 checkedUserList.value = []; // 清空选中用户列表
391 activeTabContent.value = ""; // 清空侧边栏显示 436 activeTabContent.value = ""; // 清空侧边栏显示
...@@ -403,6 +448,17 @@ const handleTabClick = (tab, event, idx) => { ...@@ -403,6 +448,17 @@ const handleTabClick = (tab, event, idx) => {
403 } 448 }
404 // 文字宽度 449 // 文字宽度
405 tabTextWidth.value = $("#" + tab.id).width() + "px"; 450 tabTextWidth.value = $("#" + tab.id).width() + "px";
451 + // 检查tab是否选中
452 + checkTab(tab);
453 +};
454 +
455 +const checkTab = (tab) => {
456 + if (!tab.type) { // 未点击过tab栏,默认设置组织结构项
457 + nextTick(() => {
458 + // 把用户选中的节点注入树结构显示选中状态
459 + corpTreeRef.value.setCheckedKeys(userTags.value.map(ele => ele.id), false)
460 + });
461 + }
406 // 组织结构树 462 // 组织结构树
407 if (tab.type === 'corp-tree') { 463 if (tab.type === 'corp-tree') {
408 if (tab.data.length) { 464 if (tab.data.length) {
...@@ -432,7 +488,7 @@ const handleTabClick = (tab, event, idx) => { ...@@ -432,7 +488,7 @@ const handleTabClick = (tab, event, idx) => {
432 userList.value = tab.data; 488 userList.value = tab.data;
433 checkedUserList.value = userTags.value.map(ele => ele.id); 489 checkedUserList.value = userTags.value.map(ele => ele.id);
434 } 490 }
435 -}; 491 +}
436 492
437 /** 493 /**
438 * 侧边栏Tab点击回调 494 * 侧边栏Tab点击回调
...@@ -541,6 +597,14 @@ const handleCheckedUserListChange = (user, checked) => { ...@@ -541,6 +597,14 @@ const handleCheckedUserListChange = (user, checked) => {
541 return ele.id!== user.id; 597 return ele.id!== user.id;
542 }); 598 });
543 } 599 }
600 + // 适配搜索栏结果的勾选显示
601 + const element = searchUserList.value[user.type];
602 + for (let index = 0; index < element.length; index++) {
603 + const ele = element[index];
604 + if (user.id === ele.id) {
605 + ele.checked = checked;
606 + }
607 + }
544 }; 608 };
545 609
546 /** 610 /**
...@@ -657,14 +721,7 @@ const confirmUserForm = () => { ...@@ -657,14 +721,7 @@ const confirmUserForm = () => {
657 const activeSearchBtn = () => { 721 const activeSearchBtn = () => {
658 is_active_search.value = !is_active_search.value; 722 is_active_search.value = !is_active_search.value;
659 search_input.value = ''; 723 search_input.value = '';
660 - // 后台数据集合 724 + searchUserList.value = {};
661 - searchUserList.value = _.cloneDeep(deptList.value[0]['user'].concat(roleList.value));
662 - //
663 - searchUserList.value.forEach((ele) => {
664 - ele.show = true;
665 - });
666 - // 如果 tags 里存在的值,需要在搜索列表中勾选
667 - checkSearchStatus();
668 }; 725 };
669 726
670 /** 727 /**
...@@ -673,38 +730,17 @@ const activeSearchBtn = () => { ...@@ -673,38 +730,17 @@ const activeSearchBtn = () => {
673 * @return {void} 730 * @return {void}
674 */ 731 */
675 const checkSearchStatus = () => { 732 const checkSearchStatus = () => {
676 - userTags.value.forEach(ele => { 733 + userTags.value.forEach(tag => {
677 - searchUserList.value.forEach(item => { 734 + for (const key in searchUserList.value) {
678 - if (ele.id === item.id) { 735 + const element = searchUserList.value[key];
679 - item.checked = true; 736 + for (let index = 0; index < element.length; index++) {
737 + const ele = element[index];
738 + if (tag.id === ele.id) {
739 + ele.checked = true;
740 + }
680 } 741 }
681 - });
682 - });
683 - // 显示选中tags的用户
684 - checkedSearchUserList.value = searchUserList.value
685 - .filter(ele => ele.checked)
686 - .map(ele => ele.id);
687 -};
688 -/**
689 - * 在搜索框中同步显示tag框选中的用户
690 - *
691 - * @param {Array} userTags - The array of selected user tags.
692 - * @param {Array} userList - The array of all users.
693 - * @param {Array} checkedUserList - The array of users with selected tags.
694 - * @return {void} No return value.
695 - */
696 -const checkUserStatus = () => {
697 - userTags.value.forEach(ele => {
698 - userList.value.forEach(item => {
699 - if (ele.id === item.id) {
700 - item.checked = true;
701 } 742 }
702 }); 743 });
703 - });
704 - // 显示选中tags的用户
705 - checkedUserList.value = userList.value
706 - .filter(ele => ele.checked)
707 - .map(ele => ele.id);
708 }; 744 };
709 745
710 /** 746 /**
...@@ -715,32 +751,37 @@ const checkUserStatus = () => { ...@@ -715,32 +751,37 @@ const checkUserStatus = () => {
715 const onClearSearch = () => { 751 const onClearSearch = () => {
716 is_active_search.value = !is_active_search.value; 752 is_active_search.value = !is_active_search.value;
717 // 同步显示tag框选中的用户 753 // 同步显示tag框选中的用户
718 - checkUserStatus(); 754 + checkTab(tabCheckedData.value);
719 }; 755 };
756 +
720 /** 757 /**
721 - * 搜索回调 758 + * 搜索栏input回调
722 - * 759 + * @param {*} val
723 - * @return {void} No return value.
724 */ 760 */
725 -const onSearch = () => { 761 +const onSearchInput = (val) => {
726 - // 后台数据集合 762 + axios.get('/admin/?a=search_user_dept_role&word=' + val)
727 - searchUserList.value = _.cloneDeep(deptList.value[0]['user'].concat(roleList.value)); 763 + .then(res => {
728 - // 764 + if (res.data.code) {
729 - searchUserList.value.forEach((ele) => { 765 + searchUserList.value = res.data.data;
730 - ele.show = true; 766 + // 给列表数据绑定默认选中状态
731 - }); 767 + for (const key in searchUserList.value) {
768 + const element = searchUserList.value[key];
769 + if (element.length) {
770 + for (let index = 0; index < element.length; index++) {
771 + const ele = element[index];
772 + ele.checked = false;
773 + }
774 + }
775 + }
732 // 如果 tags 里存在的值,需要在搜索列表中勾选 776 // 如果 tags 里存在的值,需要在搜索列表中勾选
733 checkSearchStatus(); 777 checkSearchStatus();
734 -};
735 -
736 -const onSearchInput = (val) => {
737 - searchUserList.value.forEach((ele) => {
738 - if (ele.name.indexOf(val) > -1) {
739 - ele.show = true;
740 } else { 778 } else {
741 - ele.show = false; 779 +
742 } 780 }
743 }) 781 })
782 + .catch(err => {
783 + console.warn(err);
784 + });
744 } 785 }
745 </script> 786 </script>
746 787
......