emis-sapp/components/tpx-scan-input/tpx-scan-input.vue

128 lines
2.5 KiB
Vue
Raw Normal View History

2023-12-23 07:52:34 +00:00
<template>
2024-07-16 13:25:55 +00:00
<u-row>
<u-input :placeholder="placeholder" :fontSize="fontSize" :modelValue="value"
:custom-style="`border-radius: 10rpx;padding: 11rpx 20rpx;${customStyle};`"
2024-08-06 06:40:19 +00:00
@change="handleInputChange" @blur="handleInputBlur" @focus="handleInputFocus"
2024-07-16 13:25:55 +00:00
>
<template v-if="iconPos == 'left'" v-slot:prefix>
<u-icon @click="handleScan" name="scan" :size="fontSize*1.5"></u-icon>
</template>
<template v-if="iconPos == 'right'" v-slot:suffix>
<u-icon @click="handleScan" name="scan" :size="fontSize*1.5"></u-icon>
</template>
</u-input>
2024-01-22 01:55:30 +00:00
2024-07-16 13:25:55 +00:00
<view v-if="showConfirm" @click="handleConfirm" class="ml-10">
<u-button custom-style="height: 70rpx;" :plain="true">确认</u-button>
</view>
</u-row>
2024-08-06 06:40:19 +00:00
<tpx-physics-scan v-if="showPhysics" @onChange="handleScanChange"></tpx-physics-scan>
2023-12-23 07:52:34 +00:00
</template>
<script>
import { scanCode } from "@/common/untool"
export default {
2024-08-06 06:40:19 +00:00
computed: {
showPhysics() {
let bl = false
if(this.phyTrigger == 'loaded') {
bl = true
}
if(this.phyTrigger == 'focus' && this.isInputFocused) {
bl = true
}
return bl
},
},
2023-12-23 07:52:34 +00:00
props: {
2024-01-22 01:55:30 +00:00
2023-12-23 07:52:34 +00:00
value: {
default () {
return ''
}
},
placeholder:{
default () {
return '请输入或扫码'
}
},
fontSize: {
default () {
return 26
}
},
2024-01-22 01:55:30 +00:00
iconPos: {
default () {
return "left"
}
},
2023-12-23 07:52:34 +00:00
customStyle:{
default () {
return ''
}
},
placeholderStyle:{
default () {
return ''
}
},
2024-07-16 13:25:55 +00:00
showConfirm:{
default () {
return false
}
},
2024-08-06 06:40:19 +00:00
phyTrigger:{ // 红外监听方式
default () {
return 'loaded' // loaded:组件加载 focus:输入框获取焦点
}
},
2023-12-23 07:52:34 +00:00
},
data() {
2024-08-06 06:40:19 +00:00
return {
isInputFocused: false
}
2023-12-23 07:52:34 +00:00
},
created() {
},
onHide() {
},
2024-01-29 10:48:55 +00:00
unmounted() {},
2023-12-23 07:52:34 +00:00
methods: {
async handleScan() {
const res = await scanCode()
2024-05-31 10:42:15 +00:00
this.handleScanChange(res)
2023-12-23 07:52:34 +00:00
},
handleChange(val){
this.$emit('change', val)
2024-05-31 10:42:15 +00:00
this.$emit('update:value', val)
},
handleInputChange(val){
this.$emit('inputChange', val)
this.handleChange(val)
},
handleScanChange(val){
this.$emit('scanChange', val)
this.handleChange(val)
2024-07-16 13:25:55 +00:00
},
handleConfirm(){
this.$emit('confirmClick')
2024-08-06 06:40:19 +00:00
},
handleInputBlur(){
this.isInputFocused = false
this.$emit('blur')
},
handleInputFocus(){
this.isInputFocused = true
this.$emit('focus')
2023-12-23 07:52:34 +00:00
}
}
}
</script>
<style scoped lang="scss">
</style>