Commit ec0b5cdc by 李伟康

车牌组件增加粘贴功能

1 parent 353e454e
......@@ -42,6 +42,16 @@
</div>
</template>
</div>
<template v-if="showPasteButton">
<button
class="paste"
@click="paste"
@touchstart="touchstart"
@touchend="touchend"
>
一键粘贴
</button>
</template>
</div>
<div class="license-plate-bottom">
<div
......@@ -119,7 +129,8 @@
</template>
<script type='text/ecmascript-6'>
const suffix = '港澳学挂',
city = '京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼'
city = '京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼',
platNumberRex = /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼][A-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学港澳])$/
export default {
name: 'LicensePlate',
data () {
......@@ -135,9 +146,12 @@ export default {
suffix: [],
keyboardDisabled: false,
hidden: false,
showPasteButton: false
}
},
mounted () {
/**navigator.clipboard 只支持https */
if (navigator.clipboard) this.showPasteButton = true
this.cityList = [...city]
this.letter = [...'ABCDEFGHJKLMNPQRSTUVWXYZ']
this.suffix = [...suffix]
......@@ -179,8 +193,7 @@ export default {
let {
plateNo
} = this,
plateNoErr = false,
platNumberRex = /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼][A-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学港澳])$/
plateNoErr = false
/**车牌后缀 */
if (plateNo[6] && plateNo[7] && suffix.includes(plateNo[6])) this.plateNo[7] = ''
......@@ -203,6 +216,24 @@ export default {
this.$emit('done', { value })
this.toggle()
},
async paste () {
if (navigator.clipboard) {
try {
let data = await navigator.clipboard.readText(),
value = data.toUpperCase(),
plateNo = [...value].filter(e => e && e != '' && /[\u4e00-\u9fa5\w]/.test(e))
while (plateNo.length < 8) plateNo.push('')
plateNo = plateNo.splice(0, 8)
if (platNumberRex.test(plateNo.join(''))) {
this.plateNo = plateNo
this.check()
}
} catch (error) {
console.log(error)
}
}
}
}
}
</script>
......@@ -293,6 +324,7 @@ export default {
width: calc(100% - 60px);
height: 46px;
border: none;
border-radius: 5px;
}
}
&-bottom {
......
......@@ -10,7 +10,7 @@
module.exports = {
title: '加载中...',
request: {
baseURL: 'http://scrm.test.glsx.com.cn', // 本地测试项目地址,
baseURL: 'http://scrm.dev.glsx.com.cn', // 本地测试项目地址,
// 设置超时时间
timeout: 180000,
// 携带凭证
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!