Browse Source

测试账号

remotes/origin/HEAD
wally 5 years ago
parent
commit
0d98517849
  1. 34
      App.vue
  2. 3
      config/api/user.js
  3. 24
      store/modules/user/actions.js

34
App.vue

@ -2,9 +2,11 @@
import { mapState, mapMutations, mapActions } from 'vuex'; import { mapState, mapMutations, mapActions } from 'vuex';
import { GET_USER_INFO, HEALTH_TYPE_STATUS } from 'api/api'; import { GET_USER_INFO, HEALTH_TYPE_STATUS } from 'api/api';
import { showLoading, hideLoading, showToast, showModal } from 'utils/ui'; import { showLoading, hideLoading, showToast, showModal } from 'utils/ui';
import { formatQuery } from 'utils/util';
export default { export default {
async onLaunch() { async onLaunch(options) {
console.log('options: ', options);
uni.getSetting({ uni.getSetting({
success(res) { success(res) {
if (!res.authSetting['scope.userLocation']) { if (!res.authSetting['scope.userLocation']) {
@ -17,8 +19,30 @@ export default {
}); });
try { try {
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(); 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() const startTime = +this.$moment()
.startOf('year') .startOf('year')
.format('x'); .format('x');
@ -34,15 +58,7 @@ export default {
}; };
await this.getUserInfo(params); await this.getUserInfo(params);
await this.getHealthTypeStatus(); await this.getHealthTypeStatus();
} catch (error) {
console.log('error: ', error);
}
}, },
computed: mapState('user', ['token']),
methods: {
...mapActions('user', ['login', 'getUserInfo', 'getHealthTypeStatus']),
}, },
}; };
</script> </script>

3
config/api/user.js

@ -5,3 +5,6 @@ export const SIGN_IN = `${proxyUrl}/users/signin`;
// 上传用户微信信息 // 上传用户微信信息
export const UPDATE_USER = `${proxyUrl}/users/userInfo`; export const UPDATE_USER = `${proxyUrl}/users/userInfo`;
// 通过userId 获取token
export const USER_ID_EXCHANGE_TOKEN = `${proxyUrl}/users/userId`;

24
store/modules/user/actions.js

@ -1,6 +1,6 @@
import { showLoading, hideLoading, showModal, showToast } from 'utils/ui'; import { showLoading, hideLoading, showModal, showToast } from 'utils/ui';
import { mpLogin, signIn } from 'utils/user'; 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 { GET_USER_INFO, HEALTH_TYPE_STATUS } from 'api/api';
import { http } from 'plugins/request/index'; 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; export default actions;

Loading…
Cancel
Save