| | |
| | | permission: false, |
| | | }); |
| | | |
| | | const otherIdList = ref([]); |
| | | const otherIdList = ref([]); |
| | | |
| | | const rules = { |
| | | uname: [ |
| | |
| | | urole: form1.urole, |
| | | }; |
| | | |
| | | // 编辑用户时, 区域中不在管理员管理内的区域要挑出来 最后更新时再追加进去 |
| | | // 编辑用户时, 区域中不在管理员管理内的区域要挑出来 最后更新时再追加进去 |
| | | console.log("params update", params, "============="); |
| | | |
| | | let loading = $loading(); |
| | |
| | | $message.error("表单验证失败"); |
| | | return false; |
| | | } |
| | | |
| | | let params = { |
| | | uname: form1.uname.trim(), |
| | | uid: form1.uid || undefined, |
| | |
| | | // console.log(_data, 'data'); |
| | | console.log(treeList, 'treeList'); |
| | | areaList.value = treeList; |
| | | formatAreaSelected(treeList); |
| | | formatAreaSelected(treeList); |
| | | } catch (e) { |
| | | console.log(e); |
| | | } |
| | |
| | | // } |
| | | // }); |
| | | |
| | | function formatAreaSelected(treeList) { |
| | | let roots = treeList.map(v => v.id); |
| | | let otherAreas = form1.areaId.filter(v=>!v.some((vv) => roots.includes(vv))); |
| | | let otherIds = otherAreas.map(v => v[v.length - 1]); |
| | | function formatAreaSelected(treeList) { |
| | | let roots = treeList.map(v => v.id); |
| | | let otherAreas = form1.areaId.filter(v => !v.some((vv) => roots.includes(vv))); |
| | | let otherIds = otherAreas.map(v => v[v.length - 1]); |
| | | |
| | | otherIdList.value = otherIds; |
| | | |
| | | form1.areaId = form1.areaId.filter(v=>v.some((vv) => roots.includes(vv))).map(v => { |
| | | let idx = 0; |
| | | for (let i = 0; i < roots.length; i++) { |
| | | if (v.includes(roots[i])) { |
| | | idx = v.indexOf(roots[i]); |
| | | break; |
| | | } |
| | | } |
| | | otherIdList.value = otherIds; |
| | | |
| | | return v.slice(idx); |
| | | }); |
| | | console.log('form1.areaId', form1.areaId, '============='); |
| | | |
| | | } |
| | | form1.areaId = form1.areaId.filter(v => v.some((vv) => roots.includes(vv))).map(v => { |
| | | let idx = 0; |
| | | for (let i = 0; i < roots.length; i++) { |
| | | if (v.includes(roots[i])) { |
| | | idx = v.indexOf(roots[i]); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return v.slice(idx); |
| | | }); |
| | | console.log('form1.areaId', form1.areaId, '============='); |
| | | |
| | | } |
| | | |
| | | function handleChange(value) { |
| | | let oldV = value.slice(0, value.length - 1); |
| | | let newV = value[value.length - 1]; |
| | | console.log('value', value, '=============', oldV, newV); |
| | | |
| | | let oldV = value.slice(0, value.length - 1); |
| | | let newV = value[value.length - 1]; |
| | | console.log('value', value, '=============', oldV, newV); |
| | | |
| | | // 检查新选中的项是否与已选中的项有包含关系 |
| | | const hasInclusion = checkInclusion(newV, oldV); |
| | | if (hasInclusion) { |
| | | // 弹出对话框询问用户是否取消之前的项 |
| | | $message.error('取消之前的项(新选中的项与已选中的项存在包含关系)'); |
| | | form1.areaId = value.slice(0, value.length - 1); |
| | | $message.error('取消之前的项(新选中的项与已选中的项存在包含关系)'); |
| | | form1.areaId = value.slice(0, value.length - 1); |
| | | // $confirm('取消之前的项(新选中的项与已选中的项存在包含关系)', () => { |
| | | // form1.areaId = value; |
| | | // }); |
| | |
| | | }; |
| | | |
| | | function checkInclusion(newValue, oldValue) { |
| | | // 遍历新选中的项 |
| | | for (let j = 0; j < oldValue.length; j++) { |
| | | const oldItem = oldValue[j]; |
| | | if (isIncluded(newValue, oldItem) || isIncluded(oldItem, newValue)) { |
| | | return true; |
| | | } |
| | | // 遍历新选中的项 |
| | | for (let j = 0; j < oldValue.length; j++) { |
| | | const oldItem = oldValue[j]; |
| | | if (isIncluded(newValue, oldItem) || isIncluded(oldItem, newValue)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | }; |
| | | |
| | | function isIncluded(item1, item2) { |
| | | // 新元素是一个选项 取数组的最后一个元素 |
| | | const id = item1[item1.length - 1]; |
| | | return item2.includes(id); |
| | | // 新元素是一个选项 取数组的最后一个元素 |
| | | const id = item1[item1.length - 1]; |
| | | return item2.includes(id); |
| | | }; |
| | | |
| | | onMounted(() => { |