Commit 6622cf870822962299489bf6b780fc7576538cd5
1 parent
0f8401fc
电子站牌项目
1、完善bsth-slide轮播组件,可以轮播视频,轮播到视频时,等视频播完后,继续轮播
Showing
3 changed files
with
118 additions
and
11 deletions
front-end/h5/src/components/core/plugins/bsth-slide__editor.js
| @@ -27,6 +27,9 @@ export default { | @@ -27,6 +27,9 @@ export default { | ||
| 27 | current: 1 // 下标从1开始 | 27 | current: 1 // 下标从1开始 |
| 28 | } | 28 | } |
| 29 | }, | 29 | }, |
| 30 | + mounted () { | ||
| 31 | + this.current = this.elementProps.activeIndex + 1 | ||
| 32 | + }, | ||
| 30 | methods: { | 33 | methods: { |
| 31 | p_change (page) { // 分页条change事件处理器 | 34 | p_change (page) { // 分页条change事件处理器 |
| 32 | this.current = page | 35 | this.current = page |
front-end/h5/src/components/core/plugins/bsth/bsth-slide.css
0 → 100644
front-end/h5/src/components/core/plugins/bsth/bsth-slide.js
| @@ -6,11 +6,13 @@ import PropTypes from '@luban-h5/plugin-common-props' | @@ -6,11 +6,13 @@ import PropTypes from '@luban-h5/plugin-common-props' | ||
| 6 | import { Swipe, SwipeItem } from 'vant' | 6 | import { Swipe, SwipeItem } from 'vant' |
| 7 | import 'vant/lib/swipe/style' | 7 | import 'vant/lib/swipe/style' |
| 8 | import 'vant/lib/swipe-item/style' | 8 | import 'vant/lib/swipe-item/style' |
| 9 | -import { VideoPlayer } from 'vue-video-player' | 9 | +import { videoPlayer } from 'vue-video-player' |
| 10 | import 'video.js/dist/video-js.css' | 10 | import 'video.js/dist/video-js.css' |
| 11 | 11 | ||
| 12 | import { GalleryValue, GalleryValueType } from 'core/support/resource-gallery/components/galleryValue' | 12 | import { GalleryValue, GalleryValueType } from 'core/support/resource-gallery/components/galleryValue' |
| 13 | 13 | ||
| 14 | +import './bsth-slide.css' | ||
| 15 | + | ||
| 14 | function getDefaultItems () { | 16 | function getDefaultItems () { |
| 15 | const defaultItems = [ // TODO:目前鲁班的后端渲染引擎处理不了组件属性的自定义类型,所以自定义转换成普通对象 | 17 | const defaultItems = [ // TODO:目前鲁班的后端渲染引擎处理不了组件属性的自定义类型,所以自定义转换成普通对象 |
| 16 | new GalleryValue({ type: GalleryValueType.IMAGE, url: 'https://img.yzcdn.cn/vant/apple-1.jpg' }).toObject(), | 18 | new GalleryValue({ type: GalleryValueType.IMAGE, url: 'https://img.yzcdn.cn/vant/apple-1.jpg' }).toObject(), |
| @@ -30,7 +32,13 @@ export default { | @@ -30,7 +32,13 @@ export default { | ||
| 30 | }, | 32 | }, |
| 31 | name: 'bsth-slide', | 33 | name: 'bsth-slide', |
| 32 | data () { | 34 | data () { |
| 33 | - return {} | 35 | + // eslint-disable-next-line |
| 36 | + this.private_jQuery = jQuery.noConflict() // jquery引用 | ||
| 37 | + return { | ||
| 38 | + innerInterval: 0, // 初始化值为 this.interval | ||
| 39 | + videoWidth: 0, // 视频 SwipItem 宽度 | ||
| 40 | + videoHeight: 0 // 视频 SwipItem 高度 | ||
| 41 | + } | ||
| 34 | }, | 42 | }, |
| 35 | props: { | 43 | props: { |
| 36 | editorMode: PropTypes.string({ // 编辑模式会由编辑器自动注入(值:edit, preview) | 44 | editorMode: PropTypes.string({ // 编辑模式会由编辑器自动注入(值:edit, preview) |
| @@ -59,25 +67,116 @@ export default { | @@ -59,25 +67,116 @@ export default { | ||
| 59 | render () { | 67 | render () { |
| 60 | const { items, activeIndex } = this | 68 | const { items, activeIndex } = this |
| 61 | if (this.editorMode === 'edit') { // 如果是编辑状态显示item中的activeIndex下标项 | 69 | if (this.editorMode === 'edit') { // 如果是编辑状态显示item中的activeIndex下标项 |
| 62 | - if (items.length > 0) { | ||
| 63 | - return (<div><p>{items[activeIndex].url}</p></div>) | ||
| 64 | - } else { | ||
| 65 | - return (<div><p>无轮播项目</p></div>) | ||
| 66 | - } | 70 | + return this.renderSwipeItemWithEdit(items[activeIndex]) |
| 67 | } else { | 71 | } else { |
| 68 | return ( | 72 | return ( |
| 69 | - <Swipe autoplay={+this.interval} indicator-color="red"> | 73 | + <Swipe onChange={this.swipeChange} autoplay={+this.innerInterval} indicator-color="red"> |
| 70 | { | 74 | { |
| 71 | items.map(item => ( | 75 | items.map(item => ( |
| 72 | - <SwipeItem><p>{item.url}</p></SwipeItem> | 76 | + this.renderSwipeItemWithPreview(item) |
| 73 | )) | 77 | )) |
| 74 | } | 78 | } |
| 75 | </Swipe> | 79 | </Swipe> |
| 76 | ) | 80 | ) |
| 77 | } | 81 | } |
| 78 | }, | 82 | }, |
| 79 | - mounted () {}, | 83 | + mounted () { |
| 84 | + this.innerInterval = this.interval | ||
| 85 | + | ||
| 86 | + // 使用外部元素的框架定义视频的长宽 | ||
| 87 | + let $jQuery = this.private_jQuery | ||
| 88 | + this.videoWidth = $jQuery(this.$el).width() | ||
| 89 | + this.videoHeight = $jQuery(this.$el).height() | ||
| 90 | + }, | ||
| 80 | destroyed () {}, | 91 | destroyed () {}, |
| 81 | watch: {}, | 92 | watch: {}, |
| 82 | - methods: {} | 93 | + methods: { |
| 94 | + swipeChange (index) { | ||
| 95 | + const gItem = GalleryValue.toGalleryValue(this.items[index]) | ||
| 96 | + if (gItem.type === GalleryValueType.VIDEO) { | ||
| 97 | + this.innerInterval = null | ||
| 98 | + let myVideo = this.$refs[gItem.url].player | ||
| 99 | + myVideo.play() | ||
| 100 | + } | ||
| 101 | + }, | ||
| 102 | + onPlayEnded () { | ||
| 103 | + this.innerInterval = this.interval | ||
| 104 | + }, | ||
| 105 | + renderSwipeItemWithEdit (item) { | ||
| 106 | + const gItem = GalleryValue.toGalleryValue(item) | ||
| 107 | + switch (gItem.type) { | ||
| 108 | + case GalleryValueType.IMAGE : | ||
| 109 | + return (<div><img src={gItem.url} width="100%" height="100%" /></div>) | ||
| 110 | + case GalleryValueType.VIDEO : | ||
| 111 | + return (<div><h1>预览模式查看</h1></div>) | ||
| 112 | + default : | ||
| 113 | + return (<div><p>无轮播项目</p></div>) | ||
| 114 | + } | ||
| 115 | + }, | ||
| 116 | + renderSwipeItemWithPreview (item) { | ||
| 117 | + const gItem = GalleryValue.toGalleryValue(item) | ||
| 118 | + const swipeItemWithout = ( | ||
| 119 | + <SwipeItem>未知</SwipeItem> | ||
| 120 | + ) | ||
| 121 | + const swipeItemWithImage = ( | ||
| 122 | + <SwipeItem><img src={gItem.url} width="100%" height="100%" /></SwipeItem> | ||
| 123 | + ) | ||
| 124 | + const playerOptions = { | ||
| 125 | + // 播放速度 | ||
| 126 | + playbackRates: [0.5, 1.0, 1.5, 2.0], | ||
| 127 | + // 如果true,浏览器准备好时开始回放。 | ||
| 128 | + autoplay: true, | ||
| 129 | + // 默认情况下将会消除任何音频(设置为true,才能游览器自动播放,否则报错)。 | ||
| 130 | + muted: true, | ||
| 131 | + // 导致视频一结束就重新开始。 | ||
| 132 | + loop: false, | ||
| 133 | + // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持) | ||
| 134 | + preload: 'auto', | ||
| 135 | + language: 'zh-CN', | ||
| 136 | + // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3") | ||
| 137 | + // aspectRatio: '4:3', | ||
| 138 | + // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。 | ||
| 139 | + // fluid: true, | ||
| 140 | + width: this.videoWidth, | ||
| 141 | + height: this.videoHeight, | ||
| 142 | + sources: [{ | ||
| 143 | + // 类型 | ||
| 144 | + type: 'video/mp4', | ||
| 145 | + // url地址 | ||
| 146 | + src: gItem.url | ||
| 147 | + }], | ||
| 148 | + // 你的封面地址 | ||
| 149 | + poster: '', | ||
| 150 | + // 允许覆盖Video.js无法播放媒体源时显示的默认信息。 | ||
| 151 | + notSupportedMessage: '此视频暂无法播放,请稍后再试', | ||
| 152 | + controlBar: { | ||
| 153 | + timeDivider: true, | ||
| 154 | + durationDisplay: true, | ||
| 155 | + remainingTimeDisplay: false, | ||
| 156 | + // 全屏按钮 | ||
| 157 | + fullscreenToggle: true | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + const swipeItemWithVideoRef = item.url | ||
| 161 | + const swipeItemWithVideo = ( | ||
| 162 | + <SwipeItem> | ||
| 163 | + <videoPlayer | ||
| 164 | + ref={swipeItemWithVideoRef} | ||
| 165 | + class="video-player vjs-custom-skin myVideoPlayer" | ||
| 166 | + playsinline={true} | ||
| 167 | + options={playerOptions} | ||
| 168 | + onEnded={this.onPlayEnded} | ||
| 169 | + /> | ||
| 170 | + </SwipeItem> | ||
| 171 | + ) | ||
| 172 | + switch (gItem.type) { | ||
| 173 | + case GalleryValueType.IMAGE : | ||
| 174 | + return swipeItemWithImage | ||
| 175 | + case GalleryValueType.VIDEO : | ||
| 176 | + return swipeItemWithVideo | ||
| 177 | + default : | ||
| 178 | + return swipeItemWithout | ||
| 179 | + } | ||
| 180 | + } | ||
| 181 | + } | ||
| 83 | } | 182 | } |