diff --git a/App.vue b/App.vue index e1cccfb..c7e8059 100644 --- a/App.vue +++ b/App.vue @@ -16,23 +16,27 @@ export default { }, }); - await this.login(); - - const startTime = +this.$moment() - .startOf('year') - .format('x'); - const endTime = +this.$moment() - .endOf('day') - .format('x'); - const params = { - param: { - startTime, - endTime, - token: this.token - } - }; - await this.getUserInfo(params); - await this.getHealthTypeStatus(); + try { + await this.login(); + + const startTime = +this.$moment() + .startOf('year') + .format('x'); + const endTime = +this.$moment() + .endOf('day') + .format('x'); + const params = { + param: { + startTime, + endTime, + token: this.token, + }, + }; + await this.getUserInfo(params); + await this.getHealthTypeStatus(); + } catch (error) { + console.log('error: ', error); + } }, computed: mapState('user', ['token']), diff --git a/main.js b/main.js index 904b195..1b80ae1 100644 --- a/main.js +++ b/main.js @@ -4,6 +4,17 @@ import { http } from 'plugins/request/index'; import App from './App'; import store from './store'; +// 白名单页面 +const whitePathList = ['basic-info', 'statistics', 'user-code']; +/** + * 检查url是否在是否在白名单内 + * @param {string} url path+query + */ +const checkWhitePath = url => { + let str = url.slice(7).split('/')[0]; + return whitePathList.includes(str); +}; + Vue.config.productionTip = false; Vue.prototype.$http = http; Vue.prototype.$moment = moment; @@ -23,18 +34,21 @@ Vue.prototype.goHome = () => { */ // 白名单页面 -const whiteListPath = ['/pages/basic-info/basic-info','/pages/statistics/statistics','/pages/user-code/user-code'] +const whiteListPath = [ + '/pages/basic-info/basic-info', + '/pages/statistics/statistics', + '/pages/user-code/user-code', +]; Vue.prototype.openPage = function(path, query = '') { - let url = query ? `${path}?${query}` : path; - store.commit('user/setPagePath',url) - - const choosePath = whiteListPath.indexOf(path) - if(!store.state.user.userInfo.id && choosePath === -1) { - url = '/pages/basic-info/basic-info'; - } - - uni.navigateTo({ url }); + let url = query ? `${path}?${query}` : path; + store.commit('user/setPagePath', url); + const isWhite = checkWhitePath(url); + if (!store.state.user.userInfo.id && !isWhite) { + url = '/pages/basic-info/basic-info'; + } + + uni.navigateTo({ url }); }; App.mpType = 'app'; diff --git a/store/modules/user/actions.js b/store/modules/user/actions.js index 3e78e32..3ae698e 100644 --- a/store/modules/user/actions.js +++ b/store/modules/user/actions.js @@ -12,7 +12,7 @@ const actions = { mpLogin() .then(params => signIn(params)) .then(data => { - // console.log('login data: ', data); + console.log('login data: ', data); commit('setToken', data.token); commit('setUser', data); @@ -20,7 +20,7 @@ const actions = { }) .catch(err => { console.log('login err: ', err); - // showModal(err.msg || '登录失败'); + showModal(err.msg || '登录失败'); reject(err); }); // #endif @@ -69,11 +69,11 @@ const actions = { */ getUserInfo({ commit }, params) { return new Promise((resolve, reject) => { - showLoading(); + showLoading(); http .post(GET_USER_INFO, params) .then(res => { - hideLoading(); + hideLoading(); const { data } = res.data; resolve(data); // 获取自己的信息采取设置 @@ -88,7 +88,7 @@ const actions = { } }) .catch(data => { - hideLoading(); + hideLoading(); showToast(data.msg || '查询个人信息失败'); reject(data); }); diff --git a/utils/user.js b/utils/user.js index b478e8e..601a00a 100644 --- a/utils/user.js +++ b/utils/user.js @@ -8,14 +8,14 @@ import { SIGN_IN_CLIENTS, SIGN_IN_TYPES } from 'config/config.user'; * @param {string} token 服务端返回的token数据 */ export const setToken = token => { - uni.setStorageSync('anyringToken', token); + uni.setStorageSync('token', token); }; /** * 获取token * @return {string} 本地保存的token */ -export const getToken = () => uni.getStorageSync('anyringToken'); +export const getToken = () => uni.getStorageSync('token'); /** * 提交登录信息 @@ -69,7 +69,7 @@ export const wxLogin = () => { }); }; -// 微信登录 +// 企业微信登录 export const wxWorkLogin = () => { return new Promise((resolve, reject) => { wx.qy.login({