当前位置: 首页 > news >正文

微信小程序原生车牌输入器

  1. 效果图
    在这里插入图片描述

  2. 使用得ui库 地址

  3. wxml代码

<t-popupvisible="{{customVisible}}"close-on-overlay-click="{{false}}"bind:visible-change="closePopup"placement="bottom"
><view class="block"><view class="header"><view class="btns"><t-button t-class="c-btn" bind:tap="closePopup" size="small">取消</t-button><t-buttont-class="c-btn"theme="primary"size="small"bind:tap="confirm">确定</t-button></view><view class="plates"><view class="txt">新能源</view><viewclass="plate-item {{plate.length ===index?'plate-item-active':''}}"wx:for="{{plateLength}}"wx:key="index"><view class="plate-value">{{plate[index]}}</view><view class="item__cursor" wx:if="{{ plate.length ===index }}"></view></view></view></view><view class="plate-btn"><!-- 省份的 --><view hidden="{{provicesOrNumber !== 'provice'}}"><view class="plate-province"><view class="line"><viewclass="item"hover-class="item-hover"hover-stay-time="180"wx:for="{{chineseProvinces[0]}}"bind:tap="inputPlate"data-value="{{item}}"wx:key="index">{{item}}</view></view><view class="line"><viewclass="item"hover-class="item-hover"hover-stay-time="180"wx:for="{{chineseProvinces[1]}}"bind:tap="inputPlate"data-value="{{item}}"wx:key="index">{{item}}</view></view><view class="line"><viewclass="item"hover-class="item-hover"hover-stay-time="180"wx:for="{{chineseProvinces[2]}}"bind:tap="inputPlate"data-value="{{item}}"wx:key="index">{{item}}</view></view><view class="line"><viewclass="item abc"hover-class="item-hover"hover-stay-time="180"bind:tap="toggleNumber">ABC</view><viewclass="item"hover-class="item-hover"hover-stay-time="180"wx:for="{{chineseProvinces[3]}}"bind:tap="inputPlate"data-value="{{item}}"wx:key="index">{{item}}</view><viewclass="item close"hover-class="item-hover"hover-stay-time="180"wx:key="index"bind:tap="delPlate"><t-icon name="close" color="#3d3d3d" size="24"></t-icon></view></view></view></view><!-- 数字和字母 --><view hidden="{{provicesOrNumber !== 'number'}}"><view class="plate-province plate-number"><view class="line"><viewclass="item"hover-class="item-hover"hover-stay-time="180"wx:for="{{numberAbcText[0]}}"bind:tap="inputPlate"data-value="{{item}}"wx:key="index">{{item}}</view></view><view class="line"><viewclass="item"hover-class="item-hover"hover-stay-time="180"wx:for="{{numberAbcText[1]}}"bind:tap="inputPlate"data-value="{{item}}"wx:key="index">{{item}}</view></view><view class="line"><viewclass="item"hover-class="item-hover"hover-stay-time="180"wx:for="{{numberAbcText[2]}}"bind:tap="inputPlate"data-value="{{item}}"wx:key="index">{{item}}</view></view><view class="line"><viewclass="item abc"hover-class="item-hover"hover-stay-time="180"bind:tap="toggleProvice">返回</view><viewclass="item"hover-class="item-hover"hover-stay-time="180"wx:for="{{numberAbcText[3]}}"bind:tap="inputPlate"data-value="{{item}}"wx:key="index">{{item}}</view><viewclass="item close"hover-class="item-hover"hover-stay-time="180"wx:key="index"bind:tap="delPlate"><t-icon name="close" color="#3d3d3d" size="24"></t-icon></view></view></view></view></view></view>
</t-popup>
  1. less代码(微信小程序配置less代码 地址)
.block {width: 100vw;background: #fff;border-top-left-radius: 16rpx;border-top-right-radius: 16rpx;
}.header {box-sizing: border-box;position: relative;border-width: 0px 0px 1px 0px;border-style: solid;border-color: #ededed;padding: 24rpx;.btns {width: 100%;display: flex;justify-content: space-between;gap: 0 48rpx;.c-btn {width: 0;flex: 1;margin: 0;}}.plates {position: relative;width: 100%;position: relative;box-sizing: border-box;display: flex;justify-content: space-between;padding: 0 10rpx;margin-top: 50rpx;.plate-item {box-sizing: border-box;position: relative;width: 72rpx;height: 84rpx;color: #262626;font-size: 72rpx;border-radius: 2rpx;background: #f7f7f7;display: flex;align-items: center;justify-content: center;overflow: hidden;.plate-value {font-size: 32rpx;color: #0052d9;}.item__cursor {position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);width: 1px;height: 40%;animation: 1.5s uv-cursor-flicker infinite;background-color: #0052d9;}}.plate-item-active {border: 1px solid #0052d9;}.txt {position: absolute;top: -40rpx;right: 15rpx;line-height: 28rpx;font-size: 20rpx;color: #0052d9;}}
}.plate-btn {box-sizing: border-box;background-color: #f7f7f7;padding: 12rpx 12rpx;.plate-province {display: flex;flex-direction: column;gap: 10rpx 0;.line {display: flex;align-items: center;gap: 0 10rpx;}.item {width: 68rpx;height: 80rpx;font-size: 28rpx;color: #3d3d3d;border-radius: 8rpx;background: #fff;display: flex;align-items: center;justify-content: center;}.item-hover {background-color: #f0f0f0; /* 点击时的背景色 */}.abc {width: 90rpx;}.close {width: 0;flex: 1;}}
}@keyframes uv-cursor-flicker {0% {opacity: 0;}50% {opacity: 1;}100% {opacity: 0;}
}
  1. js文件
