优化登录,修改bug

This commit is contained in:
zhouyanli
2026-07-29 17:47:10 +08:00
parent 9be76c6386
commit a6243cf466
24 changed files with 533 additions and 1012 deletions

View File

@@ -13,15 +13,20 @@ export default function request(url, data = {}, method = "GET") {
// mask: true
// });
const token = uni.getStorageSync("token") || "";
const header = {
"clientid": "resident",
'content-type': 'application/json'
};
if (token) {
header["Authorization"] = "Bearer " + token;
}
uni.request({
url: baseUrl + url,
data: data,
method: method,
header: {
"Authorization": "Bearer " + (uni.getStorageSync("token") || ''),
"clientid": "resident",
'content-type': 'application/json'
},
header,
success: (res) => {
// uni.hideLoading();
@@ -33,13 +38,12 @@ export default function request(url, data = {}, method = "GET") {
const resData = res.data || {};
// token 过期
// token 过期:仅在有 token 且过期时跳转登录页(无 token 用户正常浏览首页,由点击拦截处理)
if (resData.code === 401) {
uni.showToast({ title: '登录过期,请重新登录', icon: 'none' });
uni.clearStorageSync('token');
setTimeout(() => {
uni.reLaunch({ url: '/pageSubPack/loginSub/pwd-login' });
}, 1500);
if (token) {
uni.clearStorageSync('token');
uni.reLaunch({ url: '/pageSubPack/loginSub/login?mode=pwd' });
}
reject({ msg: '登录过期', code: 401 });
return;
}
@@ -69,14 +73,19 @@ export const putMethod = (url, data) => request(url, data, 'PUT');
// 上传
export const upload = (filePath, url) => {
return new Promise((resolve, reject) => {
const t = uni.getStorageSync("token") || "";
const uploadHeader = {
"clientid": "resident"
};
if (t) {
uploadHeader["Authorization"] = "Bearer " + t;
}
uni.uploadFile({
url: baseUrl + url,
filePath: filePath,
name: 'file',
header: {
"Authorization": "Bearer " + (uni.getStorageSync("token") || ''),
"clientid": "resident"
},
header: uploadHeader,
success: (res) => {
try {
const data = JSON.parse(res.data);