Browse Source

Merge branch 'master' of https://gitee.com/ccsens_s/healthyCode

remotes/origin/HEAD
songsong428 5 years ago
parent
commit
3fe37b73ff
  1. 38
      App.vue
  2. 4
      components/auth/auth.vue
  3. 3
      config/api/user.js
  4. 2
      main.js
  5. 12
      pages/statistics/components/date-selector.vue
  6. 8
      pages/user-code/user-code.vue
  7. 27
      store/modules/user/actions.js
  8. 10
      store/modules/user/mutations.js

38
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']),
},
},
};
</script>

4
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;
}
},
},

3
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`;

2
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';
}

12
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;

8
pages/user-code/user-code.vue

@ -108,9 +108,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;
@ -127,8 +127,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');
},
},

27
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';
@ -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);
// 获取自己的信息采取设置
// 扫别人健康码的时候不用设置
@ -114,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;

10
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;

Loading…
Cancel
Save