From 9ab42b4fb5b38a3d8380ed2c27533a1e6111719a Mon Sep 17 00:00:00 2001 From: wally <18603454788@163.com> Date: Tue, 10 Mar 2020 16:37:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=201.=20=E5=81=A5?= =?UTF-8?q?=E5=BA=B7=E4=BF=A1=E6=81=AF=E7=95=8C=E9=9D=A2=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=94=99=E8=AF=AF=202.=E6=9E=81=E9=80=9F=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/auth/auth.vue | 4 ++++ main.js | 2 +- pages/user-code/user-code.vue | 8 ++++---- store/modules/user/actions.js | 3 ++- store/modules/user/mutations.js | 10 +++++----- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/components/auth/auth.vue b/components/auth/auth.vue index 9e239d5..bfa0b3c 100644 --- a/components/auth/auth.vue +++ b/components/auth/auth.vue @@ -34,7 +34,11 @@ export default { if (value) { if (!value.wxInfo || !value.wxInfo.nickname) { this.show = true; + } else { + this.show = false; } + } else { + this.show = false; } }, }, diff --git a/main.js b/main.js index c057d11..f6b4950 100644 --- a/main.js +++ b/main.js @@ -39,7 +39,7 @@ Vue.prototype.openPage = function(path, query = '') { let url = query ? `${path}?${query}` : path; store.commit('user/setPagePath', url); const isWhite = checkWhitePath(url); - if (!store.state.user.userInfo.id && !isWhite) { + if ((!store.state.user.userInfo || !store.state.user.userInfo.id) && !isWhite) { url = '/pages/basic-info/basic-info'; } diff --git a/pages/user-code/user-code.vue b/pages/user-code/user-code.vue index 74bc90e..be70907 100644 --- a/pages/user-code/user-code.vue +++ b/pages/user-code/user-code.vue @@ -94,9 +94,9 @@ export default { // 健康状态 登记 level() { - if (!this.userInfo || !this.userInfo.healthLevel) return '正常'; + if (!this.userInfo || !this.userInfo.healthCodeList) return '正常'; let str = '正常'; - switch (this.userInfo.healthLevel[0].healthLevel) { + switch (this.userInfo.healthCodeList[0].healthLevel) { case 0: str = '正常'; break; @@ -113,8 +113,8 @@ export default { }, time() { - if (!this.userInfo || !this.userInfo.healthLevel) return; - return this.$moment(this.userInfo.healthLevel[0].time - 0).format('YYYY-MM-DD HH:mm'); + if (!this.userInfo || !this.userInfo.healthCodeList) return; + return this.$moment(this.userInfo.healthCodeList[0].time - 0).format('YYYY-MM-DD HH:mm'); }, }, diff --git a/store/modules/user/actions.js b/store/modules/user/actions.js index 3ae698e..0024847 100644 --- a/store/modules/user/actions.js +++ b/store/modules/user/actions.js @@ -52,7 +52,7 @@ const actions = { .post(UPDATE_USER, params) .then(res => { const { data } = res.data; - commit('updateUser', { type: 'wxInfo', params }); + commit('updateUser', { type: 'wxInfo', value: params }); resolve(data); }) .catch(data => { @@ -75,6 +75,7 @@ const actions = { .then(res => { hideLoading(); const { data } = res.data; + console.log('getUserInfo data: ', data); resolve(data); // 获取自己的信息采取设置 // 扫别人健康码的时候不用设置 diff --git a/store/modules/user/mutations.js b/store/modules/user/mutations.js index 3da99aa..562cf76 100644 --- a/store/modules/user/mutations.js +++ b/store/modules/user/mutations.js @@ -34,7 +34,7 @@ const mutations = { state.user = { ...user }; uni.setStorageSync('user', JSON.stringify(user)); }, - + /** * 设置健康码 * @param {object} state @@ -43,7 +43,7 @@ const mutations = { setHealthCode(state, data) { state.healthCode = data; }, - + /** * 设置个人信息 userInfo * @param {*} state @@ -52,7 +52,7 @@ const mutations = { setUserInfo(state, data) { state.userInfo = data; }, - + /** * 设置页面跳转参数 pagePath * @param {*} state @@ -61,7 +61,7 @@ const mutations = { setPagePath(state, data) { state.pagePath = data; }, - + /** * 设置健康状态类型 status * @param {*} state @@ -69,7 +69,7 @@ const mutations = { */ setStatus(state, data) { state.status = data || []; - } + }, }; export default mutations; From 0d9851784959b45dc5fe029a8dd21e7a27e05127 Mon Sep 17 00:00:00 2001 From: wally <18603454788@163.com> Date: Tue, 10 Mar 2020 17:46:54 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 38 +++++++++++++++++++++++++---------- config/api/user.js | 3 +++ store/modules/user/actions.js | 24 +++++++++++++++++++++- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/App.vue b/App.vue index c7e8059..a1419a9 100644 --- a/App.vue +++ b/App.vue @@ -2,9 +2,11 @@ import { mapState, mapMutations, mapActions } from 'vuex'; import { GET_USER_INFO, HEALTH_TYPE_STATUS } from 'api/api'; import { showLoading, hideLoading, showToast, showModal } from 'utils/ui'; +import { formatQuery } from 'utils/util'; export default { - async onLaunch() { + async onLaunch(options) { + console.log('options: ', options); uni.getSetting({ success(res) { if (!res.authSetting['scope.userLocation']) { @@ -17,8 +19,30 @@ export default { }); try { - await this.login(); + if (options.query.scene) { + const query = formatQuery(decodeURIComponent(options.query.scene)); + if (query && query.d) { + await this.getTokenByUserId({ params: { userId: query.d } }); + this.initCommon(); + } else { + await this.login(); + this.initCommon(); + return; + } + } else { + await this.login(); + this.initCommon(); + } + } catch (error) { + console.log('onLaunch error: ', error); + } + }, + computed: mapState('user', ['token']), + + methods: { + ...mapActions('user', ['login', 'getUserInfo', 'getHealthTypeStatus', 'getTokenByUserId']), + async initCommon() { const startTime = +this.$moment() .startOf('year') .format('x'); @@ -34,15 +58,7 @@ export default { }; await this.getUserInfo(params); await this.getHealthTypeStatus(); - } catch (error) { - console.log('error: ', error); - } - }, - - computed: mapState('user', ['token']), - - methods: { - ...mapActions('user', ['login', 'getUserInfo', 'getHealthTypeStatus']), + }, }, }; diff --git a/config/api/user.js b/config/api/user.js index 6b3eec6..dd9cff9 100644 --- a/config/api/user.js +++ b/config/api/user.js @@ -5,3 +5,6 @@ export const SIGN_IN = `${proxyUrl}/users/signin`; // 上传用户微信信息 export const UPDATE_USER = `${proxyUrl}/users/userInfo`; + +// 通过userId 获取token +export const USER_ID_EXCHANGE_TOKEN = `${proxyUrl}/users/userId`; diff --git a/store/modules/user/actions.js b/store/modules/user/actions.js index 0024847..dfb2a50 100644 --- a/store/modules/user/actions.js +++ b/store/modules/user/actions.js @@ -1,6 +1,6 @@ import { showLoading, hideLoading, showModal, showToast } from 'utils/ui'; import { mpLogin, signIn } from 'utils/user'; -import { UPDATE_USER } from 'api/user'; +import { UPDATE_USER, USER_ID_EXCHANGE_TOKEN } from 'api/user'; import { GET_USER_INFO, HEALTH_TYPE_STATUS } from 'api/api'; import { http } from 'plugins/request/index'; @@ -115,6 +115,28 @@ const actions = { }); }); }, + + /** + * 通过userId换取token + * @param {*} commit + * @param {object} params 提交的完整参数 + */ + getTokenByUserId({ commit }, params) { + return new Promise((resolve, reject) => { + http + .get(USER_ID_EXCHANGE_TOKEN, params) + .then(res => { + const { data } = res.data; + commit('setToken', data.token); + commit('setUser', data); + resolve(data); + }) + .catch(data => { + showToast(data.msg || '获取token失败'); + reject(data); + }); + }); + }, }; export default actions; From b1d5bdc0d9ca68a0462f205619c8fc2bb1aeb350 Mon Sep 17 00:00:00 2001 From: wally <18603454788@163.com> Date: Tue, 10 Mar 2020 22:31:46 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/statistics/components/date-selector.vue | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pages/statistics/components/date-selector.vue b/pages/statistics/components/date-selector.vue index dc386a0..f9976dc 100644 --- a/pages/statistics/components/date-selector.vue +++ b/pages/statistics/components/date-selector.vue @@ -93,19 +93,15 @@ export default { break; case '近7天': start = this.$moment() - .subtract(7, 'days') - .format('YYYY-MM-DD'); - end = this.$moment() - .subtract(1, 'days') + .subtract(6, 'days') .format('YYYY-MM-DD'); + end = this.$moment().format('YYYY-MM-DD'); break; case '近30天': start = this.$moment() - .subtract(30, 'days') - .format('YYYY-MM-DD'); - end = this.$moment() - .subtract(1, 'days') + .subtract(29, 'days') .format('YYYY-MM-DD'); + end = this.$moment().format('YYYY-MM-DD'); break; default: break;