四好公路
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.
 
 
 
 

54 lines
1.3 KiB

import Taro from '@tarojs/taro';
import request from '../services/request';
function dealError(error) {
Taro.showToast({
title: error,
icon: 'none',
duration: 1500
});
throw new Error(error);
}
export const login = (url, data) => {
return request.post(url, data, { hideErrorToast: true }).then(res => {
if (res.statusCode == 200) {
//let obj = {};
// res.cookies.map(t=>{
// const fsiota = t.split(';').find(v=> v.includes('fsiota')).split('=');
// obj[fsiota[0]] = fsiota[1];
// })
// console.log(obj);
// Taro.setStorageSync("cookie", {
// fsiota: obj.fsiota,
// sig: obj['fsiota.sig']
// })
Taro.setStorageSync('token', res.data.token)
Taro.setStorageSync('userInfo', res.data);
return res.data;
} else {
dealError(res.data.message || '请求出错');
}
}, err => {
dealError(err.message || '请求出错');
});
};
export const logout = (url, data) => {
return request.put(url, data).then(res => {
if (res.statusCode == 200 || res.statusCode == 204) {
Taro.clearStorage();
return res.data;
} else {
throw new Error(res.data.message || '登出失败');
}
}).catch(err => {
throw new Error(err.message || '请求出错');
});
};