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)
+2 -2
View File
@@ -1,5 +1,5 @@
export const URL = "https://my.gxfs123.com/api" //正式服务器
// export const URL = "https://fansdev.gxfs123.com/api" //测试服务器
// export const URL = "https://my.gxfs123.com/api" //正式服务器
export const URL = "https://fansdev.gxfs123.com/api" //测试服务器
// export const URL = "http://192.168.5.22:8080" //本地调试
// export const URL = "http://127.0.0.1:8080" //本地调试
+34
View File
@@ -1,4 +1,5 @@
import request from './http'
import { URL, appid } from './url'
export const login = (data) => {
@@ -203,4 +204,37 @@ export const getPotionsDetail = (data) => {
method: 'get',
data
})
}
// 文件上传到 OSS(若依后端)
export const uploadOssResource = (filePath) => {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: URL + '/resource/oss/upload',
filePath,
name: 'file',
header: {
'appid': appid,
'Authorization': 'Bearer ' + uni.getStorageSync('token'),
'Clientid': uni.getStorageSync('client_id')
},
success: (res) => {
try {
const parsed = typeof res.data === 'string' ? JSON.parse(res.data) : res.data
const codeOk = (res.statusCode === 200 || res.statusCode === 201 || parsed?.code === 200)
const url = parsed?.url || parsed?.data?.url || parsed?.data?.fileUrl || parsed?.fileUrl || parsed?.path || parsed?.data
if (codeOk && url) {
resolve(url)
return
}
reject(parsed || res)
} catch (e) {
reject(e)
}
},
fail: (err) => {
reject(err)
}
})
})
}