Browse Source

选择用户,性能优化

lwx_v27
liwenxuan 1 month ago
parent
commit
0466ee1a42
  1. 370
      src/components/DesignForm/public/expand/rangedUserTree.vue
  2. 4
      src/components/DesignForm/public/form/childTable.vue
  3. 23
      src/components/DesignForm/public/form/form.vue
  4. 15
      src/components/DesignForm/public/form/formGroup.vue
  5. 2
      src/components/DesignForm/public/form/formItem.vue
  6. 6
      src/widget/lowcodetransfer/lowcodeTransfer1.vue

370
src/components/DesignForm/public/expand/rangedUserTree.vue

@ -9,75 +9,54 @@ const props = withDefaults(
defineProps<{ defineProps<{
modelValue?: string modelValue?: string
disabled?: boolean disabled?: boolean
orgAndManTree?: any;
}>(), }>(),
{} {}
) )
interface User { interface User {
id: number id: number
name: string name: string
number: string number: string
key: string key: string
icon: string icon: string
department: string department: string
role: 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
}>() }>()
const userDialogEl = ref()
const loading = ref(true)
const value = ref([]) const value = ref([])
const loading = ref(true)
watch(value,(newValue)=>{
if(newValue.length > 0){
watch(value, (newValue) => { let str = ""
const checkReady = () => { let userAry = new Array
if (loading.value == false) { newValue.forEach(item =>{
if (newValue.length > 0) { //console.log(item)
let str = "" userAry.push(item)
let userAry = new Array })
str = userAry.join(',')
//console.log(str)
newValue.forEach(item => { emits('update:modelValue', str)
// userlist.value = userAry.join(',')
userAry.push(item) //
}else{
}) let str = ""
//console.log(str)
str = userAry.join(',') emits('update:modelValue', str)
//console.log(str) }
emits('update:modelValue', str) },{ deep: true })
} else { function parseStringToArray(str:string) {
let str = ""
emits('update:modelValue', str)
}
} else {
// 100ms
setTimeout(checkReady, 100)
}
}
//
checkReady()
}, { deep: true })
const openDialog = () => {
// console.log("value-----",value.value)
userDialogEl.value.open()
}
function parseStringToArray(str: string) {
try { try {
// JSON // JSON
const result = JSON.parse(str); const result = JSON.parse(str);
@ -94,127 +73,144 @@ function parseStringToArray(str: string) {
} }
} }
onBeforeMount(() => { onBeforeMount(() => {
getManConts() //
getTree() //checkReady()
setTimeout(() => {
value.value = parseStringToArray(props.modelValue) //getTree()
}, 700) setTimeout(()=>{
value.value = parseStringToArray(props.modelValue)
},500 )
}) })
const url = "/javasys/lowCode/manCont/getManContsByKeys" const url = "/javasys/lowCode/manCont/getManContsByKeys"
//console.log(attrs.value) //console.log(attrs.value)
const keys = computed(() => { const keys = computed(()=>{
if (attrs.queryBy == 'role') { if(attrs.queryBy == 'role'){
return attrs.roleRange return attrs.roleRange
} else { }else{
return attrs.orgRange return attrs.orgRange
} }
}) })
function getManContsByKeys() {
//console.log(11111)
return request({
url: url,
method: "post",
data: {
keys: keys.value,
},
});
}
const options = ref([]) const options = ref([])
const convertToAFormatComplate = ref(false)
function getManConts() { function convertToAFormat(bTree, idArray) {
getManContsByKeys().then(({ data }) => { const nodeMap = {};
data.forEach((element: any) => {
element.icon = element.name + "(" + element.number + ")" //
element.deparment = "[" + element.deparment + "] - " + element.icon function collectNodes(node, level = 0) {
element.label = element.deparment if (!node) {
element.value = element.icon //console.log(`: ${node}`);
}); return;
options.value = data
//console.log(options.value)
})
}
const treeUrl = '/javasys/lowCode/transfer/getOrgAndManTree'
function getOrgAndManTree() {
return request({
url: treeUrl,
method: 'post',
});
}
function processTreeData(node: any) {
// id4
function hasLongIdNode(node: { id: string | any[]; children: string | any[]; }) {
// id
if (node.id && node.id.length > 4) {
return true;
} }
// 便
// childrennull //console.log(` [${level}]: id=${node.id}, label=${node.label}`);
if (node.children && Array.isArray(node.children) && node.children.length > 0) { // id
for (const child of node.children) { if (node.id !== undefined && node.id !== null) {
if (hasLongIdNode(child)) { nodeMap[node.id] = node;
return true; } else {
} //console.warn(`id:`, node);
}
} }
//
if (Array.isArray(node.children)) {
node.children.forEach((child, index) => {
collectNodes(child, level + 1); // +1便
});
} else if (node.children !== null && node.children !== undefined) {
//console.warn(`children:`, node.children);
}
}
return false; //
if (Array.isArray(bTree)) {
//console.log(`bTree${bTree.length}`);
bTree.forEach((root, index) => {
//console.log(`${index + 1}`);
collectNodes(root);
});
} else {
//console.log(`bTree`);
collectNodes(bTree);
} }
// // id
function processNode(node: any) { //console.log(`id:`, Object.keys(nodeMap));
// id
if (!hasLongIdNode(node)) { // idArray
return null; const result = idArray.map(id => {
} // idnodeMap
//console.log(`id: ${id}: ${id in nodeMap}`);
const targetNode = nodeMap[id];
if (!targetNode) return null;
return {
id: targetNode.id,
number: targetNode.value ?? '', // null/undefined
name: targetNode.label ?? '',
icon: null,
key: String(targetNode.id), // keya
role: '',
deparment: '',
parentId: targetNode.parentId ?? ''
};
}).filter(Boolean);
//console.log(`:`, result);
convertToAFormatComplate.value = true
return result;
}
// function getManConts(){
const newNode = { ...node };
//
if (newNode.children && Array.isArray(newNode.children) && newNode.children.length > 0) {
//
newNode.children = newNode.children
.map((child: any) => processNode(child))
.filter((child: null) => child !== null);
// childrennull let data = convertToAFormat(props.orgAndManTree,keys.value)
if (newNode.children.length === 0) { data.forEach((element: any) => {
newNode.children = null; element.icon = element.name+"("+element.number+")"
} element.deparment = ""+element.deparment+">"+element.icon
} element.label = element.deparment
element.value = element.icon
});
options.value = data
return newNode;
}
return processNode(node);
} }
let resData = ref([])
const userList = computed({
get() { /**
@ 作者: 秦东
@ 时间: 2025-06-10 11:13:06
@ 功能: 输出结果
*/
const valPrint = (val:any) => {
if(Array.isArray(val)){
return val.join("、")
}
}
return [{
id: '全选',
label: '全选',
children: [...resData.value]
}]
const resData = computed(()=>{
if(props.orgAndManTree){
let data1 = processTreeData(props.orgAndManTree)
//console.log(data1)
getManConts()
let data2 = filterTreeByList(data1.children, options.value)
data1.children = data2
},
set() {
loading.value = false
return enrichTreeWithEmployeeInfo(options.value, data2)
}else{
return []
} }
}) })
/** /**
* 根据列表数据过滤树形数据保留value值在列表number中匹配的节点及其祖先 * 根据列表数据过滤树形数据保留value值在列表number中匹配的节点及其祖先
* @param {Array} treeData - 树形数据 * @param {Array} treeData - 树形数据
@ -334,39 +330,55 @@ function enrichTreeWithEmployeeInfo(employees: any[], treeData: string | any[])
return treeData; return treeData;
} }
function getTree() { function processTreeData(node: any) {
getOrgAndManTree().then(({ data }) => {
let data1 = processTreeData(data)
//console.log(data1)
let data2 = filterTreeByList(data1.children, options.value)
//console.log(data2)
data1.children = data2
//console.log(resData.value)
//console.log(`穿`);
resData.value = data1.children
userList.value = [{
id: '全选',
label: '全选',
children: [...resData.value]
}]
enrichTreeWithEmployeeInfo(options.value, userList.value)
loading.value = false
}) // id4
} function hasLongIdNode(node: { id: string | any[]; children: string | any[]; }) {
// id
if (node.id && node.id.length > 4) {
return true;
}
// childrennull
if (node.children && Array.isArray(node.children) && node.children.length > 0) {
for (const child of node.children) {
if (hasLongIdNode(child)) {
return true;
}
}
}
return false;
}
//
function processNode(node: any) {
// id
if (!hasLongIdNode(node)) {
return null;
}
//
const newNode = { ...node };
//
if (newNode.children && Array.isArray(newNode.children) && newNode.children.length > 0) {
//
newNode.children = newNode.children
.map((child: any) => processNode(child))
.filter((child: null) => child !== null);
// childrennull
if (newNode.children.length === 0) {
newNode.children = null;
}
}
return newNode;
}
return processNode(node);
}
</script> </script>
@ -374,7 +386,7 @@ function getTree() {
<div style="width:100%"> <div style="width:100%">
<el-tree-select node-key="number" v-model="value" :data="userList" multiple :render-after-expand="false" <el-tree-select node-key="number" v-model="value" :data="resData" multiple :render-after-expand="false"
show-checkbox clearable collapse-tags collapse-tags-tooltip :max-collapse-tags="4" filterable /> show-checkbox clearable collapse-tags collapse-tags-tooltip :max-collapse-tags="4" filterable />
</div> </div>
</template> </template>

4
src/components/DesignForm/public/form/childTable.vue

@ -19,6 +19,7 @@ import { SCOPE } from "element-plus";
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
data: any; data: any;
orgAndManTree?: any;
}>(), }>(),
{ {
data: () => { data: () => {
@ -351,6 +352,7 @@ function optionsValue3Get1(data: any, fieldName: string) {
:data="item" :data="item"
@asf-value-changed="asfValueChanged" @asf-value-changed="asfValueChanged"
@optionsValue3Get1="optionsValue3Get1" @optionsValue3Get1="optionsValue3Get1"
:org-and-man-tree="orgAndManTree"
/> />
</div> </div>
@ -362,6 +364,7 @@ function optionsValue3Get1(data: any, fieldName: string) {
:data="item" :data="item"
@asf-value-changed="asfValueChanged" @asf-value-changed="asfValueChanged"
@optionsValue3Get1="optionsValue3Get1" @optionsValue3Get1="optionsValue3Get1"
:org-and-man-tree="orgAndManTree"
/> />
</div> </div>
</div> </div>
@ -375,6 +378,7 @@ function optionsValue3Get1(data: any, fieldName: string) {
:data="item" :data="item"
@asf-value-changed="asfValueChanged" @asf-value-changed="asfValueChanged"
@optionsValue3Get1="optionsValue3Get1" @optionsValue3Get1="optionsValue3Get1"
:org-and-man-tree="orgAndManTree"
/> />
</div> </div>
</template> </template>

23
src/components/DesignForm/public/form/form.vue

@ -1716,6 +1716,27 @@ watch(
} }
); );
// ------------------------------------------------ // ------------------------------------------------
const treeUrl = '/javasys/lowCode/transfer/getOrgAndManTree'
const orgAndManTree = ref()
function getOrgAndManTree() {
return request({
url: treeUrl,
method: 'post',
});
}
function getTree1() {
getOrgAndManTree().then(({ data }) => {
orgAndManTree.value = data
})
}
const asfs: any[] = []; const asfs: any[] = [];
const tables: any[] = []; const tables: any[] = [];
function getAsfs() { function getAsfs() {
@ -1803,6 +1824,7 @@ onMounted(() => {
}); });
showOrHide("kong"); showOrHide("kong");
getAsfs(); getAsfs();
getTree1();
}); });
onUnmounted(() => { onUnmounted(() => {
if (eventName) { if (eventName) {
@ -2251,6 +2273,7 @@ const webPage = computed({
:node-key="nodeKey" :node-key="nodeKey"
:purview="purview" :purview="purview"
@optionsValue3Get2="optionsValue3Get2" @optionsValue3Get2="optionsValue3Get2"
:org-and-man-tree="orgAndManTree"
/> />
<slot></slot> <slot></slot>

15
src/components/DesignForm/public/form/formGroup.vue

@ -26,6 +26,7 @@ const props = withDefaults(
nodeKey?: string; nodeKey?: string;
purview?: any[]; purview?: any[];
alldata?: any; alldata?: any;
orgAndManTree?: any;
}>(), }>(),
{ {
data: () => { data: () => {
@ -788,7 +789,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
:label="item.label" :label="item.label"
:key="tIndex" :key="tIndex"
> >
<form-group :data="item.list" data-type="not-nested" /> <form-group :data="item.list" data-type="not-nested" :org-and-man-tree="orgAndManTree" />
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
@ -818,7 +819,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
<div class="form-table" v-if="type === 5"> <div class="form-table" v-if="type === 5">
{{ element.item ? (element.item.label ? element.item.label : 2) : 3 }} {{ element.item ? (element.item.label ? element.item.label : 2) : 3 }}
<!-- <form-group :data="element.list" data-type="not-nested" /> --> <!-- <form-group :data="element.list" data-type="not-nested" /> -->
<form-group :data="element.list" data-type="not-table" /> <form-group :data="element.list" data-type="not-table" :org-and-man-tree="orgAndManTree" />
</div> </div>
<child-table <child-table
@ -826,6 +827,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
:data="element" :data="element"
@asf-value-changed="asfValueChanged" @asf-value-changed="asfValueChanged"
@optionsValue3GetTable="optionsValue3GetTable" @optionsValue3GetTable="optionsValue3GetTable"
:org-and-man-tree="orgAndManTree"
/> />
</template> </template>
<!--格栅布局--> <!--格栅布局-->
@ -846,7 +848,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
:key="i" :key="i"
@click.stop="groupClick(col, 'gridChild')" @click.stop="groupClick(col, 'gridChild')"
> >
<form-group :data="col.list" data-type="not-nested" /> <form-group :data="col.list" data-type="not-nested" :org-and-man-tree="orgAndManTree" />
<div class="drag-control" v-if="type === 5"> <div class="drag-control" v-if="type === 5">
<div class="item-control"> <div class="item-control">
<i <i
@ -867,7 +869,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
{{ element.item.label }} {{ element.item.label }}
<Tooltips :content="element.help" /> <Tooltips :content="element.help" />
</template> </template>
<form-group :data="element.list" data-type="not-nested" /> <form-group :data="element.list" data-type="not-nested" :org-and-man-tree="orgAndManTree" />
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
</template> </template>
@ -888,7 +890,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
[element.config?.textAlign]: element.config?.textAlign, [element.config?.textAlign]: element.config?.textAlign,
}" }"
> >
<form-group :data="element.list" data-type="not-nested" /> <form-group :data="element.list" data-type="not-nested" :org-and-man-tree="orgAndManTree" />
</div> </div>
</template> </template>
<!--弹性布局--> <!--弹性布局-->
@ -898,7 +900,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
data-type="not-nested" data-type="not-nested"
v-if="type === 5" v-if="type === 5"
/> --> /> -->
<form-group :data="element.list" data-type="not-flex" v-if="type === 5" /> <form-group :data="element.list" data-type="not-flex" v-if="type === 5" :org-and-man-tree="orgAndManTree" />
<flex-box :data="element" v-else /> <flex-box :data="element" v-else />
<el-button <el-button
style="position: relative; top: -28px; left: 10px" style="position: relative; top: -28px; left: 10px"
@ -961,6 +963,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
:tablekey="props.tableinfo" :tablekey="props.tableinfo"
:numrun="props.numrun" :numrun="props.numrun"
@asf-value-changed="asfValueChanged" @asf-value-changed="asfValueChanged"
:org-and-man-tree="orgAndManTree"
/> />
<!--组件设计外功能框架--> <!--组件设计外功能框架-->

2
src/components/DesignForm/public/form/formItem.vue

@ -75,6 +75,7 @@ const props = withDefaults(
tablekey?: any; tablekey?: any;
numrun?: any; numrun?: any;
rowIndex?: any; rowIndex?: any;
orgAndManTree?: any;
}>(), }>(),
{} {}
); );
@ -1545,6 +1546,7 @@ const diGuiJilian = (val: any, options: any[]) => {
:type="type" :type="type"
:rowIndex="rowIndex" :rowIndex="rowIndex"
v-model="value" v-model="value"
:org-and-man-tree="orgAndManTree"
/> />
<component <component
v-if="['lowcodeImage'].includes(data.type)" v-if="['lowcodeImage'].includes(data.type)"

6
src/widget/lowcodetransfer/lowcodeTransfer1.vue

@ -24,7 +24,7 @@
</div> </div>
</div> </div>
<div class="rigthArea"> <!-- <div class="rigthArea">
<div style="margin-bottom: 8px;"> <div style="margin-bottom: 8px;">
<div class="transferName"><span>已选: {{ checkList.length }}</span> <div class="transferName"><span>已选: {{ checkList.length }}</span>
<ElButton link style="float: right;margin-right: 5px;" @click="clearCheckList">清空</ElButton> <ElButton link style="float: right;margin-right: 5px;" @click="clearCheckList">清空</ElButton>
@ -45,7 +45,7 @@
</ElTag> </ElTag>
</ElScrollbar> </ElScrollbar>
</div> </div> -->
</div> </div>
</template> </template>
@ -878,7 +878,7 @@ watch(selectedValueCompu, (newValue, oldValue) => {
.leftArea { .leftArea {
border: 1px solid gainsboro; border: 1px solid gainsboro;
width: 300px; width: 500px;
border-radius: 5px; border-radius: 5px;
height: 456px; height: 456px;
position: relative; position: relative;

Loading…
Cancel
Save