|
@@ -17,6 +17,10 @@ const ChildNodeSearch = defineComponent({
|
|
|
list: {
|
|
|
type: Array,
|
|
|
default: () => []
|
|
|
+ },
|
|
|
+ loading: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
}
|
|
|
},
|
|
|
emits: ['selectChildTag'],
|
|
@@ -28,9 +32,43 @@ const ChildNodeSearch = defineComponent({
|
|
|
() => props.activeRow,
|
|
|
() => {
|
|
|
activeRow.value = props.activeRow;
|
|
|
- selectItem.value = {};
|
|
|
+ initActiveRow();
|
|
|
}
|
|
|
);
|
|
|
+
|
|
|
+ const initActiveRow = () => {
|
|
|
+ if (activeRow.value.activeIndex) {
|
|
|
+ const childList = activeRow.value.children || [];
|
|
|
+ childList.forEach((subject: any) => {
|
|
|
+ if (subject.id === activeRow.value.activeIndex) {
|
|
|
+ let children: any;
|
|
|
+ let columnName = '';
|
|
|
+ if (subject.children) {
|
|
|
+ children = [
|
|
|
+ {
|
|
|
+ columnName: subject.children[0].columnName,
|
|
|
+ name: '全部',
|
|
|
+ id: ''
|
|
|
+ },
|
|
|
+ ...subject.children
|
|
|
+ ];
|
|
|
+ columnName = subject.children[0].columnName;
|
|
|
+
|
|
|
+ selectItem.value = {
|
|
|
+ ...subject,
|
|
|
+ columnName,
|
|
|
+ activeIndex: subject.activeIndex,
|
|
|
+ children
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ initActiveRow();
|
|
|
+ });
|
|
|
return () => (
|
|
|
<>
|
|
|
{activeRow.value?.id && (
|
|
@@ -57,6 +95,7 @@ const ChildNodeSearch = defineComponent({
|
|
|
: 'default'
|
|
|
}
|
|
|
onClick={() => {
|
|
|
+ if (props.loading) return;
|
|
|
activeRow.value.activeIndex = subject.id;
|
|
|
let children: any;
|
|
|
let columnName = '';
|
|
@@ -80,7 +119,7 @@ const ChildNodeSearch = defineComponent({
|
|
|
} else {
|
|
|
selectItem.value = {};
|
|
|
}
|
|
|
- emit('selectChildTag', subject);
|
|
|
+ emit('selectChildTag', activeRow.value.activeIndex);
|
|
|
}}>
|
|
|
{subject.name}
|
|
|
</NButton>
|
|
@@ -93,7 +132,7 @@ const ChildNodeSearch = defineComponent({
|
|
|
<ChildNodeSearch
|
|
|
activeRow={selectItem.value}
|
|
|
onSelectChildTag={(item: any) => {
|
|
|
- emit('selectChildTag', item);
|
|
|
+ emit('selectChildTag', item || activeRow.value.activeIndex);
|
|
|
}}
|
|
|
/>
|
|
|
</>
|
|
@@ -134,20 +173,46 @@ export default defineComponent({
|
|
|
// tagActive: {} as any,
|
|
|
childSelectId: xiaokuAi.childSelectId || (null as any)
|
|
|
});
|
|
|
- // const _initTags = () => {
|
|
|
- // const tags = catchStore.getMusicTagTree;
|
|
|
- // data.tags = [
|
|
|
- // {
|
|
|
- // columnName: tags[0].columnName,
|
|
|
- // name: '全部',
|
|
|
- // id: ''
|
|
|
- // },
|
|
|
- // ...tags
|
|
|
- // ];
|
|
|
- // data.tagActiveId = data.tags[0].id;
|
|
|
- // };
|
|
|
+
|
|
|
+ const formatParentId = (id: any, list: any, ids = [] as any) => {
|
|
|
+ for (const item of list) {
|
|
|
+ if (item.children && item.children.length > 0) {
|
|
|
+ const cIds: any = formatParentId(id, item.children, [
|
|
|
+ ...ids,
|
|
|
+ item.id
|
|
|
+ ]);
|
|
|
+ if (cIds.includes(id)) {
|
|
|
+ return cIds;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (item.id === id) {
|
|
|
+ return [...ids, id];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ids;
|
|
|
+ };
|
|
|
+
|
|
|
+ const formatParentCurrentValue = (ids: any, list: any) => {
|
|
|
+ for (const item of list) {
|
|
|
+ if (ids.includes(item.id)) {
|
|
|
+ if (item.children && item.children.length > 0) {
|
|
|
+ let lastId: any;
|
|
|
+ item.children.forEach((child: any) => {
|
|
|
+ if (ids.includes(child.id)) {
|
|
|
+ lastId = child.id;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ item.activeIndex = lastId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (item.children && item.children.length > 0) {
|
|
|
+ formatParentCurrentValue(ids, item.children);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
const changeTag = (item: any) => {
|
|
|
+ if (data.loading) return;
|
|
|
data.tagActiveId = item.id;
|
|
|
data.childSelectId = null;
|
|
|
let children: any;
|
|
@@ -195,9 +260,45 @@ export default defineComponent({
|
|
|
},
|
|
|
...tags
|
|
|
];
|
|
|
- // if (!data.tagActiveId) {
|
|
|
- // }
|
|
|
- data.tagActiveId = data.tags[0].id;
|
|
|
+ if (!data.tagActiveId) {
|
|
|
+ data.tagActiveId = data.tags[0].id;
|
|
|
+ } else {
|
|
|
+ const ids = formatParentId(xiaokuAi.childSelectId, data.tags);
|
|
|
+ formatParentCurrentValue(ids, data.tags);
|
|
|
+ data.tags.forEach((item: any) => {
|
|
|
+ if (item.id === data.tagActiveId) {
|
|
|
+ let children: any;
|
|
|
+ let columnName = '';
|
|
|
+ if (item.children) {
|
|
|
+ children = [
|
|
|
+ {
|
|
|
+ columnName: item.children[0].columnName,
|
|
|
+ name: '全部',
|
|
|
+ id: ''
|
|
|
+ },
|
|
|
+ ...item.children
|
|
|
+ ];
|
|
|
+ columnName = item.children[0].columnName;
|
|
|
+
|
|
|
+ let id: any;
|
|
|
+ item.children.forEach((item: any) => {
|
|
|
+ if (ids.includes(item.id)) {
|
|
|
+ id = item.id;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ data.selectParents = {
|
|
|
+ ...item,
|
|
|
+ columnName,
|
|
|
+ activeIndex: id || '',
|
|
|
+ children
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ data.selectParents = {};
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -248,7 +349,6 @@ export default defineComponent({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- console.log(childInstruments, 'childInstruments');
|
|
|
if (childInstruments.length > 0) {
|
|
|
selectChildObj(childInstruments);
|
|
|
}
|
|
@@ -300,8 +400,9 @@ export default defineComponent({
|
|
|
|
|
|
<ChildNodeSearch
|
|
|
activeRow={data.selectParents}
|
|
|
+ loading={data.loading}
|
|
|
onSelectChildTag={(val: any) => {
|
|
|
- data.childSelectId = val.id;
|
|
|
+ data.childSelectId = val;
|
|
|
localStorage.setItem(
|
|
|
'xiaoku-ai-search',
|
|
|
JSON.stringify({
|