Reinit project

This commit is contained in:
Limo Saplf
2019-08-31 20:44:15 +08:00
commit b51ae824c7
115 changed files with 20955 additions and 0 deletions

40
src/services/common.ts Normal file
View File

@@ -0,0 +1,40 @@
import { AreaCodes, User } from '@/types/common';
import { loadAreaCode, storeAreaCode, loadUser, storeUser } from '@/utils/storage';
import http from '@/utils/http';
export function globalState() {
return (window as any).g_app._store.getState();
}
export async function getAreaCodes(): Promise<AreaCodes> {
const areaCodeCache = loadAreaCode();
if (areaCodeCache) {
return areaCodeCache;
}
const res = await http.get<AreaCodes>('/sign/code');
if (res.ok && res.data) {
storeAreaCode(res.data);
return res.data;
}
throw Error(res.msg);
}
export async function getUserInfo(refresh = false): Promise<User> {
if (!refresh) {
const userCache = loadUser() as User;
if (userCache) {
return userCache;
}
}
const { ok, msg, data } = await http.get<User>('/user/info');
if (ok && data) {
data.token = globalState().user.user.token;
storeUser(data);
return data;
}
throw Error(msg);
}