swiper.uvue 7.3 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7
<template>
	<!-- #ifdef APP -->
	<scroll-view style="flex: 1">
		<!-- #endif -->
		<view>
			<page-head title="swiper,可滑动视图"></page-head>
			<view class="uni-margin-wrap">
杜庆泉's avatar
杜庆泉 已提交
8 9
				<swiper class="swiper" :vertical="verticalSelect" :indicator-dots="dotsSelect" :autoplay="autoplaySelect"
          :rebound="reboundSelect"
DCloud-WZF's avatar
DCloud-WZF 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
					:interval="intervalSelect" :circular="circularSelect" :indicator-color="indicatorColor"
					:indicator-active-color="indicatorColorActive" :disable-touch="disableTouchSelect" :current="currentVal"
					:current-item-id="currentItemIdVal" @change="swiperChange" @transition="swiperTransition"
					@animationfinish="swiperAnimationfinish">
					<swiper-item item-id="A">
						<view class="swiper-item uni-bg-red"><text class="swiper-item-Text">A</text></view>
					</swiper-item>
					<swiper-item item-id="B">
						<view class="swiper-item uni-bg-green"><text class="swiper-item-Text">B</text></view>
					</swiper-item>
					<swiper-item item-id="C">
						<view class="swiper-item uni-bg-blue"><text class="swiper-item-Text">C</text></view>
					</swiper-item>
				</swiper>
			</view>
			<view class="uni-list">
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">是否显示面板指示点</view>
					<switch :checked="dotsSelect" @change="dotsChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">是否自动切换</view>
					<switch :checked="autoplaySelect" @change="autoplayChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">是否循环</view>
					<switch :checked="circularSelect" @change="circularChange" />
杜庆泉's avatar
杜庆泉 已提交
37 38 39 40 41
				</view>
        <view class="uni-list-cell uni-list-cell-pd">
        	<view class="uni-list-cell-db">是否显示rebound效果</view>
        	<switch :checked="reboundSelect" @change="reboundSelectChange" />
        </view>
W
wanganxp 已提交
42
				<view class="uni-title">间隔时间(毫秒)</view>
DCloud-WZF's avatar
DCloud-WZF 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
				<view>
					<slider @change="sliderChange" :value="1000" :min="500" :max="5000" :show-value="true" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">定制指示器颜色</view>
					<switch :checked="indicatorColorSelect" @change="indicatorColorChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">纵向</view>
					<switch :checked="verticalSelect" @change="verticalChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">指定current为最后一个元素</view>
					<switch :checked="currentSelect" @change="currentChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">指定current-item-id为最后一个元素</view>
					<switch :checked="currentItemIdSelect" @change="currentItemIdChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">禁止用户 touch 操作</view>
					<switch :checked="disableTouchSelect" @change="disableTouchChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">swiperTransition 是否打印</view>
					<switch :checked="swiperTransitionSelect" @change="swiperTransitionChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">swiperAnimationfinish 是否打印</view>
					<switch :checked="swiperAnimationfinishSelect" @change="swiperAnimationfinishChange" />
				</view>
				<view class="uni-list-cell uni-list-cell-pd">
					<view class="uni-list-cell-db">swiperChange 是否打印</view>
					<switch :checked="swiperChangeSelect" @change="swiperChangeChange" />
				</view>
			</view>
		</view>
		<!-- #ifdef APP -->
	</scroll-view>
	<!-- #endif -->
