hookehuyr

联调树形结构组件接口

1 /* 1 /*
2 * @Date: 2022-06-17 14:54:29 2 * @Date: 2022-06-17 14:54:29
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-11-17 16:00:04 4 + * @LastEditTime: 2024-06-05 10:12:06
5 * @FilePath: /data-table/src/api/component.js 5 * @FilePath: /data-table/src/api/component.js
6 * @Description: 组件接口 6 * @Description: 组件接口
7 */ 7 */
...@@ -9,6 +9,9 @@ import { fn, fetch } from '@/api/fn'; ...@@ -9,6 +9,9 @@ import { fn, fetch } from '@/api/fn';
9 9
10 const Api = { 10 const Api = {
11 QUERY_COMPONENT: '/srv/?a=query_component', 11 QUERY_COMPONENT: '/srv/?a=query_component',
12 + FLOW_DEPT_LIST: '/srv/?a=flow_setting&t=flow_dept_list',
13 + FLOW_ROLE_LIST: '/srv/?a=flow_setting&t=flow_role_list',
14 + SEARCH_USER_DEPT_ROLE: '/srv/?a=flow_setting&t=search_user_dept_role',
12 } 15 }
13 16
14 /** 17 /**
...@@ -18,3 +21,22 @@ const Api = { ...@@ -18,3 +21,22 @@ const Api = {
18 * @param: name 组件名称;条件:模糊查询; 21 * @param: name 组件名称;条件:模糊查询;
19 */ 22 */
20 export const getComponentAPI = (params) => fn(fetch.get(Api.QUERY_COMPONENT, params)); 23 export const getComponentAPI = (params) => fn(fetch.get(Api.QUERY_COMPONENT, params));
24 +
25 +/**
26 + * @description: 查询部门列表
27 + * @param: form_code 表单code
28 + */
29 +export const getFlowDeptListAPI = (params) => fn(fetch.get(Api.FLOW_DEPT_LIST, params));
30 +
31 +/**
32 + * @description: 查询角色列表
33 + * @param: form_code 表单code
34 + */
35 +export const getFlowRoleListAPI = (params) => fn(fetch.get(Api.FLOW_ROLE_LIST, params));
36 +
37 +/**
38 + * @description: 查询用户部门角色
39 + * @param: form_code 表单code
40 + * @param: word 搜索内容
41 + */
42 +export const searchUserDeptRoleAPI = (params) => fn(fetch.get(Api.SEARCH_USER_DEPT_ROLE, params));
......
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-06-04 14:02:58 4 + * @LastEditTime: 2024-06-05 10:34:32
5 * @FilePath: /data-table/src/components/OrgPickerField/MyComponent.vue 5 * @FilePath: /data-table/src/components/OrgPickerField/MyComponent.vue
6 * @Description: 树形组件 6 * @Description: 树形组件
7 --> 7 -->
...@@ -148,8 +148,9 @@ ...@@ -148,8 +148,9 @@
148 @change="onSearchResultChange" 148 @change="onSearchResultChange"
149 > 149 >
150 <div> 150 <div>
151 - <p>部门</p> 151 + <p style="font-weight: bold;">部门</p>
152 - <div> 152 + <div style="border-top: 1px solid #eee; margin: 0.5rem 0;"></div>
153 + <div style="margin-bottom: 1rem;">
153 <van-checkbox 154 <van-checkbox
154 @click="onSearchResultClick(dept, $event)" 155 @click="onSearchResultClick(dept, $event)"
155 v-for="(dept) in user_dept_role.dept" 156 v-for="(dept) in user_dept_role.dept"
...@@ -161,11 +162,13 @@ ...@@ -161,11 +162,13 @@
161 shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.5rem;"> 162 shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.5rem;">
162 {{ dept.name }} 163 {{ dept.name }}
163 </van-checkbox> 164 </van-checkbox>
165 + <div v-if="!user_dept_role.dept.length" style="color: #999;">暂无数据</div>
164 </div> 166 </div>
165 </div> 167 </div>
166 <div> 168 <div>
167 <p>角色</p> 169 <p>角色</p>
168 - <div> 170 + <div style="border-top: 1px solid #eee; margin: 0.5rem 0;"></div>
171 + <div style="margin-bottom: 1rem;">
169 <van-checkbox 172 <van-checkbox
170 @click="onSearchResultClick(role, $event)" 173 @click="onSearchResultClick(role, $event)"
171 v-for="(role) in user_dept_role.role" 174 v-for="(role) in user_dept_role.role"
...@@ -177,11 +180,13 @@ ...@@ -177,11 +180,13 @@
177 shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.8rem;"> 180 shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.8rem;">
178 {{ role.name }} 181 {{ role.name }}
179 </van-checkbox> 182 </van-checkbox>
183 + <div v-if="!user_dept_role.role.length" style="color: #999;">暂无数据</div>
180 </div> 184 </div>
181 </div> 185 </div>
182 <div> 186 <div>
183 <p>成员</p> 187 <p>成员</p>
184 - <div> 188 + <div style="border-top: 1px solid #eee; margin: 0.5rem 0;"></div>
189 + <div style="margin-bottom: 1rem;">
185 <van-checkbox 190 <van-checkbox
186 @click="onSearchResultClick(user, $event)" 191 @click="onSearchResultClick(user, $event)"
187 v-for="(user) in user_dept_role.user" 192 v-for="(user) in user_dept_role.user"
...@@ -193,10 +198,9 @@ ...@@ -193,10 +198,9 @@
193 shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.5rem;"> 198 shape="square" icon-size="13px" :checked-color="styleColor.baseColor" style="margin-bottom: 0.5rem;">
194 {{ user.name }} 199 {{ user.name }}
195 </van-checkbox> 200 </van-checkbox>
201 + <div v-if="!user_dept_role.user.length" style="color: #999;">暂无数据</div>
196 </div> 202 </div>
197 </div> 203 </div>
198 -
199 - {{ search_result_checked }}
200 </van-checkbox-group> 204 </van-checkbox-group>
201 </div> 205 </div>
202 206
...@@ -219,22 +223,37 @@ ...@@ -219,22 +223,37 @@
219 import { inject, ref } from 'vue' 223 import { inject, ref } from 'vue'
220 import { useCustomFieldValue } from '@vant/use'; 224 import { useCustomFieldValue } from '@vant/use';
221 import { styleColor } from "@/constant.js"; 225 import { styleColor } from "@/constant.js";
226 +import { getFlowDeptListAPI, getFlowRoleListAPI, searchUserDeptRoleAPI } from "@/api/component.js";
222 // 大家可以根据需要是否引入VTreeNode, VTreeSearch, VTreeDrop 227 // 大家可以根据需要是否引入VTreeNode, VTreeSearch, VTreeDrop
223 import Vtree, { VTreeNode, VTreeSearch, VTreeDrop } from '@wsfe/vue-tree' 228 import Vtree, { VTreeNode, VTreeSearch, VTreeDrop } from '@wsfe/vue-tree'
224 import '@wsfe/vue-tree/style.css'; 229 import '@wsfe/vue-tree/style.css';
225 -import role_list from './flow_role_list.json' 230 +// import role_list from './flow_role_list.json'
226 -import dept_list from './flow_dept_list.json' 231 +// import dept_list from './flow_dept_list.json'
227 import $ from 'jquery'; 232 import $ from 'jquery';
228 import _ from 'lodash'; 233 import _ from 'lodash';
229 234
230 // 获取父组件传值 235 // 获取父组件传值
231 const props = inject('props'); 236 const props = inject('props');
232 -console.log("🚀 ~ file: MyComponent.vue:227 ~ props:", props);
233 237
234 const emit = defineEmits(["active"]); 238 const emit = defineEmits(["active"]);
235 239
236 -onMounted(() => { 240 +const $route = useRoute();
237 - // TODO:获取已选中数据 241 +const $router = useRouter();
242 +
243 +let role_list = [];
244 +let dept_list = [];
245 +
246 +onMounted(async () => {
247 + // TAG: 获取后台数据
248 + const flowDeptList = await getFlowDeptListAPI({ form_code: $route.query.code });
249 + if (flowDeptList.code) {
250 + role_list = flowDeptList.data;
251 + }
252 + const flowRoleList = await getFlowRoleListAPI({ form_code: $route.query.code });
253 + if (flowRoleList.code) {
254 + dept_list = flowRoleList.data;
255 + }
256 + // 获取已选中数据
238 // 如果有默认值处理 257 // 如果有默认值处理
239 if (props.value) { 258 if (props.value) {
240 let default_value = JSON.parse(props.value); 259 let default_value = JSON.parse(props.value);
...@@ -252,7 +271,7 @@ onMounted(() => { ...@@ -252,7 +271,7 @@ onMounted(() => {
252 271
253 const openTree = () => { 272 const openTree = () => {
254 showPopover.value = true; 273 showPopover.value = true;
255 - // TODO:获取数据 274 + // 获取数据
256 nextTick(() => { 275 nextTick(() => {
257 getDeptTreeData(); 276 getDeptTreeData();
258 // 获取已选择的数据 277 // 获取已选择的数据
...@@ -301,7 +320,11 @@ const is_search = ref(false); // 默认不显示搜索框 ...@@ -301,7 +320,11 @@ const is_search = ref(false); // 默认不显示搜索框
301 */ 320 */
302 const search_result_checked = ref([]); 321 const search_result_checked = ref([]);
303 322
304 -const onSearchBlur = () => { // 搜索框失去焦点 323 +const onSearchBlur = async () => { // 搜索框失去焦点
324 + const { code, data } = await searchUserDeptRoleAPI({ form_code: $route.query.code, word: searchValue.value })
325 + if (code) {
326 + user_dept_role.value = data;
327 + }
305 } 328 }
306 329
307 const onSearchFocus = () => { // 搜索框获取焦点回调 330 const onSearchFocus = () => { // 搜索框获取焦点回调
...@@ -313,7 +336,6 @@ const onSearchFocus = () => { // 搜索框获取焦点回调 ...@@ -313,7 +336,6 @@ const onSearchFocus = () => { // 搜索框获取焦点回调
313 }); 336 });
314 337
315 // 如果选中框有值,点击搜索框后把结果选中到搜索结果集里面 338 // 如果选中框有值,点击搜索框后把结果选中到搜索结果集里面
316 - // TODO:待实现 真实情况应该是请求搜索结果后做
317 handleSelectToSearch(); 339 handleSelectToSearch();
318 } 340 }
319 341
...@@ -334,6 +356,12 @@ const syncResultToList = () => { // 把弹框结果集同步到树形选择树 ...@@ -334,6 +356,12 @@ const syncResultToList = () => { // 把弹框结果集同步到树形选择树
334 } 356 }
335 357
336 const onCloseSearch = () => { // 点击搜索关闭按钮回调 358 const onCloseSearch = () => { // 点击搜索关闭按钮回调
359 + searchValue.value = ''; // 清空搜索框
360 + user_dept_role.value = {
361 + dept: [],
362 + role: [],
363 + user: []
364 + }; // 清空搜索结果
337 tabActive.value = 0; // 默认选中组织结构 365 tabActive.value = 0; // 默认选中组织结构
338 is_search.value = false; // 关闭搜索状态 366 is_search.value = false; // 关闭搜索状态
339 syncResultToList(); // 同步勾选状态 367 syncResultToList(); // 同步勾选状态
...@@ -504,44 +532,10 @@ const onCheckUserChange = (val, evt) => { ...@@ -504,44 +532,10 @@ const onCheckUserChange = (val, evt) => {
504 /**************** END *****************/ 532 /**************** END *****************/
505 533
506 /***************** 搜索结果集模块 ********************/ 534 /***************** 搜索结果集模块 ********************/
507 -
508 -// 模拟数据
509 const user_dept_role = ref({ 535 const user_dept_role = ref({
510 - "dept": [ 536 + dept: [],
511 - { 537 + role: [],
512 - "type": "dept", 538 + user: []
513 - "name": "男10组",
514 - "id": 137571
515 - }, {
516 - "type": "dept",
517 - "name": "主持组",
518 - "id": 107700
519 - }
520 - ],
521 - "role": [
522 - {
523 - "type": "role",
524 - "name": "八关斋戒",
525 - "id": 624337
526 - },
527 - {
528 - "id": 82983,
529 - "name": "场地管理",
530 - "type": "role"
531 - }
532 - ],
533 - "user": [
534 - {
535 - "id": 137918,
536 - "name": "10组寝室长",
537 - "type": "user"
538 - },
539 - {
540 - "id": 137919,
541 - "name": "11组寝室长",
542 - "type": "user"
543 - }
544 - ]
545 }); 539 });
546 540
547 const onSearchResultChange = (val) => { // 监听搜索结果集点击回调,结果集为选中项 541 const onSearchResultChange = (val) => { // 监听搜索结果集点击回调,结果集为选中项
...@@ -675,4 +669,10 @@ useCustomFieldValue(() => tree_select_value.value); ...@@ -675,4 +669,10 @@ useCustomFieldValue(() => tree_select_value.value);
675 align-items: center; 669 align-items: center;
676 } 670 }
677 } 671 }
672 +
673 +.search-container {
674 + margin: 1rem 5px;
675 + height: 60vh;
676 + overflow: scroll;
677 +}
678 </style> 678 </style>
......