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-row-notice/u-row-notice.vue | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 269 insertions(+), 0 deletions(-) diff --git a/uview-ui/components/u-row-notice/u-row-notice.vue b/uview-ui/components/u-row-notice/u-row-notice.vue new file mode 100644 index 0000000..f4683f1 --- /dev/null +++ b/uview-ui/components/u-row-notice/u-row-notice.vue @@ -0,0 +1,269 @@ +<template> + <view + v-if="show" + class="u-notice-bar" + :style="{ + background: computeBgColor, + padding: padding + }" + :class="[ + type ? `u-type-${type}-light-bg` : '' + ]" + > + <view class="u-direction-row"> + <view class="u-icon-wrap"> + <u-icon class="u-left-icon" v-if="volumeIcon" name="volume-fill" :size="volumeSize" :color="computeColor"></u-icon> + </view> + <view class="u-notice-box" id="u-notice-box"> + <view + class="u-notice-content" + id="u-notice-content" + :style="{ + animationDuration: animationDuration, + animationPlayState: animationPlayState, + }" + > + <text class="u-notice-text" @tap="click" :style="[textStyle]" + :class="['u-type-' + type]">{{showText}}</text> + </view> + </view> + <view class="u-icon-wrap"> + <u-icon @click="getMore" class="u-right-icon" v-if="moreIcon" name="arrow-right" :size="26" :color="computeColor"></u-icon> + <u-icon @click="close" class="u-right-icon" v-if="closeIcon" name="close" :size="24" :color="computeColor"></u-icon> + </view> + </view> + </view> +</template> +<script> +export default { + props: { + // 鏄剧ず鐨勫唴瀹癸紝鏁扮粍 + list: { + type: Array, + default() { + return []; + } + }, + // 鏄剧ず鐨勪富棰橈紝success|error|primary|info|warning|none + // none涓婚榛樿涓洪�忔槑鑳屾櫙锛岄粦鑹�(contentColor)瀛椾綋 + type: { + type: String, + default: 'warning' + }, + // 鏄惁鏄剧ず宸︿晶鐨勯煶閲忓浘鏍� + volumeIcon: { + type: Boolean, + default: true + }, + // 鏄惁鏄剧ず鍙充晶鐨勫彸绠ご鍥炬爣 + moreIcon: { + type: Boolean, + default: false + }, + // 鏄惁鏄剧ず鍙充晶鐨勫叧闂浘鏍� + closeIcon: { + type: Boolean, + default: false + }, + // 鏄惁鑷姩鎾斁 + autoplay: { + type: Boolean, + default: true + }, + // 鏂囧瓧棰滆壊锛屽悇鍥炬爣涔熶細浣跨敤鏂囧瓧棰滆壊 + color: { + type: String, + default: '' + }, + // 鑳屾櫙棰滆壊 + bgColor: { + type: String, + default: '' + }, + // 鏄惁鏄剧ず + show: { + type: Boolean, + default: true + }, + // 瀛椾綋澶у皬锛屽崟浣峳px + fontSize: { + type: [Number, String], + default: 26 + }, + // 闊抽噺鍠囧彮鐨勫ぇ灏� + volumeSize: { + type: [Number, String], + default: 34 + }, + // 姘村钩婊氬姩鏃剁殑婊氬姩閫熷害锛屽嵆姣忕婊氬姩澶氬皯rpx锛岃繖鏈夊埄浜庢帶鍒舵枃瀛楁棤璁哄灏戞椂锛岄兘鑳芥湁涓�涓亽瀹氱殑閫熷害 + speed: { + type: [Number, String], + default: 160 + }, + // 鎾斁鐘舵�侊紝play-鎾斁锛宲aused-鏆傚仠 + playState: { + type: String, + default: 'play' + }, + // 閫氱煡鐨勮竟璺� + padding: { + type: [Number, String], + default: '18rpx 24rpx' + } + }, + data() { + return { + textWidth: 0, // 婊氬姩鐨勬枃瀛楀搴� + boxWidth: 0, // 渚涙枃瀛楁粴鍔ㄧ殑鐖剁洅瀛愮殑瀹藉害锛屽拰鍓嶈�呬竴璧蜂负浜嗚绠楁粴鍔ㄩ�熷害 + animationDuration: '10s', // 鍔ㄧ敾鎵ц鏃堕棿 + animationPlayState: 'paused', // 鍔ㄧ敾鐨勫紑濮嬪拰缁撴潫鎵ц + showText: '' // 鏄剧ず鐨勬枃鏈� + }; + }, + watch: { + list: { + immediate: true, + handler(val) { + this.showText = val.join('锛�'); + this.$nextTick(() => { + this.initSize(); + }); + } + }, + playState(val) { + if(val == 'play') this.animationPlayState = 'running'; + else this.animationPlayState = 'paused'; + }, + speed(val) { + this.initSize(); + } + }, + computed: { + // 璁$畻瀛椾綋棰滆壊锛屽鏋滄病鏈夎嚜瀹氫箟鐨勶紝灏辩敤uview涓婚棰滆壊 + computeColor() { + if (this.color) return this.color; + // 濡傛灉鏄棤涓婚锛屽氨榛樿浣跨敤content-color + else if(this.type == 'none') return '#606266'; + else return this.type; + }, + // 鏂囧瓧鍐呭鐨勬牱寮� + textStyle() { + let style = {}; + if (this.color) style.color = this.color; + else if(this.type == 'none') style.color = '#606266'; + style.fontSize = this.fontSize + 'rpx'; + return style; + }, + // 璁$畻鑳屾櫙棰滆壊 + computeBgColor() { + if (this.bgColor) return this.bgColor; + else if(this.type == 'none') return 'transparent'; + } + }, + mounted() { + this.$nextTick(() => { + this.initSize(); + }); + }, + methods: { + initSize() { + let query = [], + boxWidth = 0, + textWidth = 0; + let textQuery = new Promise((resolve, reject) => { + uni.createSelectorQuery() + .in(this) + .select(`#u-notice-content`) + .boundingClientRect() + .exec(ret => { + this.textWidth = ret[0].width; + resolve(); + }); + }); + query.push(textQuery); + Promise.all(query).then(() => { + // 鏍规嵁t=s/v(鏃堕棿=璺▼/閫熷害)锛岃繖閲屼负浣曚笉闇�瑕佸姞涓�#u-notice-box鐨勫搴︼紝鍥犱负涓缃簡.u-notice-content鏍峰紡涓缃簡padding-left: 100% + // 鎭板阀璁$畻鍑烘潵鐨勭粨鏋滀腑宸茬粡鍖呭惈浜�#u-notice-box鐨勫搴� + this.animationDuration = `${this.textWidth / uni.upx2px(this.speed)}s`; + // 杩欓噷蹇呴』杩欐牱寮�濮嬪姩鐢伙紝鍚﹀垯鍦ˋPP涓婂姩鐢婚�熷害涓嶄細鏀瑰彉(HX鐗堟湰2.4.6锛孖OS13) + this.animationPlayState = 'paused'; + setTimeout(() => { + if(this.playState == 'play' && this.autoplay) this.animationPlayState = 'running'; + }, 10); + }); + }, + // 鐐瑰嚮閫氬憡鏍� + click(index) { + this.$emit('click'); + }, + // 鐐瑰嚮鍏抽棴鎸夐挳 + close() { + this.$emit('close'); + }, + // 鐐瑰嚮鏇村绠ご鎸夐挳 + getMore() { + this.$emit('getMore'); + } + } +}; +</script> + +<style lang="scss" scoped> +@import "../../libs/css/style.components.scss"; + +.u-notice-bar { + padding: 18rpx 24rpx; + overflow: hidden; +} + +.u-direction-row { + @include vue-flex; + align-items: center; + justify-content: space-between; +} + +.u-left-icon { + /* #ifndef APP-NVUE */ + display: inline-flex; + /* #endif */ + align-items: center; +} + +.u-notice-box { + flex: 1; + @include vue-flex; + overflow: hidden; + margin-left: 12rpx; +} + +.u-right-icon { + margin-left: 12rpx; + display: inline-flex; + align-items: center; +} + +.u-notice-content { + animation: u-loop-animation 10s linear infinite both; + text-align: right; + // 杩欎竴鍙ュ緢閲嶈锛屼负浜嗚兘璁╂粴鍔ㄥ乏鍙宠繛鎺ヨ捣鏉� + padding-left: 100%; + @include vue-flex; + flex-wrap: nowrap; +} + +.u-notice-text { + font-size: 26rpx; + word-break: keep-all; + white-space: nowrap +} + +@keyframes u-loop-animation { + 0% { + transform: translate3d(0, 0, 0); + } + + 100% { + transform: translate3d(-100%, 0, 0); + } +} +</style> -- Gitblit v1.9.3