Browse Source

fix: 完善扫描二维码逻辑

develop
song 4 years ago
parent
commit
658245fa44
  1. 1
      CHANGELOG.md
  2. 2
      rest/燕园.http
  3. 43
      src/App.vue
  4. 67
      src/components/Upload/Upload.vue
  5. 4
      src/mixins/tool.js
  6. 4
      src/pagesYanyuan/input-code/input-code.vue
  7. 60
      src/pagesYanyuan/scan-code/scan-code.vue
  8. 29
      src/store/yanyuan/mutations.js
  9. 3
      src/store/yanyuan/state.js

1
CHANGELOG.md

@ -95,6 +95,7 @@
- | 项目列表, 项目url | [32e005b](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/32e005b) - | 项目列表, 项目url | [32e005b](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/32e005b)
- | 项目列表排序 | [224c58b](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/224c58b) - | 项目列表排序 | [224c58b](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/224c58b)
- | 项目合并整理,设置页面添加 | [725491a](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/725491a) - | 项目合并整理,设置页面添加 | [725491a](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/725491a)
- | 首页用户身份判断 | [ac81030](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/ac81030)
- | 首页项目样式改变 | [8514c85](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/8514c85) - | 首页项目样式改变 | [8514c85](https://dd.tall.wiki/gitea/binbin0314/yanyuan_js/commits/8514c85)

2
rest/燕园.http

@ -121,7 +121,7 @@ Authorization: Bearer {{login.response.body.$.data.token}}
{ {
"param":{ "param":{
"id":"6" "id":"3"
} }
} }
###体验账号升级 ###体验账号升级

43
src/App.vue

@ -8,6 +8,15 @@ export default {
async onLaunch(options) { async onLaunch(options) {
// TODO: this // TODO: this
console.log('options: ', options); console.log('options: ', options);
if (options.scene === 1047) {
//
if (options.query && options.query.scene) {
const scene = options.query.scene;
const toolCode = scene.substring(scene.length - 10);
this.setEnterByCode(true);
this.setToolCode(toolCode);
}
}
this.getSystemInfo(); // this.getSystemInfo(); //
@ -35,13 +44,16 @@ export default {
computed: { computed: {
...mapGetters(['useStorage']), ...mapGetters(['useStorage']),
...mapState('user', ['token']), ...mapState('user', ['token']),
...mapState('yanyuan', ['enterByCode', 'toolCode']),
}, },
methods: { methods: {
...mapActions('user', ['getToken']), ...mapActions('user', ['getToken']),
...mapActions('socket', ['initSocket']), ...mapActions('socket', ['initSocket']),
...mapActions('yanyuan', ['getBindTool']),
...mapMutations(['setSystemInfo']), ...mapMutations(['setSystemInfo']),
...mapMutations('user', ['setToken', 'setUser']), ...mapMutations('user', ['setToken', 'setUser']),
...mapMutations('yanyuan', ['setIdentityInfo', 'setToolCode', 'setEnterByCode']),
// //
async signin() { async signin() {
@ -51,6 +63,11 @@ export default {
this.setUser(data); this.setUser(data);
this.setToken(data.token); this.setToken(data.token);
this.noPhone(data); this.noPhone(data);
//
await this.homeIdentity();
if (this.enterByCode && this.toolCode) {
await this.bindTool();
}
} else { } else {
this.$t.ui.showToast('返回数据异常'); this.$t.ui.showToast('返回数据异常');
} }
@ -81,6 +98,32 @@ export default {
}, },
}); });
}, },
/**
* 首页用户身份判断
*/
async homeIdentity() {
try {
const data = await this.$u.api.homeIdentity();
this.setIdentityInfo(data);
} catch (error) {
console.log('error: ', error);
}
},
/**
* 绑定工具箱
*/
async bindTool() {
console.log('绑定工具箱');
try {
const params = { toolCode: this.toolCode };
await this.getBindTool(params);
this.initTool();
} catch (error) {
console.error('error: ', error);
}
},
}, },
}; };
</script> </script>

67
src/components/Upload/Upload.vue

