diff --git a/miniprogram/config/api.js b/miniprogram/config/api.js index 8826f64e3..3788befce 100644 --- a/miniprogram/config/api.js +++ b/miniprogram/config/api.js @@ -37,6 +37,8 @@ export const AUTH_API = { LOGIN_RSA_PUBLIC_KEY: '/web/auth/login-rsa-public-key', LOGIN: '/web/auth/login', WECHAT_LOGIN: '/mini/auth/wechat-login', + WEB_QR_SCANNED: '/mini/auth/web-qr-scanned', + WEB_QR_CONFIRM: '/mini/auth/web-qr-confirm', LOGOUT: '/web/auth/logout', CURRENT_USER: '/web/auth/current-user', REFRESH_TOKEN: '/web/auth/refresh-token', diff --git a/miniprogram/pages.json b/miniprogram/pages.json index a7191a7ee..968105c90 100644 --- a/miniprogram/pages.json +++ b/miniprogram/pages.json @@ -22,6 +22,14 @@ "navigationBarTextStyle": "black" } }, + { + "path": "pages/login/web-qr/index", + "style": { + "navigationBarTitleText": "网页登录授权", + "navigationBarBackgroundColor": "#f3f7f5", + "navigationBarTextStyle": "black" + } + }, { "path": "pages/workbench/workbench", "style": { diff --git a/miniprogram/pages/login/web-qr/index.vue b/miniprogram/pages/login/web-qr/index.vue new file mode 100644 index 000000000..10f4d4228 --- /dev/null +++ b/miniprogram/pages/login/web-qr/index.vue @@ -0,0 +1,437 @@ + + + + + diff --git a/miniprogram/stores/user.js b/miniprogram/stores/user.js index 613fd1ad4..84baa25db 100644 --- a/miniprogram/stores/user.js +++ b/miniprogram/stores/user.js @@ -159,6 +159,38 @@ export const useUserStore = defineStore('user', () => { } } + /** 网页扫码:通知已扫;不写本地登录态 */ + async function webQrScanned(sessionId) { + const res = await request({ + url: AUTH_API.WEB_QR_SCANNED, + method: 'POST', + data: { sessionId } + }) + const result = parseResponseJson(res) + return !!(result && result.code === 200) + } + + /** 网页扫码:手机号授权确认;不写本地登录态、不跳转工作台 */ + async function webQrConfirm(params) { + const res = await request({ + url: AUTH_API.WEB_QR_CONFIRM, + method: 'POST', + data: { + sessionId: params.sessionId, + loginCode: params.loginCode, + phoneCode: params.phoneCode + } + }) + const result = parseResponseJson(res) + if (result && result.code === 200) { + return { + ok: true, + message: (result.data && result.data.message) || '电脑端即将登录,可关闭本页' + } + } + return { ok: false, message: (result && result.message) || '授权失败' } + } + function clearLoginInfo() { token.value = '' refreshToken.value = '' @@ -223,6 +255,8 @@ export const useUserStore = defineStore('user', () => { checkLoginStatus, login, wechatLogin, + webQrScanned, + webQrConfirm, logout, clearLoginInfo, navigateToHome, diff --git a/miniprogram/utils/request.js b/miniprogram/utils/request.js index f7fd6bf87..f49932834 100644 --- a/miniprogram/utils/request.js +++ b/miniprogram/utils/request.js @@ -9,7 +9,7 @@ const API_ENCRYPT_FAIL_OPEN = false const API_ENCRYPT_FIXED_SECRET = 'shanxia-web-api-crypto-fixed-secret' // TODO(config-hardcoded): 排除路径清单后续改为集中配置,避免多端重复维护。 const API_ENCRYPT_EXCLUDE_PATHS = String( - '/web/auth/login-rsa-public-key,/web/auth/login,/web/auth/refresh-token,/mini/auth/wechat-login' + '/web/auth/login-rsa-public-key,/web/auth/login,/web/auth/refresh-token,/mini/auth/wechat-login,/mini/auth/web-qr-scanned,/mini/auth/web-qr-confirm' ) .split(',') .map((item) => item.trim())