From aacfc17a0112727e848a4d3b93f075c2793aabf7 Mon Sep 17 00:00:00 2001 From: kron Date: Fri, 13 Jun 2025 16:36:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/BowTarget.vue | 3 +++ src/pages/index.vue | 22 ++++++++++------------ src/pages/user.vue | 7 +++++++ src/store.js | 16 +++++++++------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/components/BowTarget.vue b/src/components/BowTarget.vue index f6416fb..a57f83e 100644 --- a/src/components/BowTarget.vue +++ b/src/components/BowTarget.vue @@ -122,6 +122,7 @@ function calcRealY(num) { font-size: 12px; padding: 4px 7px; border-radius: 5px; + z-index: 2; } .round-tip { position: absolute; @@ -130,6 +131,7 @@ function calcRealY(num) { color: #fff; font-size: 30px; font-weight: bold; + z-index: 2; } .round-tip > text { font-size: 18px; @@ -154,6 +156,7 @@ function calcRealY(num) { position: absolute; width: 20px; height: 20px; + z-index: 1; } .header { width: 100%; diff --git a/src/pages/index.vue b/src/pages/index.vue index bb610c4..155f968 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -33,12 +33,13 @@ const handleLogin = () => { icon: "none", }); } - // console.log("getUsername", store.getUsername); - uni.getUserProfile({ - desc: "用于完善用户资料", + + // 先调用wx.getUserProfile获取用户信息 + wx.getUserProfile({ + desc: "用于完善用户资料", // 声明获取用户个人信息后的用途 success: (res) => { const { nickName, avatarUrl } = res.userInfo; - // 获取登录凭证 + // 再获取登录凭证 uni.login({ provider: "weixin", success: async (loginRes) => { @@ -59,17 +60,14 @@ const handleLogin = () => { }, fail: (err) => { console.log("获取用户信息失败:", err); + uni.showToast({ + title: "获取用户信息失败", + icon: "none", + }); }, }); }; -const isLogin = () => { - if (!user.value.id) { - showModal.value = true; - } - return !!user.value.id; -}; - const toPage = (path) => { if (!user.value.id) { showModal.value = true; @@ -106,7 +104,7 @@ onMounted(async () => { 微信登录 diff --git a/src/pages/user.vue b/src/pages/user.vue index a5bf989..82db955 100644 --- a/src/pages/user.vue +++ b/src/pages/user.vue @@ -8,6 +8,7 @@ import useStore from "@/store"; import { storeToRefs } from "pinia"; const store = useStore(); const { user } = storeToRefs(store); +const { updateUser } = store; const toOrderPage = () => { uni.navigateTo({ @@ -40,6 +41,11 @@ const toRankIntroPage = () => { url: "/pages/rank-intro", }); }; +const logout = () => { + uni.removeStorageSync("token"); + uni.navigateBack(); + updateUser(); +}; diff --git a/src/store.js b/src/store.js index 2b5de93..57c5cf2 100644 --- a/src/store.js +++ b/src/store.js @@ -1,15 +1,17 @@ import { defineStore } from "pinia"; +const defaultUser = { + id: "", + nickName: "游客", + avatarUrl: "../static/avatar.png", + trio: 0, // 大于1表示完成了新手引导 +}; + // 定义游戏相关的 store export default defineStore("store", { // 状态 state: () => ({ - user: { - id: "", - nickName: "游客", - avatarUrl: "../static/avatar.png", - trio: 0, // 大于1表示完成了新手引导 - }, + user: defaultUser, device: { deviceId: "", deviceName: "", @@ -27,7 +29,7 @@ export default defineStore("store", { // 方法 actions: { updateUser(user) { - this.user = user; + this.user = user || defaultUser; }, updateDevice(deviceId, deviceName) { this.device.deviceId = deviceId;