#简易的车牌号选择器(vue版本)

本文介绍了一个基于Vue.js的车牌号选择器组件的实现细节,包括如何通过自定义键盘输入车牌号码,以及如何处理车牌号的选择流程。该组件支持显示车牌的首字和余字,并提供了删除和关闭功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当时没有考虑到新能源车牌的问题,使用该代码的同仁注意一下哦。

github:https://github.com/JACK-Liang-2020/jar-common-tool

 

 

<template>
  <div class="container">

    <div class="in-mask"
         @click="clickMask"></div>

    <div @click="showWrap">
      <slot></slot>
    </div>

    <transition name="hehe">

      <div v-if="show">
        <!--车牌首字-->
        <div class="first-word-wrap"
             v-if="showFirst">
          <div class="first-word">
            <div class="word"
                 v-for="item in allKeyWord.province"
                 @click="selectFirstWord(item)"
                 :key="item.id">
              <span>{{item}}</span>
            </div>
            <div class="in-delete"
                 @click="deleteItem">
              <i class="cubeic-wrong"
                 style="font-size:23px;"></i>
              <span>x</span>
            </div>
          </div>
          <div class="in-close"
               @click="close">
            收起
          </div>
        </div>

        <!--车牌余字-->
        <div class="keyboard-wrap"
             v-else>

          <div class="keyboard">
            <div class="in-alphabet">
              <span v-for="(item,index) in allKeyWord.alphabet"
                    :key="index"
                    @click="clickKeyBoard(item)">{{item}}</span>
              <div class="in-delete"
                   @click="deleteItem">
                <i class="cubeic-wrong"
                   style="font-size:23px;"></i>
              </div>
            </div>
          </div>
          <div class="in-close"
               @click="close">
            收起
          </div>

        </div>
      </div>

    </transition>

  </div>
</template>
<script>
export default {
  data () {
    return {
      selectArr: [],
      allKeyWord: {
        province: ['京', '湘', '津', '鄂', '沪', '粤', '渝', '琼', '翼', '川', '晋', '贵', '辽', '云', '吉', '陕', '黑', '甘', '苏', '青', '浙', '皖', '藏', '闽', '蒙', '赣', '桂', '鲁', '宁', '豫', '新'],
        alphabet: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
      },
      show: false,
      showFirst: false
    }
  },
  watch: {
    selectArr (val) {
      this.$emit('input', val)
    }
  },
  methods: {
    showWrap () {
      this.show = true
      this.showFirst = !(this.selectArr.length > 0)
    },
    selectFirstWord (item) {
      this.addSelect(item)
      this.showFirst = false
    },
    clickKeyBoard (item) {
      this.addSelect(item)
    },
    addSelect (item) {
      // 点击自定义键盘
      if (this.selectArr.length < 7) {
        this.selectArr.push(item)
      } else {
        // this.$createToast({
        //   txt: '车牌号选择超过规定个数',
        //   type: 'txt'
        // }).show()
        // this.close()
      }
    },
    deleteItem () {
      this.selectArr.pop()
      this.showFirst = !(this.selectArr.length > 0)
    },
    close () {
      this.show = false
    },
    clickMask () {
      // console.log('clickMask')
      this.close()
    }
  },
  mounted () {
    this.selectArr = []
  }
}
</script>
<style lang="less" scoped>
.container {
  .in-mask {
    position: absolute;
    left: 0;
    top: 0;
    z-index: -1;

    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 0);
  }
  .first-word-wrap {
    // height: 9.4rem;
    background-color: #d2d5db;
    padding: 10px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    .first-word {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
      &::after {
        //重要
        width: 41px;
        content: "";
      }
      .word {
        box-sizing: border-box;
        width: 30px;
        height: 30px;
        box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.35);
        text-align: center;
        margin: 5px;
        span {
          box-sizing: border-box;
          display: flex;
          align-items: center;
          justify-content: center;
          text-align: center;
          width: 100%;
          height: 100%;
          background-color: #fff;
          color: #000;
          // border: 1px solid #fff;
          border-radius: 0.125rem;
        }
      }
    }
  }
  .keyboard-wrap {
    background-color: #d2d5db;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px;
    .keyboard {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .in-alphabet {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
        &::after {
          //重要
          width: 174px;
          content: "";
        }
        span {
          text-align: center;
          display: flex;
          align-items: center;
          justify-content: center;
          width: 30px;
          height: 30px;
          box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.35);
          background-color: #fff;
          border-radius: 5px;
          margin: 5px;
          &:active {
            background-color: #e4e4e4;
          }
          &.bordernone {
            border: none;
            box-shadow: none;
            background-color: #d2d5db;
            &:active {
              background-color: #d2d5db;
            }
          }
          &.delete {
            background-color: #465266;
          }
          // &:last-child {
          //   flex: 1;
          // }
        }
      }
    }
  }

  .in-close {
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 30px;
    box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.35);
    background-color: #fff;
    border-radius: 5px;
    margin: 5px;
    &:active {
      background-color: #e4e4e4;
    }
    &.bordernone {
      border: none;
      box-shadow: none;
      background-color: #d2d5db;
      &:active {
        background-color: #d2d5db;
      }
    }
    &.delete {
      background-color: #465266;
    }
    &:last-child {
      flex: 1;
    }
  }

  .in-delete {
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.35);
    background-color: #fff;
    border-radius: 5px;
    margin: 5px;

    &:active {
      background-color: #e4e4e4;
    }
    &.bordernone {
      border: none;
      box-shadow: none;
      background-color: #d2d5db;
      &:active {
        background-color: #d2d5db;
      }
    }
    &.delete {
      background-color: #465266;
    }
  }
}

/*淡入淡出*/
.hehe-enter,
.hehe-leave-to {
  opacity: 0;
}
.hehe-enter-to,
.hehe-leave {
  opacity: 1;
}
.hehe-enter-active,
.hehe-leave-active {
  transition: all 0.5s;
}
</style>

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值