@ -14,12 +14,7 @@
: 'icons3' : 'icons3'
" "
> >
<u-icon <u-icon class="icons" size="88" name="https://www.tall.wiki/staticrec/yanyuan/icon1.png" @click="scancode"></u-icon>
class="icons"
size="88"
name="https://www.tall.wiki/staticrec/yanyuan/icon1.png"
@click="openPage('/pagesYanyuan/scan-code/scan-code')"
></u-icon>
<u-icon <u-icon
v-if="identityInfo.isMax === 0" v-if="identityInfo.isMax === 0"
class="icons" class="icons"
@ -45,20 +40,24 @@
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import toolMixin from '@/mixins/tool';
export default { export default {
mixins: [toolMixin],
data() { data() {
return { showMenu: false, identityInfo: null }; return { showMenu: false };
}, },
computed: mapGetters('user', ['userId']), computed: {
...mapState('yanyuan', ['identityInfo']),
async mounted() { ...mapGetters('user', ['userId']),
await this.homeIdentity();
}, },
methods: { methods: {
...mapActions('yanyuan', ['getBindTool']),
// wbs // wbs
async handleUpload() { async handleUpload() {
try { try {
@ -76,7 +75,7 @@ export default {
}); });
}, 2000); }, 2000);
} catch (error) { } catch (error) {
console.log('error: ', error); console.error('error: ', error);
this.$emit('error', error); this.$emit('error', error);
} }
}, },
@ -92,24 +91,48 @@ export default {
}, },
// //
scanCode() { scancode() {
this.showMenu = false;
const that = this;
//
uni.scanCode({ uni.scanCode({
success: function (res) { onlyFromCamera: true,
console.log('条码类型:' + res.scanType); success(res) {
console.log('条码内容:' + res.result); that.$t.ui.showToast('扫码成功');
const arr = res.path.split('=');
const toolCode = arr && arr.length ? arr[arr.length - 1] : '';
that.submit(toolCode);
},
fail() {
that.failMsg('扫码失败');
},
});
},
//
failMsg(title) {
uni.showModal({
title,
content: '是否跳转到输入工具码界面?',
showCancel: true,
success: async ({ confirm }) => {
if (confirm) {
this.$t.page.openPage('/pagesYanyuan/input-code/input-code');
}
}, },
}); });
}, },
/** /**
* 首页用户身份判断 * 绑定工具箱
*/ */
async homeIdentity() { async submit(toolCode) {
try { try {
const data = await this.$u.api.homeIdentity(); const params = { toolCode };
this.identityInfo = data; await this.getBindTool(params);
this.initTool();
} catch (error) { } catch (error) {
console.log('error: ', error); console.error('error: ', error);
} }
}, },
}, },

4
src/mixins/tool.js

@ -31,8 +31,8 @@ export default {
// 工具箱是否被绑定 // 工具箱是否被绑定
if (!toolInfo || !toolInfo.bindUserId || toolInfo.isBind !== 1) { if (!toolInfo || !toolInfo.bindUserId || toolInfo.isBind !== 1) {
console.log('工具箱没有被绑定'); console.log('工具箱没有被绑定');
this.$t.page.openPage('/pagesYanyuan/scan-code/scan-code'); // this.$t.page.openPage('/pagesYanyuan/scan-code/scan-code');
// this.$t.page.openPage('/pagesYanyuan/input-code/input-code'); this.$t.page.openPage('/pagesYanyuan/input-code/input-code');
return; return;
} }

4
src/pagesYanyuan/input-code/input-code.vue

@ -62,6 +62,10 @@ export default {
}, },
async submit() { async submit() {
if (!this.toolCode) {
this.$t.ui.showToast('请输入工具码!');
return;
}
try { try {
const params = { toolCode: this.toolCode }; const params = { toolCode: this.toolCode };
await this.getBindTool(params); await this.getBindTool(params);

60
src/pagesYanyuan/scan-code/scan-code.vue

@ -1,12 +1,21 @@
<template> <template>
<view> <view>
<!--scan.wxml--> <!--scan.wxml-->
<view class="scan-view"> <!-- <view class="scan-view">
<camera class="scan-camera" mode="scanCode" binderror="cameraError" bindscancode="scancode" frame-size="large" :flash="flash"> <camera
class="scan-camera"
mode="scanCode"
binderror="cameraError"
bindscancode="scancode"
frame-size="large"
:flash="flash"
@initdone="initdone"
@scancode="scancode"
>
<cover-view class="scan-animation" :animation="animation"></cover-view> <cover-view class="scan-animation" :animation="animation"></cover-view>
</camera> </camera>
<view class="text-white">扫二维码/条形码</view> <view class="text-white">扫二维码/条形码</view>
</view> </view> -->
<!-- 这里可以处理其他内容 --> <!-- 这里可以处理其他内容 -->
<view class="w-full flex justify-around btns"> <view class="w-full flex justify-around btns">
<view class="flex flex-col text-center" @click="$t.page.openPage('/pagesYanyuan/input-code/input-code')"> <view class="flex flex-col text-center" @click="$t.page.openPage('/pagesYanyuan/input-code/input-code')">
@ -61,6 +70,7 @@
</template> </template>
<script> <script>
import { mapActions } from 'vuex';
import toolMixin from '@/mixins/tool'; import toolMixin from '@/mixins/tool';
// //
let animation = wx.createAnimation({}); let animation = wx.createAnimation({});
@ -69,39 +79,29 @@ export default {
mixins: [toolMixin], mixins: [toolMixin],
data() { data() {
return { animation, open: false, flash: 'auto' }; return { animation, open: false, flash: 'auto', src: '' };
}, },
onLoad() {},
onShow() { onShow() {
this.donghua(); // this.scancode();
},
onLoad(options) {
console.log('options: ', options);
if (options.toolCode) {
this.submit(options.toolCode);
}
}, },
methods: { methods: {
donghua() { ...mapActions('yanyuan', ['getBindTool']),
var that = this;
console.log('that: ', that); error(e) {
// console.log(e.detail);
let m = true;
setInterval(
function () {
if (m) {
animation.translateY(250).step({ duration: 3000 });
m = !m;
} else {
animation.translateY(-10).step({ duration: 3000 });
m = !m;
}
// that.setData({ animation: animation.export() });
}.bind(this),
3000,
);
},
scancode(e) {
//
let res = e.detail.result;
console.log('res: ', res);
}, },
// initdone(e) {
// console.log('e: ', e);
// this.scancode();
// },
// //
openElectric() { openElectric() {
this.open = !this.open; this.open = !this.open;

29
src/store/yanyuan/mutations.js

@ -119,11 +119,38 @@ const mutations = {
/** /**
* 设置zarit是否测评 * 设置zarit是否测评
* @param {object} state * @param {object} state
* @param {array} show * @param {Boolean} show
*/ */
setIsTest(state, show) { setIsTest(state, show) {
state.isTest = show; state.isTest = show;
}, },
/**
* 设置首页用户身份
* @param {object} state
* @param {object} data
*/
setIdentityInfo(state, data) {
state.identityInfo = data;
},
/**
* 设置是不是通过扫码进入
* @param {object} state
* @param {Boolean} show
*/
setEnterByCode(state, show) {
state.enterByCode = show;
},
/**
* 设置二维码携带的工具箱code
* @param {object} state
* @param {object} data
*/
setToolCode(state, data) {
state.toolCode = data;
},
}; };
export default mutations; export default mutations;

3
src/store/yanyuan/state.js

@ -14,6 +14,9 @@ const state = {
code: 'NLCP', code: 'NLCP',
reportId: '', // 测评ID 脑力测评ID或zaritID reportId: '', // 测评ID 脑力测评ID或zaritID
isTest: false, // zarit是否测评 isTest: false, // zarit是否测评
identityInfo: null, // 首页用户身份
enterByCode: false, // 是不是通过扫码进入
toolCode: '', // 二维码携带的工具箱code
}; };
export default state; export default state;

Loading…
Cancel
Save