forked from mfay/IOReportMgt
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
|
4 years ago
|
import constant from "../../utils/constant";
|
||
|
|
import { request } from "../../utils/request";
|
||
|
|
const BASE_URL = 'http://localhost:8080/';
|
||
|
|
interface IqyLoginRes {
|
||
|
|
code: string,
|
||
|
|
errMsg: string,
|
||
|
|
}
|
||
|
|
const qyLogin = async () => {
|
||
|
|
return new Promise<IqyLoginRes>((resolve, reject) => {
|
||
|
|
return;
|
||
|
|
(wx as any).qy.login({
|
||
|
|
success: (loginRes: IqyLoginRes) => {
|
||
|
|
resolve(loginRes);
|
||
|
|
},
|
||
|
|
fail: () => {
|
||
|
|
wx.hideLoading();
|
||
|
|
// 登录失败
|
||
|
|
reject({ code: undefined })
|
||
|
|
}
|
||
|
|
});
|
||
|
|
})
|
||
|
|
}
|
||
|
|
const login = async () => {
|
||
|
|
// const { code } = await qyLogin()
|
||
|
|
const code = ''
|
||
|
|
if (typeof code == "undefined") {
|
||
|
|
// 登录失败
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const { data: { token } } = await request<API.Result<{ token: string }>>({
|
||
|
|
url: BASE_URL + 'api/login', data: { code, }, method: "POST"
|
||
|
|
})
|
||
|
|
wx.setStorageSync(constant.SYS_TOKEN, token);
|
||
|
|
const { data } = await request<API.Result<User.userInfo>>({ url: BASE_URL + 'api/userInfo', data: token, method: "POST" })
|
||
|
|
wx.setStorageSync(constant.ROLE_LIST, data.roles)
|
||
|
|
wx.setStorageSync(constant.USER_INFO, data)
|
||
|
|
return data;
|
||
|
|
}
|
||
|
|
|
||
|
|
export default { login }
|