86 lines
2.0 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: JSON.parse(Cache.get('USER_INFO')||'{}') || null,
2023-07-15 17:51:20 +08:00
token: Cache.get("TOKEN") || null
};
const mutations = {
setUserInfo(state, data) {
state.userInfo = data
Cache.set("USER_INFO", data)
2023-07-15 17:51:20 +08:00
},
LOGOUT(state) {
Cache.clear('USER_INFO')
Cache.clear('TOKEN')
2023-08-03 17:44:02 +08:00
uni.showModal({
content: '登录已过期,是否重新登录?',
success(e) {
if(e.confirm)uni.redirectTo({
url:'/pages/oaLogin/oaLogin'
})
}
})
2023-07-15 17:51:20 +08:00
},
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
};