小程序 车牌输入
admin
2024-01-22 22:04:38
0

html

{show?'show':'hide'}}">

  

  

    完成

  

  

  

    {keyboard}}" wx:for-item="rows" wx:for-index="rowIndex" wx:key="rowIndex">

      {rows}}" wx:for-item="col" wx:key="col">

        {col.disabled}}" class="col disabled">{{col.value}}

        {col.empty}}" class="col empty">{{col.value}}

        {col.backspace}}" class="col backspace" bindtap="delete">

          

        

        {col}}">{{col}}

      

    

  

  

  

js

Component({

  properties: {

    /**

     * 键盘类型 

     * 1:省份简称

     * 2:蓝牌普通车牌:车牌号数字+字母

     * 3:新能源车牌

     */

    keyboardType: {

      type: Number,

      value: 1

    },

  },

  data: {

    keyboard: [],

    show: false,

    provinces: [

      ['京', '津', '沪', '渝', '冀', '豫', '云', '辽', '黑'],

      ['湘', '皖', '鲁', '新', '苏', '浙', '赣', '鄂', '桂'],

      ['甘', '晋', '蒙', '陕', '吉', '闽', '贵', '粤', '青'],

      ['藏', '川', '宁', '琼', '使', '无', {

        value: '',

        empty: true

      }, {

        value: '',

        empty: true

      }, {

        value: '',

        backspace: true

      }],

    ],

    nomals: [

      ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],

      ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', {

        value: 'O',

        disabled: true

      }, 'P', '港'],

      ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '澳'],

      ['Z', 'X', 'C', 'V', 'B', 'N', 'M', '学', '领', {

        value: '',

        backspace: true

      }],

    ],

    ecos: [

      ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],

      ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', {

        value: 'O',

        disabled: true

      }, 'P', {

        value: '港',

        disabled: true

      }],

      ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', {

        value: '澳',

        disabled: true

      }],

      ['Z', 'X', 'C', 'V', 'B', 'N', 'M', {

        value: '学',

        disabled: true

      }, {

        value: '领',

        disabled: true

      }, {

        value: '',

        backspace: true

      }],

    ]

  },

  lifetimes: {

    created() {},

    attached() {

      this.change(this.properties.keyboardType);

    },

    detached() {}

  },

  methods: {

    change(keyboardType) {

      switch (parseInt(keyboardType)) {

        case 1:

          this.setData({

            keyboard: this.data.provinces

          });

          break;

        case 2:

          this.setData({

            keyboard: this.data.nomals

          });

          break;

        case 3:

          this.setData({

            keyboard: this.data.ecos

          });

          break;

      }

    },

    show() {

      if (!this.data.show) {

        this.setData({

          show: true

        });

      }

    },

    hide(e) {

      this.setData({

        show: false

      });

    },

    delete(e) {

      this.triggerEvent('delete');

    },

    click(e) {

      this.triggerEvent('click', e.target.dataset.value);

    }

  }

})

css

.custom-keyboard {

  display: flex;

  flex-direction: column;

  border-top: 1rpx solid #e6e6e6;

  position: absolute;

  bottom: 0;

  width: 100%;

  transform: translateY(100%);

  transition: all .5s cubic-bezier(0, 1, 0.5, 1);

}

.custom-keyboard.show {

  transform: translateY(0%);

}

.custom-keyboard.hide {

  transform: translateY(100%);

}

.custom-keyboard .toolbar {

  display: flex;

  flex-direction: row;

  align-items: center;

  justify-content: flex-end;

  padding: 15rpx 10rpx;

  color: #05aeff;

  background-color: #ffffff;

}

.custom-keyboard .keyboard {

  background-color: #d1d4db;

  display: flex;

  flex-direction: column;

  padding: 40rpx 10rpx;

}

.custom-keyboard .keyboard .row {

  display: flex;

  flex-direction: row;

  align-items: center;

  justify-content: space-around;

  margin-bottom: 20rpx;

}

