Files
hht-tongbo/components/SearchBox.vue
2022-10-12 08:51:05 +08:00

101 lines
1.9 KiB
Vue

<template>
<view class="search_wraper">
<input
type="text"
class="filter_input search_input"
:value="value"
@input="handleChange($event)">
<view class="buttons_wraper">
<span class="iconfont icon_scan" @tap="toScan">&#xe6e2;</span>
<span v-show="seaShow" class="iconfont icon_search" @tap="toSearch">&#xe6e1;</span>
</view>
</view>
</template>
<script>
import permision from "@/utils/permission.js"
export default {
data() {
return {
cur: ''
};
},
model: {
prop: 'value',
event: 'input'
},
props: {
value: String,
seaShow: {
type: Boolean,
default: false
},
},
methods: {
handleChange ($event) {
if ($event.target.value) {
this.cur = $event.target.value
}
},
toSearch () {
this.$emit('toSearch', this.cur)
},
async toScan() {
// #ifdef APP-PLUS
let status = await this.checkPermission();
if (status !== 1) {
return;
}
// #endif
uni.scanCode({
success: (res) => {
this.$emit('input', 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>
<style lang="stylus">
@import '../common/style/mixin.styl';
.search_wraper
position relative
_wh(100%, 70rpx)
.search_input
padding-right: 140rpx;
.buttons_wraper
position absolute
top 0
right 0
_wh(auto, 70rpx)
</style>