diff --git a/App.vue b/App.vue index 554c450..6c4adc6 100644 --- a/App.vue +++ b/App.vue @@ -17,94 +17,15 @@ export default { }); await this.login(); - await this.getUserInfo(); - await this.getHealthTypeStaus(); + const params = { param: { token: this.token } }; + await this.getUserInfo(params); + await this.getHealthTypeStaus(); }, computed: mapState('user', ['token']), methods: { - ...mapMutations('user', ['setStatus','setUserInfo','setHealthCode']), - ...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' - }); - } - } - }, - + ...mapActions('user', ['login', 'getUserInfo', 'getHealthTypeStatus']), }, }; diff --git a/pages.json b/pages.json index 5fe768c..3cbbcfa 100644 --- a/pages.json +++ b/pages.json @@ -1,18 +1,15 @@ { "pages": [ - // { - // "path": "pages/my-trips/my-trips", - // "style": { - // "navigationBarTitleText": "我的行程" - // } - // }, - { "path": "pages/index/index", "style": { "navigationBarTitleText": "山大健康码" } }, + { + "path": "pages/user-code/user-code", + "style": {"navigationBarTitleText": "健康码"} + }, { "path": "pages/statistics/statistics", "style": { "navigationBarTitleText": "统计" } @@ -69,10 +66,7 @@ "path": "pages/healthy-card/healthy-card", "style": {} }, - { - "path": "pages/user-code/user-code", - "style": {} - }, + { "path": "pages/service-agreement/service-agreement", "style": { diff --git a/pages/index/index.vue b/pages/index/index.vue index 24bbbe2..6e24aec 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -4,8 +4,11 @@ + + + @@ -33,14 +36,23 @@ export default { // 扫一扫 // 只允许通过相机扫码 - // TODO: 扫码业务 onScan() { - uni.scanCode({ + wx.scanCode({ onlyFromCamera: true, + scanType: ['qrCode', 'wxCode'], success: 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) {}, + }); + } }, }); }, diff --git a/pages/user-code/user-code.vue b/pages/user-code/user-code.vue index c43b673..f528242 100644 --- a/pages/user-code/user-code.vue +++ b/pages/user-code/user-code.vue @@ -1,25 +1,171 @@ - diff --git a/store/modules/user/actions.js b/store/modules/user/actions.js index 380492d..2dda995 100644 --- a/store/modules/user/actions.js +++ b/store/modules/user/actions.js @@ -1,6 +1,7 @@ import { showModal, showToast } from 'utils/ui'; import { mpLogin, signIn } from 'utils/user'; import { UPDATE_USER } from 'api/user'; +import { GET_USER_INFO, HEALTH_TYPE_STATUS } from 'api/api'; import { http } from 'plugins/request/index'; const actions = { @@ -11,7 +12,7 @@ const actions = { mpLogin() .then(params => signIn(params)) .then(data => { - console.log('login data: ', data); + // console.log('login data: ', data); commit('setToken', data.token); 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; diff --git a/store/modules/user/state.js b/store/modules/user/state.js index fff4bf3..48f05d9 100644 --- a/store/modules/user/state.js +++ b/store/modules/user/state.js @@ -2,7 +2,7 @@ const state = { token: '', user: null, healthCode: '', // 健康码 - userInfo: '', // 个人基本信息 + userInfo: null, // 个人基本信息 pagePath: '', //页面跳转参数 status: [], // 健康状态类型 };