From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001 From: spring <2396852758@qq.com> Date: 星期三, 28 五月 2025 16:48:52 +0800 Subject: [PATCH] 初始化项目 --- uview-ui/components/u-number-keyboard/u-number-keyboard.vue | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 158 insertions(+), 0 deletions(-) diff --git a/uview-ui/components/u-number-keyboard/u-number-keyboard.vue b/uview-ui/components/u-number-keyboard/u-number-keyboard.vue new file mode 100644 index 0000000..6425a1f --- /dev/null +++ b/uview-ui/components/u-number-keyboard/u-number-keyboard.vue @@ -0,0 +1,158 @@ +<template> + <view class="u-keyboard" @touchmove.stop.prevent="() => {}"> + <view class="u-keyboard-grids"> + <view + class="u-keyboard-grids-item" + :class="[btnBgGray(index) ? 'u-bg-gray' : '', index <= 2 ? 'u-border-top' : '', index < 9 ? 'u-border-bottom' : '', (index + 1) % 3 != 0 ? 'u-border-right' : '']" + :style="[itemStyle(index)]" + v-for="(item, index) in numList" + :key="index" + :hover-class="hoverClass(index)" + :hover-stay-time="100" + @tap="keyboardClick(item)"> + <view class="u-keyboard-grids-btn">{{ item }}</view> + </view> + <view class="u-keyboard-grids-item u-bg-gray" hover-class="u-hover-class" :hover-stay-time="100" @touchstart.stop="backspaceClick" + @touchend="clearTimer"> + <view class="u-keyboard-back u-keyboard-grids-btn"> + <u-icon name="backspace" :size="38" :bold="true"></u-icon> + </view> + </view> + </view> + </view> +</template> + +<script> + export default { + props: { + // 閿洏鐨勭被鍨嬶紝number-鏁板瓧閿洏锛宑ard-韬唤璇侀敭鐩� + mode: { + type: String, + default: 'number' + }, + // 鏄惁鏄剧ず閿洏鐨�"."绗﹀彿 + dotEnabled: { + type: Boolean, + default: true + }, + // 鏄惁鎵撲贡閿洏鎸夐敭鐨勯『搴� + random: { + type: Boolean, + default: false + } + }, + data() { + return { + backspace: 'backspace', // 閫�鏍奸敭鍐呭 + dot: '.', // 鐐� + timer: null, // 闀挎寜澶氭鍒犻櫎鐨勪簨浠剁洃鍚� + cardX: 'X' // 韬唤璇佺殑X绗﹀彿 + }; + }, + computed: { + // 閿洏闇�瑕佹樉绀虹殑鍐呭 + numList() { + let tmp = []; + if (!this.dotEnabled && this.mode == 'number') { + if (!this.random) { + return [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; + } else { + return this.$u.randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]); + } + } else if (this.dotEnabled && this.mode == 'number') { + if (!this.random) { + return [1, 2, 3, 4, 5, 6, 7, 8, 9, this.dot, 0]; + } else { + return this.$u.randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, this.dot, 0]); + } + } else if (this.mode == 'card') { + if (!this.random) { + return [1, 2, 3, 4, 5, 6, 7, 8, 9, this.cardX, 0]; + } else { + return this.$u.randomArray([1, 2, 3, 4, 5, 6, 7, 8, 9, this.cardX, 0]); + } + } + }, + // 鎸夐敭鐨勬牱寮忥紝鍦ㄩ潪涔卞簭&&鏁板瓧閿洏&&涓嶆樉绀虹偣鎸夐挳鏃讹紝index涓�9鏃讹紝鎸夐敭鍗犱綅涓や釜绌洪棿 + itemStyle() { + return index => { + let style = {}; + if (this.mode == 'number' && !this.dotEnabled && index == 9) style.flex = '0 0 66.6666666666%'; + return style; + }; + }, + // 鏄惁璁╂寜閿樉绀虹伆鑹诧紝鍙湪闈炰贡搴�&&鏁板瓧閿洏&&涓斿厑璁哥偣鎸夐敭鐨勬椂鍊� + btnBgGray() { + return index => { + if (!this.random && index == 9 && (this.mode != 'number' || (this.mode == 'number' && this.dotEnabled))) return true; + else return false; + }; + }, + hoverClass() { + return index => { + if (!this.random && index == 9 && (this.mode == 'number' && this.dotEnabled || this.mode == 'card')) return 'u-hover-class'; + else return 'u-keyboard-hover'; + } + } + }, + methods: { + // 鐐瑰嚮閫�鏍奸敭 + backspaceClick() { + this.$emit('backspace'); + clearInterval(this.timer); //鍐嶆娓呯┖瀹氭椂鍣紝闃叉閲嶅娉ㄥ唽瀹氭椂鍣� + this.timer = null; + this.timer = setInterval(() => { + this.$emit('backspace'); + }, 250); + }, + clearTimer() { + clearInterval(this.timer); + this.timer = null; + }, + // 鑾峰彇閿洏鏄剧ず鐨勫唴瀹� + keyboardClick(val) { + // 鍏佽閿洏鏄剧ず鐐规ā寮忓拰瑙﹀彂闈炵偣鎸夐敭鏃讹紝灏嗗唴瀹硅浆涓烘暟瀛楃被鍨� + if (this.dotEnabled && val != this.dot && val != this.cardX) val = Number(val); + this.$emit('change', val); + } + } + }; +</script> + +<style lang="scss" scoped> + @import "../../libs/css/style.components.scss"; + + .u-keyboard { + position: relative; + z-index: 1003; + } + + .u-keyboard-grids { + @include vue-flex; + flex-wrap: wrap; + } + + .u-keyboard-grids-item { + flex: 0 0 33.3333333333%; + text-align: center; + font-size: 50rpx; + color: #333; + @include vue-flex; + align-items: center; + justify-content: center; + height: 110rpx; + font-weight: 500; + } + + .u-bg-gray { + background-color: $u-border-color; + } + + .u-keyboard-back { + font-size: 36rpx; + } + + .u-keyboard-hover { + background-color: #e7e6eb; + } +</style> -- Gitblit v1.9.3