vue 移动端车牌键盘

摘要:
----˃{{item}}{{item}}˂s

1.npm install input-plate-number --save 样式可以,键盘相对严谨,但是输入有bug,

2.npm installvue-carplate --save 插件样式个人看来是最好看的,键盘的输入最严谨,但是没有新能源车牌的选项,

3.https://github.com/Pinenutss/LicensePlate 插件是样式不好看,键盘的输入也不严谨,但是有新能源车牌,

https://github.com/liaoyinglong/plate-number-input依赖 样式、键盘输入都可以,但和项目(37.5px)不适配,也不好修改

4.最终使用手写的车牌键盘(vue+vant),易于修改各种需求

vue 移动端车牌键盘第1张车牌键盘vue 移动端车牌键盘第2张
<template>
  <div class="plateNumber">
    <div class="wrap">
      <van-tabs v-model="formData.commonCard">
        <van-tab title="普通车牌" name="1"></van-tab>
        <van-tab title="新能源车牌" name="2"></van-tab>
      </van-tabs>
      <!-- 车牌号码输入框 -->
      <div class="num-box">
        <div :  @click="clickFirstWrap()">
          <span>{{ formData.num0 }}</span>
        </div>
        <div :  @click="clickKeyWordWrap(1)">
          <span>{{ formData.num1 }}</span>
        </div>
        <em class="spot"></em>
        <div :  @click="clickKeyWordWrap(2)">
          <span>{{ formData.num2 }}</span>
        </div>
        <div :  @click="clickKeyWordWrap(3)">
          <span>{{ formData.num3 }}</span>
        </div>
        <div :  @click="clickKeyWordWrap(4)">
          <span>{{ formData.num4 }}</span>
        </div>
        <div :  @click="clickKeyWordWrap(5)">
          <span>{{ formData.num5 }}</span>
        </div>
        <div :  @click="clickKeyWordWrap(6)">
          <span>{{ formData.num6 }}</span>
        </div>
        <div
          v-if="formData.commonCard == '2'":class="{ active: isActive == 7, num1: true }"@click="clickKeyWordWrap(7)"
        >
          <span>{{ formData.num7 }}</span>
        </div>
      </div>
      <div style="margin: 16px; margin-top: 1rem">
        <van-button round block type="info" @click="submitFn()">确认</van-button>
      </div>
    </div>
    <div   v-if="firstWrapStatus">
      <div   >
        <van-button v-for="(item, index) in abbPlate._1" :key="index" @click="selectFirstWord(item)">{{ item }}</van-button>
      </div>
      <div   >
        <van-button v-for="(item, index) in abbPlate._2" :key="index" @click="selectFirstWord(item)">{{ item }}</van-button>
      </div>
      <div   >
        <van-button v-for="(item, index) in abbPlate._3" :key="index" @click="selectFirstWord(item)">{{ item }}</van-button>
      </div>
      <div   >
        <van-button v-for="(item, index) in abbPlate._4" :key="index" @click="selectFirstWord(item)">{{ item }}</van-button>
      </div>
      <div   >
        <van-button v-for="(item, index) in abbPlate._5" :key="index" @click="selectFirstWord(item)">{{ item }}</van-button>
        <span class="bordernone"></span>
      </div>

    </div>
    <div   v-if="keyBoardStatus">
      <!-- <div class="number-wrap"></div>
      <div class="letter-wrap"></div>
      <div class="cn-wrap"></div> -->
      <div    v-if="activeKeyWordIndex !== 1">
        <van-button v-for="(item, index) in allKeyWord._1" :key="index" @click="clickKeyBoard(item)">{{ item }}</van-button>
      </div>
      <div   v-if="activeKeyWordIndex !== 1">
        <van-button v-for="(item, index) in allKeyWord._2" :key="index" @click="clickKeyBoard(item)">{{ item }}</van-button>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
      </div>
      <div class="keyboard">
        <van-button v-for="(item, index) in allKeyWord._3" :key="index" @click="clickKeyBoard(item)">{{ item }}</van-button>
      </div>
      <div class="keyboard">
        <van-button v-for="(item, index) in allKeyWord._4" :key="index" @click="clickKeyBoard(item)">{{ item }}</van-button>
      </div>
      <div class="keyboard">
         <van-button v-for="(item, index) in allKeyWord._5" :key="index" @click="clickKeyBoard(item)">{{ item }}</van-button>
      </div>
      <div class="keyboard">
        <van-button v-for="(item, index) in allKeyWord._6" :key="index" @click="clickKeyBoard(item)">{{ item }}</van-button>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
        <!-- <span   @click="deleteWord"><img src="http://t.zoukankan.com/@/assets/images/icon-delete.png" alt="" /></span> -->
      </div>
      <div   v-if="(activeKeyWordIndex === 6 && formData.commonCard == '1') || activeKeyWordIndex === 7">
        <span v-for="(item, index) in allKeyWord._7" :key="index" @click="clickKeyBoard(item)">{{ item }}</span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
      </div>
      <div class="cancel">
        <span @click="clearInput()">清除</span>
        <span @click="keyBoardStatus = false">关闭</span>
      </div>
    </div>
  </div>
