|
@@ -16,6 +16,7 @@ export type Props = {
|
|
|
allText?: string;
|
|
allText?: string;
|
|
|
notDefault?: boolean;
|
|
notDefault?: boolean;
|
|
|
disabled?: boolean;
|
|
disabled?: boolean;
|
|
|
|
|
+ currentId?: string | number;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export type Mapper = {
|
|
export type Mapper = {
|
|
@@ -58,6 +59,7 @@ const getTreeSelect = (
|
|
|
options: TreeOption[],
|
|
options: TreeOption[],
|
|
|
value: string
|
|
value: string
|
|
|
): null | TreeOption => {
|
|
): null | TreeOption => {
|
|
|
|
|
+ console.log('options', options, value);
|
|
|
for (const option of options) {
|
|
for (const option of options) {
|
|
|
if (option.value === value) {
|
|
if (option.value === value) {
|
|
|
return option;
|
|
return option;
|
|
@@ -71,6 +73,30 @@ const getTreeSelect = (
|
|
|
return null;
|
|
return null;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+const recursiveSearch = (nodes, currentId) => {
|
|
|
|
|
+ // 如果没有节点,直接返回
|
|
|
|
|
+ if (!nodes || !nodes.length) return;
|
|
|
|
|
+
|
|
|
|
|
+ // 遍历当前节点
|
|
|
|
|
+ for (const node of nodes) {
|
|
|
|
|
+ // 检查是否符合条件
|
|
|
|
|
+ if (node.value === currentId) {
|
|
|
|
|
+ // 如果只需要第一个,直接返回
|
|
|
|
|
+ return [node]; // 终止递归
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果有子节点,递归查询
|
|
|
|
|
+ if (node.children && node.children.length) {
|
|
|
|
|
+ const found = recursiveSearch(node.children, currentId);
|
|
|
|
|
+ // 如果已经找到第一个,终止递归
|
|
|
|
|
+ if(found){
|
|
|
|
|
+ return found;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
const allOption: TreeOption = { label: "全部", value: "" };
|
|
const allOption: TreeOption = { label: "全部", value: "" };
|
|
|
|
|
|
|
|
export const useTreeSelect = <T>(
|
|
export const useTreeSelect = <T>(
|
|
@@ -84,7 +110,13 @@ export const useTreeSelect = <T>(
|
|
|
// 级联控件需要数据
|
|
// 级联控件需要数据
|
|
|
const options = computed<TreeOption[]>(() => {
|
|
const options = computed<TreeOption[]>(() => {
|
|
|
const dataOptions = treeSelectOptionCover(optionsRaw.value, mapping);
|
|
const dataOptions = treeSelectOptionCover(optionsRaw.value, mapping);
|
|
|
- return props.hideAll ? dataOptions : [allOption, ...dataOptions];
|
|
|
|
|
|
|
+ let listOptions = props.hideAll ? dataOptions : [allOption, ...dataOptions]
|
|
|
|
|
+ console.log('listOptions1', listOptions, props.currentId);
|
|
|
|
|
+ console.log('listOptions2', recursiveSearch(listOptions, props.currentId));
|
|
|
|
|
+ if (props.currentId){
|
|
|
|
|
+ return recursiveSearch(listOptions, props.currentId) || listOptions
|
|
|
|
|
+ }
|
|
|
|
|
+ return listOptions;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 级联控件续高亮value
|
|
// 级联控件续高亮value
|