From ea566950990d72fac100034d16286d0b14e1d033 Mon Sep 17 00:00:00 2001 From: duanshuwen Date: Fri, 26 Dec 2025 22:59:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=99=BB=E5=BD=95=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.config.json | 2 +- src/App.vue | 9 +- src/constant/base.js | 2 +- src/hooks/useGoLogin.js | 26 +-- src/manager/LoginManager.js | 9 +- src/manifest.json | 2 +- .../components/chat/ChatMainList/index.vue | 207 +++++++----------- src/pages/login/index.vue | 45 ++-- 8 files changed, 115 insertions(+), 187 deletions(-) diff --git a/project.config.json b/project.config.json index d102f1b..b241ab1 100644 --- a/project.config.json +++ b/project.config.json @@ -1,5 +1,5 @@ { - "appid": "wx5e79df5996572539", + "appid": "wx23f86d809ae80259", "compileType": "miniprogram", "libVersion": "3.8.10", "packOptions": { diff --git a/src/App.vue b/src/App.vue index 8d59ab8..c5a706b 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,11 +2,16 @@ import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"; import { getEvnUrl } from "@/request/api/config"; import { refreshToken } from "@/hooks/useGoLogin"; -import { checkPhone } from "@/manager/LoginManager"; +import { getStorageSyncToken } from "@/constant/token"; onLaunch(async () => { await getEvnUrl({ versionValue: "1.0.3" }); - refreshToken(); + + const token = getStorageSyncToken(); + + if (token) { + refreshToken(); + } }); onShow(() => { diff --git a/src/constant/base.js b/src/constant/base.js index 5da6ec7..1140fe7 100644 --- a/src/constant/base.js +++ b/src/constant/base.js @@ -12,7 +12,7 @@ import rawConfigs from '../../client-configs.json' with { type: 'json' }; export const CLIENT_CONFIGS = rawConfigs; // 获取当前用户端配置 -export const getCurrentConfig = () => CLIENT_CONFIGS.zhinian; +export const getCurrentConfig = () => CLIENT_CONFIGS.duohua; export const clientId = getCurrentConfig().clientId; export const appId = getCurrentConfig().appId; diff --git a/src/hooks/useGoLogin.js b/src/hooks/useGoLogin.js index 452319d..f9f7c2e 100644 --- a/src/hooks/useGoLogin.js +++ b/src/hooks/useGoLogin.js @@ -1,5 +1,5 @@ -import { wxLogin } from "../request/api/LoginApi"; -import { loginAuth, bindPhone, checkPhone } from "@/manager/LoginManager"; +import { wxLogin, checkUserPhone } from "../request/api/LoginApi"; +import { loginAuth, bindPhone } from "@/manager/LoginManager"; import { clientId } from "@/constant/base"; import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant"; import { getStorageSyncToken, setStorageSyncToken } from "../constant/token"; @@ -22,8 +22,9 @@ export const onLogin = async (e) => { } await loginAuth(e).then(async () => { + console.log("loginAuth resolve success"); // 检查手机号是否绑定 - const checkRes = await checkPhone(); + const checkRes = await checkUserPhone(); if (checkRes.data) { resolve(); return; @@ -61,26 +62,12 @@ export const checkToken = () => { }; // 刷新token -export const refreshToken = () => { +export const refreshToken = () => { return new Promise(async (resolve) => { - const token = getStorageSyncToken(); - - if (!token) { - resolve(true); - return; - } - - const checkRes = await checkPhone(); - - if (!checkRes.data) { - resolve(true); - return; - } - uni.login({ provider: "weixin", //使用微信登录 success: async ({ code }) => { - console.log("refreshToken", code); + console.log("进入 refreshToken success", code); const params = { openIdCode: [code], grant_type: "wechat", @@ -88,6 +75,7 @@ export const refreshToken = () => { clientId: clientId, }; console.log("获取到的微信授权params:", JSON.stringify(params)); + const response = await wxLogin(params); if (response.access_token) { diff --git a/src/manager/LoginManager.js b/src/manager/LoginManager.js index 289dffb..913fcea 100644 --- a/src/manager/LoginManager.js +++ b/src/manager/LoginManager.js @@ -4,7 +4,6 @@ import { checkUserPhone, } from "../request/api/LoginApi"; import { getWeChatAuthCode } from "./AuthManager"; -import { useAppStore } from "@/store"; import { clientId } from "@/constant/base"; import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant"; import { removeStorageSyncToken, setStorageSyncToken } from "../constant/token"; @@ -26,6 +25,7 @@ const loginAuth = (e) => { console.log("获取到的微信授权response:", response); if (response.access_token) { + console.log("进入条件"); setStorageSyncToken(response.access_token); // 登录成功后,触发登录成功事件 uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS); @@ -45,9 +45,4 @@ const bindPhone = async (params) => { } }; -const checkPhone = async () => { - const response = await checkUserPhone(); - return response; -}; - -export { loginAuth, bindPhone, checkPhone }; +export { loginAuth, bindPhone }; diff --git a/src/manifest.json b/src/manifest.json index 4a7d719..263a004 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -60,7 +60,7 @@ 朵花:wx23f86d809ae80259 */ "mp-weixin": { - "appid": "wx5e79df5996572539", + "appid": "wx23f86d809ae80259", "setting": { "urlCheck": false, "minified": true diff --git a/src/pages/index/components/chat/ChatMainList/index.vue b/src/pages/index/components/chat/ChatMainList/index.vue index fe6d8f4..b4e2053 100644 --- a/src/pages/index/components/chat/ChatMainList/index.vue +++ b/src/pages/index/components/chat/ChatMainList/index.vue @@ -2,79 +2,42 @@ - + - + - + @@ -85,21 +48,15 @@ @@ -108,17 +65,9 @@ - + @@ -243,7 +192,7 @@ const handleScroll = ThrottleUtils.createThrottle(({ detail }) => { }, 50); // 处理滚动到底部事件 -const handleScrollToLower = () => {}; +const handleScrollToLower = () => { }; // 滚动到底部 - 优化版本,确保打字机效果始终可见 const scrollToBottom = () => { @@ -474,53 +423,53 @@ const initWebSocket = async () => { }; // 处理WebSocket消息 - const handleWebSocketMessage = (data) => { - const aiMsgIndex = chatMsgList.value.length - 1; - if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) { - console.error("处理WebSocket消息时找不到对应的AI消息项"); - return; - } +const handleWebSocketMessage = (data) => { + const aiMsgIndex = chatMsgList.value.length - 1; + if (!chatMsgList.value[aiMsgIndex] || aiMsgIndex < 0) { + console.error("处理WebSocket消息时找不到对应的AI消息项"); + return; + } - // 确保消息内容是字符串类型 - if (data.content && typeof data.content !== "string") { - data.content = String(data.content); - } + // 确保消息内容是字符串类型 + if (data.content && typeof data.content !== "string") { + data.content = String(data.content); + } - // 直接拼接内容到AI消息 - if (data.content) { - if (chatMsgList.value[aiMsgIndex].isLoading) { + // 直接拼接内容到AI消息 + if (data.content) { + if (chatMsgList.value[aiMsgIndex].isLoading) { + chatMsgList.value[aiMsgIndex].msg = ""; + } + chatMsgList.value[aiMsgIndex].msg += data.content; + chatMsgList.value[aiMsgIndex].isLoading = false; + nextTick(() => scrollToBottom()); + } + + // 处理完成状态 + if (data.finish) { + const msg = chatMsgList.value[aiMsgIndex].msg; + if (!msg || chatMsgList.value[aiMsgIndex].isLoading) { + chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试"; + chatMsgList.value[aiMsgIndex].isLoading = false; + if (data.toolCall) { chatMsgList.value[aiMsgIndex].msg = ""; } - chatMsgList.value[aiMsgIndex].msg += data.content; - chatMsgList.value[aiMsgIndex].isLoading = false; - nextTick(() => scrollToBottom()); } - // 处理完成状态 - if (data.finish) { - const msg = chatMsgList.value[aiMsgIndex].msg; - if (!msg || chatMsgList.value[aiMsgIndex].isLoading) { - chatMsgList.value[aiMsgIndex].msg = "未获取到内容,请重试"; - chatMsgList.value[aiMsgIndex].isLoading = false; - if (data.toolCall) { - chatMsgList.value[aiMsgIndex].msg = ""; - } - } - - // 处理toolCall - if (data.toolCall) { - chatMsgList.value[aiMsgIndex].toolCall = data.toolCall; - } - - // 处理question - if (data.question && data.question.length > 0) { - chatMsgList.value[aiMsgIndex].question = data.question; - } - - // 重置会话状态 - isSessionActive.value = false; + // 处理toolCall + if (data.toolCall) { + chatMsgList.value[aiMsgIndex].toolCall = data.toolCall; } - }; + + // 处理question + if (data.question && data.question.length > 0) { + chatMsgList.value[aiMsgIndex].question = data.question; + } + + // 重置会话状态 + isSessionActive.value = false; + } +}; // 重置消息状态 const resetMessageState = () => { @@ -551,13 +500,13 @@ const sendMessage = async (message, isInstruct = false) => { uni.showLoading({ title: "正在连接服务器...", }); - + // 尝试重新初始化WebSocket连接 try { await initWebSocket(); // 等待短暂时间确保连接建立 await new Promise(resolve => setTimeout(resolve, 1000)); - + // 检查连接是否成功建立 if (!webSocketConnectStatus) { uni.hideLoading(); diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 8d91a2e..dea7c9f 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -17,17 +17,9 @@ @@ -63,12 +45,14 @@ import { ref, computed } from "vue"; import { getServiceAgreement, getPrivacyAgreement, + checkUserPhone } from "@/request/api/LoginApi"; import { onLogin, goBack, refreshToken } from "@/hooks/useGoLogin"; import CheckBox from "@/components/CheckBox/index.vue"; import AgreePopup from "./components/AgreePopup/index.vue"; -import { zniconsMap } from "@/static/fonts/znicons.js"; +import { zniconsMap } from "@/static/fonts/znicons"; import { getCurrentConfig } from "@/constant/base"; +import { getStorageSyncToken } from "@/constant/token"; const needWxLogin = ref(false); const isAgree = ref(false); @@ -106,7 +90,7 @@ const getPhoneNumber = (e) => { }); goBack(); }) - .catch(() => {}); + .catch(() => { }); }; // 处理同意协议点击事件 @@ -142,14 +126,21 @@ getPrivacyAgreementData(); // 页面显示时刷新token onShow(async () => { - const res = await refreshToken(); + const token = getStorageSyncToken(); - needWxLogin.value = res; + if (token) { + const res = await checkUserPhone(); + + needWxLogin.value = res.data; + } else { + needWxLogin.value = true; + } });