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<{
modelValue?: string
disabled?: boolean
orgAndManTree?: any;
}>(),
{}
)
interface User {
id: number
name: string
number: string
key: string
icon: string
department: string
role: string
id: number
name: string
number: string
key: string
icon: string
department: string
role: string
label: string
value: string
}
const emits = defineEmits<{
(e: 'update:modelValue', value: string): void
}>()
const userDialogEl = ref()
const loading = ref(true)
const value = ref([])
watch(value, (newValue) => {
const checkReady = () => {
if (loading.value == false) {
if (newValue.length > 0) {
let str = ""
let userAry = new Array
newValue.forEach(item => {
userAry.push(item)
})
str = userAry.join(',')
//console.log(str)
emits('update:modelValue', str)
} else {
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) {
const loading = ref(true)
watch(value,(newValue)=>{
if(newValue.length > 0){
let str = ""
let userAry = new Array
newValue.forEach(item =>{
//console.log(item)
userAry.push(item)
})
str = userAry.join(',')
//console.log(str)
emits('update:modelValue', str)
// userlist.value = userAry.join(',')
//
}else{
let str = ""
//console.log(str)
emits('update:modelValue', str)
}
},{ deep: true })
function parseStringToArray(str:string) {
try {
// JSON
const result = JSON.parse(str);
@ -94,127 +73,144 @@ function parseStringToArray(str: string) {
}
}
onBeforeMount(() => {
getManConts()
getTree()
setTimeout(() => {
value.value = parseStringToArray(props.modelValue)
}, 700)
//
//checkReady()
//getTree()
setTimeout(()=>{
value.value = parseStringToArray(props.modelValue)
},500 )
})
const url = "/javasys/lowCode/manCont/getManContsByKeys"
//console.log(attrs.value)
const keys = computed(() => {
if (attrs.queryBy == 'role') {
return attrs.roleRange
} else {
return attrs.orgRange
}
const keys = computed(()=>{
if(attrs.queryBy == 'role'){
return attrs.roleRange
}else{
return attrs.orgRange
}
})
function getManContsByKeys() {
//console.log(11111)
return request({
url: url,
method: "post",
data: {
keys: keys.value,
},
});
}
const options = ref([])
function getManConts() {
getManContsByKeys().then(({ data }) => {
data.forEach((element: any) => {
element.icon = element.name + "(" + element.number + ")"
element.deparment = "[" + element.deparment + "] - " + element.icon
element.label = element.deparment
element.value = element.icon
});
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;
const convertToAFormatComplate = ref(false)
function convertToAFormat(bTree, idArray) {
const nodeMap = {};
//
function collectNodes(node, level = 0) {
if (!node) {
//console.log(`: ${node}`);
return;
}
// childrennull
if (node.children && Array.isArray(node.children) && node.children.length > 0) {
for (const child of node.children) {
if (hasLongIdNode(child)) {
return true;
}
}
// 便
//console.log(` [${level}]: id=${node.id}, label=${node.label}`);
// id
if (node.id !== undefined && node.id !== null) {
nodeMap[node.id] = node;
} 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);
}
//
function processNode(node: any) {
// id
if (!hasLongIdNode(node)) {
return null;
}
// id
//console.log(`id:`, Object.keys(nodeMap));
// idArray
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;
}
//
const newNode = { ...node };
function getManConts(){
//
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;
}
}
let data = convertToAFormat(props.orgAndManTree,keys.value)
data.forEach((element: any) => {
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中匹配的节点及其祖先
* @param {Array} treeData - 树形数据
@ -334,39 +330,55 @@ function enrichTreeWithEmployeeInfo(employees: any[], treeData: string | any[])
return treeData;
}
function getTree() {
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
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
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>
@ -374,7 +386,7 @@ function getTree() {
<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 />
</div>
</template>

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

@ -19,6 +19,7 @@ import { SCOPE } from "element-plus";
const props = withDefaults(
defineProps<{
data: any;
orgAndManTree?: any;
}>(),
{
data: () => {
@ -351,6 +352,7 @@ function optionsValue3Get1(data: any, fieldName: string) {
:data="item"
@asf-value-changed="asfValueChanged"
@optionsValue3Get1="optionsValue3Get1"
:org-and-man-tree="orgAndManTree"
/>
</div>
@ -362,6 +364,7 @@ function optionsValue3Get1(data: any, fieldName: string) {
:data="item"
@asf-value-changed="asfValueChanged"
@optionsValue3Get1="optionsValue3Get1"
:org-and-man-tree="orgAndManTree"
/>
</div>
</div>
@ -375,6 +378,7 @@ function optionsValue3Get1(data: any, fieldName: string) {
:data="item"
@asf-value-changed="asfValueChanged"
@optionsValue3Get1="optionsValue3Get1"
:org-and-man-tree="orgAndManTree"
/>
</div>
</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 tables: any[] = [];
function getAsfs() {
@ -1803,6 +1824,7 @@ onMounted(() => {
});
showOrHide("kong");
getAsfs();
getTree1();
});
onUnmounted(() => {
if (eventName) {
@ -2251,6 +2273,7 @@ const webPage = computed({
:node-key="nodeKey"
:purview="purview"
@optionsValue3Get2="optionsValue3Get2"
:org-and-man-tree="orgAndManTree"
/>
<slot></slot>

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

@ -26,6 +26,7 @@ const props = withDefaults(
nodeKey?: string;
purview?: any[];
alldata?: any;
orgAndManTree?: any;
}>(),
{
data: () => {
@ -788,7 +789,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
:label="item.label"
: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-tabs>
</div>
@ -818,7 +819,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
<div class="form-table" v-if="type === 5">
{{ 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-table" />
<form-group :data="element.list" data-type="not-table" :org-and-man-tree="orgAndManTree" />
</div>
<child-table
@ -826,6 +827,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
:data="element"
@asf-value-changed="asfValueChanged"
@optionsValue3GetTable="optionsValue3GetTable"
:org-and-man-tree="orgAndManTree"
/>
</template>
<!--格栅布局-->
@ -846,7 +848,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
:key="i"
@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="item-control">
<i
@ -867,7 +869,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
{{ element.item.label }}
<Tooltips :content="element.help" />
</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>
</template>
@ -888,7 +890,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
[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>
</template>
<!--弹性布局-->
@ -898,7 +900,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
data-type="not-nested"
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 />
<el-button
style="position: relative; top: -28px; left: 10px"
@ -961,6 +963,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
:tablekey="props.tableinfo"
:numrun="props.numrun"
@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;
numrun?: any;
rowIndex?: any;
orgAndManTree?: any;
}>(),
{}
);
@ -1545,6 +1546,7 @@ const diGuiJilian = (val: any, options: any[]) => {
:type="type"
:rowIndex="rowIndex"
v-model="value"
:org-and-man-tree="orgAndManTree"
/>
<component
v-if="['lowcodeImage'].includes(data.type)"

6
src/widget/lowcodetransfer/lowcodeTransfer1.vue

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

Loading…
Cancel
Save