diff --git a/package-lock.json b/package-lock.json
index 334766c..9563571 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8,7 +8,7 @@
"name": "wechat-pc-frontend",
"version": "1.0.0",
"dependencies": {
- "@batiao/batiao-sdk-vue-vite": "^1.0.357",
+ "@batiao/batiao-sdk-vue-vite": "^1.0.386",
"@element-plus/icons-vue": "^2.3.1",
"axios": "^1.6.8",
"body-parser": "^2.3.0",
@@ -80,9 +80,9 @@
}
},
"node_modules/@batiao/batiao-sdk-vue-vite": {
- "version": "1.0.357",
- "resolved": "http://maven.batiao8.com/repository/npm-releases/@batiao/batiao-sdk-vue-vite/-/batiao-sdk-vue-vite-1.0.357.tgz",
- "integrity": "sha512-CGp16f+z7kLJSZocrj8wuttwUI4LuhAM3F9EE8+LManpsaGG5GPeDCfIfmYI9am97vnn4Fl1J0JGSSZiafjZyg==",
+ "version": "1.0.395",
+ "resolved": "http://maven.batiao8.com/repository/npm-releases/@batiao/batiao-sdk-vue-vite/-/batiao-sdk-vue-vite-1.0.395.tgz",
+ "integrity": "sha512-i4tdbKk4RAcmOyL4HeXr4p2tgzaAcJG9DJc2UyzKteOWtsaJbG9jAGbuaq/XxfWqCNP1nGRakrltVMpQzRbWOQ==",
"license": "UNLICENSED",
"dependencies": {
"quickjs-emscripten": "^0.32.0"
diff --git a/src/App.vue b/src/App.vue
index 68fd092..9fc9825 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -17,24 +17,22 @@ import AppFooter from '@/components/common/AppFooter.vue'
import PaymentDialog from '@/components/PaymentDialog.vue'
import { useUserStore } from '@/stores/user'
import api from '@/api'
+import { handleWxLoginCallback } from '@/utils/wxLogin'
const userStore = useUserStore()
const paymentDialog = ref(null)
-onMounted(() => {
+onMounted(async () => {
+ // 1. 尝试处理微信登录回调
+ const isWxLoginSuccess = await handleWxLoginCallback()
+ if (isWxLoginSuccess) {
+ // 微信登录成功后拉取用户信息
+ userStore.fetchProfile().catch(() => { })
+ return
+ }
+
+ // 2. 正常 token 验证
if (localStorage.getItem('token') && !userStore.tokenChecked) {
- // 用静默验证:401时不跳转登录页(避免注册/登录页被拦截)
- // api.auth.profileSilent().then(res => {
- // userStore.username = res.username
- // userStore.isVip = res.is_vip
- // userStore.avatarUrl = res.avatar_url
- // userStore.membershipExpireAt = res.membership_expire_at
- // userStore.tokenChecked = true
- // userStore.tokenValid = true
- // }).catch(() => {
- // userStore.tokenChecked = true
- // userStore.tokenValid = false
- // })
userStore.fetchProfile().catch(() => { })
}
})
diff --git a/src/api/authService.js b/src/api/authService.js
index 473a75d..f05b735 100644
--- a/src/api/authService.js
+++ b/src/api/authService.js
@@ -1,5 +1,6 @@
import { get, postJson } from "@/utils/requestService";
import appConfig from "@/utils/appConfig";
+import config from "@/config.json";
export default {
/**
@@ -29,7 +30,21 @@ export default {
},
/**
- * 3. 获取微信扫码登录二维码
+ * 3. 微信开放平台 code 登录
+ */
+ async loginByWxCode(code) {
+ return await postJson(appConfig.baseURL, "/user/login", {
+ type: "weixin",
+ data: {
+ // appid: config.wxAppId,
+ code: code,
+ code_type: "wx-web"
+ }
+ });
+ },
+
+ /**
+ * 4. 获取微信扫码登录二维码 (可能废弃)
*/
async getLoginCode(data) {
return await postJson(appConfig.baseURL, "/weixin/qrcode", data);
diff --git a/src/components/LoginDialog.vue b/src/components/LoginDialog.vue
index a90a924..dac46e4 100644
--- a/src/components/LoginDialog.vue
+++ b/src/components/LoginDialog.vue
@@ -29,18 +29,11 @@
-
- “装样大师” 网页版
-