78 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-07-15 17:51:20 +08:00
import { commonAuth } from '@/api/pubic.js'
import { loginMobile } from '@/api/user.js'
import Routine from '@/libs/routine.js'
import Cache from '@/utils/cache';
const state = {
userInfo: Cache.get('USER_INFO') || null,
token: Cache.get("TOKEN") || null
};
const mutations = {
setUserInfo(state, data) {
state.userInfo = data
uni.setStorageSync("USER_INFO", data)
},
LOGOUT(state) {
Cache.clear('USER_INFO')
Cache.clear('TOKEN')
},
UPDATE_USERINFO(state, data) {
let time = res.data.result.expires_time - Cache.time();
state.userInfo = data.result.user
state.token = data.result.token
Cache.set("USER_INFO", data.result.user, time)
Cache.set("TOKEN", data.result.token, time)
},
SET_USERINFO(state, data){
let time = Cache.time();
state.userInfo = data.user
state.token = data.token
Cache.set("USER_INFO", data.user, time)
Cache.set("TOKEN", data.token, time)
2023-07-15 17:51:20 +08:00
}
};
const actions = {
MobileLogin({ state, commit }, force) {
let data = {
auth_token: uni.getStorageSync('auth_token'),
phone: force.account,
sms_code: force.captcha,
spread: that.$Cache.get("spread"),
// #ifdef APP-PLUS
user_type: 'app',
// #endif
// #ifdef H5
user_type: 'h5',
// #endif
}
loginMobile(data).then(res => {
console.log('手机号登录', res);
})
},
async getWxLogin({ state, commit }, force) {
let newCode = null
Routine.getCode().then(code => {
newCode = code;
})
Routine.getUserProfile().then(res => {
let userInfo = res.userInfo;
userInfo.code = newCode;
commonAuth({
auth: {
type: 'routine',
auth: userInfo
}
}).then(res => {
commit("UPDATE_USERINFO", res.data);
})
})
}
};
export default {
state,
mutations,
actions
};