hookehuyr

fix 组织结构组件-组织结构-新增单选模式

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-03 20:35:36 4 + * @LastEditTime: 2024-08-05 14:40:59
5 * @FilePath: /data-table/src/components/OrgPickerField/MyComponent.vue 5 * @FilePath: /data-table/src/components/OrgPickerField/MyComponent.vue
6 * @Description: 树形组件 6 * @Description: 树形组件
7 --> 7 -->
...@@ -89,6 +89,8 @@ ...@@ -89,6 +89,8 @@
89 :showFooter="false" 89 :showFooter="false"
90 :cascade="false" 90 :cascade="false"
91 :defaultExpandAll="false" 91 :defaultExpandAll="false"
92 + @check="deptTreeCheck"
93 + @uncheck="deptTreeUncheck"
92 @checked-change="deptTreeCheckedChange" 94 @checked-change="deptTreeCheckedChange"
93 style=" height: 60vh; overflow: scroll;" 95 style=" height: 60vh; overflow: scroll;"
94 > 96 >
...@@ -262,7 +264,7 @@ import '@wsfe/vue-tree/style.css'; ...@@ -262,7 +264,7 @@ import '@wsfe/vue-tree/style.css';
262 // import dept_list from './flow_dept_list.json' 264 // import dept_list from './flow_dept_list.json'
263 import $ from 'jquery'; 265 import $ from 'jquery';
264 import _ from 'lodash'; 266 import _ from 'lodash';
265 -import { showDialog } from 'vant'; 267 +import { showDialog, showToast } from 'vant';
266 268
267 // 获取父组件传值 269 // 获取父组件传值
268 const props = inject('props'); 270 const props = inject('props');
...@@ -275,6 +277,21 @@ const $router = useRouter(); ...@@ -275,6 +277,21 @@ const $router = useRouter();
275 let role_list = []; 277 let role_list = [];
276 let dept_list = []; 278 let dept_list = [];
277 279
280 +let check_type = ref(''); // 单选/多选模式
281 +const validateGroupObject = (obj) => {
282 + let flag = false;
283 +
284 + // 获取有值的数组属性
285 + const nonEmptyArrays = [...obj.dept, ...obj.user, ...obj.role];
286 +
287 + // 确保只有一个数组属性有值
288 + if (nonEmptyArrays.length > 1) {
289 + flag = true;
290 + }
291 +
292 + return flag
293 +}
294 +
278 // 处理Tab显示问题 295 // 处理Tab显示问题
279 const tree_tabs = ['dept', 'role', 'user']; 296 const tree_tabs = ['dept', 'role', 'user'];
280 const tabList = computed(() => { 297 const tabList = computed(() => {
...@@ -315,6 +332,8 @@ onMounted(async () => { ...@@ -315,6 +332,8 @@ onMounted(async () => {
315 // 获取已选中数据 332 // 获取已选中数据
316 // 如果有默认值处理 333 // 如果有默认值处理
317 props.value = props.component_props.default; 334 props.value = props.component_props.default;
335 + // TEST
336 + check_type.value = 'single'; // 默认单选
318 if (props.value) { 337 if (props.value) {
319 props.value.forEach(item => { 338 props.value.forEach(item => {
320 if (item.type === 'dept') { 339 if (item.type === 'dept') {
...@@ -549,7 +568,35 @@ const getDeptTreeData = () => { // 获取组织结构数据 ...@@ -549,7 +568,35 @@ const getDeptTreeData = () => { // 获取组织结构数据
549 deptTreeRef.value.setExpand(35697, true); 568 deptTreeRef.value.setExpand(35697, true);
550 } 569 }
551 570
571 +const deptTreeCheck = (node) => { // 组织结构单选勾中
572 + if (check_type.value === 'single' && treeCheckedCount.value) {
573 + showToast('单选模式下,只能勾选一个')
574 + // 移除树结构选中的项
575 + deptTreeRef.value?.setChecked(node.id, false);
576 + }
577 +}
578 +
579 +const deptTreeUncheck = (node) => { // 组织结构单选取消
580 + if (check_type.value === 'single') {
581 + // 移除选中框显示
582 + const index = checkedGroup.value['dept'].findIndex(item => item.id === node.id);
583 + checkedGroup.value['dept'].splice(index, 1);
584 + }
585 +}
586 +
587 +const treeCheckedCount = computed(() => { // 选中框的数量是否大于一
588 + let dept_count = checkedGroup.value.dept.length;
589 + let user_count = checkedGroup.value.user.length;
590 + let role_count = checkedGroup.value.role.length;
591 +
592 + return dept_count + user_count + role_count >= 1;
593 +});
594 +
552 const deptTreeCheckedChange = (arr) => { // 组织结构勾选回调 595 const deptTreeCheckedChange = (arr) => { // 组织结构勾选回调
596 + if (check_type.value === 'single' && treeCheckedCount.value) {
597 + return false
598 + }
599 +
553 checkedGroup.value.dept = arr.map((item) => { 600 checkedGroup.value.dept = arr.map((item) => {
554 return { 601 return {
555 id: item.id, 602 id: item.id,
......