feat:新增登录页面与相关功能,移除自动登录,对接用户反馈功能

This commit is contained in:
2025-10-08 02:29:48 +08:00
parent 0ec86fba8e
commit 8560ff778e
10 changed files with 317 additions and 35 deletions
+17 -1
View File
@@ -19,7 +19,7 @@ const request = (option) => {
method: option.method,
data: option.data,
header: {
"Content-Type": "application/x-www-form-urlencoded",
"Content-Type": option.headers && option.headers["Content-Type"] ? option.headers["Content-Type"] : (option.method && option.method.toUpperCase() === 'POST' ? 'application/json' : 'application/x-www-form-urlencoded'),
...option.headers,
'appid': appid,
'Authorization': "Bearer " + uni.getStorageSync('token'),
@@ -42,6 +42,22 @@ const request = (option) => {
return
}
// 未登录或 token 失效处理(支持多种后端返回)
if (res.statusCode === 401 || res.data?.code === 401 || res.data?.code === 40101) {
try {
// 清理本地登录态
uni.removeStorageSync('token')
// 计算重定向地址
const pages = getCurrentPages()
const current = pages && pages.length ? pages[pages.length - 1] : null
const route = current && current.route ? ('/' + current.route) : '/pages/index/index'
const query = current && current.options ? Object.keys(current.options).map(k => `${k}=${encodeURIComponent(current.options[k])}`).join('&') : ''
const redirect = encodeURIComponent(query ? `${route}?${query}` : route)
// 跳转到登录页
uni.reLaunch({ url: `/pages/login/index?redirect=${redirect}` })
} catch (e) {}
}
// 检查业务状态码
if (res.data && res.data.code !== 200) {
console.warn(`业务状态码错误: ${res.data.code}`, res.data)