import { deepClone } from "@/utils/util";
const app = getApp();
const chineseProvinces = [["京", "津", "沪", "渝", "冀", "豫", "云", "辽", "黑", "湘"],["皖", "鲁", "新", "苏", "浙", "赣", "鄂", "桂", "甘", "晋"],["蒙", "陕", "吉", "闽", "贵", "粤", "青", "藏", "川", "宁"],["琼", "使", "领", "学", "警", "港", "澳"],
];const numberAbcText = [["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],["A", "S", "D", "F", "G", "H", "J", "K", "L"],["Z", "X", "C", "V", "B", "N", "M"],
];Component({// 虚拟化组件节点options: {virtualHost: true,},externalClasses: [],properties: {propPlate: {type: [String, Array],value: "",},visible: {type: Boolean,value: false,},},observers: {visible: function () {this.setData({customVisible: this.data.visible,});},propPlate: function () {let propPlate = deepClone(this.data.propPlate);if (!Array.isArray(propPlate)) {propPlate = propPlate.split("");}this.setData({plate: propPlate,});},},data: {customVisible: false, // popup 状态plateLength: 8, // 车牌的长度  固定是8 最后一位是新能源plate: [], // 车牌chineseProvinces,numberAbcText,provicesOrNumber: "provice", // 省份(provice) / 字母数字(number)},lifetimes: {},methods: {// 关闭popupclosePopup() {this.setData({customVisible: !this.data.customVisible,});this.triggerEvent("change", false);},// 确定confirm() {this.triggerEvent("backData", {plate: deepClone(this.data.plate),});this.closePopup();},// 选择车牌 省份/数字inputPlate(e) {let value = e.currentTarget.dataset.value;if (this.data.plate.length >= 8) {return;}let plate = this.data.plate;plate.push(value);this.setData({plate,});},// 删除车牌delPlate() {let plate = this.data.plate;plate.pop();this.setData({plate,});},toggleNumber() {this.setData({provicesOrNumber: "number",});},toggleProvice() {this.setData({provicesOrNumber: "provice",});},},
});
  1. json文件
{"component": true,"usingComponents": {"t-popup": "tdesign-miniprogram/popup/popup","t-button": "tdesign-miniprogram/button/button","t-icon": "tdesign-miniprogram/icon/icon"}
}

6.使用

<view>车牌:{{licensePlate}}</view>
<button bind:tap="openPlateLicense">点击显示车牌输入器</button>
<plate-licenseprop-plate="{{licensePlate}}"visible="{{plateLicenseVisible}}"bind:change="closePlateLicence"bind:backData="backPlateLicense" />
// js方法openPlateLicense() {this.setData({plateLicenseVisible: true,});},closePlateLicence() {this.setData({plateLicenseVisible: false,});},backPlateLicense(e) {let plate = e.detail.plate;this.setData({licensePlate: plate.join(""),});}, 
http://www.dtcms.com/a/565036.html

相关文章:

  • 百度的网址是什么呢优化学校网站建设方案
  • Node.Js Express Sqlite3 接口开发
  • docker上部署 PolarDB-X v2.4.2数据库
  • 待办事项全栈实现:Vue3 + Node.js (Koa) + MySQL深度整合,构建生产级任务管理系统的技术实践
  • 【Solidity 从入门到精通】前言
  • 天硕工业级SSD深度解析:NVMe性能分层的根源与高可靠选型指南
  • 人证查验一体机:公安安全检查的智能新助手
  • Python 查找并高亮显示指定 Excel 数据
  • 如何把xmind里的一整段文字变成独立主题的方法
  • 免费CDN
  • 【Java】流程控制
  • 公司网站开源源码现在pc端网站开发用的什么技术
  • 【weblogic】JND注入漏洞
  • 简单建设一个网站的过程安徽建设工程协会网站
  • Spring Security权限认证机制详解 实战
  • java每日精进 11.03【基于Spring AOP和事件驱动的资源操作消息处理流程(类似于若依框架的@Log注解)】
  • Spring 从 0 → 1 保姆级笔记:IOC、DI、多配置、Bean 生命周期一次讲透
  • SpringBoot 项目基于责任链模式实现复杂接口的解耦和动态编排
  • Java 入门核心知识点分类学习
  • 叫人做网站后不提供源码商机网创业好项目
  • 【2052】范围判断
  • (1)pytest+Selenium自动化测试-序章
  • 用Python来学微积分29-原函数与不定积分完全指南
  • JavaSE---文件(File)、IO流(基础)
  • 论坛类网站备案吗红色专题网站首页模板
  • 网页设计师主要是做什么的呢深圳seo
  • C++多线程之 安全日志系统
  • 哪里有做效果图的网站wordpress文章内模板
  • Nof1:探索大语言模型作为量化交易者的极限(翻译)
  • 做网站整理信息的表格免费有效的推广网站