</template>
<script>export default{
  data() {
    return{
      formData: {
        commonCard: '1',
        num0: '',
        num1: '',
        num2: '',
        num3: '',
        num4: '',
        num5: '',
        num6: '',
        num7: ''},
      abbPlate: {
        _1: ['京','沪','津','渝','鲁','冀','晋'],
        _2: ['蒙','辽','吉','黑','苏','浙','皖'],
        _3: ['闽','赣','豫','湘','鄂','粤','桂'],
        _4: ['琼','川','贵','云','藏','陕','甘'],
        _5: ['青','宁','新','港','澳','台'],
      },
      allKeyWord: {
        _1: [1, 2, 3, 4, 5, 6, 7],
        _2: [8, 9, 0],
        _3: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
        _4: ['H', 'J', 'K', 'L', 'M', 'N', 'O'],
        _5: ['P', 'Q', 'R', 'S', 'T', 'U', 'V'],
        _6: ['W', 'X', 'Y', 'Z'],
        _7: ['港', '澳', '学', '领', '警']
      },
      activeKeyWordIndex: 0, //当前车牌号
      keyBoardStatus: false,
      firstWrapStatus: false, //选择弹窗
      confirmTitle: '',
      submitConfirm: false,
      submitConfirmFalse: false,
      submitConfirmText: '',

      isActive: 0}
  },
  mounted() {},
  methods: {
    clearInput() {
      this.formData ={
        commonCard: '1',
        num0: '',
        num1: '',
        num2: '',
        num3: '',
        num4: '',
        num5: '',
        num6: '',
        num7: ''}
    },
    clickFirstWrap() {
      //点击第一个输入框
      this.firstClickStatus = true
      this.firstWrapStatus = true
      this.keyBoardStatus = false
      this.formData.num0 = ''

      this.activeKeyWordIndex = 0},
    selectFirstWord(value) {
      //选择省份
      //if (event.target.localName !== 'span') {
      //return
      //}
      //this.formData.num0 = event.target.innerText
      this.formData.num0 =value
      this.firstSelectStatus = true
      this.firstWrapStatus = false
      this.firstClickStatus = false
      this.keyBoardStatus = true
      this.activeKeyWordIndex = 1
      //this.$refs.num1.focus()
      //document.getElementById('num1').focus()
},
    clickKeyBoard(item) {
      //点击自定义键盘
console.log(item)
      this.formData['num' + this.activeKeyWordIndex] =item

      if (this.formData.commonCard === '1') {
        this.activeKeyWordIndex++
        if (this.activeKeyWordIndex > 6) {
          this.keyBoardStatus = false
          this.submitFn()
        }
      } else{
        this.activeKeyWordIndex++
        if (this.activeKeyWordIndex > 7) {
          this.keyBoardStatus = false
          this.submitFn()
        }
      }
    },
    deleteWord() {
      //退格
      //console.log(this.activeKeyWordIndex)
      //console.log(this.formData['num' + (this.activeKeyWordIndex - 1)])
      if (this.activeKeyWordIndex > 1) {
        this.formData['num' + (this.activeKeyWordIndex - 1)] = ''
        this.activeKeyWordIndex--}
    },
    clickKeyWordWrap(activeKeyWordIndex) {
      console.log(activeKeyWordIndex)
      this.keyBoardStatus = true
      this.activeKeyWordIndex =activeKeyWordIndex
      this.formData['num' + this.activeKeyWordIndex] = ''

      this.isActive =activeKeyWordIndex
    },
    submitFn() {
      let plateLicense
      if (this.formData.commonCard === '1') {
        plateLicense = this.plate_license_1
        plateLicense = this.palindrome(plateLicense)
        if (plateLicense.length < 7) {
          //alert('请输入正确的车牌号')
          this.$toast('请输入正确的车牌号')
          return}
      }
      if (this.formData.commonCard === '2') {
        plateLicense = this.plate_license_2
        plateLicense = this.palindrome(plateLicense)
        if (plateLicense.length < 8) {
          //alert('请输入正确的车牌号')
           this.$toast('请输入正确的车牌号')
          return}
      }
      this.$emit('getPlateLicense', plateLicense)
      console.log(plateLicense)
      //alert(plateLicense)
},
    palindrome(str) {
      var arr = str.split('')
      arr = arr.filter(function(val) {
        return(
          val !== ' ' &&val !== ',' &&val !== '.' &&val !== '?' &&val !== ':' &&val !== ';' &&val !== '`' &&val !== "'" &&val !== '_' &&val !== '/' &&val !== '-' &&val !== '\' &&val !== '' &&val !== '(' &&val !== ')')
      })
      return arr.join('')
    },
    checkIsHasSpecialStr(str) {
      var flag = false
      var arr = str.split('')
      arr.forEach(val =>{
        if(
          val === '!' ||val === '}' ||val === '{' ||val === ']' ||val === '[' ||val === '&' ||val === '$' ||val === '@' ||val === ' ' ||val === ',' ||val === '.' ||val === '?' ||val === ':' ||val === ';' ||val === '`' ||val === "'" ||val === '_' ||val === '/' ||val === '-' ||val === '\' ||val === '' ||val === '(' ||val === ')') {
          flag = true}
      })
      returnflag
    },
    checkIsHasChineseStr(str) {
      var Reg = /.*[u4e00-u9fa5]+.*/
      if(Reg.test(str)) {
        return true}
      return false}
  },
  computed: {
    plate_license_1() {
      return(
        this.formData.num0 +
        this.formData.num1 +
        this.formData.num2 +
        this.formData.num3 +
        this.formData.num4 +
        this.formData.num5 +
        this.formData.num6
      )
    },
    plate_license_2() {
      return(
        this.formData.num0 +
        this.formData.num1 +
        this.formData.num2 +
        this.formData.num3 +
        this.formData.num4 +
        this.formData.num5 +
        this.formData.num6 +
        this.formData.num7
      )
    }
  }
}
</script>
<style lang="scss" scoped>
/deep/.van-tabs__line {
    background-color: #1989fa;
}
/deep/.van-button--normal {
    padding: 0;
}
.plateNumber {
  //font-size: 24px;
}
.flex-items-center {
  display: flex;
  align-items: center;
}
@-webkit-keyframes active {
  0%{
    opacity: 0.8;
  }
  50%{
    opacity: 0.4;
  }
  100%{
    opacity: 0.8;
  }
}

@keyframes active {
  0%{
    opacity: 0.8;
  }
  50%{
    opacity: 0.4;
  }
  100%{
    opacity: 0.8;
  }
}

//.active {//-webkit-animation: active 2.2s infinite;//animation: active 2.2s infinite;//background-color: #1989fa;//}
.wrap {
  height: 11.1rem;
  padding: 0.85rem 0.6rem;
  background-color: #fff;
  border-radius: 0.5rem;
  //input输入框
  .num-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    .spot {
       0.1rem;
      height: 0.1rem;
      border-radius: 50%;
      background-color: #d8d8d8;
    }
    & >div {
       1rem;
      height: 1rem;
      border: 1px solid #e4e4e4;
      &.first {
        position: relative;
        text-align: center;
        line-height: 1.7rem;
        font-weight: 200;
        .input-wrap {
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          &.active {
            z-index: 100;
          }
        }
        em {
          color: #979797;
          //font-size: 1.6rem;
          line-height: 1.7rem;
        }
        span {
          display: inline-block;
           100%;
          height: 100%;
          //background-color: #9cbce2;
          color: #000;
          line-height: 1rem;
        }
      }
      &.active {
        border: 1px solid #4a90e2;
        &:after {
          border-bottom: 0.5rem solid #4a90e2;
        }
      }
      span {
        display: flex;
        align-items: center;
        justify-content: center;
         100%;
        height: 100%;
        //font-size: 1rem;
        color: #000;
        &.first {
          background-color: #9cbce2;
          color: #fff;
          text-indent: 0.4rem;
          border-radius: 0;
        }
      }
    }
  }

  .info {
    //font-size: 0.5rem;
    margin-top: 0.9rem;
    color: #000;
    text-align: left;
    img {
       0.6rem;
      vertical-align: middle;
    }
  }
}
.first-word-wrap {
  //height: 9.4rem;
  background-color: #e0e0e0;
  padding: 0.4rem 0.4rem 0.6rem;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  .first-word {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.45rem;
    .word {
      box-sizing: border-box;
       1rem;
      height: 1rem;
      //border: 1px solid #9cbce2;
      box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.35);
      border-radius: 0.16rem;
      text-align: center;
      &.bordernone {
        border: none;
        box-shadow: none;
      }
      span {
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
         100%;
        height: 100%;
        background-color: #fff;
        color: #000;
        //border: 1px solid #fff;
        border-radius: 0.125rem;
      }
      img {
         1.6rem;
      }
    }
    &:nth-last-of-type(1) {
      margin-bottom: 0rem;
    }
  }
}
.keyboard-wrap {
  background-color: #e0e0e0;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.7rem 0.6rem 0.4rem;
  .keyboard {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 1rem;
    margin-bottom: 0.3rem;
    span {
      text-align: center;
      display: flex;
       1rem;
      align-items: center;
      justify-content: center;
      height: 1rem;
      box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.35);
      background-color: #fff;
      border-radius: 0.125rem;
      &:active {
        background-color: #e4e4e4;
      }
      &.bordernone {
        border: none;
        box-shadow: none;
        background-color: #e0e0e0;
        &:active {
          background-color: #e0e0e0;
        }
      }
      &.delete{
        background-image: linear-gradient(to left, #25aae1, #1989fa, #25aae1);
        img {
           1.15rem;
        }
      }
    }
  }
  .cancel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    //margin-top: -1.25rem;
span {
      display: flex;
      align-items: center;
      justify-content: center;
       3.6rem;
      height: 1rem;
      background-image: linear-gradient(to left, #25aae1, #1989fa, #25aae1);
      color: #fff;
      border-radius: 0.125rem;
    }
  }
}
</style>

