修改扫码

This commit is contained in:
x
2026-06-03 13:05:15 +08:00
parent 19801f44a6
commit b60645131e
11 changed files with 233 additions and 125 deletions

View File

@@ -8,10 +8,12 @@
:focus="focusState"
@focus="handleFocus"
@blur="handleBlur"
@input="handleInput"
@confirm="handleSend">
<view class="zd-row buttons_wraper">
<uni-icons v-show="value !== '' && value !== null && value !== undefined" class="pdr10" type="clear" size="24" color="#666" @tap="toDel"></uni-icons>
<uni-icons type="scan" size="22" :color="focusState ? '#ff6a00' : '#4e6ef2'" @tap="focusState=true"></uni-icons>
<uni-icons type="camera" size="28" style="marginLeft: 30rpx;" @tap="toPhone"></uni-icons>
</view>
</view>
</template>
@@ -42,6 +44,13 @@
// }
this.focusState = false
},
handleInput (e) {
this.$emit('input', e.target.value)
// this.$emit('handleInput', e.target.value)
if (e.target.value.length) {
this.$emit('handleInput', e.target.value)
}
},
toDel () {
this.$emit('input', '')
this.$emit('handleDel')
@@ -51,7 +60,49 @@
if (e.target.value.length) {
this.$emit('handleChange', e.target.value)
}
},
async toPhone() {
// #ifdef APP-PLUS
let status = await this.checkPermission();
if (status !== 1) {
return;
}
// #endif
uni.scanCode({
success: (res) => {
this.$emit('input', res.result)
this.$emit('handleChange', res.result)
},
fail: (err) => {
// uni.showToast({
// title: '出错',
// icon: 'none'
// })
}
});
}
// #ifdef APP-PLUS
,
async checkPermission(code) {
let status = permision.isIOS ? await permision.requestIOS('camera') :
await permision.requestAndroid('android.permission.CAMERA');
if (status === null || status === 1) {
status = 1;
} else {
uni.showModal({
content: "需要相机权限",
confirmText: "设置",
success: function(res) {
if (res.confirm) {
permision.gotoAppSetting();
}
}
})
}
return status;
}
// #endif
}
}
</script>