.custom-keyboard .keyboard .row:last-child {

  margin-bottom: 0;

}

.custom-keyboard .keyboard .row .col {

  width: 65rpx;

  height: 84rpx;

  line-height: 84rpx;

  text-align: center;

  background-color: #ffffff;

  border-radius: 10rpx;

  margin-right: 15rpx;

  box-shadow: 0rpx 6rpx 5rpx #888888;

}

.custom-keyboard .keyboard .row .col:last-child {

  margin-right: 0;

}

.custom-keyboard .keyboard .row .col:active {

  box-shadow: 0rpx 0rpx 0rpx #888888;

}


 

.custom-keyboard .keyboard .row .col.disabled {

  color: #c6c6c8;

}

.custom-keyboard .keyboard .row .col.empty {

  background-color: transparent;

  box-shadow: unset;

}

.custom-keyboard .keyboard .row .col.backspace {

  display: flex;

  flex-direction: column;

  align-items: center;

  justify-content: center;

}

.custom-keyboard .keyboard .row .col.backspace .icon {

  width: 42rpx;

  height: 28rpx;

}

.custom-keyboard .footer {

  height: env(safe-area-inset-bottom);

  background-color: #d1d4db;

}

html2

  {item.focus?'focus':''}} {{item.eco?'eco':''}}" wx:for="{{numbers}}" wx:key="index" data-index="{{index}}" bindtap="click">

    {index}}" bindtap="click">{{item.value}}

    {item.focus&&item.value==''}}">

  

js2

Component({

  properties: {

  },

  data: {

    numbers: [{

      value: '',

      focus: true

    }, {

      value: '',

      focus: false

    }, {

      value: '',

      focus: false

    }, {

      value: '',

      focus: false

    }, {

      value: '',

      focus: false

    }, {

      value: '',

      focus: false

    }, {

      value: '',

      focus: false

    }, {

      value: '',

      focus: false,

      eco: true

    }]

  },

  lifetimes: {

    created() {},

    attached() {},

    detached() {}

  },

  methods: {

    click(e) {

      const _index = e.target.dataset.index;

      const _nums = this.data.numbers;

      _nums.forEach((item, index) => {

        item.focus = index == _index;

      });

      this.setData({

        numbers: _nums

      });

      this.triggerEvent('focus', _index);

    },

    /**

     * {

     *    index: Number,

     *    value: String,

     *    remove: Boolean

     * }

     */

    change(data) {

      const {

        index,

        value,

        remove

      } = data;

      const _nums = this.data.numbers;

      _nums[index].value = remove ? '' : value;

      const len = _nums.length;

      let nextIndex = remove ? index - 1 : index + 1;

      if (remove && nextIndex < 0) {

        nextIndex = len - 1;

      }

      if (!remove && nextIndex >= len)

        nextIndex = 0;

      _nums.forEach((item, idx) => {

        item.focus = idx == nextIndex;

      });

      this.setData({

        numbers: _nums

      });

      this.triggerEvent('focus', nextIndex);

    }

  }

})

css2

.custom-car-number-input {

  display: flex;

  flex-direction: row;

  align-items: center;

  justify-content: space-around;

}

.custom-car-number-input .cell {

  width: 70rpx;

  height: 120rpx;

  display: flex;

  flex-direction: row;

  align-items: center;

  justify-content: center;

  font-size: 40rpx;

  background-color: #f7f7f7;

  border-radius: 10rpx;

  color: #333;

}

.custom-car-number-input .cell.focus {

  border: 1rpx solid #0099ff;

  box-shadow: 0rpx 0rpx 10rpx #0099ff;

}

.custom-car-number-input .cell .cursor {

  width: 2rpx;

  height: 30rpx;

  background-color: #0099ff;

  animation: flashing 1.2s infinite steps(1, start);

}

@keyframes flashing {

  0%,

  100% {

    background-color: #0099ff;

  }

  50% {

    background-color: transparent;

  }

}

