Browse Source

选择用户优化

lwx_v12
liwenxuan 4 weeks ago
parent
commit
de285cb23a
  1. 201
      src/components/formTable/index.vue
  2. 332
      src/components/lowCode/assistant/rangedUserTree.vue
  3. 2
      src/views/formTable/taskListPage.vue

201
src/components/formTable/index.vue

@ -636,7 +636,7 @@ function checkRangedUserTreesAndGet(){
onMounted(() => { onMounted(() => {
getAsfs() getAsfs()
checkRangedUserTreesAndGet()
getInitModel() getInitModel()
nextTick(() => { nextTick(() => {
@ -1915,6 +1915,7 @@ watch(
}) */ }) */
const treeUrl = '/javasys/lowCode/transfer/getOrgAndManTree' const treeUrl = '/javasys/lowCode/transfer/getOrgAndManTree'
const orgAndManTree = ref() const orgAndManTree = ref()
function getOrgAndManTree() { function getOrgAndManTree() {
return request({ return request({
url: treeUrl, url: treeUrl,
@ -1925,15 +1926,196 @@ function getTree1() {
getOrgAndManTree().then(({ data }) => { getOrgAndManTree().then(({ data }) => {
orgAndManTree.value = data orgAndManTree.value = data
}) }).finally(()=>{
console.log(rangedUserTrees)
// 使
const configArray = rangedUserTrees;
const groupedNames = groupExpandUserConfigs(configArray);
console.log(groupedNames);
groupedNames.forEach((element:any) => {
let keys = element.keys
let arr = []
arr.push(modifyTreeData(orgAndManTree.value,keys))
element.tree = arr
rangedUserTrees.forEach((item:any) => {
let i = 0
element.groupArray.forEach((el:any) => {
if(item.name==el){
i++
}
});
if(i>0){
item.tree = element.tree
}
});
});
rangedUserTrees1.value = rangedUserTrees
})
} }
const rangedUserTrees: any[] = [];
function modifyTreeData(treeData, idList) {
console.log("modifyTreeDataMinimal 执行了");
const idArray = Array.isArray(idList) ? idList : [idList];
if (idArray.length === 0 || !treeData) {
return Array.isArray(treeData) ? [] : null;
}
const roots = Array.isArray(treeData) ? treeData : [treeData];
//
const nodeMap = new Map();
const parentMap = new Map();
// 使
const stack = [...roots];
while (stack.length > 0) {
const node = stack.pop();
if (!node?.id) continue;
nodeMap.set(node.id, node);
if (node.children) {
for (const child of node.children) {
if (child?.id) {
parentMap.set(child.id, node.id);
stack.push(child);
}
}
}
}
//
const keepIds = new Set();
for (const id of idArray) {
let currentId = id;
while (currentId && nodeMap.has(currentId)) {
keepIds.add(currentId);
currentId = parentMap.get(currentId);
}
}
// -
const result = [];
const processedIds = new Set(); // ID
//
for (const root of roots) {
if (!root?.id || !keepIds.has(root.id) || processedIds.has(root.id)) {
continue;
}
processedIds.add(root.id);
result.push(buildNodeTree(root, keepIds, idArray, processedIds));
}
//
nodeMap.clear();
parentMap.clear();
keepIds.clear();
processedIds.clear();
return Array.isArray(treeData) ? result : result[0] || null;
}
//
function buildNodeTree(node, keepIds, idArray, processedIds) {
const newNode = {
id: node.id,
label: node.label,
value: node.value
};
//
if (idArray.includes(node.id)) {
newNode.label = `${node.label}(${node.value || ''})`;
newNode.number = newNode.label;
}
//
if (node.children && node.children.length > 0) {
const children = [];
for (const child of node.children) {
if (child?.id && keepIds.has(child.id) && !processedIds.has(child.id)) {
processedIds.add(child.id);
children.push(buildNodeTree(child, keepIds, idArray, processedIds));
}
}
if (children.length > 0) {
newNode.children = children;
}
}
return newNode;
}
function groupExpandUserConfigs(configs) {
// Map
// keyvaluenameskeys
const groupMap = new Map();
configs.forEach(config => {
// queryBy使
let range, rangeType;
if (config.control.queryBy === 'org') {
range = config.control.orgRange;
rangeType = 'orgRange';
} else {
range = config.control.roleRange;
rangeType = 'roleRange';
}
// key
const sortedRange = [...range].sort().join(',');
// key
if (!groupMap.has(sortedRange)) {
groupMap.set(sortedRange, {
names: [],
keys: range, // keys
rangeType: rangeType
});
}
// name
groupMap.get(sortedRange).names.push(config.name);
});
// Map
const result = [];
for (const groupInfo of groupMap.values()) {
result.push({
groupArray: groupInfo.names,
keys: groupInfo.keys,
rangeType: groupInfo.rangeType //
});
}
return result;
}
const rangedUserTrees1= ref([]);
const rangedUserTrees :any= [];
function getAsfs() { function getAsfs() {
setTimeout(() => { /* setTimeout(() => { */
if(props.formData.list&&props.formData.list.length>0){
let dataList = ref({}); let dataList = ref({});
dataList.value = props.formData.list; dataList.value = props.formData.list;
@ -2011,8 +2193,15 @@ function getAsfs() {
} }
} }
} }
checkRangedUserTreesAndGet()
} }
}, 500); }else{
setTimeout(()=>{
getAsfs()
},100)
}
/* }, 500); */
} }
/* function getAsfs() { /* function getAsfs() {
@ -2114,7 +2303,7 @@ defineExpose({
'design-form': type === 5, 'design-form': type === 5,
'detail-form': type === 3 'detail-form': type === 3
}"> }">
<FormItemGroup :tableinfo="formData.form" :data="formData.list" :alldata="formData" :org-and-man-tree="orgAndManTree" /> <FormItemGroup :tableinfo="formData.form" :data="formData.list" :alldata="formData" :org-and-man-tree="rangedUserTrees1" />
<slot></slot> <slot></slot>
</el-form> </el-form>
</div> </div>

332
src/components/lowCode/assistant/rangedUserTree.vue

@ -1,10 +1,8 @@
<script lang='ts' setup> <script lang='ts' setup>
import { criteriaForPeopleList } from '@/api/hr/org/type'
import SvgIcon from '@/components/svgIcon/index.vue' import { computed,ref,watch,onBeforeMount} from 'vue'
import { useAttrs,computed, onMounted, nextTick,ref,watch,onBeforeMount} from 'vue'
import request from '@/utils/axios/index'
const attrs = useAttrs()
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
modelValue?: string modelValue?: string
@ -12,20 +10,11 @@ const props = withDefaults(
types?:number types?:number
control?:any control?:any
orgAndManTree?: any; orgAndManTree?: any;
data?: any;
}>(), }>(),
{} {}
) )
interface User {
id: number
name: string
number: string
key: string
icon: string
department: string
role: string
label: string
value: string
}
const emits = defineEmits<{ const emits = defineEmits<{
(e: 'update:modelValue', value: string): void (e: 'update:modelValue', value: string): void
}>() }>()
@ -73,7 +62,6 @@ function parseStringToArray(str:string) {
} }
} }
onBeforeMount(() => { onBeforeMount(() => {
checkorgAndManTree()
setTimeout(()=>{ setTimeout(()=>{
value.value = parseStringToArray(props.modelValue) value.value = parseStringToArray(props.modelValue)
},500 ) },500 )
@ -81,267 +69,79 @@ onBeforeMount(() => {
const keys = computed(()=>{ const resData = computed(()=>{
if(attrs.queryBy == 'role'){ return checkorgAndManTree1()
return attrs.roleRange
}else{
return attrs.orgRange
}
}) })
function checkorgAndManTree1(){
// 使 let result = []
const treeData = { let i = 0
"id": "102", props.orgAndManTree.forEach((element : any) => {
"label": "企管部", if(element.hasOwnProperty('tree')&&hasNodesInTree(element.tree)){
"parentId": "309", i++
"children": [
{
"id": "284148167597887488",
"label": "荣潇亭",
"parentId": "102",
"children": null,
"value": "303086",
"treeAttrs": null,
"disabled": null,
"type": null
},
{
"id": "272",
"label": "企管",
"parentId": "102",
"children": [
{
"id": "284148287831805952",
"label": "吴可楠",
"parentId": "272",
"children": null,
"value": "303122",
"treeAttrs": null,
"disabled": null,
"type": null
}
],
"value": null,
"treeAttrs": null,
"disabled": null,
"type": null
} }
], });
"value": null, if(i==props.orgAndManTree.length){
"treeAttrs": null, props.orgAndManTree.forEach((item : any) => {
"disabled": null,
"type": null
};
const idList = ["284148167597887488", "284148287831805952"];
const resData = ref()
const checkorgAndManTree = (()=>{ if(props.data.name==item.name){
if(props.orgAndManTree&&props.orgAndManTree.children&&props.orgAndManTree.children.length>0){ console.log(item.tree)
//alert(1) result = item.tree
let arr = [] }
arr.push(modifyTreeData(props.orgAndManTree,keys.value))
});
resData.value = arr return result
}else{ }else{
setTimeout(()=>{ setTimeout(()=>{
checkorgAndManTree() checkorgAndManTree1()
},100) },100)
} }
})
const resultExample = [{
"id": "102",
"label": "企管部",
"parentId": "309",
"children": [
{
"id": "284148167597887488",
"label": "荣潇亭(303086)",
"parentId": "102",
"children": null,
"value": "303086",
"treeAttrs": null,
"disabled": null,
"type": null,
"number": "荣潇亭(303086)"
},
{
"id": "272",
"label": "企管",
"parentId": "102",
"children": [
{
"id": "284148287831805952",
"label": "吴可楠(303122)",
"parentId": "272",
"children": null,
"value": "303122",
"treeAttrs": null,
"disabled": null,
"type": null,
"number": "吴可楠(303122)"
}
],
"value": null,
"treeAttrs": null,
"disabled": null,
"type": null
}
],
"value": null,
"treeAttrs": null,
"disabled": null,
"type": null
}]
}
function modifyTreeData(treeData, idList) { /**
// * 判断树形结构是否存在节点
const newTreeData = JSON.parse(JSON.stringify(treeData)); * @param {Array} tree 树形结构数组最外层为数组每个节点可能包含children属性
* @returns {boolean} 存在节点返回true否则返回false
// idList */
const idArray = Array.isArray(idList) ? idList : [idList]; function hasNodesInTree(tree) {
if (idArray.length === 0) return Array.isArray(newTreeData) ? [] : null; // false
if (!Array.isArray(tree)) {
// 1. ididid return false;
const nodeMap = new Map(); // id
const parentMap = new Map(); // id id
const multiParentIds = new Set(); // id
function collectNodes(node, parentId) {
if (!node || typeof node !== 'object' || !node.id) return; //
//
if (!nodeMap.has(node.id)) {
nodeMap.set(node.id, node);
}
//
if (parentMap.has(node.id)) {
//
if (parentMap.get(node.id) !== parentId) {
multiParentIds.add(node.id);
}
} else {
parentMap.set(node.id, parentId); //
}
// idid
if (node.children && Array.isArray(node.children)) {
node.children.forEach(child => collectNodes(child, node.id));
}
}
//
if (Array.isArray(newTreeData)) {
newTreeData.forEach(root => collectNodes(root, null)); // idnull
} else {
collectNodes(newTreeData, null);
}
//
if (multiParentIds.size > 0) {
console.warn(`以下节点存在多个父节点,可能导致重复:${Array.from(multiParentIds).join(', ')}`);
} }
// 2. ID+parentMap //
const keepIds = new Set(); function checkNode(node) {
idArray.forEach(targetId => { // null/undefined
let currentId = targetId; if (node == null) {
// parentIdnull return false;
while (currentId !== null && nodeMap.has(currentId)) {
keepIds.add(currentId);
currentId = parentMap.get(currentId); //
}
});
// 3. keepIdsparentId
function filterTree(node) {
if (!node || typeof node !== 'object' || !keepIds.has(node.id)) {
return null;
}
//
const filteredNode = { ...node };
// keepIdsparentIdid
if (filteredNode.children && Array.isArray(filteredNode.children)) {
//
const validChildren = new Map(); // id
filteredNode.children.forEach(child => {
// keepIdsidid
if (child && typeof child === 'object' && child.id &&
keepIds.has(child.id) && parentMap.get(child.id) === filteredNode.id) {
const filteredChild = filterTree(child);
if (filteredChild) {
validChildren.set(filteredChild.id, filteredChild); // id
}
}
});
// null
filteredNode.children = Array.from(validChildren.values());
if (filteredNode.children.length === 0) {
filteredNode.children = null;
}
} else {
filteredNode.children = null;
} }
// true
return filteredNode; return true;
} }
// // true
let filteredTree; for (const node of tree) {
if (Array.isArray(newTreeData)) { if (checkNode(node)) {
// keepIdsnull // 使
filteredTree = newTreeData return true;
.map(root => {
if (root && keepIds.has(root.id) && parentMap.get(root.id) === null) {
return filterTree(root);
}
return null;
})
.filter(Boolean);
} else {
filteredTree = (keepIds.has(newTreeData.id) && parentMap.get(newTreeData.id) === null)
? filterTree(newTreeData)
: null;
}
// 4. labelnumber
function modifyLabels(node) {
if (!node || typeof node !== 'object') return;
if (idArray.includes(node.id)) {
const newLabel = `${node.label}(${node.value || ''})`;
node.label = newLabel;
node.number = newLabel;
} }
//
if (node.children && Array.isArray(node.children)) { if (Array.isArray(node?.children) && hasNodesInTree(node.children)) {
node.children.forEach(child => modifyLabels(child)); return true;
} }
} }
// //
if (Array.isArray(filteredTree)) { return false;
filteredTree.forEach(root => modifyLabels(root));
} else {
modifyLabels(filteredTree);
}
return filteredTree;
} }
const valPrint = (val:any) => { const valPrint = (val:any) => {
if(Array.isArray(val)){ if(Array.isArray(val)){
@ -364,20 +164,6 @@ const valPrint = (val:any) => {
/* ::v-deep .el-tree-node__expand-icon {
font-size: 38px;
width: 34px;
height: 34px;
line-height: 34px;
}
::v-deep .el-tree-node__expand-icon::before {
font-size: 38px;
}
*/
.el-tree-node__expand-icon { .el-tree-node__expand-icon {
color: var(--el-tree-expand-icon-color); color: var(--el-tree-expand-icon-color);

2
src/views/formTable/taskListPage.vue

@ -656,7 +656,7 @@ const performAction = (val) => {}
<TimeAxis v-if="activeName=='4'" ref="cardPageRef" v-model:page-id-ary="pageIdAry" :app-key="appKey" :app-id="appId" :task-id="taskId" :task-key="taskKey" :task-title="taskTitle" :stateList-info="stateList" :state-form="stateForm" :app-flow-info="appFlowInfo" :form-table-str="formTableStr" /> <TimeAxis v-if="activeName=='4'" ref="cardPageRef" v-model:page-id-ary="pageIdAry" :app-key="appKey" :app-id="appId" :task-id="taskId" :task-key="taskKey" :task-title="taskTitle" :stateList-info="stateList" :state-form="stateForm" :app-flow-info="appFlowInfo" :form-table-str="formTableStr" />
<mapPage v-if="activeName=='6'" ref="cardPageRef" v-model:page-id-ary="pageIdAry" :app-key="appKey" :app-id="appId" :task-id="taskId" :task-key="taskKey" :task-title="taskTitle" :stateList-info="stateList" :state-form="stateForm" :app-flow-info="appFlowInfo" :form-table-str="formTableStr" /> <mapPage v-if="activeName=='6'" ref="cardPageRef" v-model:page-id-ary="pageIdAry" :app-key="appKey" :app-id="appId" :task-id="taskId" :task-key="taskKey" :task-title="taskTitle" :stateList-info="stateList" :state-form="stateForm" :app-flow-info="appFlowInfo" :form-table-str="formTableStr" />
<AppPageInfo v-model:is-show="openAppPage" :app-info="appContent" :app-page-info="lookInfo" :state-form="stateForm" :app-flow-info="appFlowInfo" :form-table-str="formTableStr" @searchData="chaxunData" /> <AppPageInfo v-if="openAppPage" v-model:is-show="openAppPage" :app-info="appContent" :app-page-info="lookInfo" :state-form="stateForm" :app-flow-info="appFlowInfo" :form-table-str="formTableStr" @searchData="chaxunData" />
</div> </div>
</template> </template>
<style lang='scss' scoped> <style lang='scss' scoped>

Loading…
Cancel
Save