Commit ec0b5cdc by 李伟康

车牌组件增加粘贴功能

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