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-message-input/u-message-input.vue | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 311 insertions(+), 0 deletions(-)
diff --git a/uview-ui/components/u-message-input/u-message-input.vue b/uview-ui/components/u-message-input/u-message-input.vue
new file mode 100644
index 0000000..f64bb19
--- /dev/null
+++ b/uview-ui/components/u-message-input/u-message-input.vue
@@ -0,0 +1,311 @@
+<template>
+ <view class="u-char-box">
+ <view class="u-char-flex">
+ <input :disabled="disabledKeyboard" :value="valueModel" type="number" :focus="focus" :maxlength="maxlength" class="u-input" @input="getVal"/>
+ <view v-for="(item, index) in loopCharArr" :key="index">
+ <view :class="[breathe && charArrLength == index ? 'u-breathe' : '', 'u-char-item',
+ charArrLength === index && mode == 'box' ? 'u-box-active' : '',
+ mode === 'box' ? 'u-box' : '']" :style="{
+ fontWeight: bold ? 'bold' : 'normal',
+ fontSize: fontSize + 'rpx',
+ width: width + 'rpx',
+ height: width + 'rpx',
+ color: inactiveColor,
+ borderColor: charArrLength === index && mode == 'box' ? activeColor : inactiveColor
+ }">
+ <view class="u-placeholder-line" :style="{
+ display: charArrLength === index ? 'block' : 'none',
+ height: width * 0.5 +'rpx'
+ }"
+ v-if="mode !== 'middleLine'"
+ ></view>
+ <view v-if="mode === 'middleLine' && charArrLength <= index" :class="[breathe && charArrLength == index ? 'u-breathe' : '', charArrLength === index ? 'u-middle-line-active' : '']"
+ class="u-middle-line" :style="{height: bold ? '4px' : '2px', background: charArrLength === index ? activeColor : inactiveColor}"></view>
+ <view v-if="mode === 'bottomLine'" :class="[breathe && charArrLength == index ? 'u-breathe' : '', charArrLength === index ? 'u-buttom-line-active' : '']"
+ class="u-bottom-line" :style="{height: bold ? '4px' : '2px', background: charArrLength === index ? activeColor : inactiveColor}"></view>
+ <block v-if="!dotFill"> {{ charArr[index] ? charArr[index] : ''}}</block>
+ <block v-else>
+ <text class="u-dot">{{ charArr[index] ? '鈼�' : ''}}</text>
+ </block>
+ </view>
+ </view>
+ </view>
+ </view>
+</template>
+
+<script>
+ /**
+ * messageInput 楠岃瘉鐮佽緭鍏ユ
+ * @description 璇ョ粍浠朵竴鑸敤浜庨獙璇佺敤鎴风煭淇¢獙璇佺爜鐨勫満鏅紝涔熷彲浠ョ粨鍚坲View鐨勯敭鐩樼粍浠朵娇鐢�
+ * @tutorial https://www.uviewui.com/components/messageInput.html
+ * @property {String Number} maxlength 杈撳叆瀛楃涓暟锛堥粯璁�4锛�
+ * @property {Boolean} dot-fill 鏄惁鐢ㄥ渾鐐瑰~鍏咃紙榛樿false锛�
+ * @property {String} mode 妯″紡閫夋嫨锛岃涓婃柟"鍩烘湰浣跨敤"璇存槑锛堥粯璁ox锛�
+ * @property {String Number} value 棰勭疆鍊�
+ * @property {Boolean} breathe 鏄惁寮�鍚懠鍚告晥鏋滐紝瑙佷笂鏂硅鏄庯紙榛樿true锛�
+ * @property {Boolean} focus 鏄惁鑷姩鑾峰彇鐒︾偣锛堥粯璁alse锛�
+ * @property {Boolean} bold 瀛椾綋鍜岃緭鍏ユí绾挎槸鍚﹀姞绮楋紙榛樿true锛�
+ * @property {String Number} font-size 瀛椾綋澶у皬锛屽崟浣峳px锛堥粯璁�60锛�
+ * @property {String} active-color 褰撳墠婵�娲昏緭鍏ユ鐨勬牱寮忥紙榛樿#497bff锛�
+ * @property {String} inactive-color 闈炴縺娲昏緭鍏ユ鐨勬牱寮忥紝鏂囧瓧棰滆壊鍚屾鍊硷紙榛樿#606266锛�
+ * @property {String | Number} width 杈撳叆妗嗗搴︼紝鍗曚綅rpx锛岄珮绛変簬瀹斤紙榛樿80锛�
+ * @property {Boolean} disabled-keyboard 绂佹鐐瑰嚮杈撳叆妗嗗敜璧风郴缁熼敭鐩橈紙榛樿false锛�
+ * @event {Function} change 杈撳叆鍐呭鍙戠敓鏀瑰彉鏃惰Е鍙戯紝鍏蜂綋瑙佸畼缃戣鏄�
+ * @event {Function} finish 杈撳叆瀛楃涓暟杈緈axlength鍊兼椂瑙﹀彂锛岃瀹樼綉璇存槑
+ * @example <u-message-input mode="bottomLine"></u-message-input>
+ */
+ export default {
+ name: "u-message-input",
+ props: {
+ // 鏈�澶ц緭鍏ラ暱搴�
+ maxlength: {
+ type: [Number, String],
+ default: 4
+ },
+ // 鏄惁鐢ㄥ渾鐐瑰~鍏�
+ dotFill: {
+ type: Boolean,
+ default: false
+ },
+ // 鏄剧ず妯″紡锛宐ox-鐩掑瓙妯″紡锛宐ottomLine-妯嚎鍦ㄥ簳閮ㄦā寮忥紝middleLine-妯嚎鍦ㄤ腑閮ㄦā寮�
+ mode: {
+ type: String,
+ default: "box"
+ },
+ // 棰勭疆鍊�
+ value: {
+ type: [String, Number],
+ default: ''
+ },
+ // 褰撳墠婵�娲昏緭鍏tem锛屾槸鍚﹀甫鏈夊懠鍚告晥鏋�
+ breathe: {
+ type: Boolean,
+ default: true
+ },
+ // 鏄惁鑷姩鑾峰彇鐒︾偣
+ focus: {
+ type: Boolean,
+ default: false
+ },
+ // 瀛椾綋鏄惁鍔犵矖
+ bold: {
+ type: Boolean,
+ default: false
+ },
+ // 瀛椾綋澶у皬
+ fontSize: {
+ type: [String, Number],
+ default: 60
+ },
+ // 婵�娲绘牱寮�
+ activeColor: {
+ type: String,
+ default: '#497bff'
+ },
+ // 鏈縺娲荤殑鏍峰紡
+ inactiveColor: {
+ type: String,
+ default: '#606266'
+ },
+ // 杈撳叆妗嗙殑澶у皬锛屽崟浣峳px锛屽绛変簬楂�
+ width: {
+ type: [Number, String],
+ default: '80'
+ },
+ // 鏄惁闅愯棌鍘熺敓閿洏锛屽鏋滄兂鐢ㄨ嚜瀹氫箟閿洏鐨勮瘽锛岄渶璁剧疆姝ゅ弬鏁颁负true
+ disabledKeyboard: {
+ type: Boolean,
+ default: false
+ }
+ },
+ watch: {
+ // maxlength: {
+ // // 姝ゅ�艰缃负true锛屼細鍦ㄧ粍浠跺姞杞藉悗鏃犻渶maxlength鍙樺寲灏变細鎵ц涓�娆℃湰鐩戝惉鍑芥暟锛屾棤闇�鍐峜reated鐢熷懡鍛ㄦ湡涓鐞�
+ // immediate: true,
+ // handler(val) {
+ // this.maxlength = Number(val);
+ // }
+ // },
+ value: {
+ immediate: true,
+ handler(val) {
+ // 杞负瀛楃涓�
+ val = String(val);
+ // 瓒呭嚭閮ㄥ垎鎴帀
+ this.valueModel = val.substring(0, this.maxlength);
+ }
+ },
+ },
+ data() {
+ return {
+ valueModel: ""
+ }
+ },
+ computed: {
+ // 鏄惁鏄剧ず鍛煎惛鐏晥鏋�
+ animationClass() {
+ return (index) => {
+ if (this.breathe && this.charArr.length == index) return 'u-breathe';
+ else return '';
+ }
+ },
+ // 鐢ㄤ簬鏄剧ず瀛楃
+ charArr() {
+ return this.valueModel.split('');
+ },
+ charArrLength() {
+ return this.charArr.length;
+ },
+ // 鏍规嵁闀垮害锛屽惊鐜緭鍏ユ鐨勪釜鏁帮紝鍥犱负澶存潯灏忕▼搴忔暟鍊间笉鑳界敤浜巚-for
+ loopCharArr() {
+ return new Array(this.maxlength);
+ }
+ },
+ methods: {
+ getVal(e) {
+ let {
+ value
+ } = e.detail
+ this.valueModel = value;
+ // 鍒ゆ柇闀垮害鏄惁瓒呭嚭浜唌axlength鍊硷紝鐞嗚涓婁笉浼氬彂鐢燂紝鍥犱负input缁勪欢璁剧疆浜唌axlength灞炴�у��
+ if (String(value).length > this.maxlength) return;
+ // 鏈揪鍒癿axlength涔嬪墠锛屽彂閫乧hange浜嬩欢锛岃揪鍒板悗鍙戦�乫inish浜嬩欢
+ this.$emit('change', value);
+ if (String(value).length == this.maxlength) {
+ this.$emit('finish', value);
+ }
+ }
+ }
+ }
+</script>
+
+<style scoped lang="scss">
+ @import "../../libs/css/style.components.scss";
+
+ @keyframes breathe {
+ 0% {
+ opacity: 0.3;
+ }
+
+ 50% {
+ opacity: 1;
+ }
+
+ 100% {
+ opacity: 0.3;
+ }
+ }
+
+ .u-char-box {
+ text-align: center;
+ }
+
+ .u-char-flex {
+ @include vue-flex;
+ justify-content: center;
+ flex-wrap: wrap;
+ position: relative;
+ }
+
+ .u-input {
+ position: absolute;
+ top: 0;
+ left: -100%;
+ width: 200%;
+ height: 100%;
+ text-align: left;
+ z-index: 9;
+ opacity: 0;
+ background: none;
+ }
+
+ .u-char-item {
+ position: relative;
+ width: 90rpx;
+ height: 90rpx;
+ margin: 10rpx 10rpx;
+ font-size: 60rpx;
+ font-weight: bold;
+ color: $u-main-color;
+ line-height: 90rpx;
+ @include vue-flex;
+ justify-content: center;
+ align-items: center;
+ }
+
+ .u-middle-line {
+ border: none;
+ }
+
+ .u-box {
+ box-sizing: border-box;
+ border: 2rpx solid #cccccc;
+ border-radius: 6rpx;
+ }
+
+ .u-box-active {
+ overflow: hidden;
+ animation-timing-function: ease-in-out;
+ animation-duration: 1500ms;
+ animation-iteration-count: infinite;
+ animation-direction: alternate;
+ border: 2rpx solid $u-type-primary;
+ }
+
+ .u-middle-line-active {
+ background: $u-type-primary;
+ }
+
+ .u-breathe {
+ animation: breathe 2s infinite ease;
+ }
+
+ .u-placeholder-line {
+ /* #ifndef APP-NVUE */
+ display: none;
+ /* #endif */
+ position: absolute;
+ left: 50%;
+ top: 50%;
+ transform: translate(-50%, -50%);
+ width: 2rpx;
+ height: 40rpx;
+ background: #333333;
+ animation: twinkling 1.5s infinite ease;
+ }
+
+ .u-animation-breathe {
+ animation-name: breathe;
+ }
+
+ .u-dot {
+ font-size: 34rpx;
+ line-height: 34rpx;
+ }
+
+ .u-middle-line {
+ height: 4px;
+ background: #000000;
+ width: 80%;
+ position: absolute;
+ border-radius: 2px;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ }
+
+ .u-buttom-line-active {
+ background: $u-type-primary;
+ }
+
+ .u-bottom-line {
+ height: 4px;
+ background: #000000;
+ width: 80%;
+ position: absolute;
+ border-radius: 2px;
+ bottom: 0;
+ left: 50%;
+ transform: translate(-50%);
+ }
+</style>
--
Gitblit v1.9.3