用css绘制收银键盘

news/2025/3/22 4:02:03/

最近需求说需要自己弄个收银键盘,于是乎直接上手搓

主要基于Vue3写的,主要是CSS

<template><view class="container"><view class="info"><image class="img" src="" mode=""></image><text class="name">达达</text></view><view class="inputBox"><view class="concent flex flex_just_sb flex_items_c"><view class="insideBox"><text class="title">付款金额</text><view class="price"><text class="value">¥</text><text class="number">{{payMuch}}</text></view></view></view></view><div class="btn"><view class="btn_box"><view class="line_one"><button @click="_handleKeyPress('1')" type="primary">1</button><button @click="_handleKeyPress('2')" type="primary">2</button><button @click="_handleKeyPress('3')" type="primary">3</button><button @click="_handleKeyPress('D')" type="primary">清除</button></view><view class="btn_bottom"><view class="line_two"><view class="line-left"><view class="line_box"><view class="line_two"><button @click="_handleKeyPress('4')" type="primary">4</button><button @click="_handleKeyPress('5')" type="primary">5</button><button @click="_handleKeyPress('6')" type="primary">6</button></view><view class="line_three"><button @click="_handleKeyPress('7')" type="primary">7</button><button @click="_handleKeyPress('8')" type="primary">8</button><button @click="_handleKeyPress('9')" type="primary">9</button></view><view class="line_four"><button type="primary"></button><button @click="_handleKeyPress('0')" type="primary">0</button><button @click="_handleKeyPress('.')" type="primary">.</button></view></view></view><view class="line-right"><button type="primary" @click="_handleKeyPress('S')">优惠<br />买单</button></view></view></view></view></div></view>
</template><script setup>import {reactive,ref} from 'vue';import {preferentialPay} from '@/api/store'import {onLoad,onShow} from '@dcloudio/uni-app'const payMuch = ref('0')const payPrice = ref(0)const confirmOrderStatus = ref(false)const isdisabled = ref(false)//处理按键function _handleKeyPress(num) {//不同按键处理逻辑// -1 代表无效按键,直接返回if (num == -1) return false;switch (String(num)) {//小数点case ".":_handleDecimalPoint();break;//删除键case "D":_handleDeleteKey();break;//确认键case "S":_handleConfirmKey();break;default:_handleNumberKey(num);break;}}//处理数字function _handleNumberKey(num) {let S = payMuch.value;//如果有小数点且小数点位数不小于2if (S.indexOf(".") > -1 && S.substring(S.indexOf(".") + 1).length < 2) payMuch.value = S + num;//没有小数点if (!(S.indexOf(".") > -1)) {//如果第一位是0,只能输入小数点if (num == 0 && S.length == 0) payMuch.value = "0.";else {if (S.length && Number(S.charAt(0)) === 0) {payMuch.value = num;return;}payMuch.value = S + num;}}}function _handleConfirmKey() {let S = payMuch.value;//未输入if (!S.length || Number(S) === 0) {showTotal("您目前未输入!");return false;}//将 8. 这种转换成 8.00if (S.indexOf(".") > -1 && S.indexOf(".") === S.length - 1) S = Number(S.substring(0, S.length - 1)).toFixed(2);//保留两位S = Number(S).toFixed(2);confirmOrder();}//处理小数点函数function _handleDecimalPoint() {//如果包含小数点,直接返回if (payMuch.value.indexOf(".") > -1) return false;//如果小数点是第一位,补0if (!payMuch.value.length) payMuch.value = "0.";//如果不是,添加一个小数点else payMuch.value = payMuch.value + ".";}//处理删除键function _handleDeleteKey() {let S = payMuch.value;//如果没有输入,直接返回if (S.length <= 1) return (payMuch.value = "0");//否则删除最后一个payMuch.value = S.substring(0, S.length - 1);}async function toPayMethods(){const {data,result,msg} = await preferentialPay({// 处理你需要处理的支付逻辑})}function showTotal(e) {uni.showToast({title: e,icon: 'none',duration: 2000,mask: true})}function confirmOrder() {var val = payMuch.value;if (val && val > 0) {payPrice.value = val;toPayMethods();confirmOrderStatus.value = true;isdisabled.value = true;} else {showTotal('请输入正确的付款金额!')confirmOrderStatus.value = false;isdisabled.value = false;}}
</script><style lang="scss" scoped>.container {.info {display: flex;align-items: center;justify-content: center;padding-top: 40upx;.img {background: greenyellow;width: 80upx;height: 80upx;border-radius: 50%;}.name {font-weight: bold;font-size: 32upx;color: #323233;line-height: 48upx;padding-left: 20upx;}}.inputBox {// margin-top: 20upx;width: 90vw;min-height: 100upx;background: #fff;border: 0.0625upx solid #999;// border-radius: 0.375rem;margin: 40upx auto;padding: 0 12upx;line-height: 100upx;.concent {.insideBox {display: flex;align-items: center;justify-content: space-between;width: 100%;.title {// display: flex;width: 160upx;font-weight: 500;font-size: 40upx;color: #323233;line-height: 36upx;text-align: right;opacity: 0.6;}.price {display: flex;align-items: flex-end;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;.value {font-weight: 500;font-size: 30upx;color: #323233;text-align: left;}.number {font-weight: 500;font-size: 48upx;color: #323233;text-align: left;&:last-child {white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 450upx;}}}}}}.btn {background: #fff;position: fixed;bottom: 0;.btn_box {border-top: solid 0.0625rem #ccc;.line_one {display: flex;button {width: 5.8125rem;// height: 3.75rem;font-size: 2rem;background: none;color: #333;border-radius: 0;padding: 0;border: none;border-right: solid 0.0625rem #ccc;}button:last-child {border-right: none;}}.btn_bottom {.line_two {display: flex;.line-left {.line_box {.line_two {display: flex;border-top: solid 0.0625rem #ccc;button {width: 5.8rem;// height: 3.75rem;font-size: 2rem;background: none;color: #333;border-radius: 0;padding: 0;border: none;border-right: solid 0.0625rem #ccc;}button:last-child {border-right: none;}}.line_three {border-top: solid 0.0625rem #ccc;display: flex;button {width: 5.8rem;// height: 3.75rem;font-size: 2rem;background: none;color: #333;border-radius: 0;padding: 0;border: none;border-right: solid 0.0625rem #ccc;}button:last-child {border-right: none;}}.line_four {display: flex;border-top: solid 0.0625rem #ccc;button {width: 5.8rem;// height: 3.75rem;font-size: 2rem;background: none;color: #333;border-radius: 0;padding: 0;border: none;border-right: solid 0.0625rem #ccc;}button:last-child {border-right: none;}}}}.line-right {button {width: 6rem;height: 100%;padding: 0;border-radius: 0;font-size: 1.375rem;line-height: 6.375rem;}}}}}}}
</style>

文章来源:https://blog.csdn.net/junhian/article/details/146365006
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ppmy.cn/news/1580678.html

相关文章

医疗数据大集结

医疗数据大集结 一、医疗大语言模型数据集1.1 中文医疗数据集1.2 英文 / 多语言医疗数据集 二、医疗大语言模型 / 预训练模型2.1 开源预训练医疗大语言模型&#xff08;以英文 / 生物医学为主&#xff09;2.2 多语言医疗大模型2.3 英文医疗大语言模型 三、医疗大语言模型评测基…

browser-use WebUI + DeepSeek 基于AI的UI自动化解决方案

browser-use WebUI 一、browser-use是什么Browser-use采用的技术栈为&#xff1a; 二、browser-use webui 主要功能使用场景 三、使用教程1.python 安装2、把项目clone下来3、安装依赖4、配置环境5、启动6、配置1.配置 Agent2.配置要用的大模型3.关于浏览器的一些设置 四、Deep…

【实战ES】实战 Elasticsearch:快速上手与深度实践-8.2.1AWS OpenSearch无服务器方案

&#x1f449; 点击关注不迷路 &#x1f449; 点击关注不迷路 &#x1f449; 点击关注不迷路 文章大纲 8.2.1AWS OpenSearch 无服务器方案深度解析与实践指南1. Serverless架构的核心价值与行业趋势1.1 传统Elasticsearch集群的运维挑战1.2 Serverless技术演进路线技术特性对比…

如何用Python和Selenium实现表单的自动填充与提交?

在今天的数字化时代&#xff0c;自动化工具可以极大地提高工作效率。很多人可能会觉得填表单是个繁琐的任务&#xff0c;不过你知道吗&#xff1f;用Python和Selenium可以轻松解决这一问题&#xff01;本文将带你走进如何利用这两个强大的工具&#xff0c;实现表单的自动填充和…

深入理解 C# 反射 的使用

总目录 前言 反射是.NET框架中一个强大的特性&#xff0c;允许程序在运行时检查和操作类型信息。通过反射&#xff0c;开发者可以动态地创建对象、调用方法、访问属性等&#xff0c;为程序提供了极大的灵活性。本文将详细讲解C#反射的使用方法及其应用场景。 一、什么是反射&a…

高效创作利器:Windows上快速搭建Stable Diffusion 3.5并实现远程访问

文章目录 前言1. 本地部署ComfyUI2. 下载 Stable Diffusion3.5 模型3. 演示文生图4. 公网使用Stable Diffusion 3.5 大模型4.1 创建远程连接公网地址 5. 固定远程访问公网地址 前言 对于追求极致效率和作品质量的创作者来说&#xff0c;本地部署 AI 模型并实现远程访问已经从梦…

在Spring Boot项目中接入DeepSeek深度求索,感觉笨笨的呢

文章目录 引言1. 什么是DeepSeek&#xff1f;2. 准备工作2.1 注册DeepSeek账号 3.实战演示3.1 application增加DS配置3.2 编写service3.3 编写controller3.4 编写前端界面chat.html3.5 测试 总结 引言 在当今快速发展的数据驱动时代&#xff0c;企业越来越重视数据的价值。为了…

C#通过SignalR直接返回流式响应内容

1、背景 实现流式响应基本上分为两大技术方案&#xff1a;&#xff08;1&#xff09;基于HTTP的Stream处理&#xff1b;&#xff08;2&#xff09;基于socket的连接。前者的实现方式有&#xff1a;《C#通过API接口返回流式响应内容—SSE方式》和《C#通过API接口返回流式响应内…