import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
|
|
Vue.use(Vuex); //vue的插件机制
|
|
|
|
import api from '@/api/api.js'
|
|
|
|
//Vuex.Store 构造器选项
|
|
const store = new Vuex.Store({
|
|
state: {
|
|
configList: [], //配置列表
|
|
count : 10,
|
|
userInfo : {},
|
|
certifiedIndividual : {
|
|
imageReverseSide: '',
|
|
imageStraight: '',
|
|
card: '',
|
|
name: '',
|
|
},
|
|
},
|
|
getters: {
|
|
// 通过报错的方式阻止缓存,这里的报错千万不要修复
|
|
isVedio(state){
|
|
return state.configList.open.content == 'Y'
|
|
},
|
|
},
|
|
mutations: {
|
|
// 初始化配置
|
|
initConfig(state){
|
|
api('getConfig', res => {
|
|
if(res.code == 200){
|
|
// state.configList = res.result
|
|
res.result.forEach(n => {
|
|
state.configList[n.keyValue] = n
|
|
})
|
|
}
|
|
})
|
|
let config = ['getPrivacyPolicy', 'getUserAgreement', 'getPublishPostNotice']
|
|
config.forEach(k => {
|
|
api(k, res => {
|
|
if (res.code == 200) {
|
|
state.configList[k] = res.result
|
|
}
|
|
})
|
|
})
|
|
},
|
|
getIsVedio(state){
|
|
api('getIsVedio', res => {
|
|
state.configList.isVedio = res.result
|
|
})
|
|
},
|
|
login(state){
|
|
uni.showLoading({
|
|
title: '登录中...'
|
|
})
|
|
uni.login({
|
|
success(res) {
|
|
if(res.errMsg != "login:ok"){
|
|
return
|
|
}
|
|
|
|
api('loginLogin', {
|
|
code : res.code
|
|
}, res => {
|
|
|
|
uni.hideLoading()
|
|
|
|
if(res.code != 200){
|
|
return
|
|
}
|
|
|
|
state.userInfo = res.result.userInfo
|
|
uni.setStorageSync('token', res.result.token)
|
|
|
|
|
|
if(!state.userInfo.nickName || !state.userInfo.headImage){
|
|
|
|
if(state.configList.open && state.configList.open.content != 'Y'){
|
|
|
|
state.userInfo.headImage = 'https://tennis-oss.xzaiyp.top/2024-10-09/385774b4-d94a-4d45-993a-ae4ddd0b2751.jpg'
|
|
state.userInfo.nickName = '帧视界' + Math.floor(Math.random() * 1000000)
|
|
api('infoUpdateInfo', {
|
|
headImage: state.userInfo.headImage,
|
|
nickName: state.userInfo.nickName,
|
|
})
|
|
return uni.navigateBack(-1)
|
|
}
|
|
|
|
uni.navigateTo({
|
|
url: '/pages/auth/wxUserInfo'
|
|
})
|
|
}else{
|
|
uni.navigateBack(-1)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
},
|
|
getUserInfo(state){
|
|
api('infoGetInfo', res => {
|
|
if(res.code == 200){
|
|
|
|
res.result.idCardOpen = parseInt(res.result.idCardOpen)
|
|
|
|
state.userInfo = res.result
|
|
|
|
if(res.result.idCardOpen){
|
|
this.commit('getCartInfo')
|
|
}
|
|
}
|
|
})
|
|
},
|
|
getCartInfo(state){
|
|
// this.userInfo.idCardOpen 1企业认证 2个人认证
|
|
api(['infoGetCompanyCertification',
|
|
'infoGetCertification'][state.userInfo.idCardOpen - 1],
|
|
res => {
|
|
if(res.code == 200){
|
|
state.certifiedIndividual = res.result || {}
|
|
}
|
|
})
|
|
},
|
|
},
|
|
actions: {},
|
|
})
|
|
|
|
export default store
|