Browse Source

选择用户多选单选兼容

lwx_v12
liwenxuan 2 weeks ago
parent
commit
3743e482b0
  1. 15
      src/components/formTable/index.vue
  2. 123
      src/components/lowCode/assistant/rangedUserTree.vue

15
src/components/formTable/index.vue

@ -1951,13 +1951,23 @@ function getTree1() {
}
});
});
rangedUserTrees1.value = rangedUserTrees
rangedUserTrees1.value = JSON.parse(JSON.stringify(rangedUserTrees))
rangedUserTrees.forEach((item:any) => {
// tree
if (item.hasOwnProperty('tree')) {
// tree
delete item.tree;
}
})
})
}
function modifyTreeData(treeData, idList) {
//console.log("modifyTreeDataMinimal ");
let gkFlag = true
@ -2178,7 +2188,6 @@ function formatAllNodes(node, processedIds) {
}
function groupExpandUserConfigs(configs) {
// Map
// keyvaluenameskeys

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

@ -17,27 +17,79 @@ const emits = defineEmits<{
(e: 'update:modelValue', value: string): void
}>()
const value = ref([])
const treeData = ref([]) //
const isDataLoaded = ref(false) //
const loading = ref(false) //
const treeSelectRef = ref() //
watch(value, (newValue) => {
if (newValue.length > 0) {
let str = ""
let userAry = new Array
newValue.forEach(item => {
userAry.push(item)
})
str = userAry.join(',')
emits('update:modelValue', str)
//
const lastSelectedValue = ref(null)
//
const handleValueChange = (newValue) => {
if (!multiSelect.value) {
//
if (newValue.length === 0) {
//
emits('update:modelValue', '');
lastSelectedValue.value = null;
} else if (newValue.length === 1) {
//
const currentValue = newValue[0];
emits('update:modelValue', currentValue);
lastSelectedValue.value = currentValue;
} else {
//
const newSelections = newValue.filter(item => item !== lastSelectedValue.value);
if (newSelections.length > 0) {
//
const latestSelection = newSelections[newSelections.length - 1];
value.value = [latestSelection];
emits('update:modelValue', latestSelection);
lastSelectedValue.value = latestSelection;
} else {
//
value.value = newValue;
}
}
} else {
let str = ""
emits('update:modelValue', str)
//
if (newValue.length > 0) {
let str = ""
let userAry = new Array
if(Array.isArray(newValue)){
newValue.forEach(item => {
userAry.push(item)
})
str = userAry.join(',')
emits('update:modelValue', str)
}else{
let a = new Array
a.push(newValue)
a.forEach(item => {
userAry.push(item)
})
str = userAry.join(',')
emits('update:modelValue', str)
}
} else {
let str = ""
emits('update:modelValue', str)
}
}
}, { deep: true })
}
watch(value, handleValueChange, { deep: true })
const multiSelect = computed(()=>{
if(props.data.control.multiSelect && props.data.control.multiSelect == "1"){
return true
}else{
return false
}
})
function parseStringToArray(str: string) {
try {
@ -54,10 +106,33 @@ function parseStringToArray(str: string) {
onBeforeMount(() => {
setTimeout(() => {
value.value = parseStringToArray(props.modelValue)
const initialValue = parseStringToArray(props.modelValue)
value.value = initialValue;
if (initialValue.length > 0 && !multiSelect.value) {
lastSelectedValue.value = initialValue[initialValue.length - 1];
}
}, 500)
})
//
const processTreeData = (data: any[]) => {
return data.map(node => {
const newNode = { ...node };
// multiSelectfalseid5
if (!multiSelect.value && node.id && node.id.toString().length < 5) {
newNode.disabled = true;
}
//
if (newNode.children && Array.isArray(newNode.children)) {
newNode.children = processTreeData(newNode.children);
}
return newNode;
});
}
//
const loadFullData = async () => {
if (isDataLoaded.value) return treeData.value;
@ -69,9 +144,13 @@ const loadFullData = async () => {
await new Promise(resolve => setTimeout(resolve, 800));
const result = await checkorgAndManTree1();
treeData.value = result;
// multiSelect
const processedData = !multiSelect.value ? processTreeData(result) : result;
treeData.value = processedData;
isDataLoaded.value = true;
return result;
return processedData;
} catch (error) {
console.error('加载组织数据失败:', error);
return [];
@ -111,7 +190,7 @@ function checkorgAndManTree1() {
if (i == props.orgAndManTree.length) {
props.orgAndManTree.forEach((item: any) => {
if (props.data.name == item.name) {
console.log(item.tree)
//console.log(item.tree)
result = item.tree
}
});
@ -167,9 +246,9 @@ const valPrint = (val: any) => {
node-key="number"
v-model="value"
:data="resData"
multiple
multiple
:render-after-expand="false"
show-checkbox
show-checkbox
clearable
collapse-tags
collapse-tags-tooltip
@ -234,4 +313,10 @@ const valPrint = (val: any) => {
color: #909399;
font-size: 14px;
}
.el-select-dropdown__item.is-disabled {
background-color: unset;
color: #606266;
cursor: not-allowed;
}
</style>
Loading…
Cancel
Save