5.不用插件的舶来品

<template>
  <div class="plateNumber">
    <div class="wrap">
      <div class="radio-box">
        <label class="flex-items-center">
          <img v-if="formData.commonCard == 1" src="http://t.zoukankan.com/@/assets/images/icon_chose_s@2x.png" alt="" />
          <img v-else src="http://t.zoukankan.com/@/assets/images/icon_chose_n@2x.png" alt="" />
          <input type="radio" v-model="formData.commonCard" value="1" />普通车牌
        </label>
        <label class="flex-items-center">
          <img v-if="formData.commonCard == 2" src="http://t.zoukankan.com/@/assets/images/icon_chose_s@2x.png" alt="" />
          <img v-else src="http://t.zoukankan.com/@/assets/images/icon_chose_n@2x.png" alt="" />
          <input type="radio" v-model="formData.commonCard" value="2" />新能源车牌
        </label>
      </div>
      <div class="card-header">车牌号码:</div>
      <div class="num-box">
        <div   @click="clickFirstWrap()">
          <span>{{ formData.num0 }}</span>
        </div>
        <div   @click="clickKeyWordWrap(1)">
          <span>{{ formData.num1 }}</span>
        </div>
        <em class="spot"></em>
        <div   @click="clickKeyWordWrap(2)">
          <span>{{ formData.num2 }}</span>
        </div>
        <div   @click="clickKeyWordWrap(3)">
          <span>{{ formData.num3 }}</span>
        </div>
        <div   @click="clickKeyWordWrap(4)">
          <span>{{ formData.num4 }}</span>
        </div>
        <div   @click="clickKeyWordWrap(5)">
          <span>{{ formData.num5 }}</span>
        </div>
        <div   @click="clickKeyWordWrap(6)">
          <span>{{ formData.num6 }}</span>
        </div>
        <div v-if="formData.commonCard == '2'"   @click="clickKeyWordWrap(7)">
          <span>{{ formData.num7 }}</span>
        </div>
      </div>

      <div class="submit-box">
        <button @click="submitFn()">确认</button>
      </div>
    </div>
    <div   v-if="firstWrapStatus">
      <div   @click="selectFirstWord($event)">
        <div class="word">
          <span>京</span>
        </div>
        <div class="word">
          <span>湘</span>
        </div>
        <div class="word">
          <span>津</span>
        </div>
        <div class="word">
          <span>鄂</span>
        </div>
        <div class="word">
          <span>沪</span>
        </div>
        <div class="word">
          <span>粤</span>
        </div>
        <div class="word">
          <span>渝</span>
        </div>
        <div class="word">
          <span>琼</span>
        </div>
      </div>
      <div   @click="selectFirstWord($event)">
        <div class="word">
          <span>翼</span>
        </div>
        <div class="word">
          <span>川</span>
        </div>
        <div class="word">
          <span>晋</span>
        </div>
        <div class="word">
          <span>贵</span>
        </div>
        <div class="word">
          <span>辽</span>
        </div>
        <div class="word">
          <span>云</span>
        </div>
        <div class="word">
          <span>吉</span>
        </div>
        <div class="word">
          <span>陕</span>
        </div>
      </div>
      <div   @click="selectFirstWord($event)">
        <div class="word">
          <span>黑</span>
        </div>
        <div class="word">
          <span>甘</span>
        </div>
        <div class="word">
          <span>苏</span>
        </div>
        <div class="word">
          <span>青</span>
        </div>
        <div class="word">
          <span>浙</span>
        </div>
        <div class="word">
          <span>皖</span>
        </div>
        <div class="word">
          <span>藏</span>
        </div>
        <div class="word">
          <span>闽</span>
        </div>
      </div>
      <div   @click="selectFirstWord($event)">
        <div class="word">
          <span>蒙</span>
        </div>
        <div class="word">
          <span>赣</span>
        </div>
        <div class="word">
          <span>桂</span>
        </div>
        <div class="word">
          <span>鲁</span>
        </div>
        <div class="word">
          <span>宁</span>
        </div>
        <div class="word">
          <span>豫</span>
        </div>
        <div class="word">
          <span>新</span>
        </div>
        <div class="word bordernone">
          <!-- <img src="http://t.zoukankan.com/@/assets/images/icon-switch.png" alt=""> -->
        </div>
      </div>
    </div>
    <div   v-if="keyBoardStatus === true">
      <!-- <div class="number-wrap"></div>
      <div class="letter-wrap"></div>
      <div class="cn-wrap"></div> -->
      <div   v-if="activeKeyWordIndex !== 1">
        <span v-for="(item, index) in allKeyWord._1" :key="index" @click="clickKeyBoard(item)">{{ item }}</span>
      </div>
      <div   v-if="activeKeyWordIndex !== 1">
        <span v-for="(item, index) in allKeyWord._2" :key="index" @click="clickKeyBoard(item)">{{ item }}</span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
      </div>
      <div class="keyboard">
        <span v-for="(item, index) in allKeyWord._3" :key="index" @click="clickKeyBoard(item)">{{ item }}</span>
      </div>
      <div class="keyboard">
        <span v-for="(item, index) in allKeyWord._4" :key="index" @click="clickKeyBoard(item)">{{ item }}</span>
      </div>
      <div class="keyboard">
        <span v-for="(item, index) in allKeyWord._5" :key="index" @click="clickKeyBoard(item)">{{ item }}</span>
      </div>
      <div class="keyboard">
        <span v-for="(item, index) in allKeyWord._6" :key="index" @click="clickKeyBoard(item)">{{ item }}</span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
        <span class="bordernone"></span>
        <!-- <span   v-if="activeKeyWordIndex === 1"></span>
          <span   v-if="activeKeyWordIndex === 1"></span> -->
        <!-- <span @click="deleteWord" v-if="activeKeyWordIndex === 1">x</span> -->
      </div>
      <div   v-if="activeKeyWordIndex !== 1">
        <span v-for="(item, index) in allKeyWord._7" :key="index" @click="clickKeyBoard(item)">{{ item }}</span>
        <span class="bordernone"></span>
        <span   @click="deleteWord"><img src="http://t.zoukankan.com/@/assets/images/icon-delete.png" alt="" /></span>
      </div>
      <div class="cancel">
        <span @click="keyBoardStatus = false">完成</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      formData: {
        commonCard: '1',
        num0: '',
        num1: '',
        num2: '',
        num3: '',
        num4: '',
        num5: '',
        num6: '',
        num7: ''
      },
      allKeyWord: {
        _1: [1, 2, 3, 4, 5, 6, 7],
        _2: [8, 9, 0],
        _3: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
        _4: ['H', 'J', 'K', 'L', 'M', 'N', 'O'],
        _5: ['P', 'Q', 'R', 'S', 'T', 'U', 'V'],
        _6: ['W', 'X', 'Y', 'Z'],
        _7: ['港', '澳', '学', '领', '警']
      },
      activeKeyWordIndex: 1, // 当前车牌号
      keyBoardStatus: false,
      firstWrapStatus: false, // 选择弹窗
      confirmTitle: '',
      submitConfirm: false,
      submitConfirmFalse: false,
      submitConfirmText: ''
    }
  },
  mounted() {},
  methods: {
    clickFirstWrap() {
      // 点击第一个输入框
      this.firstClickStatus = true
      this.firstWrapStatus = true
      this.keyBoardStatus = false
      this.formData.num0 = ''
    },
    selectFirstWord(event) {
      // 选择省份
      if (event.target.localName !== 'span') {
        return
      }
      this.formData.num0 = event.target.innerText
      this.firstSelectStatus = true
      this.firstWrapStatus = false
      this.firstClickStatus = false
      this.keyBoardStatus = true
      this.activeKeyWordIndex = 1
      // this.$refs.num1.focus()
      // document.getElementById('num1').focus()
    },
    clickKeyBoard(item) {
      // 点击自定义键盘
      console.log(item)
      this.formData['num' + this.activeKeyWordIndex] = item

      if (this.formData.commonCard === '1') {
        this.activeKeyWordIndex++
        if (this.activeKeyWordIndex > 6) {
          this.keyBoardStatus = false
        }
      } else {
        this.activeKeyWordIndex++
        if (this.activeKeyWordIndex > 7) {
          this.keyBoardStatus = false
        }
      }
    },
    deleteWord() {
      // 退格
      // console.log(this.activeKeyWordIndex)
      // console.log(this.formData['num' + (this.activeKeyWordIndex - 1)])
      if (this.activeKeyWordIndex > 1) {
        this.formData['num' + (this.activeKeyWordIndex - 1)] = ''
        this.activeKeyWordIndex--
      }
    },
    clickKeyWordWrap(activeKeyWordIndex) {
      this.keyBoardStatus = true
      this.activeKeyWordIndex = activeKeyWordIndex
      this.formData['num' + this.activeKeyWordIndex] = ''
    },
    submitFn() {
      let plateLicense
      if (this.formData.commonCard === '1') {
        plateLicense = this.plate_license_1
        plateLicense = this.palindrome(plateLicense)
        if (plateLicense.length < 7) {
          alert('请输入正确的车牌号')
          return
        }
      }
      if (this.formData.commonCard === '2') {
        plateLicense = this.plate_license_2
        plateLicense = this.palindrome(plateLicense)
        if (plateLicense.length < 8) {
          alert('请输入正确的车牌号')
          return
        }
      }
      this.$emit('getPlateLicense', plateLicense)
      console.log(plateLicense)
      alert(plateLicense)
    },
    palindrome(str) {
      var arr = str.split('')
      arr = arr.filter(function (val) {
        return (
          val !== ' ' &&
          val !== ',' &&
          val !== '.' &&
          val !== '?' &&
          val !== ':' &&
          val !== ';' &&
          val !== '`' &&
          val !== "'" &&
          val !== '_' &&
          val !== '/' &&
          val !== '-' &&
          val !== '\' &&
          val !== '' &&
          val !== '(' &&
          val !== ')'
        )
      })
      return arr.join('')
    },
    checkIsHasSpecialStr(str) {
      var flag = false
      var arr = str.split('')
      arr.forEach(val => {
        if (
          val === '!' ||
          val === '}' ||
          val === '{' ||
          val === ']' ||
          val === '[' ||
          val === '&' ||
          val === '$' ||
          val === '@' ||
          val === ' ' ||
          val === ',' ||
          val === '.' ||
          val === '?' ||
          val === ':' ||
          val === ';' ||
          val === '`' ||
          val === "'" ||
          val === '_' ||
          val === '/' ||
          val === '-' ||
          val === '\' ||
          val === '' ||
          val === '(' ||
          val === ')'
        ) {
          flag = true
        }
      })
      return flag
    },
    checkIsHasChineseStr(str) {
      var Reg = /.*[u4e00-u9fa5]+.*/
      if (Reg.test(str)) {
        return true
      }
      return false
    }
  },
  computed: {
    plate_license_1() {
      return (
        this.formData.num0 +
        this.formData.num1 +
        this.formData.num2 +
        this.formData.num3 +
        this.formData.num4 +
        this.formData.num5 +
        this.formData.num6
      )
    },
    plate_license_2() {
      return (
        this.formData.num0 +
        this.formData.num1 +
        this.formData.num2 +
        this.formData.num3 +
        this.formData.num4 +
        this.formData.num5 +
        this.formData.num6 +
        this.formData.num7
      )
    }
  }
}
</script>
<style lang="scss" scoped>
html {
  font-size: 20px !important;
}
.plateNumber {
  font-size: 24px;
}
.flex-items-center {
  display: flex;
  align-items: center;
}
.wrap {
  height: 11.1rem;
  margin: 0.5rem 0.6rem;
  padding: 0.85rem 0.6rem;
  background-color: #fff;
  border-radius: 0.5rem;
  .radio-box {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    // font-size: 0.7rem;
    text-align: right;
    color: #4a4a4a;
    input[type='radio'] {
      display: none;
    }
    label {
      padding-left: 0.6rem;
      cursor: pointer;
      img {
         0.8rem;
        margin-right: 0.1rem;
      }
    }
  }
  .card-header {
    // font-size: 0.75rem;
    margin: 0.2rem 0 0.5rem;
    color: #4a4a4a;
  }
  // input输入框
  .num-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .spot {
       0.2rem;
      height: 0.2rem;
      border-radius: 50%;
      background-color: #d8d8d8;
    }
    & > div {
       1.8rem;
      height: 1.8rem;
      border: 1px solid #e4e4e4;
      &.first {
        position: relative;
        text-align: center;
        line-height: 1.7rem;
        font-weight: 200;
        .input-wrap {
          position: absolute;
          top: 0;
          left: 0;
          right: 0;
          bottom: 0;
          &.active {
            z-index: 100;
          }
        }
        em {
          color: #979797;
          // font-size: 1.6rem;
          line-height: 1.7rem;
        }
        span {
          display: inline-block;
           100%;
          height: 100%;
          // background-color: #9cbce2;
          color: #828282;
          line-height: 1.8rem;
        }
      }
      &.active {
        border: 1px solid #4a90e2;
        &:after {
          border-bottom: 0.5rem solid #4a90e2;
        }
      }
      span {
        display: flex;
        align-items: center;
        justify-content: center;
         100%;
        height: 100%;
        // font-size: 1rem;
        color: #828282;
        &.first {
          background-color: #9cbce2;
          color: #fff;
          text-indent: 0.4rem;
          border-radius: 0;
        }
      }
    }
  }
  .submit-box {
    button {
       100%;
      height: 2.2rem;
      border-radius: 0.25rem;
      // font-size: 0.75rem;
      margin-top: 0.7rem;
      background: linear-gradient(320deg, rgba(74, 144, 226, 1) 0%, rgba(101, 172, 248, 1) 100%);
      color: #fff;
    }
  }
  .info {
    // font-size: 0.5rem;
    margin-top: 0.9rem;
    color: #828282;
    text-align: left;
    img {
       0.6rem;
      vertical-align: middle;
    }
  }
}
.first-word-wrap {
  // height: 9.4rem;
  background-color: #d2d5db;
  padding: 0.6rem 0.8rem 1.1rem;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  .first-word {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.45rem;
    .word {
      box-sizing: border-box;
       1.8rem;
      height: 1.8rem;
      // border: 1px solid #9cbce2;
      box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.35);
      border-radius: 0.16rem;
      text-align: center;
      &.bordernone {
        border: none;
        box-shadow: none;
      }
      span {
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
         100%;
        height: 100%;
        background-color: #fff;
        color: #000;
        // border: 1px solid #fff;
        border-radius: 0.125rem;
      }
      img {
         1.6rem;
      }
    }
    &:nth-last-of-type(1) {
      margin-bottom: 0rem;
    }
  }
}
.keyboard-wrap {
  background-color: #d2d5db;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.6rem 0.6rem 0.4rem;
  .keyboard {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 2rem;
    margin-bottom: 0.3rem;
    span {
      text-align: center;
      display: flex;
       1.8rem;
      align-items: center;
      justify-content: center;
      height: 1.8rem;
      margin: 0 0.3rem;
      box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.35);
      background-color: #fff;
      border-radius: 0.125rem;
      &:active {
        background-color: #e4e4e4;
      }
      &.bordernone {
        border: none;
        box-shadow: none;
        background-color: #d2d5db;
        &:active {
          background-color: #d2d5db;
        }
      }
      &.delete {
        background-color: #465266;
        img {
           1.15rem;
        }
      }
    }
  }
  .cancel {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    span {
      display: flex;
      align-items: center;
      justify-content: center;
       3.6rem;
      height: 1.8rem;
      background-color: #465266;
      color: #fff;
      border-radius: 0.125rem;
    }
  }
}
</style>

