uniapp踩坑之项目:uniapp数字键盘组件—APP端

2023-11-05 18:30

本文主要是介绍uniapp踩坑之项目:uniapp数字键盘组件—APP端,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

//在components文件夹创建digitKeyboard文件夹,再创建digitKeyboard.vue

<!-- 数字键盘 -->
<template><view class="digit-keyboard"><view class="digit-keyboard_bg" @tap="hide"></view><view class="digit-keyboard_area"><!-- <view class="input-area"><view class="item">{{label}}:</view><view class="item"><input :placeholder="inputVal" v-model="val" class="input" @input="input" disabled /></view><view class="item"><button type="primary" size="mini" @tap="confirm">确定</button></view></view> --><view class="number-area"><view class="item" @tap="modifyNum(1)">1</view><view class="item" @tap="modifyNum(2)">2</view><view class="item" @tap="modifyNum(3)">3</view><view class="item" @tap="modifyNum('del')"><icon type="cancel" size="20" /></view><view class="item" @tap="modifyNum(4)">4</view><view class="item" @tap="modifyNum(5)">5</view><view class="item" @tap="modifyNum(6)">6</view><view class="item" @tap="modifyNum('add')">加1</view><view class="item" @tap="modifyNum(7)">7</view><view class="item" @tap="modifyNum(8)">8</view><view class="item" @tap="modifyNum(9)">9</view><view class="item" style="background-color:#2278FA;color: #ffffff;" @tap="confirm">确定</view><view class="item" @tap="modifyNum('-')">-</view><view class="item" @tap="modifyNum(0)">0</view><view class="item" @tap="modifyNum('.')">.</view><view class="item" @tap="modifyNum('clear')">清除</view></view></view></view>
</template><script>
import NP from '../../utils/numberPrecision'
export default {props: {inputVal: {type: [String],default: ''},label: {type: String,default: '现金'},},data() {return {val: ''};},created() {},methods: {input() {// this.$emit('cancel');let val = this.val;console.log(val);this.$emit('inputFocus', val);},//隐藏hide() {this.$emit('cancel');},confirm() {let val = this.val;let valNew = val.slice(-1);if (valNew == '.') {val = val.slice(0, -1);}this.$emit('confirm', val);},modifyNum(sign) {let {val} = this;//删除if (sign == 'del') {if (val.length > 0) {let valNew = val.slice(0, -1);if (valNew.length == 0) {val = '';} else {val = valNew;}}} else if (sign == 'add') { //加1val = NP.plus(Number(val), 1) + '';} else if (sign == 'minus') { //减1val = NP.minus(Number(val), 1) + '';} else if (sign == 'clear') { //清除val = '';} else if (sign == '-') { //代表负数if (val.indexOf('-') == -1) {val = '-' + val;}} else if (sign == '.') { //点符号if (val.indexOf('.') == -1 && val.length > 0) {val = val + '.';}} else {if ((val == '0' && sign == '0') || (val == '-0' && sign == '0') || (val == '0' && sign != '.') || (val == '-0' && sign != '.')) {return;}val = val + sign;}//小数点大于3位不赋值let arr = val.split('.');if (arr.length == 2 && arr[1].length > 3) {return;}this.$emit('inputFocus', val);this.val = val;}}
}
</script><style lang="scss" scoped>
.digit-keyboard {position: fixed;left: 0;top: 0;width: 100%;height: 100%;z-index: 999;
}.digit-keyboard_bg {width: 100%;height: 100%;background: rgba($color: #000000, $alpha: 0.5);
}.digit-keyboard_area {position: absolute;bottom: 0;left: 0;width: 100%;background: #efefef;padding-bottom: 20upx;
}.input-area {display: flex;align-items: center;padding: 10upx;background: #ffffff;.item {font-size: 28upx;&:nth-of-type(2) {flex: 1 0 auto;padding-right: 10upx;}&:nth-of-type(3) {font-size: 0;}}.input {background: #eeeeee;text-indent: 10upx;font-size: 28upx;height: 60upx;}
}.number-area {display: flex;justify-content: space-around;flex-wrap: wrap;text-align: center;.item {margin-top: 20upx;flex: 0 0 22%;background: #ffffff;line-height: 80upx;font-size: 30upx;font-weight: bold;}
}
</style>

//main.js全局引入

// 数字键盘组件 在项目里main.js中配置如下代码

import digitKeyboard from './components/digitKeyboard/digitKeyboard.vue'
Vue.component('digitKeyboard', digitKeyboard)

 //单页面使用

//html
<input 
class="content-input" 
@click="clickInput" 
@input="input" 
v-model="inputValue" /><!-- 数字键盘 -->
<view>
<digitKeyboard 
v-if="isShowKeyboardWindow" 
@inputFocus="inputKeyboard" 
:inputVal="inputVal" 
:label="label" 
@cancel="isShowKeyboardWindow = false" 
@confirm="keyboardConfirm" />
</view>//data
// 数字键盘 
inputVal: '',
label: '现金支付',
isShowKeyboardWindow: false,//是否显示键盘窗口//js
// 数字键盘
inputKeyboard(e) {// console.log(e, '00000000000')this.inputValue = e //输入框双向绑定if (e) {this.isChecked1 = falsethis.isChecked2 = falsethis.isChecked3 = falsethis.isChecked4 = falsethis.isChecked5 = falsethis.isChecked6 = false}},keyboardConfirm(val) {console.log(val)this.inputValue = valthis.isShowKeyboardWindow = falsethis.isChecked1 = false;this.isChecked2 = false;this.isChecked3 = false;this.isChecked4 = false;this.isChecked5 = false;this.isChecked6 = false;},
// 输入框点击事件
clickInput() {this.isShowKeyboardWindow = true // 数字键盘组件显示},
//充值按钮
recharge: function (e) {// 进行判断if (this.inputValue !== '' || null || undefined) {// 为数字// 可调用支付接口// #ifdef APP-PLUSif (this.spaceCheck) {this.commitDialog()} else {// this.cancelDialog()}this.$refs.popupRef.show();// #endif}// 进行判断if ((this.inputValue == '' || null || undefined) && this.current_tag == '' &&this.isChecked1 == false &&this.isChecked2 == false &&this.isChecked3 == false &&this.isChecked4 == false &&this.isChecked5 == false &&this.isChecked6 == false) { // 为空// console.log(33333333);uni.showToast({title: '请选择数值或输入内容!',duration: 2000,icon: 'none',});return false}else if ((this.inputValue == '' || null || undefined) && this.current_tag &&this.isChecked1 == false &&this.isChecked2 == false &&this.isChecked3 == false &&this.isChecked4 == false &&this.isChecked5 == false &&this.isChecked6 == false) {uni.showToast({title: '请选择数值或输入内容!',duration: 2000,icon: 'none',});return false}if (this.current_tag || this.isChecked2 == true) {// 进行判断// 可调用支付接口// #ifdef APP-PLUSif (this.spaceCheck) {this.commitDialog()} else {// this.cancelDialog()}this.$refs.popupRef.show();// #endif}                    }

上一篇文章, 

vue2踩坑之项目:Swiper轮播图使用_意初的博客-CSDN博客文章浏览阅读456次。首先安装swiper插件,解决方法:npm 版本太高,切换一下就好了,引入Swiper,mounted里面调用https://blog.csdn.net/weixin_43928112/article/details/133681437

这篇关于uniapp踩坑之项目:uniapp数字键盘组件—APP端的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/351695

相关文章

基于 Cursor 开发 Spring Boot 项目详细攻略

《基于Cursor开发SpringBoot项目详细攻略》Cursor是集成GPT4、Claude3.5等LLM的VSCode类AI编程工具,支持SpringBoot项目开发全流程,涵盖环境配... 目录cursor是什么?基于 Cursor 开发 Spring Boot 项目完整指南1. 环境准备2. 创建

Vue和React受控组件的区别小结

《Vue和React受控组件的区别小结》本文主要介绍了Vue和React受控组件的区别小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录背景React 的实现vue3 的实现写法一:直接修改事件参数写法二:通过ref引用 DOMVu

Three.js构建一个 3D 商品展示空间完整实战项目

《Three.js构建一个3D商品展示空间完整实战项目》Three.js是一个强大的JavaScript库,专用于在Web浏览器中创建3D图形,:本文主要介绍Three.js构建一个3D商品展... 目录引言项目核心技术1. 项目架构与资源组织2. 多模型切换、交互热点绑定3. 移动端适配与帧率优化4. 可

sky-take-out项目中Redis的使用示例详解

《sky-take-out项目中Redis的使用示例详解》SpringCache是Spring的缓存抽象层,通过注解简化缓存管理,支持Redis等提供者,适用于方法结果缓存、更新和删除操作,但无法实现... 目录Spring Cache主要特性核心注解1.@Cacheable2.@CachePut3.@Ca

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

Springboot项目构建时各种依赖详细介绍与依赖关系说明详解

《Springboot项目构建时各种依赖详细介绍与依赖关系说明详解》SpringBoot通过spring-boot-dependencies统一依赖版本管理,spring-boot-starter-w... 目录一、spring-boot-dependencies1.简介2. 内容概览3.核心内容结构4.

在ASP.NET项目中如何使用C#生成二维码

《在ASP.NET项目中如何使用C#生成二维码》二维码(QRCode)已广泛应用于网址分享,支付链接等场景,本文将以ASP.NET为示例,演示如何实现输入文本/URL,生成二维码,在线显示与下载的完整... 目录创建前端页面(Index.cshtml)后端二维码生成逻辑(Index.cshtml.cs)总结

Spring Boot项目如何使用外部application.yml配置文件启动JAR包

《SpringBoot项目如何使用外部application.yml配置文件启动JAR包》文章介绍了SpringBoot项目通过指定外部application.yml配置文件启动JAR包的方法,包括... 目录Spring Boot项目中使用外部application.yml配置文件启动JAR包一、基本原理

Springboot项目登录校验功能实现

《Springboot项目登录校验功能实现》本文介绍了Web登录校验的重要性,对比了Cookie、Session和JWT三种会话技术,分析其优缺点,并讲解了过滤器与拦截器的统一拦截方案,推荐使用JWT... 目录引言一、登录校验的基本概念二、HTTP协议的无状态性三、会话跟android踪技术1. Cook

springboot项目中集成shiro+jwt完整实例代码

《springboot项目中集成shiro+jwt完整实例代码》本文详细介绍如何在项目中集成Shiro和JWT,实现用户登录校验、token携带及接口权限管理,涉及自定义Realm、ModularRe... 目录简介目的需要的jar集成过程1.配置shiro2.创建自定义Realm2.1 LoginReal