uniapp、微信小程序车牌的录入的解决方案

结合uv-ui进行编写,键盘使用uv-ui的组件,其他由我们自己编写。

javascript 复制代码
<template>
  <div class="addCarContent">
    <div class="boxContent">
      <div class="carCodeInput" @click="getIndex">
        <div
          :class="[index === 0 && showActive ? 'input_active' : '', 'input']"
        >
          {{ CarCode[0] }}
        </div>
        <div
          :class="[index === 1 && showActive ? 'input_active' : '', 'input']"
        >
          {{ CarCode[1] }}
        </div>
        <div class="point"></div>
        <div
          :class="[index === 2 && showActive ? 'input_active' : '', 'input']"
        >
          {{ CarCode[2] }}
        </div>
        <div
          :class="[index === 3 && showActive ? 'input_active' : '', 'input']"
        >
          {{ CarCode[3] }}
        </div>
        <div
          :class="[index === 4 && showActive ? 'input_active' : '', 'input']"
        >
          {{ CarCode[4] }}
        </div>
        <div
          :class="[index === 5 && showActive ? 'input_active' : '', 'input']"
        >
          {{ CarCode[5] }}
        </div>
        <div
          :class="[index === 6 && showActive ? 'input_active' : '', 'input']"
        >
          {{ CarCode[6] }}
        </div>
        <div
          :class="[index === 7 && showActive ? 'input_active' : '', 'input']"
        >
          {{ CarCode[7] }}
        </div>
      </div>
    </div>
    <uv-keyboard
      ref="keyboard"
      mode="car"
      @change="change"
      :showTips="false"
      @confirm="confirm"
      @backspace="backspace"
      :autoChange="true"
      :overlay="true"
      :safeAreaInsetBottom="true"
      :confirmText="'完成'"
      @changeCarInputMode="changeCarInputMode"
      @close="closeKey"
    >
      <template v-slot:abc>
        <text v-if="isABC">省份</text>
        <text v-else>ABC</text>
      </template>
    </uv-keyboard>
  </div>
</template>

<script>
export default {
  data() {
    return {
      CarCode: ["", "", "", "", "", "", "", ""],
      index: "",
      isABC: false,
      showActive: false,
      checkboxValue: ["true"],
    };
  },
  onShow() {
    this.getIndex();
  },
  mounted() {},

  methods: {
    closeKey() {
      this.showActive = false;
    },
    changeCarInputMode(e) {
      this.isABC = e;
    },
    getIndex() {
      let index = this.CarCode.indexOf("");
      if (index !== -1) {
        this.index = index;
      } else {
        this.index = 7;
      }
      this.$refs.keyboard.open();
      this.showActive = true;
    },
    change(e) {
      console.log("change", e, this.index);
      if (this.index <= 7) {
        this.CarCode[this.index] = e;
        this.index++;
        if (this.index > 7) {
          this.$refs.keyboard.close();
          this.showActive = false;
          this.index--;
        }
      }
      console.log("changeEnd", this.CarCode);
    },
    confirm() {
      console.log("confirm");
    },
    backspace() {
      console.log("backspace", this.index);
      if (this.index === 1) {
        this.$refs.keyboard.changeCarMode();
      }
      if (this.index >= 0) {
        if (this.CarCode[this.index] === "") {
          this.index--;
          this.CarCode[this.index] = "";
        } else {
          this.CarCode[this.index] = "";
        }
        if (this.index < 0) {
          this.index = 0;
        }
      }
      this.$forceUpdate();
      console.log("backspaceEnd", this.CarCode, this.index);
    },
  },
};
</script>
相关推荐
孙 悟 空16 小时前
uni-app:监听页面返回,禁用返回操作
前端·javascript·uni-app
mosen8681 天前
uniapp中uni.scss如何引入页面内或生效
前端·uni-app·scss
lyz2468591 天前
uniapp popup弹窗组件的自定义使用方法
uni-app
沙尘暴炒饭1 天前
uniapp 前端解决精度丢失的问题 (后端返回分布式id)
前端·uni-app
牛牛科技1 天前
生产管理系统PHP+Uniapp源码
uni-app
Smile_ping1 天前
uniapp——APP读取bin文件,解析文件的数据内容(一)
uni-app·uniapp 读取文件·app端读取bin文件
CDERP-plus1 天前
uniapp 3分钟集成轮播广告图
uni-app·erp·erp移动端
Liberty_yes1 天前
uniapp input苹果中文键盘输入拼音直接切换输入焦点监听失效
uni-app
街尾杂货店&1 天前
webpakc介绍
uni-app
洗发水很好用2 天前
uniApp打包H5发布到服务器(docker)
uni-app