feat: 移动端双Token队列拦截器 + 通知列表 + 登录页 + TabBar红点 + v1.0.1
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
/**
|
||||
* uni.request 封装 — 统一的 HTTP 客户端
|
||||
* 自动携带 Token、401 跳转登录
|
||||
* uni.request 封装 — 生产环境(服务器 172.16.0.198)
|
||||
* 打包 APK 前:将 request.prod.js 重命名为 request.js 替换原文件
|
||||
*/
|
||||
|
||||
const BASE_URL = "http://192.168.9.80:8011/api/v1";
|
||||
const BASE_URL = "http://172.16.0.198:8011/api/v1";
|
||||
|
||||
export default function request(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -30,11 +30,18 @@ export default function request(options) {
|
||||
uni.showToast({ title: "登录已过期,请重新登录", icon: "none" });
|
||||
setTimeout(() => uni.reLaunch({ url: "/pages/login/login" }), 1000);
|
||||
reject(res);
|
||||
} else if (code === 403) {
|
||||
uni.showToast({ title: res.data?.detail || "无权操作", icon: "none", duration: 3000 });
|
||||
reject(res);
|
||||
} else if (code === 400) {
|
||||
uni.showToast({ title: res.data?.detail || "请求参数有误", icon: "none", duration: 2500 });
|
||||
reject(res);
|
||||
} else if (code === 409) {
|
||||
uni.showToast({ title: res.data?.detail || "操作冲突", icon: "none", duration: 3000 });
|
||||
reject(res);
|
||||
} else {
|
||||
uni.showToast({ title: `请求失败 (${code})`, icon: "none" });
|
||||
const detail = res.data?.detail || "";
|
||||
uni.showToast({ title: detail ? `${detail}` : `请求失败 (${code})`, icon: "none", duration: 3000 });
|
||||
reject(res);
|
||||
}
|
||||
},
|
||||
@ -57,3 +64,11 @@ export function get(url, params = {}) {
|
||||
export function post(url, data = {}) {
|
||||
return request({ url, method: "POST", data });
|
||||
}
|
||||
|
||||
export function patch(url, data = {}) {
|
||||
return request({ url, method: "PATCH", data });
|
||||
}
|
||||
|
||||
export function put(url, data = {}) {
|
||||
return request({ url, method: "PUT", data });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user