</template>
<script>
	export default {
		data() {
			return {
				background: ['color1', 'color2', 'color3'],
杜庆泉's avatar
杜庆泉 已提交
89 90
				dotsSelect: false,
        reboundSelect:false,
DCloud-WZF's avatar
DCloud-WZF 已提交
91 92 93 94 95 96
				autoplaySelect: false,
				circularSelect: false,
				indicatorColorSelect: false,
				verticalSelect: false,
				currentSelect: false,
				currentItemIdSelect: false,
杜庆泉's avatar
杜庆泉 已提交
97
				intervalSelect: 2000,
DCloud-WZF's avatar
DCloud-WZF 已提交
98 99 100 101 102 103 104
				indicatorColor: "",
				indicatorColorActive: "",
				currentVal: 0,
				currentItemIdVal: "",
				disableTouchSelect: false,
				swiperTransitionSelect: false,
				swiperAnimationfinishSelect: false,
杜庆泉's avatar
杜庆泉 已提交
105 106
				swiperChangeSelect: false,
        currentValChange:0
DCloud-WZF's avatar
DCloud-WZF 已提交
107
			}
杜庆泉's avatar
杜庆泉 已提交
108 109
		},
		methods: {
杜庆泉's avatar
杜庆泉 已提交
110

杜庆泉's avatar
杜庆泉 已提交
111 112
			swiperChange: function (e : SwiperChangeEvent) {
        this.currentValChange = e.detail.current
杜庆泉's avatar
杜庆泉 已提交
113
        console.log(this.currentValChange)
DCloud-WZF's avatar
DCloud-WZF 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
				if (this.swiperChangeSelect) {
					console.log("swiperChange")
					console.log(e)
				}
			},
			swiperTransition: function (e : SwiperTransitionEvent) {
				if (this.swiperTransitionSelect) {
					console.log("swiperTransition")
					console.log(e)
				}
			},
			swiperAnimationfinish: function (e : SwiperAnimationFinishEvent) {
				if (this.swiperAnimationfinishSelect) {
					console.log("swiperAnimationfinish")
					console.log(e)
				}
			},

			dotsChange: function (e : SwitchChangeEvent) {
				this.dotsSelect = e.detail.value
			},
			swiperTransitionChange: function (e : SwitchChangeEvent) {
				this.swiperTransitionSelect = e.detail.value
			},
			swiperChangeChange: function (e : SwitchChangeEvent) {
				this.swiperChangeSelect = e.detail.value
			},
			swiperAnimationfinishChange: function (e : SwitchChangeEvent) {
				this.swiperAnimationfinishSelect = e.detail.value
			},
			autoplayChange: function (e : SwitchChangeEvent) {
				this.autoplaySelect = e.detail.value
			},
			verticalChange: function (e : SwitchChangeEvent) {
				this.verticalSelect = e.detail.value
			},
			disableTouchChange: function (e : SwitchChangeEvent) {
				this.disableTouchSelect = e.detail.value
			},
			currentItemIdChange: function (e : SwitchChangeEvent) {
				this.currentItemIdSelect = e.detail.value
				if (this.currentItemIdSelect) {
					this.currentItemIdVal = 'C'
				} else {
					this.currentItemIdVal = 'A'
				}
			},
			currentChange: function (e : SwitchChangeEvent) {
				this.currentSelect = e.detail.value
				if (this.currentSelect) {
					this.currentVal = 2
				} else {
					this.currentVal = 0
				}

			},
			circularChange: function (e : SwitchChangeEvent) {
				this.circularSelect = e.detail.value
				console.log(this.circularSelect)
杜庆泉's avatar
杜庆泉 已提交
173 174 175 176 177
			},
      reboundSelectChange: function (e : SwitchChangeEvent) {
      	this.reboundSelect = e.detail.value
      	console.log(this.reboundSelect)
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
			sliderChange(e : SliderChangeEvent) {
				this.intervalSelect = e.detail.value
			},
			indicatorColorChange(e : SwitchChangeEvent) {
				this.indicatorColorSelect = e.detail.value
				if (this.indicatorColorSelect) {
					// 选择了定制指示器颜色
					this.indicatorColor = "#ff00ff"
					this.indicatorColorActive = "#0000ff"
				} else {
					// 没有选择颜色
					this.indicatorColor = ""
					this.indicatorColorActive = ""
				}
			}
		}
	}
</script>

<style>
	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;
	}

	.swiper {
		height: 300rpx;
	}

	.swiper-item {
		width: 100%;
		height: 300rpx;
	}

	.swiper-item-Text {
		width: 100%;
		text-align: center;
		line-height: 300rpx;
	}
杜庆泉's avatar
杜庆泉 已提交
217
</style>