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>
相关推荐
佩淇呢2 小时前
uniapp vue3 梯形选项卡组件
前端·vue.js·uni-app
[廾匸]6 小时前
uni-app获取设备唯一值、静态IP以及公网IP的方法
uni-app·ip·imei·唯一值
luckycoke13 小时前
小程序的右侧抽屉开关动画手写效果
前端·javascript·微信小程序·uni-app
微刻时光14 小时前
好课程:uni-app实战音频小说app小程序
小程序·uni-app
慢慢雨夜14 小时前
uniapp 苹果安全域适配
java·前端·uni-app
梦屿千寻!!14 小时前
uni-app
uni-app
Zww089114 小时前
uniapp微信小程序用户授权方法
微信小程序·小程序·uni-app
慢慢雨夜1 天前
解决uniapp视频video组件进入全屏再退出全屏后,cover-view失效的问题
uni-app
码海扬帆:前端探索之旅1 天前
UNI-APP 富文本编辑器,可以对图片、文字格式进行编辑和混排。
uni-app
奔跑的小G1 天前
【uni-app】命令行创建 uni-app 项目
uni-app