feat: 调整了跳转的交互

This commit is contained in:
2026-04-29 16:31:59 +08:00
parent bf76fa89c9
commit 3e572052e8
4 changed files with 66 additions and 3 deletions

View File

@@ -11,3 +11,9 @@ export const SEND_MESSAGE_CONTENT_TEXT = "SEND_MESSAGE_CONTENT_TEXT";
// 发送消息命令类型
export const SEND_MESSAGE_COMMAND_TYPE = "SEND_MESSAGE_COMMAND_TYPE";
// 切换到伴游tab
export const SWITCH_TO_COMPANION_TAB = "SWITCH_TO_COMPANION_TAB";
// 切换到发现tab
export const SWITCH_TO_DISCOVERY_TAB = "SWITCH_TO_DISCOVERY_TAB";

View File

@@ -21,6 +21,18 @@ export const MessageType = {
notice: 4,
};
/// 跳转类型: 0商品 1提示词 2链接 3组件指令
export const JumpType = {
// 商品
commodity: 0,
// 提示词
prompt: 1,
// 链接
link: 2,
// 组件指令
command: 3,
};
/// 组件的名称
export const CompName = {
// 快速预定卡片

View File

@@ -196,6 +196,7 @@
import { onMounted, nextTick, onUnmounted, ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import {
SWITCH_TO_COMPANION_TAB,
SCROLL_TO_BOTTOM,
SEND_MESSAGE_CONTENT_TEXT,
SEND_MESSAGE_COMMAND_TYPE,
@@ -463,6 +464,14 @@ const addNoticeListener = () => {
handleReplyInstruct(item);
}
});
uni.$on(SWITCH_TO_COMPANION_TAB, () => {
tabIndex.value = 1;
});
uni.$on(SWITCH_TO_DISCOVERY_TAB, () => {
tabIndex.value = 0;
});
};
/// =============生命周期函数↓================

View File

@@ -20,6 +20,11 @@
<script setup>
import { onMounted, ref } from "vue";
import { SEND_MESSAGE_CONTENT_TEXT, SEND_MESSAGE_COMMAND_TYPE, SWITCH_TO_COMPANION_TAB } from "@/constant/constant";
import { navigateTo } from "@/router";
import { getAccessToken } from "@/constant/token";
import { checkToken } from "@/hooks/useGoLogin";
import FindTabs from "./components/FindTabs/index.vue";
import CardSwiper from "./components/CardSwiper/index.vue";
import QuickQuestions from "./components/QuickQuestions/index.vue";
@@ -27,6 +32,7 @@ import discoveryCover from "@/components/ImageSwiper/images/2025-07-12_180248.jp
import { homeTabsData, homeTabContentData, homeQuickQuestionData } from "../../request/api/MainPageDataApi";
import { useAppStore } from "@/store";
import { JumpType } from "../../model/ChatModel";
const appStore = useAppStore();
/// 从个渠道获取如二维码
const sceneId = appStore.sceneId || "";
@@ -101,20 +107,50 @@ const configDataList = (data) => {
tabContentId: item.tabContent.id,
jumpContent: item.tabContent.jumpContent,
jumpDesc: item.tabContent.jumpDesc,
jumpType: item.tabContent.jumpType,
jumpType: item.tabContent.jumpType,/// 跳转类型: 0商品 1提示词 2链接 3组件指令
}));
}
/// 卡片点击事件
const handleCardClick = (item) => {
console.log(JSON.stringify(item));
handleClick(item);
};
/// 快速问题点击事件
const handleQuickQuestionClick = (item) => {
console.log(JSON.stringify(item));
handleClick(item);
};
const handleClick = async (item) => {
await checkToken();
console.log(`执行点击事件: ${item.jumpType},参数:${JSON.stringify(item.jumpContent)}`);
/// 商品
if (item.jumpType === JumpType.commodity) {
uni.navigateTo({
url: `/pages/goods/index?commodityId=${item.jumpContent}`,
});
}
/// 提示词
else if (item.jumpType === JumpType.prompt) {
uni.$emit(SWITCH_TO_COMPANION_TAB); /// 切换到伴游tab
uni.$emit(SEND_MESSAGE_CONTENT_TEXT, item.jumpContent);
}
/// 链接
else if (item.jumpType === JumpType.link) {
if (item.jumpContent) {
const token = getAccessToken();
navigateTo(item.jumpContent, { token: token });
}
}
/// 组件指令
else if (item.jumpType === JumpType.command) {
uni.$emit(SWITCH_TO_COMPANION_TAB); /// 切换到伴游tab
uni.$emit(SEND_MESSAGE_COMMAND_TYPE, { type: item.jumpContent, title: item.jumpDesc });
}
}
/// 组件挂载后请求数据
onMounted(() => {
queryTabsList();