Browse Source

选择组织控件支持多选,支持限制数据范围

qin_26
liwenxuan 2 months ago
parent
commit
f8642d90bc
  1. 14
      src/components/DesignForm/public/expand/org.vue
  2. 105
      src/widget/org/cont.vue

14
src/components/DesignForm/public/expand/org.vue

@ -137,14 +137,20 @@ function haveOrgTreeInfo() {
// IDIDididid
const targetIds = props.data.control.range
//
const filteredTree = filterOrganizationTree(data, targetIds);
orgTreeList.value = filteredTree
console.log(targetIds)
if(targetIds&&targetIds.length>0){
//
const filteredTree = filterOrganizationTree(data, targetIds);
orgTreeList.value = filteredTree
}else{
orgTreeList.value = data;
}
//liwenxuan 250916 end
//orgTreeList.value = data;
})

105
src/widget/org/cont.vue

@ -5,6 +5,8 @@
-->
<script lang='ts' setup>
import { getgovcont } from '@/api/hr/org/index'
import { orgInfo } from "@/api/hr/org/type";
import { getOrgTreeList } from "@/api/hr/org/index";
const props = defineProps({
orgid:{
type: String,
@ -25,29 +27,21 @@ const pickOrgVal = (val:any) => {
if(val != "" && val != null){
if(hasComma(val)){
let arr = commaStringToNumberArray(val)
let str= ''
arr.forEach((element, index, array) => {
//
const isLast = index === array.length - 1;
str = ''
let item = element+""
getgovcont({id:element*1,idstr:item})
.then(({data}) =>{
str+=data.name+","
})
.finally(()=>{
if(isLast){
//alert(1)
str = removeLastChar(str)
orgName.value = str
}
const interval = setInterval(() => {
// reffalse
if (!orgTreeLoading.value) {
})
clearInterval(interval);
let str= ''
str = replaceOrgIdWithName(val,orgTreeList.value)
orgName.value = str
});
}
}, 200);
}else{
@ -120,12 +114,77 @@ function commaStringToNumberArray(str: string) {
});
}
const orgTreeLoading = ref(true); //
onBeforeMount(() => {
pickOrgVal(props.orgid)
//pickOrgVal(props.orgid)
getOrgTreeList({ orgid: 309 })
.then(({ data }) => {
console.log("行政组织树对照值", data);
orgTreeList.value = data;
})
.finally(() => {
orgTreeLoading.value = false;
});
})
/**
* 2. 核心方法输入ID逗号字符串返回名称逗号字符串
* @param {string} idStr - 逗号分隔的ID字符串 "102,103"
* @returns {string} 逗号分隔的名称字符串 "企管部,IT"
*/
function replaceOrgIdWithName(idStr: string,orgTreeData: any) {
//
if (!idStr || typeof idStr !== "string") {
return "";
}
// 1ID
const idToNameMap = {};
// ID
function traverseNodes(nodes: any[]) {
// child: null
if (!nodes || !nodes.length) return;
nodes.forEach((node: { id: string | number; name: any; child: any; }) => {
// IDIDkey
idToNameMap[node.id] = node.name;
//
traverseNodes(node.child);
});
}
//
traverseNodes(orgTreeData);
// 2ID
const result = idStr
.split(",") // ID "102,103" ["102", "103"]
.map(idItem => {
const pureId = idItem.trim(); // "102, 103"
const idNum = Number(pureId); // ID
// IDID
return idToNameMap[idNum] || pureId;
})
.join(","); //
return result;
}
const orgTreeList = ref<orgInfo[]>();
//
const orgTreeProps = {
children: "child",
label: "name",
}; //
onMounted(() => {
pickOrgVal(props.orgid)
});
watch(() =>props.orgid,(val:string) => {
// console.log("-4->",val)

Loading…
Cancel
Save