维基小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

113 lines
2.3 KiB

<script>
import { mapState, mapMutations, mapActions } from 'vuex';
import { GET_USER_INFO, HEALTH_TYPE_STATUS } from 'api/api';
export default {
async onLaunch() {
uni.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
uni.authorize({
scope: 'scope.userLocation',
success() {},
});
}
},
});
await this.login();
await this.getUserInfo();
await this.getHealthTypeStaus();
},
computed: mapState('user', ['token']),
methods: {
...mapMutations('user', ['setStatus','setUserInfo','setHealthCode']),
...mapActions('user', ['login']),
/**
* 查询个人信息
*/
async getUserInfo() {
try {
const { token } = this;
const params = {
param: {
token
}
};
const res = await this.$http.post(GET_USER_INFO, params);
const {
success,
code,
msg,
data
} = res.data;
if (success && code === 200) {
this.setUserInfo(data);
if(data.healthCodeList && data.healthCodeList.length>0){
const oldCode = data.healthCodeList[0].healthCode;
this.setHealthCode(oldCode)
}
this.success = true;
} else {
uni.showToast({
title: msg || '查询个人信息成功',
icon: 'none'
});
}
} catch (error) {
console.log('error: ', error);
if (error.msg) {
uni.showToast({
title: error.msg || '查询个人信息失败',
icon: 'none'
});
}
}
},
/**
* 查询健康状态类型
*/
async getHealthTypeStaus() {
try {
const res = await this.$http.post(HEALTH_TYPE_STATUS);
const {
success,
code,
msg,
data
} = res.data;
if (success && code === 200) {
this.success = true;
this.setStatus(data)
} else {
uni.showToast({
title: msg || '申请健康码成功',
icon: 'none'
});
}
} catch (error) {
console.log('error: ', error);
if (error.msg) {
uni.showToast({
title: error.msg || '申请健康码失败',
icon: 'none'
});
}
}
},
},
};
</script>
<style lang="scss">
@import 'colorui/main.scss';
@import 'colorui/icon.scss';
@import 'colorui/animation.scss';
@import 'common/style/global';
@import 'common/style/iconfont';
</style>