beelink/src/store/index.ts
2020-10-30 10:35:39 +08:00

89 lines
2.1 KiB
TypeScript

import { getaddr, userinfo } from '@/api';
import { isProxy } from 'vue';
import { createStore } from 'vuex'
export default createStore({
state: {
userinfo:{
accesstoken: "",
apiToken: "",
birthday: "",
country: "",
countryValue: "",
cover: "",
code:"",
createdAt: "",
currency: "",
currencyValue: "",
deletedAt: null,
desc: "",
email: "",
img: "",
interest: "",
language: "中文",
languageValue: "zh",
live: "",
livetime: "",
loginType: 0,
memberid: 0,
mobile: "",
money: "",
moneyValue: 0,
msg: "",
mtongue: "",
name: "",
password: "",
position: 0,
publish: 0,
score: "",
status: false,
tlanguage: "中文",
tlanguageValue: 1,
type: 1,
uid: "",
updatedAt: "",
video: "",
willsay: [{name: "请选择", level: 0}],
willsayValue: [{name: "0", level: 0}],
zoneStr: "中途岛GMT-11:00",
zoneid: 1,
},
islogin: false
},
mutations: {
setUserInfo(state, userinfo){
userinfo.money = userinfo.money.toString()
state.userinfo = userinfo
state.islogin = true;
},
login(state, islogin: boolean){
state.islogin = islogin;
},
setLanguage(state, data){
const split = new Date().toString().split(" ");
const timeZoneFormatted = split[split.length - 2] + " " + split[split.length - 1];
state.userinfo.language = data[1] // English 中文
state.userinfo.languageValue = data[0] // 'en' 'zh'
state.userinfo.zoneStr = timeZoneFormatted;
state.userinfo.currency = data[2];
}
},
actions: {
async setUserInfo({ commit }){
const user = await userinfo();
if(user != '未登录'){
commit('setUserInfo', user);
} else {
const info = await getaddr();
commit("setLanguage", info)
}
},
async getip({ commit }){
const info = await getaddr();
commit("setLanguage", info)
}
},
modules: {
}
})