Files
hht-xzhy-uni/components/SearchBox.vue

123 lines
2.7 KiB
Vue
Raw Normal View History

2025-09-01 17:18:37 +08:00
<template>
<view class="search_wraper">
<input
type="text"
class="filter_input pdr120"
confirm-type="go"
2025-09-10 15:17:51 +08:00
:placeholder="placeholder"
2025-09-01 17:18:37 +08:00
:value="value"
:focus="focusState"
@focus="handleFocus"
@blur="handleBlur"
@confirm="handleSend">
<view class="zd-row buttons_wraper">
2025-12-04 13:59:33 +08:00
<uni-icons v-show="value !== '' && value !== null && value !== undefined" class="pdr10 icon_del" type="clear" color="#666" @tap="toDel"></uni-icons>
2026-01-12 13:38:13 +08:00
<uni-icons class="icon_scan" type="scan" :color="focusState ? '#ff6a00' : '#4e6ef2'" @tap="focusState=true"></uni-icons>
<!-- <uni-icons class="icon_camera" type="camera" :color="focusState ? '#ff6a00' : '#4e6ef2'" @tap="toPhone"></uni-icons> -->
2025-09-01 17:18:37 +08:00
</view>
</view>
</template>
<script>
import permision from "@/utils/permission.js"
export default {
data() {
return {
focusState: false
};
},
model: {
prop: 'value',
event: 'input'
},
props: {
2025-09-10 15:17:51 +08:00
value: String,
placeholder: String,
2025-09-01 17:18:37 +08:00
},
methods: {
handleFocus () {
this.focusState = true
},
handleBlur (e) {
this.$emit('input', e.target.value)
// if (e.target.value.length) {
// this.$emit('handleChange', e.target.value)
// }
this.focusState = false
},
toDel () {
this.$emit('input', '')
this.$emit('handleDel')
},
handleSend (e) {
this.$emit('input', e.target.value)
if (e.target.value.length) {
this.$emit('handleChange', e.target.value)
}
2025-12-01 14:00:44 +08:00
},
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;
2025-09-01 17:18:37 +08:00
}
2025-12-01 14:00:44 +08:00
// #endif
2025-09-01 17:18:37 +08:00
}
}
</script>
<style lang="stylus">
@import '../common/style/mixin.styl';
.search_wraper
position relative
2025-12-04 13:59:33 +08:00
_wh(100%, 70rpx)
2025-09-01 17:18:37 +08:00
.pdr120
padding-right: 120rpx;
.buttons_wraper
position absolute
top 0
right 10rpx
_wh(auto, 80rpx)
.pdr10
padding-right 10rpx
2025-12-04 13:59:33 +08:00
.icon_del
font-size 40rpx !important
.icon_scan, .icon_camera
font-size 46rpx !important
2025-09-01 17:18:37 +08:00
</style>