| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import Vuex from 'vuex';
- import http from '../plugins/http';
- export default new Vuex.Store({
- state: {
- sessionKey: '',
- safeArea: {
- top: 0,
- botton: 0
- },
- systemInfo: {
- statusBarHeight: 44
- },
- userInfo: null,
- userStoreInfo: null
- },
- mutations: {
- setUserInfo(state, userInfo) {
- state.userInfo = userInfo;
- },
- setSessionKey(state, sessionKey) {
- state.sessionKey = sessionKey;
- },
- setSystemInfo(state, systemInfo) {
- state.çç = systemInfo;
- },
- setUserStoreInfo(state, userStoreInfo) {
- state.userStoreInfo = userStoreInfo;
- }
- },
- actions: {
- getUserInfo(context) {
- return http.http.get('/user/my').then(res => {
- console.log(res)
- if (res.sex || res.nickname.indexOf('用户') === -1) {
- context.commit('setUserInfo', res);
- } else {
- context.commit('setUserInfo', null);
- }
- return Promise.resolve(res);
- });
- },
- getUserStore(context) {
- if (!context.state.userInfo) {
- return Promise.reject();
- }
- return http.http
- .postJson('/store/all', {
- query: {
- userId: context.state.userInfo.id
- }
- })
- .then(res => {
- if (res.empty) {
- context.commit('setUserStoreInfo', null);
- return Promise.reject();
- } else {
- context.commit('setUserStoreInfo', res.content[0]);
- return Promise.resolve(res.content[0]);
- }
- });
- }
- }
- });
|