Browse Source

1.扫码

2.用户健康码页面
remotes/origin/HEAD
wally 5 years ago
parent
commit
25289bdf40
  1. 85
      App.vue
  2. 16
      pages.json
  3. 20
      pages/index/index.vue
  4. 154
      pages/user-code/user-code.vue
  5. 53
      store/modules/user/actions.js
  6. 2
      store/modules/user/state.js

85
App.vue

@ -17,94 +17,15 @@ export default {
}); });
await this.login(); await this.login();
await this.getUserInfo(); const params = { param: { token: this.token } };
await this.getUserInfo(params);
await this.getHealthTypeStaus(); await this.getHealthTypeStaus();
}, },
computed: mapState('user', ['token']), computed: mapState('user', ['token']),
methods: { methods: {
...mapMutations('user', ['setStatus','setUserInfo','setHealthCode']), ...mapActions('user', ['login', 'getUserInfo', 'getHealthTypeStatus']),
...mapActions('user', ['login']),
/**
* 查询个人信息
*/
async getUserInfo() {
try {
showLoading();
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'
});
}
hideLoading();
} catch (error) {
hideLoading();
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> </script>

16
pages.json

@ -1,18 +1,15 @@
{ {
"pages": [ "pages": [
// {
// "path": "pages/my-trips/my-trips",
// "style": {
// "navigationBarTitleText": "我的行程"
// }
// },
{ {
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {
"navigationBarTitleText": "山大健康码" "navigationBarTitleText": "山大健康码"
} }
}, },
{
"path": "pages/user-code/user-code",
"style": {"navigationBarTitleText": "健康码"}
},
{ {
"path": "pages/statistics/statistics", "path": "pages/statistics/statistics",
"style": { "navigationBarTitleText": "统计" } "style": { "navigationBarTitleText": "统计" }
@ -69,10 +66,7 @@
"path": "pages/healthy-card/healthy-card", "path": "pages/healthy-card/healthy-card",
"style": {} "style": {}
}, },
{
"path": "pages/user-code/user-code",
"style": {}
},
{ {
"path": "pages/service-agreement/service-agreement", "path": "pages/service-agreement/service-agreement",
"style": { "style": {

20
pages/index/index.vue

@ -4,8 +4,11 @@
<home v-if="navIndex === 0" /> <home v-if="navIndex === 0" />
<mine v-else /> <mine v-else />
</view> </view>
<!-- 底部菜单 -->
<nav-bottom @change="onNavChange" @scan="onScan" class="nav-bottom"></nav-bottom> <nav-bottom @change="onNavChange" @scan="onScan" class="nav-bottom"></nav-bottom>
<!-- 获取用户信息的授权组件 -->
<auth /> <auth />
</view> </view>
</template> </template>
@ -33,14 +36,23 @@ export default {
// //
// //
// TODO:
onScan() { onScan() {
uni.scanCode({ wx.scanCode({
onlyFromCamera: true, onlyFromCamera: true,
scanType: ['qrCode', 'wxCode'],
success: res => { success: res => {
console.log('res: ', res); console.log('res: ', res);
console.log('条码类型:' + res.scanType); //
console.log('条码内容:' + res.result); if (res && res.path) {
const path = `${res.path}&scan=true`;
this.openPage(res.path);
} else {
uni.showModal({
title: '提示',
content: '您的微信版本不支持此功能, 请使用微信APP的扫码功能',
success: function(res) {},
});
}
}, },
}); });
}, },

154
pages/user-code/user-code.vue

@ -1,25 +1,171 @@
<template> <template>
<view>扫了别人的码 看其健康状态</view> <view class="padding-lg">
<template v-if="userInfo">
<view class="padding bg-purple shadow-blur radius margin-bottom-xl">
<view>
<view class="text-lg text-bold margin-bottom">个人申报信息</view>
<view class="text-df text-grey">
<text class="margin-right">{{ userInfo.name }}</text>
<text>{{ post }}</text>
</view>
<view class="text-df text-grey">
身份证
<text>{{ userInfo.idCard }}</text>
</view>
<view class="text-df text-grey">
手机号
<text>{{ userInfo.phone }}</text>
</view>
<view class="text-df text-grey">
学号
<text>{{ userInfo.no }}</text>
</view>
<view class="text-df text-grey">
登记时间
<text>{{ time }}</text>
</view>
<view class="text-df text-grey">
健康状态
<text>{{ level }}</text>
</view>
</view>
</view>
<view class="padding-top-xl">
<image
:src="userInfo.healthCodeList[0].healthCode"
class="img solid radius"
mode="aspectFit"
/>
</view>
</template>
</view>
</template> </template>
<script> <script>
import { mapActions } from 'vuex';
import { formatQuery } from 'utils/util'; import { formatQuery } from 'utils/util';
export default { export default {
data() { data() {
return {}; return {
userInfo: null,
// userInfo: {
// healthCodeList: [
// {
// healthCode: 'https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/gh_33446d7f7a26_430.jpg',
// healthLevel: 0,
// time: Date.now(),
// },
// ],
// id: '123',
// idCard: '1407241989****019X',
// no: '080800009',
// phone: '18603454788',
// post: 0,
// name: '',
// },
timer: null,
};
}, },
onLoad(options) { computed: {
//
post() {
if (!this.userInfo) return '学生';
let str = '学生';
console.log('this.userInfo.post: ', this.userInfo.post);
switch (this.userInfo.post) {
case 0:
str = '学生';
break;
case 1:
str = '老师';
break;
case 2:
str = '工作人员';
break;
default:
break;
}
return str;
},
//
level() {
if (!this.userInfo || !this.userInfo.healthLevel) return '正常';
let str = '正常';
switch (this.userInfo.healthLevel[0].healthLevel) {
case 0:
str = '正常';
break;
case 1:
str = '隔离中或疑似';
break;
case 2:
str = '确诊';
break;
default:
break;
}
return str;
},
time() {
if (!this.userInfo || !this.userInfo.healthLevel) return;
return this.$moment(this.userInfo.healthLevel[0].time - 0).format('YYYY-MM-DD HH:mm');
},
},
async onLoad(options) {
this.init(options);
},
methods: {
...mapActions('user', ['getUserInfo']),
init(options) {
try { try {
console.log('options: ', options);
const query = formatQuery(decodeURIComponent(options.scene)); const query = formatQuery(decodeURIComponent(options.scene));
console.log('query: ', query); console.log('query: ', query);
const { d } = query;
if (!d) {
uni.showToast({
title: '二维码参数错误',
icon: 'none',
duration: 3000,
});
}
const params = { param: { userId: d } };
this.getUserInfoData(params);
} catch (error) { } catch (error) {
console.log('error: ', error); console.log('error: ', error);
} }
}, },
/**
* 获取场所的基本信息
* @param {object} params 提交给后端的参数
*/
async getUserInfoData(params) {
this.timer && clearInterval(this.timer);
if (!this.token) {
this.timer = setTimeout(() => {
this.getUserInfoData(params);
}, 100);
} else {
this.userInfo = await this.getUserInfo(params);
}
},
},
}; };
</script> </script>
<style lang="scss"> <style lang="scss" scoped>
.img {
display: block;
width: 400rpx;
height: 400rpx;
margin: 0 auto;
}
</style> </style>

53
store/modules/user/actions.js

@ -1,6 +1,7 @@
import { showModal, showToast } from 'utils/ui'; import { 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 } from 'api/user';
import { GET_USER_INFO, HEALTH_TYPE_STATUS } from 'api/api';
import { http } from 'plugins/request/index'; import { http } from 'plugins/request/index';
const actions = { const actions = {
@ -11,7 +12,7 @@ const actions = {
mpLogin() mpLogin()
.then(params => signIn(params)) .then(params => signIn(params))
.then(data => { .then(data => {
console.log('login data: ', data); // console.log('login data: ', data);
commit('setToken', data.token); commit('setToken', data.token);
commit('setUser', data); commit('setUser', data);
@ -60,6 +61,56 @@ const actions = {
}); });
}); });
}, },
/**
* 查询基本信息
* @param {*} commit
* @param {object} params 提交的完整数据
*/
getUserInfo({ commit }, params) {
return new Promise((resolve, reject) => {
http
.post(GET_USER_INFO, params)
.then(res => {
const { data } = res.data;
resolve(data);
// 获取自己的信息采取设置
// 扫别人健康码的时候不用设置
if (params.param.token) {
commit('setUserInfo', data);
}
if (data.healthCodeList && data.healthCodeList.length > 0) {
const oldCode = data.healthCodeList[0].healthCode;
commit('setHealthCode', oldCode);
}
})
.catch(data => {
showToast(data.msg || '查询个人信息成功');
reject(data);
});
});
},
/**
* 查询健康状态类型
* @param {*} commit
*/
async getHealthTypeStatus({ commit }) {
return new Promise((resolve, reject) => {
http
.post(HEALTH_TYPE_STATUS)
.then(res => {
const { data } = res.data;
resolve(data);
commit('setStatus', data);
})
.catch(data => {
showToast(data.msg || '查询健康类型失败');
reject(data);
});
});
},
}; };
export default actions; export default actions;

2
store/modules/user/state.js

@ -2,7 +2,7 @@ const state = {
token: '', token: '',
user: null, user: null,
healthCode: '', // 健康码 healthCode: '', // 健康码
userInfo: '', // 个人基本信息 userInfo: null, // 个人基本信息
pagePath: '', //页面跳转参数 pagePath: '', //页面跳转参数
status: [], // 健康状态类型 status: [], // 健康状态类型
}; };

Loading…
Cancel
Save