feat: 增加xtScanInput组件2
This commit is contained in:
parent
7641469088
commit
aed96df1c9
|
@ -3,7 +3,7 @@
|
||||||
@focus="handleFocus" clearable/>
|
@focus="handleFocus" clearable/>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, defineProps, defineEmits, computed, onMounted } from "vue";
|
import { ref, defineProps, defineEmits, computed, onMounted, nextTick } from "vue";
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
|
|
||||||
const scanValue = ref('')
|
const scanValue = ref('')
|
||||||
|
@ -23,30 +23,50 @@ const props = defineProps({
|
||||||
const emit = defineEmits(['scan']);
|
const emit = defineEmits(['scan']);
|
||||||
const inputType = ref('text')
|
const inputType = ref('text')
|
||||||
|
|
||||||
|
onMounted(()=>{
|
||||||
|
nextTick(()=>{
|
||||||
|
// const inputElement = document.querySelector('input[type="text"]');
|
||||||
|
const inputElement = scanInput.value.$el.querySelector('input');
|
||||||
|
|
||||||
|
inputElement.addEventListener("compositionstart", (event) => {
|
||||||
|
|
||||||
|
ElMessage.info('请确保输入法为英文!')
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
function handleKeyDown(e) {
|
function handleKeyDown(e) {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
|
// inputType.value = 'text'
|
||||||
|
// e.target.readOnly = false
|
||||||
const value = scanValue.value.trim()
|
const value = scanValue.value.trim()
|
||||||
if (/[\u4e00-\u9fa5]/.test(value)) {
|
if (/[\u4e00-\u9fa5]/.test(value)) {
|
||||||
ElMessage.error('扫码内容包含中文或输入法异常,请切换为英文输入法后重试!')
|
ElMessage.error('扫码内容包含中文或输入法异常,请切换为英文输入法后重试!')
|
||||||
scanValue.value = ''
|
scanValue.value = ''
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (value) {
|
else if (value) {
|
||||||
// inputType.value = 'text'
|
|
||||||
// props.onScan && props.onScan(value)
|
// props.onScan && props.onScan(value)
|
||||||
emit('scan', value)
|
emit('scan', value)
|
||||||
if (props.clearAfterScan) {
|
if (props.clearAfterScan) {
|
||||||
scanValue.value = ''
|
scanValue.value = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
ElMessage.error('请扫描正确的条码/二维码!')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleFocus(e) {
|
function handleFocus(e) {
|
||||||
// 尽量提示和引导用户切换输入法为英文
|
// 尽量提示和引导用户切换输入法为英文
|
||||||
e.target.setAttribute('inputmode', 'text')
|
e.target.setAttribute('inputmode', 'text')
|
||||||
e.target.setAttribute('lang', 'en')
|
e.target.setAttribute('lang', 'en')
|
||||||
// ElMessage.info('请确保输入法为英文!')
|
// ElMessage.info('请确保输入法为英文!')
|
||||||
|
// e.target.readOnly = true
|
||||||
// inputType.value = 'password'
|
// inputType.value = 'password'
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue