index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. import { Button, Icon, Popup, Slider, Swipe, SwipeItem, Tab, Tabs } from 'vant'
  2. import {
  3. defineComponent,
  4. onMounted,
  5. reactive,
  6. nextTick,
  7. onUnmounted,
  8. ref,
  9. watch,
  10. Transition,
  11. computed
  12. } from 'vue'
  13. import iconBack from './image/back.svg'
  14. import styles from './index.module.less'
  15. import Plyr from 'plyr'
  16. import 'plyr/dist/plyr.css'
  17. import request from '@/helpers/request'
  18. import { state } from '@/state'
  19. import { useRoute } from 'vue-router'
  20. import { listenerMessage, postMessage } from '@/helpers/native-message'
  21. import MusicScore from './component/musicScore'
  22. import iconMenu from './image/icon-menu.svg'
  23. import iconDian from './image/icon-dian.svg'
  24. import iconPoint from './image/icon-point.svg'
  25. import Points from './component/points'
  26. export default defineComponent({
  27. name: 'CoursewarePlay',
  28. setup() {
  29. const handleInit = () => {
  30. postMessage({
  31. api: 'setRequestedOrientation',
  32. content: {
  33. orientation: 0
  34. }
  35. })
  36. postMessage({
  37. api: 'setBarStatus',
  38. content: {
  39. status: 0
  40. }
  41. })
  42. postMessage({
  43. api: 'setStatusBarVisibility',
  44. content: {
  45. isVisibility: 0
  46. }
  47. })
  48. }
  49. handleInit()
  50. const route = useRoute()
  51. const data = reactive({
  52. detail: null,
  53. active: '',
  54. itemActive: '',
  55. knowledgePointList: [] as any,
  56. showHead: true,
  57. players: [] as any
  58. })
  59. const activeData = reactive({
  60. model: true, // 遮罩
  61. currentTime: 10
  62. })
  63. const itemList = computed(() => {
  64. const list: any = []
  65. for (let i = 0; i < data.knowledgePointList.length; i++) {
  66. const item = data.knowledgePointList[i]
  67. for (let j = 0; j < item.materialList.length; j++) {
  68. const material = item.materialList[j]
  69. if (popupData.itemActive === '') {
  70. popupData.tabActive = material.knowledgePointId
  71. popupData.tabName = item.name
  72. popupData.itemActive = material.id
  73. popupData.itemName = material.name
  74. }
  75. list.push({
  76. ...material
  77. })
  78. }
  79. }
  80. // console.log('🚀 ~ list', list)
  81. return list
  82. })
  83. const getDetail = async () => {
  84. try {
  85. const res: any = await request.get(
  86. state.platformApi + `/lessonCoursewareDetail/detail/${route.query.id}`
  87. )
  88. if (Array.isArray(res?.data)) {
  89. data.detail = res.data
  90. }
  91. if (Array.isArray(res?.data?.knowledgePointList)) {
  92. data.knowledgePointList = res.data.knowledgePointList.map((n: any) => {
  93. n.index = 0
  94. return n
  95. })
  96. }
  97. } catch (error) {}
  98. }
  99. const videoInit = () => {
  100. console.log(document.querySelectorAll('.player'))
  101. data.players = Plyr.setup('.player', {
  102. debug: false,
  103. ratio: '16:9',
  104. clickToPlay: true,
  105. controls: [
  106. 'play-large',
  107. 'play',
  108. 'progress',
  109. 'current-time',
  110. 'duration',
  111. 'mute',
  112. 'volume',
  113. 'restart'
  114. ]
  115. })
  116. data.players.forEach((p: Plyr) => {
  117. // console.log(p)
  118. p.on('play', () => {
  119. console.log('开始播放了')
  120. data.showHead = false
  121. })
  122. p.on('pause', () => {
  123. console.log('暂停了')
  124. data.showHead = true
  125. })
  126. p.on('controlsshown', () => {
  127. console.log('显示控件')
  128. data.showHead = true
  129. })
  130. p.on('controlshidden', () => {
  131. console.log('控件隐藏')
  132. data.showHead = false
  133. })
  134. })
  135. console.log('🚀 ~ player', data.players)
  136. }
  137. const testFile = ref('')
  138. onMounted(() => {
  139. // const o = new ActiveXObject("wscript.shell")
  140. getDetail()
  141. postMessage(
  142. {
  143. api: 'getCourseFilePath',
  144. content: {
  145. url: 'https://daya.ks3-cn-beijing.ksyuncs.com/01/1672976208474.jpg',
  146. materialId: '1610610237357969409',
  147. updateTime: '2023-01-04 20:12:58',
  148. type: 'VIDEO' // SONG VIDEO IMAGE
  149. }
  150. },
  151. (res) => {
  152. if (res?.content) {
  153. testFile.value = 'customScheme://' + res.content.localPath
  154. fetch(testFile.value)
  155. }
  156. }
  157. )
  158. })
  159. listenerMessage('getCourseFilePath', (res) => {
  160. if (res?.content) {
  161. testFile.value = res.content.localPath
  162. }
  163. })
  164. // 返回
  165. const goback = () => {
  166. // history.go(-1)
  167. postMessage({ api: 'back' })
  168. }
  169. // 所有的切换
  170. const handleChange = () => {
  171. // console.log('切换了')
  172. const iframes = document.querySelectorAll('.musicIframe')
  173. Array.from(iframes).map((f: any) => {
  174. f.contentWindow.postMessage({ api: 'setPlayState' }, '*')
  175. })
  176. data.players.forEach((p: any) => {
  177. p.stop()
  178. })
  179. }
  180. onUnmounted(() => {
  181. postMessage({
  182. api: 'setRequestedOrientation',
  183. content: {
  184. orientation: 1
  185. }
  186. })
  187. postMessage({
  188. api: 'setBarStatus',
  189. content: {
  190. status: 1
  191. }
  192. })
  193. postMessage({
  194. api: 'setStatusBarVisibility',
  195. content: {
  196. isVisibility: 1
  197. }
  198. })
  199. })
  200. const popupData = reactive({
  201. open: false,
  202. activeIndex: 0,
  203. tabActive: '',
  204. tabName: '',
  205. itemActive: '',
  206. itemName: ''
  207. })
  208. // 切换素材
  209. const toggleMaterial = () => {
  210. const index = itemList.value.findIndex((n: any) => n.id == popupData.itemActive)
  211. popupData.activeIndex = index
  212. console.log('🚀 ~ popupData', popupData.activeIndex)
  213. }
  214. // 上一个知识点, 下一个知识点
  215. const handlePreAndNext = (type: string) => {
  216. console.log(popupData.tabActive)
  217. const tabIndex = data.knowledgePointList.findIndex((n: any) => n.id == popupData.tabActive)
  218. const itemIndex = itemList.value.findIndex((n: any) => n.id == popupData.itemActive)
  219. console.log("🚀 ~ tab", tabIndex, itemIndex)
  220. }
  221. // 去点名,签退
  222. const gotoRollCall = (pageTag: string) => {
  223. postMessage({
  224. api: 'open_app_page',
  225. content: {
  226. action: 'app',
  227. pageTag: pageTag,
  228. url: '',
  229. params: JSON.stringify({ courseId: route.query.courseId })
  230. }
  231. })
  232. }
  233. return () => (
  234. <div class={styles.coursewarePlay}>
  235. <Swipe
  236. style={{ height: '100vh' }}
  237. showIndicators={false}
  238. loop={false}
  239. initialSwipe={popupData.activeIndex}
  240. vertical
  241. lazyRender={true}
  242. onChange={(val: any) => {
  243. // item.index = val
  244. // popupData.itemActive = `${item.id}-${item?.materialList?.[item.index]?.id}`
  245. }}
  246. >
  247. {itemList.value.map((m: any) => {
  248. return (
  249. <SwipeItem>
  250. {m.type === 'VIDEO' ? (
  251. <div class={styles.videoItem}>
  252. <video class="player">
  253. <source src={m.content} type="video/mp4" />
  254. </video>
  255. </div>
  256. ) : m.type === 'IMG' ? (
  257. <div class={styles.imgItem}>
  258. <img src={m.content} />
  259. </div>
  260. ) : (
  261. <div class={styles.songItem}>
  262. <MusicScore music={m} />
  263. </div>
  264. )}
  265. </SwipeItem>
  266. )
  267. })}
  268. </Swipe>
  269. <div
  270. class={styles.playModel}
  271. onClick={() => {
  272. activeData.model = !activeData.model
  273. }}
  274. ></div>
  275. <Transition name="top">
  276. {activeData.model && (
  277. <div class={styles.headerContainer}>
  278. <div class={styles.backBtn} onClick={() => goback()}>
  279. <Icon name={iconBack} />
  280. 返回
  281. </div>
  282. <div class={styles.menu}>{popupData.tabName}</div>
  283. </div>
  284. )}
  285. </Transition>
  286. <Transition name="right">
  287. {activeData.model && (
  288. <div class={styles.rightFixedBtns}>
  289. <div class={styles.fullBtn} onClick={() => (popupData.open = true)}>
  290. <img src={iconMenu} />
  291. <span>知识点</span>
  292. </div>
  293. {route.query.courseId && (
  294. <>
  295. <div
  296. class={[styles.fullBtn, styles.point]}
  297. onClick={() => gotoRollCall('student_roll_call')}
  298. >
  299. <img src={iconDian} />
  300. <span>点名</span>
  301. </div>
  302. <div class={styles.fullBtn} onClick={() => gotoRollCall('sign_out')}>
  303. <img src={iconPoint} />
  304. <span>签退</span>
  305. </div>
  306. </>
  307. )}
  308. </div>
  309. )}
  310. </Transition>
  311. <Transition name="left">
  312. {activeData.model && (
  313. <div class={styles.leftFixedBtns}>
  314. <div class={[styles.fullBtn, styles.prePoint]} onClick={() => handlePreAndNext('up')}>
  315. <span style={{ textAlign: 'center' }}>
  316. 上一
  317. <br />
  318. 知识点
  319. </span>
  320. </div>
  321. <div class={styles.fullBtn} onClick={() => handlePreAndNext('down')}>
  322. <span style={{ textAlign: 'center' }}>
  323. 下一
  324. <br />
  325. 知识点
  326. </span>
  327. </div>
  328. </div>
  329. )}
  330. </Transition>
  331. <Transition name="bottom">
  332. {activeData.model && (
  333. <div class={styles.bottomFixedContainer}>
  334. <div class={styles.time}>
  335. <span>03:12</span>
  336. <span>10:12</span>
  337. </div>
  338. <Slider
  339. buttonSize={16}
  340. style={{ margin: '8px 0' }}
  341. v-model:modelValue={activeData.currentTime}
  342. min={0}
  343. max={100}
  344. />
  345. <div class={styles.actions}>
  346. <div>
  347. <Icon name="play-circle" />
  348. <Icon name="pause-circle" />
  349. </div>
  350. <div>长笛的呼吸练习</div>
  351. </div>
  352. </div>
  353. )}
  354. </Transition>
  355. <Popup
  356. class={styles.popup}
  357. overlayClass={styles.overlayClass}
  358. position="right"
  359. round
  360. v-model:show={popupData.open}
  361. >
  362. <Points
  363. data={data.knowledgePointList}
  364. tabActive={popupData.tabActive}
  365. itemActive={popupData.itemActive}
  366. onHandleSelect={(res: any) => {
  367. // console.log(res)
  368. popupData.tabActive = res.tabActive
  369. popupData.itemActive = res.itemActive
  370. popupData.open = false
  371. toggleMaterial()
  372. }}
  373. />
  374. </Popup>
  375. </div>
  376. )
  377. }
  378. })