| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- // components/media-carousel/media-carousel.js
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- // 媒体列表
- mediaList: {
- type: Array,
- value: [],
- observer: function(newVal) {
- this.setData({
- totalCount: newVal.length
- });
- }
- },
- // 是否显示指示器
- showIndicator: {
- type: Boolean,
- value: true
- },
- // 指示器颜色
- indicatorColor: {
- type: String,
- value: 'rgba(255, 255, 255, 0.6)'
- },
- // 指示器激活颜色
- indicatorActiveColor: {
- type: String,
- value: '#fff'
- },
- // 是否自动播放
- autoplay: {
- type: Boolean,
- value: true
- },
- // 自动播放间隔时间
- interval: {
- type: Number,
- value: 3000
- },
- // 滑动动画时长
- duration: {
- type: Number,
- value: 500
- },
- // 是否循环播放
- circular: {
- type: Boolean,
- value: true
- },
- },
- /**
- * 组件的初始数据
- */
- data: {
- currentIndex: 0,
- totalCount: 0
- },
- /**
- * 组件的方法列表
- */
- methods: {
- // 轮播切换事件
- onChange(e) {
- const { current } = e.detail;
- this.setData({
- currentIndex: current
- });
-
- // 触发自定义事件
- this.triggerEvent('change', {
- current: current,
- total: this.data.totalCount
- });
- },
- // 图片加载成功
- onImageLoad(e) {
- const { index } = e.currentTarget.dataset;
- this.triggerEvent('imageload', {
- index: index,
- item: this.data.mediaList[index]
- });
- },
- // 图片加载失败
- onImageError(e) {
- const { index } = e.currentTarget.dataset;
- this.triggerEvent('imageerror', {
- index: index,
- item: this.data.mediaList[index]
- });
- },
- // 视频开始播放
- onVideoPlay(e) {
- const { index } = e.currentTarget.dataset;
- this.triggerEvent('videoplay', {
- index: index,
- item: this.data.mediaList[index]
- });
- },
- // 视频暂停
- onVideoPause(e) {
- const { index } = e.currentTarget.dataset;
- this.triggerEvent('videopause', {
- index: index,
- item: this.data.mediaList[index]
- });
- },
- // 视频播放结束
- onVideoEnded(e) {
- const { index } = e.currentTarget.dataset;
- this.triggerEvent('videoended', {
- index: index,
- item: this.data.mediaList[index]
- });
- },
- // 视频播放错误
- onVideoError(e) {
- const { index } = e.currentTarget.dataset;
- this.triggerEvent('videoerror', {
- index: index,
- item: this.data.mediaList[index]
- });
- }
- }
- });
|