h5
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.
 
 
 
 

52 lines
1.3 KiB

const actions = {
/**
* 通过userId获取token
* @param {any} commit
* @param {string} userId 用户id
*/
async getTokenByUserId({ commit }, userId) {
try {
const res = await uni.$u.api.getToken(userId);
commit('setToken', res.token);
commit('setUser', res);
uni.$storage.setStorageSync('anyringToken', res.token || '');
uni.$storage.setStorageSync('user', JSON.stringify(res) || '');
return res;
} catch (error) {
uni.$ui.showToast(error.msg || '获取个人信息失败');
throw error;
}
},
/**
* 发送验证码
* @param {ant} commit
* @param {object} params 要提交的数据
* @param {string} params.phone 手机号
*/
async sendCode({ commit }, params) {
try {
const res = await uni.$u.api.getSmsCode(params);
return res;
} catch (error) {
uni.$ui.showToast(error.msg || '验证码发送失败');
throw error;
}
},
/**
* 根据refreshToken重新获取token
* @param {string} refreshToken
*/
async getTokenByRefreshToken({ commit }, refreshToken) {
try {
const res = await uni.$u.api.getNewToken(refreshToken);
return res;
} catch (error) {
uni.$ui.showToast(error.msg);
throw error;
}
},
};
export default actions;