表单设计-树形选择、级联选择优化

dianlixunjian
滕嵩 2024-06-19 14:20:37 +08:00
parent 0ca73b71b9
commit 0ff6ca27b7
2 changed files with 33 additions and 32 deletions

View File

@ -26,11 +26,11 @@
<div class="options-box">
<Input
:value="label"
@blur="updateLabelOrValue('label', label, value, $event.target.value)"
@input="updateLabelOrValue('label', label, value, $event.target.value)"
/>
<Input
:value="value"
@blur="updateLabelOrValue('value', label, value, $event.target.value)"
@input="updateLabelOrValue('value', label, value, $event.target.value)"
class="options-value"
/>
<!-- {{ key }}-{{ label }}-{{ value }} -->
@ -89,24 +89,24 @@
// ref
const treeDataAndOptions = ref<TreeItem[]>([]);
//
let len: number = 1;
watch(
() => formConfig.value.currentItem?.component,
() => formConfig.value.currentItem.component,
() => {
if (formConfig.value.currentItem?.component == 'Select') {
treeDataAndOptions.value = [];
key = 'options';
} else if (formConfig.value.currentItem?.component == 'TreeSelect') {
if (formConfig.value.currentItem?.component == 'TreeSelect') {
//
treeDataAndOptions.value = formConfig.value.currentItem?.componentProps?.treeData;
key = 'treeData';
} else if (formConfig.value.currentItem?.component == 'Cascader') {
//
treeDataAndOptions.value = formConfig.value.currentItem?.componentProps?.options;
key = 'options';
} else if (formConfig.value.currentItem?.component == 'Transfer') {
treeDataAndOptions.value = [];
// 穿
key = 'dataSource';
} else {
// --
key = 'options';
}
},
{ deep: true, immediate: true },
@ -119,13 +119,12 @@
}
//
function addTreeNode(value) {
len = 1;
getLength(treeDataAndOptions.value);
let length = getLength(1, treeDataAndOptions.value);
getTree().insertNodeByKey({
parentKey: value,
node: {
label: `选项${len}`,
value: len,
label: `选项${length}`,
value: `${length}`,
},
//
push: 'push',
@ -137,16 +136,18 @@
getTree().deleteNodeByKey(value);
refresh();
}
//
function getLength(treeDataOrOptions) {
treeDataOrOptions.forEach((to) => {
if (to.value) {
len++;
}
//
function getLength(length, treeDataOrOptions) {
treeDataOrOptions?.forEach((to) => {
if (to.children) {
getLength(to.children);
length = getLength(length, to.children);
}
if (length == to.value) {
length++;
length = getLength(length, treeDataOrOptions);
}
});
return length;
}
// labelvalue
function updateLabelOrValue(type, label, value, newLabelOrValue) {

View File

@ -390,17 +390,6 @@ export const commonComponents: IVFormComponent[] = [
],
},
},
{
component: 'Divider',
label: '分割线',
icon: 'radix-icons:divider-horizontal',
colProps: { span: 24 },
field: '',
componentProps: {
orientation: 'center',
dashed: true,
},
},
];
export const baseComponents: IVFormComponent[] = [
@ -581,6 +570,17 @@ export const baseComponents: IVFormComponent[] = [
maxSize: 100,
},
},
{
component: 'Divider',
label: '分割线',
icon: 'radix-icons:divider-horizontal',
colProps: { span: 24 },
field: '',
componentProps: {
orientation: 'center',
dashed: true,
},
},
];
// // https://next.antdv.com/components/transfer-cn