This commit is contained in:
quantulr
2023-08-31 16:24:37 +08:00
parent 0288146b0d
commit 5bbe958729
32 changed files with 317 additions and 105 deletions

View File

@ -0,0 +1,7 @@
function formatAmount(amount) {
return (amount / 10000).toFixed(2);
}
module.exports = {
formatAmount: formatAmount,
};

View File

@ -46,9 +46,11 @@ class HttpClient {
url = `${this.baseUrl}${req.url}${paramsString}`;
}
const app = getApp();
const header: any = req.header ?? {};
if (!authWhitelist.includes(req.url)) {
header.Authorization = `Bearer ${app.globalData.authToken}`;
if (!authWhitelist.includes(req.url) && !header.Authorization) {
header.Authorization = `Bearer ${app?.globalData?.authToken}`;
}
return new Promise(function (resolve, reject) {
wx.request({

View File

@ -1,8 +1,10 @@
import { getInfo } from "../api/login";
export const setToken = (token?: string) => {
getApp().globalData.authToken = token;
wx.setStorage({
key: "auth-token",
data: token,
data: token ?? "",
});
};
// 如果不存在token则跳转到身份选择页面
@ -17,7 +19,17 @@ export const requiredAuth = () => {
});
}
};
export const getToken = () => {
const token = wx.getStorageSync("auth-token");
return token;
};
export const getUserInfo = async () => {
const { userInfo } = getApp().globalData;
if (!userInfo) {
const token = getApp().globalData.authToken;
const resp = await getInfo(token);
return resp;
}
};

View File

@ -0,0 +1,7 @@
function hasPermission(permission, permissions) {
return permissions.indexOf(permission) != -1;
}
module.exports = {
hasPermission: hasPermission,
};