Parcourir la source

新增中奖轮播组件

hwb0 il y a 3 ans
Parent
commit
a7e713547a
3 fichiers modifiés avec 234 ajouts et 4 suppressions
  1. 201 0
      components/prize-news/prize-news.vue
  2. 32 2
      pages/index/index.vue
  3. 1 2
      pages/user/index.vue

+ 201 - 0
components/prize-news/prize-news.vue

@@ -0,0 +1,201 @@
+<!-- 横向滚动播放 -->
+<template>
+	<view class='text-scroll-wrap'>
+		<view class="text-content" :style="{ left:leftMove+'px' }">
+			<view class="text-item" v-for="(item,index) in myList" :key="index">
+				<view class="text">
+					<image :src="item.url" class="image"></image>
+					<view class="title">
+						<view class="name">{{ item.text }}</view>
+						<view class="prize">刮出</view>
+						<view class="prize">{{ item.text }}</view>
+					</view>
+				</view>
+			</view>
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		name: 'prize-news',
+		components: {},
+		props: {
+			list: { // 滚动列表
+				type: Array,
+				default: () => {
+					return [];
+				}
+			},
+			type: { // 类型
+				type: String,
+				default: 'text',
+				validator: (value) => {
+					return ['text', 'image'].indexOf(value) !== -1;
+				}
+			},
+			textKey: { // 文字key值
+				type: String,
+				default: ''
+			},
+			imageKey: { // 图片key值
+				type: String,
+				default: ''
+			},
+			actives: { // 如果需要,此为已选列表
+				type: Array,
+				default: () => {
+					return [];
+				}
+			},
+			duration: { // 间隔时间
+				type: [Number, String],
+				default: 20
+			},
+			delay: { // 延迟时间
+				type: [Number, String],
+				default: 0
+			},
+			initPosition: { // 初始位置
+				type: String,
+				default: 'left',
+				validator: (value) => {
+					return ['left', 'right'].indexOf(value) !== -1;
+				}
+			}
+		},
+		data() {
+			return {
+				myList: [],
+				leftMove: 0,
+				firstItemWidth: 0,
+				wrapWidth: 0,
+			};
+		},
+		// 组件实例化之前
+		beforeCreate() {},
+		// 组件创建完成
+		created() {
+			this.myList = this.list;
+		},
+		// 组件挂载之前
+		beforeMount() {},
+		// 组件挂载之后
+		mounted() {
+			let query = uni.createSelectorQuery().in(this);
+			query.select('.text-item').boundingClientRect(data => {
+				this.firstItemWidth = data.width;
+			}).exec();
+			query.select('.text-scroll-wrap').boundingClientRect(data => {
+				this.wrapWidth = data.width;
+				this.initPosition === 'left' ? this.leftMove = 0 : this.leftMove = this.wrapWidth;
+			}).exec();
+			if (this.delay <= 0) {
+				this.scrollContent();
+			} else {
+				let t = setTimeout(() => {
+					clearTimeout(t);
+					this.scrollContent();
+				}, Number(this.delay));
+			}
+
+		},
+		// 组件数据更新时
+		beforeUpdate() {},
+		// 组价更新
+		updated() {},
+		// 组件销毁前
+		beforeDestroy() {},
+		// 组件销毁后
+		destroyed() {},
+		// 页面方法
+		methods: {
+			// 点击此项
+			clickThis(e) {
+				// console.log(e.currentTarget.dataset.text);
+				this.$emit('change', e.currentTarget.dataset.text);
+			},
+			// 滚动
+			scrollContent() {
+				let num = this.initPosition === 'left' ? 0 : this.wrapWidth;
+				setInterval(() => {
+					num--;
+					if (num < 0 && Math.abs(num) >= this.firstItemWidth) {
+						this.myList.push(this.myList[0]);
+						this.myList.splice(0, 1);
+						num += this.firstItemWidth;
+						let query = uni.createSelectorQuery().in(this);
+						query.selectAll('.text-item').boundingClientRect(data => {
+							this.firstItemWidth = data[1].width;
+						}).exec();
+					}
+					this.leftMove = num;
+				}, Number(this.duration));
+			}
+		}
+	};
+</script>
+
+<style lang='scss'>
+	.text-scroll-wrap {
+		overflow: hidden;
+		width: 100%;
+		height: 50rpx;
+		line-height: 50rpx;
+		margin-bottom: 12rpx;
+		position: relative;
+
+		.text-content {
+			display: inline-block;
+			white-space: nowrap;
+			height: 100%;
+			position: absolute;
+			top: 0;
+
+			.text-item {
+				height: 100%;
+				display: inline-block;
+				overflow: hidden;
+				font-size: 28rpx;
+				color: #666;
+
+				.text {
+					display: flex;
+					align-items: center;
+					height: 50rpx;
+					padding: 0 40rpx 0 0;
+					margin: 0 80rpx;
+					background: rgba(255, 255, 255, .5);
+					border-radius: 20rpx;
+					font-size: 24rpx;
+
+					.image {
+						display: inline-block;
+						width: 50rpx;
+						height: 50rpx;
+						vertical-align: middle;
+						border-radius: 50%;
+					}
+					
+					.title {
+						display: flex;
+						align-items: center;
+						
+						.name{
+							margin: 0 16rpx;
+						}
+						
+						.prize{
+							color: #F27120;
+						}
+					}
+				}
+
+				&.active .text {
+					background: #1E90FF;
+					color: #fff;
+				}
+			}
+		}
+	}
+</style>

