From df52c039d869ac567f20fc4ecb0b79c74a9d9815 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Sat, 19 Sep 2026 21:16:00 +0800 Subject: [PATCH] =?UTF-8?q?fix+feat:=20=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8C=89=E9=92=AE=E4=B8=8D=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D(isMiniApp=E7=BC=96=E8=AF=91=E6=9C=9F?= =?UTF-8?q?=E5=88=A4=E5=AE=9A)=EF=BC=9B=E9=9D=99=E9=BB=98=E7=99=BB?= =?UTF-8?q?=E5=BD=95ensureLogin=E2=80=94=E2=80=94=E6=94=B6=E8=97=8F/?= =?UTF-8?q?=E6=B8=B8=E5=AE=A2=E9=97=AE=E7=AD=94=E9=A2=9D=E5=BA=A6=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E4=B8=80=E9=94=AE=E6=97=A0=E6=84=9F=E7=99=BB=E5=BD=95?= =?UTF-8?q?=EF=BC=9B=E7=89=88=E6=9C=ACv1.4.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/manifest.json | 2 +- client/src/pages/chat/chat.vue | 9 ++++++++- client/src/pages/detail/detail.vue | 26 +++++++++++++++----------- client/src/pages/login/login.vue | 12 +++++------- client/src/pages/news/news.vue | 14 +++++++++++++- client/src/stores/user.js | 22 ++++++++++++++++++++++ 6 files changed, 64 insertions(+), 21 deletions(-) diff --git a/client/src/manifest.json b/client/src/manifest.json index 70a70b2..3273520 100644 --- a/client/src/manifest.json +++ b/client/src/manifest.json @@ -1,7 +1,7 @@ { "name": "宇之然AI维度", "appid": "wxdad62baf4ccd09e3", - "versionName": "1.4.5", + "versionName": "1.4.6", "versionCode": "100", "description": "AI 知识探索社区 — 从5个维度系统理解人工智能", "uni-app": { diff --git a/client/src/pages/chat/chat.vue b/client/src/pages/chat/chat.vue index 1216fe2..fdd44d9 100644 --- a/client/src/pages/chat/chat.vue +++ b/client/src/pages/chat/chat.vue @@ -208,8 +208,15 @@ function goLogin() { uni.navigateTo({ url: '/pages/login/login' }) } -function onQuotaTap() { +async function onQuotaTap() { if (isGuest.value) { + // 静默登录一键升级(微信 code 换 token 无感),失败再显式引导 + const ok = await userStore.ensureLogin() + if (ok) { + uni.showToast({ title: '已升级为登录用户,每天 5 次', icon: 'success' }) + loadQuota() + return + } uni.showModal({ title: '游客体验', content: '每天可免费提问 3 次;登录后每天 5 次,答对检测题还能点亮知识星球', diff --git a/client/src/pages/detail/detail.vue b/client/src/pages/detail/detail.vue index f507536..85d4bfb 100644 --- a/client/src/pages/detail/detail.vue +++ b/client/src/pages/detail/detail.vue @@ -229,18 +229,22 @@ function retryQuiz() { async function toggleCollect() { if (!userStore.isLoggedIn) { - uni.showModal({ - title: '登录后收藏', - content: '登录后即可收藏喜欢的 AI 知识', - confirmText: '去登录', - cancelText: '暂不', - success: (res) => { - if (res.confirm) { - uni.navigateTo({ url: '/pages/login/login' }) + // 静默登录(微信 code 换 token,用户无感);失败再显式引导 + const ok = await userStore.ensureLogin() + if (!ok) { + uni.showModal({ + title: '登录后收藏', + content: '登录后即可收藏喜欢的 AI 知识', + confirmText: '去登录', + cancelText: '暂不', + success: (res) => { + if (res.confirm) { + uni.navigateTo({ url: '/pages/login/login' }) + } } - } - }) - return + }) + return + } } try { if (isCollected.value) { diff --git a/client/src/pages/login/login.vue b/client/src/pages/login/login.vue index c3aad1e..c3afaaa 100644 --- a/client/src/pages/login/login.vue +++ b/client/src/pages/login/login.vue @@ -135,14 +135,12 @@ import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app' import { ref } from 'vue' import { useUserStore } from '@/stores/index' -const isMiniApp = ref(false) +// 编译期判定:MP-WEIXIN 构建即小程序(运行时系统信息与按钮显示无关,避免旧API字段缺失导致按钮不渲染) // #ifdef MP-WEIXIN -try { - const sysInfo = uni.getSystemInfoSync() - if (sysInfo && sysInfo.version && sysInfo.platform) { - isMiniApp.value = true - } -} catch (e) {} +const isMiniApp = ref(true) +// #endif +// #ifndef MP-WEIXIN +const isMiniApp = ref(false) // #endif const activeTab = ref('login') diff --git a/client/src/pages/news/news.vue b/client/src/pages/news/news.vue index 51307bc..2ff6555 100644 --- a/client/src/pages/news/news.vue +++ b/client/src/pages/news/news.vue @@ -173,7 +173,19 @@ function goBack() { uni.navigateBack() } -function onFavorite() { +async function onFavorite() { + // 静默登录后提示(收藏态由详情页统一管理) + const ok = await userStore.ensureLogin() + if (!ok) { + uni.showModal({ + title: '登录后收藏', + content: '登录后即可收藏资讯', + confirmText: '去登录', + cancelText: '暂不', + success: (res) => { if (res.confirm) uni.navigateTo({ url: '/pages/login/login' }) } + }) + return + } isCollected.value = !isCollected.value uni.showToast({ title: isCollected.value ? '已收藏' : '已取消收藏', icon: 'none' }) } diff --git a/client/src/stores/user.js b/client/src/stores/user.js index 29ccb1c..0e7e8ee 100644 --- a/client/src/stores/user.js +++ b/client/src/stores/user.js @@ -28,6 +28,27 @@ export const useUserStore = defineStore('user', () => { return data } + /** + * 静默登录(微信小程序):code 换 token,用户无感知。 + * 已登录直接返回 true;失败返回 false(调用方再引导显式登录)。 + */ + async function ensureLogin() { + if (token.value) return true + // #ifdef MP-WEIXIN + try { + const loginRes = await new Promise((resolve, reject) => { + uni.login({ success: resolve, fail: reject }) + }) + if (!loginRes.code) return false + await login(loginRes.code, {}) + return true + } catch (e) { return false } + // #endif + // #ifndef MP-WEIXIN + return false + // #endif + } + async function h5Login(loginData) { const data = await authApi.h5Login(loginData) token.value = data.token @@ -110,6 +131,7 @@ export const useUserStore = defineStore('user', () => { isSubscribed, subscriptionLevel, login, + ensureLogin, h5Login, h5Register, fetchMe,