This commit is contained in:
木瓜一块八 2025-08-20 16:21:09 +08:00
parent 94c95d593e
commit 4bcb3a6371
3 changed files with 46 additions and 11 deletions

View File

@ -23,9 +23,17 @@ export function buildDynamicStructure(data, parentId = null, currentLevel = 1) {
resultNode.second_level_name = node.name; resultNode.second_level_name = node.name;
} else if (currentLevel === 3) { } else if (currentLevel === 3) {
resultNode.third_level_name = node.name; resultNode.third_level_name = node.name;
// 使用后端自带的 source 字段(若存在)
if (node.source !== undefined) {
resultNode.source = node.source;
}
} else if (currentLevel === 4) { } else if (currentLevel === 4) {
// 第四级节点也需要保存name字段 // 第四级节点也需要保存name字段
resultNode.name = node.name; resultNode.name = node.name;
// 使用后端自带的 source 字段(若存在)
if (node.source !== undefined) {
resultNode.source = node.source;
}
} }
// 3. 递归处理子节点 // 3. 递归处理子节点
@ -41,10 +49,17 @@ export function buildDynamicStructure(data, parentId = null, currentLevel = 1) {
// 第四级特殊处理为product_list // 第四级特殊处理为product_list
resultNode.product_list = children.map(child => ({ resultNode.product_list = children.map(child => {
id: child.id, const obj = {
first_level_name: child.name // 修复:使用 child.name 而不是 child.third_level_name id: child.id,
})); first_level_name: child.name // 修复:使用 child.name 而不是 child.third_level_name
}
// 仅在后端提供时透传 source
if (child.source !== undefined) {
obj.source = child.source
}
return obj
});
} }
} }

View File

@ -105,9 +105,10 @@
</aside> </aside>
</template> </template>
<script> <script>
import { reqNcMatchMenu } from '@/api/ncmatch'; import { reqNcMatchMenu, reqSearch } from '@/api/ncmatch';
import { buildDynamicStructure } from './buildNcmatchTree'; import { buildDynamicStructure } from './buildNcmatchTree';
import Talk from '@/views/homePage/dialog/talk/index.vue'; import Talk from '@/views/homePage/dialog/talk/index.vue';
import eventBus from '@/utils/eventBus'
export default { export default {
name: 'menuAside', name: 'menuAside',
components: { components: {
@ -168,13 +169,34 @@ export default {
}); });
}, },
goSearch(product) { goSearch(product) {
this.keyword = 'A800'; console.log("product",product);
this.publish_type ='1'; if(product.source=='search'){
this.$router.push({
path: '/ncmatch/search',
// search /ncmatchHome/search
const keywordFromItem = product && (product.first_level_name || product.product_name || product.second_level_name)
this.keyword = keywordFromItem || this.keyword || ''
this.publish_type = this.publish_type || '1'
this.$router.push({
path: '/ncmatchHome/search',
query: {
keyword: this.keyword,
publish_type: this.publish_type,
display_page: 'list',
current_page: 1,
page_size: 8
}
}).catch(err => {
if (err && err.name !== 'NavigationDuplicated') {
// ignore duplicate
// console.error(err)
}
}) })
this.performFormalSearch(this.keyword, this.publish_type); this.performFormalSearch(this.keyword, this.publish_type);
}else{
this.openTalk()
}
}, },
async openTalk() { async openTalk() {

View File

@ -207,7 +207,6 @@ export default {
// //
return reqSupplyAndDemandFirstCategory({to_page: 'show', url_link: window.location.href }).then(res => { return reqSupplyAndDemandFirstCategory({to_page: 'show', url_link: window.location.href }).then(res => {
if (res.status) { if (res.status) {
this.$message.success('获取一级分类成功')
this.firstCategories = Array.isArray(res.data) ? res.data : [] this.firstCategories = Array.isArray(res.data) ? res.data : []
if (this.firstCategories.length > 0) { if (this.firstCategories.length > 0) {
this.activeFirstId = this.firstCategories[0].id this.activeFirstId = this.firstCategories[0].id
@ -228,7 +227,6 @@ export default {
loadSecondCategories(firstId) { loadSecondCategories(firstId) {
// first_level_id / // first_level_id /
return reqSupplyAndDemandFirstCategory({ to_page: 'show',url_link: window.location.href, first_level_id: firstId }).then(res => { return reqSupplyAndDemandFirstCategory({ to_page: 'show',url_link: window.location.href, first_level_id: firstId }).then(res => {
this.$message.success('获取二级级分类成功')
if (res.status) { if (res.status) {
this.secondCategories = Array.isArray(res.data) ? res.data : [] this.secondCategories = Array.isArray(res.data) ? res.data : []
} else { } else {