2020-10-10 02:19:38 +00:00
|
|
|
import router from '@/router';
|
|
|
|
import store from '@/store';
|
|
|
|
import { LoginData, UserInfo } from '@/types';
|
|
|
|
import { saveValue } from '@/utils/common';
|
|
|
|
import { message } from 'ant-design-vue';
|
|
|
|
import { get, post, setToken } from './base'
|
2020-09-24 07:33:12 +00:00
|
|
|
|
2020-10-09 01:45:13 +00:00
|
|
|
|
2020-10-10 00:59:54 +00:00
|
|
|
/**
|
|
|
|
* 用户名密码登录
|
|
|
|
* @param phone 手机号
|
|
|
|
* @param password 密码
|
|
|
|
*/
|
|
|
|
|
2020-10-10 02:19:38 +00:00
|
|
|
export async function loginpass(phone: string, password: string){
|
|
|
|
const res = await post<LoginData>("login",{type: 2,username: phone, password: password});
|
|
|
|
console.log(res.code)
|
|
|
|
if(res.code == 1){
|
|
|
|
message.error(res.msg)
|
|
|
|
}else{
|
|
|
|
console.log(res.data)
|
|
|
|
if(!saveValue("token", res.data?.api_token) && !saveValue("memberid", res.data?.memberid) ){
|
|
|
|
message.error("存储错误, 请允许网页使用本地存储!")
|
|
|
|
}else{
|
|
|
|
setToken();
|
|
|
|
store.commit("login");
|
|
|
|
router.push("/mine/archives")
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 06:31:10 +00:00
|
|
|
}
|
2020-10-10 00:59:54 +00:00
|
|
|
|
|
|
|
/**
|
2020-10-10 02:19:38 +00:00
|
|
|
* 用户头像和用户名字
|
2020-10-10 00:59:54 +00:00
|
|
|
*/
|
2020-10-10 02:19:38 +00:00
|
|
|
export async function userinfo(){
|
|
|
|
const user = await get<UserInfo>('personalInfo');
|
|
|
|
console.log(user.data?.img)
|
|
|
|
return {
|
|
|
|
head: user.data?.img,
|
|
|
|
username: user.data?.name
|
|
|
|
}
|
|
|
|
}
|