当前位置:   article > 正文

uniapp:小程序数字键盘功能样式实现

uniapp:小程序数字键盘功能样式实现

代码如下:

  1. <template>
  2. <view>
  3. <view>
  4. <view class="money-input">
  5. <view class="input-container" @click="toggleBox">
  6. <view class="input-wrapper">
  7. <view class="input-iconone">
  8. <image src="https://picture-warehouseone.oss-cn-beijing.aliyuncs.com/rmb.png" mode="aspectFit"
  9. style="width: 60rpx; height: 60rpx;"></image>
  10. </view>
  11. <view
  12. style="width: auto; height: 100%;line-height: 156rpx; padding-left: 80rpx; font-size: 80rpx; color: #333;">
  13. {{nums}}
  14. </view>
  15. <view class="input-icon" :class="{active: showBox}"></view>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="numbers">
  20. <view style=" display: flex; flex-flow: row wrap; justify-content: flex-start; align-content: flex-start; width: 72%; height: auto;">
  21. <view @click="changeNums(item,index)" :class="item.class" :style="getListitemstyle(index)"
  22. v-for="(item,index) in numbers">
  23. {{item.text}}
  24. </view>
  25. </view>
  26. <view style="width: 28%; height: auto; display: flex; flex-flow: column wrap; ">
  27. <view @click="jianshao()" class="oner" :style="styleos">
  28. <image src="https://picture-warehouseone.oss-cn-beijing.aliyuncs.com/jianshao.png" mode="aspectFit"
  29. style="width: 50rpx; height: 50rpx;"></image>
  30. </view>
  31. <view class="onerplus" @click="ok()" :style="stylelv">
  32. 确认
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view>{{sets}}</view>
  38. </view>
  39. </template>
  40. <script>
  41. export default {
  42. data() {
  43. return {
  44. active: {
  45. background: ' #f2f2f2',
  46. color: '#d4d4d4'
  47. }, //这是确定按钮的样式
  48. styleos: {
  49. background: '#ffffff' //这是确认的初始颜色
  50. },
  51. stylelv: {
  52. background: '#9cd7b7' //确认按钮颜色初始
  53. },
  54. nums: '',
  55. sets:this.set,//获取set中编辑数据
  56. isimit: false, //判断备注是否超过了最大限制标志位
  57. showBox: false, //是否显示‘|’
  58. activeIndex: 0, //默认选中索引
  59. sumindex: -1, //数字键盘索引
  60. numbers: [
  61. {
  62. text: '1',
  63. class: 'oner',
  64. background: '#ffffff'
  65. },
  66. {
  67. text: '2',
  68. class: 'oner',
  69. background: '#ffffff'
  70. },
  71. {
  72. text: '3',
  73. class: 'oner',
  74. background: '#ffffff'
  75. },
  76. {
  77. text: '4',
  78. class: 'oner',
  79. background: '#ffffff'
  80. },
  81. {
  82. text: '5',
  83. class: 'oner',
  84. background: '#ffffff'
  85. },
  86. {
  87. text: '6',
  88. class: 'oner',
  89. background: '#ffffff'
  90. },
  91. {
  92. text: '7',
  93. class: 'oner',
  94. background: '#ffffff'
  95. },
  96. {
  97. text: '8',
  98. class: 'oner',
  99. background: '#ffffff'
  100. },
  101. {
  102. text: '9',
  103. class: 'oner',
  104. background: '#ffffff'
  105. },
  106. {
  107. text: '0',
  108. class: 'big',
  109. background: '#ffffff'
  110. },
  111. {
  112. text: '.',
  113. class: 'oner',
  114. background: '#ffffff'
  115. },
  116. ]
  117. }
  118. },
  119. created() {
  120. },
  121. methods: {
  122. comfors() {
  123. if (this.valuemark) {
  124. this.active.background = "#33955f"
  125. setTimeout(() => {
  126. this.active.background = "#3eb575"
  127. this.showremark = false
  128. }, 150)
  129. }
  130. },
  131. input(e) {
  132. console.log('输入内容:', e);
  133. // console.log('this.index.lenth', this.value.length)
  134. this.valuemark = e
  135. if (this.valuemark) {
  136. this.active.background = '#3eb575'
  137. this.active.color = '#ffffff'
  138. } else {
  139. this.active.background = '#f2f2f2'
  140. this.active.color = '#d4d4d4'
  141. }
  142. },
  143. ok() {
  144. this.stylelv.background = '#3bab6f'
  145. setTimeout(() => {
  146. this.stylelv.background = '#9cd7b7'
  147. }, 150)
  148. },
  149. jianshao() {
  150. this.styleos.background = '#f7f7f7'
  151. setTimeout(() => {
  152. this.styleos.background = '#ffffff'
  153. }, 150)
  154. if (this.nums) {
  155. this.nums = this.nums.substring(0, this.nums.length - 1)
  156. }
  157. },
  158. changeNums(item, index) {
  159. this.numbers.forEach((item, idx) => {
  160. if (idx === index) {
  161. item.background = '#f7f7f7';
  162. setTimeout(() => {
  163. item.background = '#ffffff';
  164. }, 150)
  165. }
  166. });
  167. this.sumindex = index
  168. // console.log('this.sumindex', this.sumindex)
  169. if (item.text == '.') {
  170. console.log(this.nums.indexOf(".") != -1)
  171. if (this.nums.indexOf(".") != -1 || this.nums.length == 0) {
  172. return false
  173. }
  174. }
  175. if (this.nums.split('.') && this.nums.split('.')[1]) {
  176. if (this.nums.split('.')[1].length >= 2) {
  177. return false
  178. }
  179. }
  180. // this.nums.length
  181. console.log('this.nums.length',this.nums.length)
  182. this.nums = this.nums + item.text
  183. if(this.nums.length >6){
  184. this.nums = this.nums.slice(0,6)
  185. uni.showToast({
  186. title: '最多只能输入6位数哦',
  187. icon: 'none'
  188. });
  189. return;
  190. }
  191. },
  192. getListitemstyle(index) {
  193. return {
  194. background: this.numbers[index].background
  195. };
  196. },
  197. toggleBox() {
  198. this.showBox = true //点击后输入框出现“|”每隔一段时间闪动
  199. },
  200. },
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .Classify {
  205. width: 100%;
  206. display: flex;
  207. height: 120rpx;
  208. margin-top: 10rpx;
  209. padding-left: 20rpx;
  210. padding-right: 30rpx;
  211. align-items: center;
  212. margin-bottom: -12rpx;
  213. justify-self: flex-start;
  214. }
  215. .Expenditure {
  216. width: auto;
  217. height: 60rpx;
  218. color: #c7c7c7;
  219. font-size: 30rpx;
  220. text-align: center;
  221. line-height: 60rpx;
  222. margin-left: 20rpx;
  223. border-radius: 10rpx;
  224. background-color: #f7f7f7;
  225. padding: 0rpx 20rpx 0rpx 20rpx;
  226. }
  227. .Expendituretime {
  228. width: auto;
  229. color: black;
  230. display: flex;
  231. height: 60rpx;
  232. font-size: 30rpx;
  233. line-height: 60rpx;
  234. margin-left: 32rpx;
  235. align-items: center;
  236. border-radius: 10rpx;
  237. background-color: #f7f7f7;
  238. justify-content: space-evenly;
  239. padding: 0rpx 15rpx 0rpx 20rpx;
  240. }
  241. .Expenditurelv {
  242. width: auto;
  243. height: 60rpx;
  244. color: #3eb575;
  245. font-size: 30rpx;
  246. text-align: center;
  247. line-height: 60rpx;
  248. margin-left: 20rpx;
  249. border-radius: 10rpx;
  250. background-color: #ebf7f1;
  251. padding: 0rpx 20rpx 0rpx 20rpx;
  252. }
  253. .ExpenditureH {
  254. width: auto;
  255. height: 60rpx;
  256. color: #f5c53a;
  257. font-size: 30rpx;
  258. text-align: center;
  259. line-height: 60rpx;
  260. margin-left: 20rpx;
  261. border-radius: 10rpx;
  262. background-color: #fdf8eb;
  263. padding: 0rpx 20rpx 0rpx 20rpx;
  264. }
  265. .ExpenditureL {
  266. width: auto;
  267. height: 60rpx;
  268. color: #8c8bc3;
  269. font-size: 30rpx;
  270. text-align: center;
  271. line-height: 60rpx;
  272. margin-left: 20rpx;
  273. border-radius: 10rpx;
  274. background-color: #f1f3f6;
  275. padding: 0rpx 20rpx 0rpx 20rpx;
  276. }
  277. .money-input {
  278. width: 100%;
  279. height: 150rpx;
  280. padding: 0 40rpx 0 40rpx;
  281. }
  282. .Type {
  283. width: 100%;
  284. height: 154px;
  285. display: flex;
  286. margin-top: 20rpx;
  287. align-items: center;
  288. flex-flow: row wrap;
  289. justify-content: flex-start;
  290. overflow-y: auto;
  291. }
  292. .Type-box {
  293. display: flex;
  294. width: 120rpx;
  295. height: 140rpx;
  296. align-items: center;
  297. flex-flow: column wrap;
  298. justify-content: center;
  299. margin: 0 0rpx 10rpx 5rpx;
  300. }
  301. .Typeboxactive {
  302. display: flex;
  303. width: 120rpx;
  304. height: 140rpx;
  305. align-items: center;
  306. flex-flow: column wrap;
  307. justify-content: center;
  308. margin: 0 0rpx 10rpx 5rpx;
  309. background-color: #cbcbcb;
  310. }
  311. .inctiveclass {
  312. width: 80rpx;
  313. display: flex;
  314. height: 80rpx;
  315. font-size: 22rpx;
  316. border-radius: 50%;
  317. align-items: center;
  318. justify-content: center;
  319. background-color: #e7e7e7;
  320. }
  321. .activeclass {
  322. width: 80rpx;
  323. display: flex;
  324. height: 80rpx;
  325. border-radius: 50%;
  326. align-items: center;
  327. justify-content: center;
  328. background-color: #3eb575;
  329. }
  330. .numbers {
  331. width: 100%;
  332. display: flex;
  333. height: 480rpx;
  334. margin-top: 10rpx;
  335. background-color: #fafafa;
  336. justify-content: flex-start;
  337. }
  338. .remark {
  339. width: 100%;
  340. color: #50648a;
  341. height: 100rpx;
  342. font-size: 32rpx;
  343. padding: 20rpx 0 0 30rpx;
  344. }
  345. .oner {
  346. display: flex;
  347. width: 165rpx;
  348. height: 100rpx;
  349. font-size: 34rpx;
  350. font-weight: bold;
  351. align-items: center;
  352. border-radius: 10rpx;
  353. justify-content: center;
  354. margin: 15rpx auto 5rpx;
  355. background-color: #ffffff;
  356. }
  357. .onerplus {
  358. display: flex;
  359. width: 165rpx;
  360. color: #ffffff;
  361. height: 338rpx;
  362. font-size: 34rpx;
  363. font-weight: bold;
  364. align-items: center;
  365. border-radius: 10rpx;
  366. justify-content: center;
  367. margin: 15rpx auto 5rpx;
  368. background-color: #9cd7b7;
  369. }
  370. .big {
  371. display: flex;
  372. width: 342rpx;
  373. height: 100rpx;
  374. font-size: 34rpx;
  375. font-weight: bold;
  376. align-items: center;
  377. border-radius: 10rpx;
  378. margin: 15rpx auto 5rpx;
  379. justify-content: center;
  380. background-color: #ffffff;
  381. }
  382. .input-container {
  383. position: relative;
  384. width: 100%;
  385. height: 156rpx;
  386. display: flex;
  387. }
  388. .input-wrapper {
  389. position: relative;
  390. width: 100%;
  391. height: 100%;
  392. border-bottom: 1px solid #ccc;
  393. padding: 0 20rpx;
  394. box-sizing: border-box;
  395. display: flex;
  396. justify-content: flex-start;
  397. align-items: center;
  398. }
  399. .input-icon {
  400. height: 106rpx;
  401. width: 5rpx;
  402. background-color: #cbcbcb;
  403. display: none;
  404. }
  405. .active {
  406. display: block;
  407. animation: blink 1s infinite; //点击后|出现
  408. }
  409. @keyframes blink {
  410. 0% {
  411. opacity: 0;
  412. }
  413. 50% {
  414. opacity: 1;
  415. }
  416. 100% {
  417. opacity: 0;
  418. }
  419. }
  420. .input-iconone {
  421. position: absolute;
  422. top: 50%;
  423. left: 2rpx;
  424. transform: translateY(-50%);
  425. color: #666;
  426. }
  427. .input-field {
  428. width: 100%;
  429. height: 100%;
  430. line-height: 156rpx;
  431. padding-left: 80rpx;
  432. font-size: 80rpx;
  433. color: #333;
  434. }
  435. .remarks {
  436. width: 68px;
  437. height: 30px;
  438. display: flex;
  439. justify-content: flex-start;
  440. align-items: center;
  441. }
  442. .box-text {
  443. display: flex;
  444. justify-content: center;
  445. color: #c7c7c7;
  446. align-items: center;
  447. width: 100%;
  448. margin-top: 10rpx;
  449. height: 40rpx;
  450. text-align: center;
  451. font-size: 24rpx;
  452. }
  453. .box-ative {
  454. display: flex;
  455. justify-content: center;
  456. color: #000000;
  457. align-items: center;
  458. width: 100%;
  459. margin-top: 10rpx;
  460. height: 40rpx;
  461. text-align: center;
  462. font-size: 24rpx;
  463. }
  464. .top {
  465. position: relative;
  466. width: 100%;
  467. height: 30%;
  468. }
  469. .window {
  470. width: 100rpx;
  471. height: 100%;
  472. display: flex;
  473. justify-content: center;
  474. align-items: center;
  475. position: absolute;
  476. }
  477. .center {
  478. position: relative;
  479. width: 100%;
  480. height: 30%;
  481. display: flex;
  482. padding: 0 30rpx 0 30rpx;
  483. justify-content: center;
  484. align-items: center;
  485. }
  486. .bottom {
  487. width: 100%;
  488. height: 40%;
  489. position: relative;
  490. }
  491. .comfors {
  492. left: 0;
  493. top: 0;
  494. right: 0;
  495. bottom: 0;
  496. margin: auto;
  497. position: absolute;
  498. width: 380rpx;
  499. height: 100rpx;
  500. border-radius: 10rpx;
  501. background-color: #f2f2f2;
  502. display: flex;
  503. justify-content: center;
  504. align-items: center;
  505. color: #d4d4d4;
  506. border: 1rpx solid #f2f2f2;
  507. }
  508. .Record-remarks-number-of-words {
  509. position: absolute;
  510. left: 30rpx;
  511. bottom: -20rpx;
  512. color: #d4d4d4;
  513. }
  514. </style>

uniapp中直接运行即可。运行效果:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/249507
推荐阅读
相关标签
  

闽ICP备14008679号