.custom-car-number-input .cell.eco {

  background-color: rgba(54, 210, 146, .2);

}

.custom-car-number-input .cell.eco.focus {

  border-color: #36d292;

  box-shadow: 0rpx 0rpx 10rpx #36d292;

}

.custom-car-number-input .cell.eco .cursor {

  background-color: #36d292;

  animation: flashing-eco 1.2s infinite steps(1, start);

}

@keyframes flashing-eco {

  0%,

  100% {

    background-color: #36d292;

  }

  50% {

    background-color: transparent;

  }

}

相关内容

热门资讯

原创 4... 写在文章前的声明:在本文之前的说明:本文中所列的投资信息,只是一个对基金资产净值进行排行的客观描述,...
胜宏科技港股大涨49% 做完英... 记者 陈月芹 4月21日,全球AI算力板龙头胜宏科技(02476.HK)登陆港交所,上市首日股价大涨...
永赢基金:聚焦“科技新锐”,科... 数据来源:Wind,时间统计区间为2025/1/1-2026/4/21,指数过往表现不预示未来,不构...
五大阅读趋势显现!当当网发布2... 在第31个世界读书日即将来临之际及首个全民阅读活动周期间,当当网正式发布2026国民阅读洞察报告。 ...
业绩逐季回暖 老百姓大药房一季... 上证报中国证券网讯(记者 夏子航)4月22日晚,老百姓大药房发布2025年年报和2026年一季报。今...
中国20强城市大洗牌:苏州接近... 中国的城市经济竞争格局一直在变化,每年发布的GDP数据都会对城市经济实力进行重新排列。2025年榜又...
直击金宏气体股东会:预期年内氦... 《科创板日报》4月22日讯(记者 郭辉)金宏气体日前举行2025年度股东大会。会上该公司审议了公司年...
5月1日起,俄据悉将叫停哈萨克... 据行业消息人士透露,俄罗斯将于5月1日起停止经友谊管道转运哈萨克斯坦输往德国的石油,相关调整计划已送...
深化具身智能生态布局 京东携手... 4 月 22 日,京东与国内消费级人形机器人头部企业松延动力正式达成三年期战略合作。双方将围绕产品研...
原创 帮... 先问你一个问题,美伊停火今晚到期,按常理避险情绪该升温,黄金应该涨吧?结果恰恰相反——原油涨了,黄金...
300295、600889,将... 三六五网、南京化纤,将被*ST。 公司股票自4月23日开市起停牌一天,于4月24日开市起复牌并实施退...
能源大变天!外媒:羡慕中国的石... 这一次油价突破 110 美元的能源危机,着实魔幻。如果放在十年前,没人会相信中国能在这场风波中获利,...
黄金涨跌两难,现在还能上车吗? 中新网4月22日电(记者 左雨晴) 四月以来,美伊局势反复拉扯,美联储降息预期一变再变。黄金价格在4...
“我身体健康”,库克现身员工大... 当地时间4月21日,受苹果官宣CEO换届影响,公司股价盘中下探超2%,总市值失守4万亿美元关口,收盘...
库克留下一个悬念 工程师能否拯救创新节奏? 听筒Tech(ID:tingtongtech)原创 文 | 赵 森 ...
探索消费信贷与社交支付深度融合... 腾讯这一金融产品再添新功能,4月19日,北京商报记者注意到,微信分付灰度测试转账功能引发热议,在向微...
土耳其主要银行股指早盘下跌2% 每经AI快讯,4月20日,土耳其主要银行股指早盘下跌2%。 每日经济新闻
好用的OTA代运营源头厂家 在如今竞争激烈的酒旅行业中,OTA代运营服务成为了众多酒店、民宿提升竞争力的关键。但市场上的代运营厂...
成都五一出游全国热门第三 “五一”假期临近,同程旅行最新发布的《2026“五一”旅行趋势报告》显示,今年“五一”期间成都同时位...