|
@@ -64,22 +64,16 @@ import Tool, { ToolItem, ToolType } from './component/tool'
|
|
|
import Tools from './component/tools/pen'
|
|
|
import Pen from './component/tools/pen'
|
|
|
import iconPen from './image/icon-pen.png'
|
|
|
+import { useThrottle, useThrottleFn, useDebounceFn } from '@vueuse/core'
|
|
|
|
|
|
export default defineComponent({
|
|
|
name: 'CoursewarePlay',
|
|
|
setup() {
|
|
|
const pageVisibility = usePageVisibility()
|
|
|
- const isPlay = ref(false)
|
|
|
/** 页面显示和隐藏 */
|
|
|
- watch(pageVisibility, (value) => {
|
|
|
- const activeItem = data.itemList[popupData.activeIndex]
|
|
|
- if (activeItem.type != 'VIDEO') return
|
|
|
+ watch(() => pageVisibility.value, (value) => {
|
|
|
if (value == 'hidden') {
|
|
|
- isPlay.value = !activeItem.videoEle?.paused
|
|
|
- togglePlay(activeItem, false)
|
|
|
- } else {
|
|
|
- // 页面显示,并且
|
|
|
- if (isPlay.value) togglePlay(activeItem, true)
|
|
|
+ handleStop()
|
|
|
}
|
|
|
})
|
|
|
/** 设置播放容器 16:9 */
|
|
@@ -87,9 +81,9 @@ export default defineComponent({
|
|
|
width: '100vw'
|
|
|
})
|
|
|
const setContainer = () => {
|
|
|
- let min = Math.min(screen.width, screen.height)
|
|
|
- let max = Math.max(screen.width, screen.height)
|
|
|
- let width = min * (16 / 9)
|
|
|
+ const min = Math.min(screen.width, screen.height)
|
|
|
+ const max = Math.max(screen.width, screen.height)
|
|
|
+ const width = min * (16 / 9)
|
|
|
if (width > max) {
|
|
|
parentContainer.width = '100vw'
|
|
|
return
|
|
@@ -244,18 +238,22 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- console.log(list, 'list')
|
|
|
+ // console.log(list, 'list')
|
|
|
|
|
|
- let _firstIndex = list.findIndex((n: any) => n.knowledgePointMaterialRelationId == route.query.kId || n.materialId == route.query.kId)
|
|
|
+ let _firstIndex = list.findIndex(
|
|
|
+ (n: any) =>
|
|
|
+ n.knowledgePointMaterialRelationId == route.query.kId || n.materialId == route.query.kId
|
|
|
+ )
|
|
|
_firstIndex = _firstIndex > -1 ? _firstIndex : 0
|
|
|
const item = list[_firstIndex]
|
|
|
|
|
|
- console.log(_firstIndex, '_firstIndex', route.query.kId, 'route.query.kId', item)
|
|
|
+ // console.log(_firstIndex, '_firstIndex', route.query.kId, 'route.query.kId', item)
|
|
|
// 是否自动播放
|
|
|
if (activeData.isAutoPlay) {
|
|
|
item.autoPlay = true
|
|
|
}
|
|
|
popupData.activeIndex = _firstIndex
|
|
|
+ popupData.playIndex = _firstIndex
|
|
|
popupData.tabName = item.tabName
|
|
|
popupData.tabActive = item.knowledgePointId
|
|
|
popupData.itemActive = item.id
|
|
@@ -429,6 +427,7 @@ export default defineComponent({
|
|
|
const popupData = reactive({
|
|
|
open: false,
|
|
|
activeIndex: 0,
|
|
|
+ playIndex: 0,
|
|
|
tabActive: '',
|
|
|
tabName: '',
|
|
|
itemActive: '',
|
|
@@ -439,18 +438,16 @@ export default defineComponent({
|
|
|
|
|
|
/**停止所有的播放 */
|
|
|
const handleStop = () => {
|
|
|
- for (let i = 0; i < data.itemList.length; i++) {
|
|
|
- const activeItem = data.itemList[i]
|
|
|
- if (activeItem.type === 'VIDEO') {
|
|
|
- activeItem.videoEle?.pause()
|
|
|
- activeItem.videoEle?.stop()
|
|
|
- }
|
|
|
- // console.log('🚀 ~ activeItem:', activeItem)
|
|
|
- // 停止曲谱的播放
|
|
|
- if (activeItem.type === 'SONG') {
|
|
|
- activeItem.iframeRef?.contentWindow?.postMessage({ api: 'setPlayState' }, '*')
|
|
|
- }
|
|
|
+ const videos = document.querySelectorAll('video')
|
|
|
+ for (let i = 0; i < videos.length; i++) {
|
|
|
+ const videoEle = videos[i] as HTMLVideoElement
|
|
|
+ videoEle.pause();
|
|
|
}
|
|
|
+ data.itemList.forEach((item: any) => {
|
|
|
+ if (item.type === 'SONG') {
|
|
|
+ item.iframeRef?.contentWindow?.postMessage({ api: 'setPlayState' }, '*')
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
// 切换素材
|
|
|
const toggleMaterial = (itemActive: any) => {
|
|
@@ -465,7 +462,7 @@ export default defineComponent({
|
|
|
closeToast()
|
|
|
activeData.timer = setTimeout(() => {
|
|
|
activeData.model = false
|
|
|
- Object.values(data.videoRefs).map((n: any) => n.toggleHideControl(false))
|
|
|
+ Object.values(data.videoRefs).map((n: any) => n?.toggleHideControl(false))
|
|
|
}, 4000)
|
|
|
}
|
|
|
/** 立即收起所有的模态框 */
|
|
@@ -473,11 +470,11 @@ export default defineComponent({
|
|
|
clearTimeout(activeData.timer)
|
|
|
closeToast()
|
|
|
activeData.model = false
|
|
|
- Object.values(data.videoRefs).map((n: any) => n.toggleHideControl(false))
|
|
|
+ Object.values(data.videoRefs).map((n: any) => n?.toggleHideControl(false))
|
|
|
}
|
|
|
- const toggleModel = (type: boolean = true) => {
|
|
|
+ const toggleModel = (type = true) => {
|
|
|
activeData.model = type
|
|
|
- Object.values(data.videoRefs).map((n: any) => n.toggleHideControl(type))
|
|
|
+ Object.values(data.videoRefs).map((n: any) => n?.toggleHideControl(type))
|
|
|
}
|
|
|
|
|
|
// 去点名,签退
|
|
@@ -498,7 +495,7 @@ export default defineComponent({
|
|
|
if (item && item.type === 'VIDEO') {
|
|
|
const videoEle: HTMLVideoElement = item.videoEle
|
|
|
if (videoEle) {
|
|
|
- if (videoEle.paused) {
|
|
|
+ if (videoEle?.paused) {
|
|
|
closeToast()
|
|
|
videoEle.play()
|
|
|
} else {
|
|
@@ -585,40 +582,55 @@ export default defineComponent({
|
|
|
if (popupData.activeIndex == index) return
|
|
|
handleStop()
|
|
|
clearTimeout(acitveTimer.value)
|
|
|
- const oldIndex = popupData.activeIndex
|
|
|
checkedAnimation(popupData.activeIndex, index)
|
|
|
- popupData.activeIndex = index
|
|
|
-
|
|
|
- acitveTimer.value = setTimeout(
|
|
|
- () => {
|
|
|
- const item = data.itemList[index]
|
|
|
- if (item) {
|
|
|
- popupData.tabActive = item.knowledgePointId
|
|
|
- popupData.itemActive = item.id
|
|
|
- popupData.itemName = item.name
|
|
|
- popupData.tabName = item.tabName
|
|
|
- if (item.type == 'SONG') {
|
|
|
- activeData.model = true
|
|
|
- }
|
|
|
- if (item.type === 'VIDEO') {
|
|
|
- // 自动播放下一个视频
|
|
|
- clearTimeout(activeData.timer)
|
|
|
- closeToast()
|
|
|
- item.autoPlay = true
|
|
|
- nextTick(() => {
|
|
|
- item.videoEle?.play()
|
|
|
- })
|
|
|
+ nextTick(() => {
|
|
|
+ popupData.activeIndex = index
|
|
|
+
|
|
|
+ acitveTimer.value = setTimeout(
|
|
|
+ () => {
|
|
|
+ popupData.playIndex = index
|
|
|
+ const item = data.itemList[index]
|
|
|
+ if (item) {
|
|
|
+ popupData.tabActive = item.knowledgePointId
|
|
|
+ popupData.itemActive = item.id
|
|
|
+ popupData.itemName = item.name
|
|
|
+ popupData.tabName = item.tabName
|
|
|
+ if (item.type == 'SONG') {
|
|
|
+ activeData.model = true
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- requestAnimationFrame(() => {
|
|
|
- const _effectIndex = effectIndex.value + 1
|
|
|
- effectIndex.value = _effectIndex >= effects.length - 1 ? 0 : _effectIndex
|
|
|
- })
|
|
|
- },
|
|
|
- activeData.isAnimation ? 800 : 0
|
|
|
- )
|
|
|
+ requestAnimationFrame(() => {
|
|
|
+ const _effectIndex = effectIndex.value + 1
|
|
|
+ effectIndex.value = _effectIndex >= effects.length - 1 ? 0 : _effectIndex
|
|
|
+
|
|
|
+ if (item && item.type === 'VIDEO') {
|
|
|
+ // 自动播放下一个视频
|
|
|
+ clearTimeout(activeData.timer)
|
|
|
+ closeToast()
|
|
|
+ item.autoPlay = true
|
|
|
+ nextTick(() => {
|
|
|
+ item.videoEle?.play()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ activeData.isAnimation ? 800 : 0
|
|
|
+ )
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
+ const onChangeSwiper = useDebounceFn((type: string, itemActive?: any) => {
|
|
|
+ if (type === 'up') {
|
|
|
+ handlePreAndNext('up')
|
|
|
+ }
|
|
|
+ if (type === 'down') {
|
|
|
+ handlePreAndNext('down')
|
|
|
+ }
|
|
|
+ if (type === 'change') {
|
|
|
+ popupData.open = false
|
|
|
+ toggleMaterial(itemActive)
|
|
|
+ }
|
|
|
+ }, 200)
|
|
|
/** 是否有转场动画 */
|
|
|
const checkedAnimation = (index: number, nextIndex?: number) => {
|
|
|
const item = data.itemList[index]
|
|
@@ -698,7 +710,7 @@ export default defineComponent({
|
|
|
onClick={() => {
|
|
|
clearTimeout(activeData.timer)
|
|
|
activeData.model = !activeData.model
|
|
|
- Object.values(data.videoRefs).map((n: any) => n.toggleHideControl(activeData.model))
|
|
|
+ Object.values(data.videoRefs).map((n: any) => n?.toggleHideControl(activeData.model))
|
|
|
}}
|
|
|
>
|
|
|
<div
|
|
@@ -711,19 +723,21 @@ export default defineComponent({
|
|
|
>
|
|
|
<div class={styles.wraps}>
|
|
|
{data.itemList.map((m: any, mIndex: number) => {
|
|
|
- const isRender = Math.abs(popupData.activeIndex - mIndex) < 5
|
|
|
- const isEmtry = Math.abs(popupData.activeIndex - mIndex) > 3
|
|
|
- // if (isRender) {
|
|
|
- // m.isRender = true
|
|
|
- // }
|
|
|
- return isRender ? (
|
|
|
+ const isRenderItem = Math.abs(popupData.activeIndex - mIndex) < 2
|
|
|
+ const isRender = Math.abs(popupData.playIndex - mIndex) < 2
|
|
|
+ const isEmtry = popupData.activeIndex != mIndex
|
|
|
+ // 判断是否是当前选中的元素
|
|
|
+ const activeEle = popupData.playIndex === mIndex ? true : false
|
|
|
+
|
|
|
+ return isRenderItem ? (
|
|
|
<div
|
|
|
key={'index' + mIndex}
|
|
|
+ data-id={'data' + mIndex}
|
|
|
class={[
|
|
|
styles.itemDiv,
|
|
|
- popupData.activeIndex === mIndex && styles.itemActive,
|
|
|
+ activeEle && styles.itemActive,
|
|
|
activeData.isAnimation && styles.acitveAnimation,
|
|
|
- Math.abs(popupData.activeIndex - mIndex) < 2 ? styles.show : styles.hide
|
|
|
+ isRenderItem ? styles.show : styles.hide
|
|
|
]}
|
|
|
style={
|
|
|
mIndex < popupData.activeIndex
|
|
@@ -743,7 +757,7 @@ export default defineComponent({
|
|
|
activeData.timer = setTimeout(() => {
|
|
|
activeData.model = !activeData.model
|
|
|
Object.values(data.videoRefs).map((n: any) =>
|
|
|
- n.toggleHideControl(activeData.model)
|
|
|
+ n?.toggleHideControl(activeData.model)
|
|
|
)
|
|
|
if (activeData.model) {
|
|
|
setModelOpen()
|
|
@@ -751,22 +765,19 @@ export default defineComponent({
|
|
|
}, 300)
|
|
|
}}
|
|
|
>
|
|
|
- {m.type === 'VIDEO' ? (
|
|
|
+ {m.type === 'VIDEO' && (
|
|
|
<>
|
|
|
<VideoPlay
|
|
|
ref={(v: any) => (data.videoRefs[mIndex] = v)}
|
|
|
item={m}
|
|
|
- isActive={popupData.activeIndex === mIndex}
|
|
|
+ isActive={activeEle}
|
|
|
isEmtry={isEmtry}
|
|
|
onLoadedmetadata={(videoItem: any) => {
|
|
|
m.videoEle = videoItem
|
|
|
+ m.isprepare = true
|
|
|
}}
|
|
|
onTogglePlay={(paused: boolean) => {
|
|
|
// console.log('播放切换', paused)
|
|
|
- // 首次播放完成
|
|
|
- if (!m.isprepare) {
|
|
|
- m.isprepare = true
|
|
|
- }
|
|
|
m.autoPlay = false
|
|
|
if (paused || popupData.open || popupData.guideOpen) {
|
|
|
clearTimeout(activeData.timer)
|
|
@@ -794,9 +805,9 @@ export default defineComponent({
|
|
|
)}
|
|
|
</Transition>
|
|
|
</>
|
|
|
- ) : m.type === 'IMG' ? (
|
|
|
- <img src={m.content} />
|
|
|
- ) : (
|
|
|
+ )}
|
|
|
+ {isRender && m.type === 'IMG' && <img src={m.content} />}
|
|
|
+ {isRender && m.type === 'SONG' && (
|
|
|
<MusicScore
|
|
|
activeModel={activeData.model}
|
|
|
data-vid={m.id}
|
|
@@ -807,7 +818,9 @@ export default defineComponent({
|
|
|
/>
|
|
|
)}
|
|
|
</div>
|
|
|
- ) : null
|
|
|
+ ) : (
|
|
|
+ ''
|
|
|
+ )
|
|
|
})}
|
|
|
</div>
|
|
|
<Transition name="right">
|
|
@@ -859,7 +872,16 @@ export default defineComponent({
|
|
|
<div class={styles.leftFixedBtns} onClick={(e: Event) => e.stopPropagation()}>
|
|
|
{popupData.activeIndex != 0 && (
|
|
|
<div class={[styles.btnsWrap, styles.prePoint]}>
|
|
|
- <div class={styles.fullBtn} onClick={() => handlePreAndNext('up')}>
|
|
|
+ <div
|
|
|
+ class={styles.fullBtn}
|
|
|
+ onClick={() => {
|
|
|
+ // useThrottleFn(() => {
|
|
|
+ // handlePreAndNext('up')
|
|
|
+ // }, 300)
|
|
|
+ // onChangeSwiper('up')
|
|
|
+ handlePreAndNext('up')
|
|
|
+ }}
|
|
|
+ >
|
|
|
<img src={iconUp} />
|
|
|
<span style={{ textAlign: 'center' }}>上一个</span>
|
|
|
</div>
|
|
@@ -867,7 +889,18 @@ export default defineComponent({
|
|
|
)}
|
|
|
{popupData.activeIndex != data.itemList.length - 1 && (
|
|
|
<div class={styles.btnsWrap}>
|
|
|
- <div class={styles.fullBtn} onClick={() => handlePreAndNext('down')}>
|
|
|
+ <div
|
|
|
+ class={styles.fullBtn}
|
|
|
+ onClick={() => {
|
|
|
+ // console.log('click down')
|
|
|
+ // useThrottleFn(() => {
|
|
|
+ // console.log('click down pass')
|
|
|
+ // handlePreAndNext('down')
|
|
|
+ // }, 300)
|
|
|
+ // onChangeSwiper('down')
|
|
|
+ handlePreAndNext('down')
|
|
|
+ }}
|
|
|
+ >
|
|
|
<span style={{ textAlign: 'center' }}>下一个</span>
|
|
|
<img src={iconDown} />
|
|
|
</div>
|
|
@@ -957,6 +990,7 @@ export default defineComponent({
|
|
|
tabActive={popupData.tabActive}
|
|
|
itemActive={popupData.itemActive}
|
|
|
onHandleSelect={(res: any) => {
|
|
|
+ // onChangeSwiper('change', res.itemActive)
|
|
|
popupData.open = false
|
|
|
toggleMaterial(res.itemActive)
|
|
|
}}
|