+ 32 - 2
pages/index/index.vue

@@ -20,6 +20,10 @@
 						<text>所有盲票</text>
 					</view>
 				</view>
+				<view class="box-top-news">
+					<prize-news :list="list" duration="35" />
+					<prize-news :list="list" duration="15" />
+				</view>
 			</view>
 			<view class="box-ticket">
 				<swiper class="image-container" circular :vertical="true" :current="currentIndex" :autoplay="false"
@@ -72,11 +76,13 @@
 	import CustomTabBar from '../../components/custom-tab-bar/custom-tab-bar.vue'
 	import Carousel from '../../components/vear-carousel/vear-carousel'
 	import PayPopup from '../../components/pay-popup/pay-popup.vue'
+	import PrizeNews from '../../components/prize-news/prize-news.vue'
 	export default {
 		components: {
 			CustomTabBar,
 			Carousel,
-			PayPopup
+			PayPopup,
+			PrizeNews
 		},
 		data() {
 			return {
@@ -93,7 +99,20 @@
 				currentPrizeIndex: 2,
 
 				payInfo: {},
-				prizeList: []
+				prizeList: [],
+				list: [{
+					url: 'https://mp-public-test-1307117429.cos.ap-shanghai.myqcloud.com/EJSFMIQFND7IYJO3T37Q.png',
+					text: '测试'
+				}, {
+					url: 'https://mp-public-test-1307117429.cos.ap-shanghai.myqcloud.com/EJSFMIQFND7IYJO3T37Q.png',
+					text: '测试'
+				}, {
+					url: 'https://mp-public-test-1307117429.cos.ap-shanghai.myqcloud.com/EJSFMIQFND7IYJO3T37Q.png',
+					text: '测试'
+				}, {
+					url: 'https://mp-public-test-1307117429.cos.ap-shanghai.myqcloud.com/EJSFMIQFND7IYJO3T37Q.png',
+					text: '测试'
+				}],
 			};
 		},
 		onLoad(opthios) {
@@ -346,11 +365,13 @@
 		background: url(https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/index_bg.jpeg) center center;
 
 		&-top {
+			position: relative;
 			display: flex;
 			justify-content: space-between;
 			padding: 130rpx 0 0 40rpx;
 
 			&-action {
+				z-index: 20;
 				display: flex;
 
 				&-item {
@@ -378,6 +399,7 @@
 			}
 
 			&-tip {
+				z-index: 20;
 				display: flex;
 				flex-direction: column;
 				align-items: flex-end;
@@ -396,6 +418,14 @@
 					background-color: #FFFFCC;
 				}
 			}
+			
+			&-news {
+				position: absolute;
+				left: 0;
+				bottom: 0;
+				z-index: 10;
+				width: 100vw;
+			}
 		}
 
 		&-ticket {

+ 1 - 2
pages/user/index.vue

@@ -54,7 +54,6 @@
 		<view class="cancel">
 			<u-cell icon="close-circle" title="退出登录" :isLink="true" :border="false" @click="logout"></u-cell>
 		</view>
-
 		<custom-tab-bar :activeValue="'user'" />
 	</view>
 </template>
@@ -67,7 +66,7 @@
 	export default {
 		components: {
 			CustomTabBar,
-			Auth
+			Auth,
 		},
 		data() {
 			return {