免责声明:文章转载自《vue 移动端车牌键盘》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ffmpeg文档16-音频编码器C#之文件的读写(一)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Vue指令和事件

/** * 语法糖的概念: * 语法糖是指在不影响功能的情况下,添加某种方法实现同样的; * 使用语法糖,可以简化代码的书写 * 比如 v-on:click='func' @click='func' * v-bind:src :src */ <!-- v-on 可以监听原生DOM事件click,dbclick,keyup,mousemove...

vue页面出现乱码,那么就需要在当前页面设置编码为utf-8

HTML出现中文乱码时修改如下:<html lang="zh-CN"> 这个必须设置zh-CN中文简体,如果设置成 lang="en" 表示英文,如果内容是中文就有可能出现乱码<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">或者可以简写为:&l...

vue 优化小技巧 之 require.context()

1、require.context() 回忆一下 当我们引入组件时   第一步 创建一个子组件   第二步 import ... form ...     第三步 components:{..}       第四步 页面使用 <...></...>   代码实现:                                 ...

理解 line-height

1.专有名词理解:   line-height(行高):两条相邻基线之间的距离,有时为了方便,将相邻底线之间的距离作为行高           font-size(字体大小):顶线到底线之间的距离   行间距:行高减去字体大小就为行间距,会平均分成两部分,顶部一份,底部一份 2.行间距的理解   (1)line-height为固定数值时:100px    ...

【转】前端精选文摘:BFC 神奇背后的原理

BFC 已经是一个耳听熟闻的词语了,网上有许多关于 BFC 的文章,介绍了如何触发 BFC 以及 BFC 的一些用处(如清浮动,防止 margin 重叠等)。虽然我知道如何利用 BFC 解决这些问题,但当别人问我 BFC 是什么,我还是不能很有底气地解释清楚。于是这两天仔细阅读了CSS2.1 spec 和许多文章来全面地理解BFC。 一、BFC是...

VUEX

在Vue中组件之间的共享数据的方式:1、父组件向子组件传值:v-bind 属性绑定2、子组件向父组件传值:v-on 事件绑定3、兄弟组件之间进行传值:EventBus$on 接收数据的那个组件$emit 发送数据的那个组件 上面的3种方式适用于小项目中的组件通信,当项目变的庞大的时候,就有些力不从心了。 上图中,左侧图片是未使用vuex进行数据传递的。当...