index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <a-layout>
  3. <a-layout-sider v-model:collapsed="collapsed" :trigger="null" collapsible collapsedWidth="0">
  4. <div class="classTitle">
  5. <div>{{ classDetail.courseName }}</div>
  6. </div>
  7. <a-menu
  8. v-model:openKeys="openKeys"
  9. v-model:selectedKeys="selectedKeys"
  10. theme="dark"
  11. mode="inline"
  12. @click="menuClick"
  13. >
  14. <a-sub-menu :key="String(idx + 1)" v-for="(item, idx) in classTimeList">
  15. <template #title>{{ item.name }}</template>
  16. <a-menu-item :key="itemc.id" v-for="(itemc, idxc) in item.classHours">
  17. <span class="mr-2">
  18. <CheckSquareOutlined v-if="selectedKeys.includes(itemc.id)" />
  19. <BorderOutlined v-else />
  20. </span>
  21. <span>{{ itemc.name }}</span>
  22. </a-menu-item>
  23. </a-sub-menu>
  24. </a-menu>
  25. </a-layout-sider>
  26. <a-layout>
  27. <a-layout-header style="padding: 0 20px">
  28. <div class="flex-between">
  29. <div>
  30. <menu-unfold-outlined
  31. v-if="collapsed"
  32. class="trigger"
  33. @click="() => (collapsed = !collapsed)"
  34. style="font-size: 30px; color: #fff"
  35. />
  36. <menu-fold-outlined
  37. v-else
  38. class="trigger"
  39. @click="() => (collapsed = !collapsed)"
  40. style="font-size: 30px; color: #fff"
  41. />
  42. </div>
  43. <div @click="isLike">
  44. <a-tooltip title="收藏" style="cursor: pointer" :getPopupContainer="(trigger) => trigger.parentElement">
  45. <heart-outlined :style="{ 'font-size': '20px', color: classDetail.isCollect ? '#ff4d4f' : '#fff' }" />
  46. </a-tooltip>
  47. </div>
  48. </div>
  49. </a-layout-header>
  50. <a-layout-content style="overflow-y: auto">
  51. <a-card :bordered="false">
  52. <div v-if="videoUrl">
  53. <video
  54. style="height: 900px; width: 100%; background-color: #000"
  55. ref="videoRef"
  56. controls
  57. Controlslist="nodownload noplaybackrate noremoteplayback disablePictureInPicture"
  58. @timeupdate="timeUpdate"
  59. :currentTime="currentTimenew"
  60. :poster="videoPoster"
  61. >
  62. <source :src="videoUrl" type="video/mp4" />
  63. <source :src="videoUrl" type="video/ogg" />
  64. 您的浏览器不支持 HTML5 video 标签。
  65. </video>
  66. </div>
  67. <rightMenu
  68. :idsObj="idsObj"
  69. :dataList="classTimeData"
  70. ref="rightNenuRef"
  71. @videoSpeed="videoSpeed"
  72. @videoStopTime="videoStopTime"
  73. ></rightMenu>
  74. </a-card>
  75. <a-card :bordered="false" class="mt-3">
  76. <div>
  77. <div>
  78. <div v-for="(item,idx) in webCon" >
  79. <a :href="item.href" target="_blank">{{ item.title }}</a>
  80. </div>
  81. </div>
  82. <a-divider />
  83. <div>
  84. 在小学和初中,我们已经接触过一些集合.例如,自然数的集合,同一平面内到一个定点的距离等于定长的点的集合(即圆)等.为了更有效地使用集合语言,我们需要进一步了解集合的有关知识.下面先从集合的含义开始.
  85. 看下面的例子:<br/>
  86. (1)1~10之间的所有偶数;<br/>
  87. (2)立德中学今年人学的全体高一学生;<br/>
  88. (3)所有的正方形;<br/>
  89. (4)到直线l的距离等于定长d的所有点<br/>
  90. (5)方程x’-3x+2=0的所有实数根;<br/>
  91. (6)地球上的四大洋.<br/>
  92. 例(1)中,我们把1~10之间的每一个偶数作为元素,这些元素的全体就是一个集合;同样地,<br/>
  93. 例(2)中,把立德中学今年人学的每一位高一学生作为元素,这些元素的全体也是一个集合.
  94. </div>
  95. </div>
  96. </a-card>
  97. <div style="display: flex; justify-content: center">
  98. <a-card :bordered="false" class="mt-2" style="width: 100%">
  99. <a-tabs v-model:activeKey="tabsActiveKey">
  100. <a-tab-pane key="1" tab="讲义" style="height: 800px">
  101. <handouts :itemObj="itemObj" :hourId="classHourData.id" v-if="classHourData"></handouts>
  102. </a-tab-pane>
  103. <a-tab-pane key="2" tab="字幕" style="height: 800px">
  104. <subtitleBox :url="danmuObj.url" v-if="tabsActiveKey == 2" @videoSpeed="videoSpeed"></subtitleBox>
  105. </a-tab-pane>
  106. <a-tab-pane key="3" tab="笔记" style="min-height: 800px">
  107. <note
  108. :idsObj="idsObj"
  109. ref="noteRef"
  110. v-if="tabsActiveKey == 3"
  111. @videoSpeed="videoSpeed"
  112. @videoStopTime="videoStopTime"
  113. ></note>
  114. </a-tab-pane>
  115. <a-tab-pane key="4" tab="问答" style="min-height: 800px">
  116. <askDiv
  117. :idsObj="idsObj"
  118. ref="askDivRef"
  119. v-if="tabsActiveKey == 4"
  120. @videoSpeed="videoSpeed"
  121. @videoStopTime="videoStopTime"
  122. ></askDiv>
  123. </a-tab-pane>
  124. </a-tabs>
  125. </a-card>
  126. </div>
  127. <forumBtn :forumData="forumData" resourceType="0"></forumBtn>
  128. </a-layout-content>
  129. </a-layout>
  130. </a-layout>
  131. </template>
  132. <script setup name="classCentre">
  133. import classCentre from '@/api/student/classCentre'
  134. import rightMenu from './rightMenu.vue'
  135. import { useRoute, useRouter } from 'vue-router'
  136. import sysConfig from '@/config/index'
  137. import note from './note.vue'
  138. import askDiv from './ask.vue'
  139. import handouts from './handouts.vue'
  140. import subtitleBox from './subtitle.vue'
  141. import Broadcast from '@/utils/Broadcast.js'
  142. const route = useRoute()
  143. const router = useRouter()
  144. const classDetail = ref({})
  145. const classTimeList = ref([])
  146. const classTimeData = ref([])
  147. const openKeys = ref(['1'])
  148. const selectedKeys = ref([])
  149. const collapsed = ref(false)
  150. const videoRef = ref()
  151. const currentTimenew = ref(0)
  152. const idsObj = computed(() => {
  153. let item = findNodeByKey(classTimeList.value, selectedKeys.value[0], classTimeList.value[0])
  154. return {
  155. courseId: route.query.id,
  156. chapterId: selectedKeys.value[0],
  157. hourId: classHourData.value?.id,
  158. ...item
  159. }
  160. })
  161. function findNodeByKey(list, id, parent = null) {
  162. for (const item of list) {
  163. const itemWithParent = {
  164. ...item,
  165. parent: parent
  166. }
  167. if (itemWithParent.id === id) {
  168. return itemWithParent
  169. }
  170. if (item.classHours && Array.isArray(item.classHours)) {
  171. const found = findNodeByKey(item.classHours, id, itemWithParent)
  172. if (found) return found
  173. }
  174. }
  175. return null
  176. }
  177. const videoPoster = computed(() => {
  178. return classTimeData.value.find((r) => r.funcType == 0)?.url
  179. })
  180. const getClassData = () => {
  181. classCentre.addViewCount({ courseId: route.query.id })
  182. classCentre.courseDetail({ courseId: route.query.id }).then((data) => {
  183. classDetail.value = data
  184. classCentre.coursechapterList({ courseId: data.courseId }).then((data) => {
  185. classTimeList.value = data
  186. selectedKeys.value = selectedKeys.value[0] ? selectedKeys.value : [data[0]?.classHours[0].id]
  187. if (selectedKeys.value[0]) {
  188. menuClick()
  189. }
  190. })
  191. })
  192. }
  193. const getClassStatus = (e) => {
  194. classCentre
  195. .classGetStatus({
  196. examPaperId: e.relateId
  197. })
  198. .then((res) => {
  199. const idx = classTimeData.value.findIndex((item) => item.funcType == e.funcType)
  200. classTimeData.value[idx].status = res.isFinish
  201. classTimeData.value[idx].answerId = res.answerId
  202. })
  203. }
  204. const classHourData = ref()
  205. const rightNenuRef = ref()
  206. const menuClick = (e) => {
  207. rightNenuRef.value.onClose()
  208. if (e) {
  209. addClassPlan(1)
  210. }
  211. classCentre.courseTimeDetail({ id: e?.key ? e.key : selectedKeys.value[0] }).then((data) => {
  212. classHourData.value = data
  213. classTimeData.value = data.courseRelates.map((r) => {
  214. return {
  215. ...r,
  216. url: sysConfig.FILE_URL + r.url
  217. }
  218. })
  219. videoUrl.value = classTimeData.value.find((r) => r.funcType == 1)?.url
  220. nextTick(() => {
  221. videoRef.value.src = classTimeData.value.find((r) => r.funcType == 1)?.url
  222. videoStart()
  223. footprintClassAdd()
  224. getVideoTime()
  225. const funcType4Item = classTimeData.value.find((r) => r.funcType == 4)
  226. const funcType5Item = classTimeData.value.find((r) => r.funcType == 5)
  227. if (funcType4Item) {
  228. getClassStatus(funcType4Item)
  229. }
  230. if (funcType5Item) {
  231. getClassStatus(funcType5Item)
  232. }
  233. })
  234. })
  235. }
  236. const tabsActiveKey = ref('1')
  237. const noteRef = ref()
  238. const askDivRef = ref()
  239. const itemObj = computed(() => {
  240. let item = classTimeData.value.length > 0 ? classTimeData.value.find((r) => r.funcType == 2) : { url: '' }
  241. return item
  242. })
  243. const danmuObj = computed(() => {
  244. let item = classTimeData.value.length > 0 ? classTimeData.value.find((r) => r.funcType == 3) : { url: '' }
  245. return item
  246. })
  247. const videoUrl = ref('')
  248. const newsschedule = ref(0)
  249. const currTime = ref(null)
  250. const maxTime = ref(0)
  251. const initialtime = ref(0)
  252. const videoContext = ref()
  253. const timeStamp1 = ref()
  254. const allTime = ref()
  255. const biNum = ref()
  256. const currentTime = ref()
  257. const videoStart = () => {
  258. videoContext.value = videoRef.value
  259. if (initialtime.value > 0) {
  260. videoContext.value.currentTime = initialtime.value
  261. timeStamp1.value = initialtime.value
  262. }
  263. }
  264. const timeUpdate = (e) => {
  265. //获取当前播放时间 durationinitialtime
  266. if (timeStamp1.value != parseInt(e.target.currentTime)) {
  267. allTime.value = parseInt(e.target.duration) //视频总时长(秒)
  268. //对播放的时间进行整
  269. timeStamp1.value = parseInt(e.target.currentTime) //播放进度 (秒)
  270. biNum.value = Math.floor((timeStamp1.value / allTime.value) * 10000) / 100 //暂时没用到
  271. currentTime.value = e.target.currentTime
  272. if (e.srcElement.currentTime - currTime.value > 3) {
  273. addClassPlan(3)
  274. }
  275. if (currTime.value - e.srcElement.currentTime > 3) {
  276. addClassPlan(3)
  277. }
  278. currTime.value = e.srcElement.currentTime
  279. }
  280. }
  281. const videoJumpTime = ref(false)
  282. const videoSpeed = (e) => {
  283. videoJumpTime.value = true
  284. currentTimenew.value = parseFloat(e.startTime)
  285. }
  286. const forumData = computed(() => {
  287. let item = findNodeByKey(classTimeList.value, selectedKeys.value[0], classTimeList.value[0]) ?? {}
  288. if (!item.src) {
  289. item.src = classTimeData.value.find((r) => r.funcType == 1)?.url
  290. }
  291. return {
  292. id: classHourData.value?.id,
  293. title: item.parent?.name,
  294. videoUrl: btoa(encodeURIComponent(videoRef.value?.src ? videoRef.value.src : item.src)),
  295. courseId: route.query.id,
  296. chapterId: selectedKeys.value[0],
  297. courseName: classDetail.value?.courseName,
  298. chapterName: classHourData.value?.name
  299. }
  300. })
  301. const showPdf = ref(true)
  302. function errorHandler() {
  303. showPdf.value = false
  304. }
  305. const getVideoTime = () => {
  306. classCentre
  307. .theLastDetail({
  308. funcType: 1,
  309. type: 1,
  310. hourId: classHourData.value?.id
  311. })
  312. .then((data) => {
  313. if (data.endTime) {
  314. initialtime.value = parseFloat(data.endTime) / 1000
  315. currentTimenew.value = parseFloat(data.endTime) / 1000
  316. }
  317. })
  318. }
  319. // 毫秒转换时分秒
  320. function msToHMS(ms) {
  321. if (typeof ms !== 'number' || isNaN(ms)) return '00:00:00'
  322. let totalSeconds = Math.floor(ms / 1000)
  323. let hours = String(Math.floor(totalSeconds / 3600)).padStart(2, '0')
  324. let minutes = String(Math.floor((totalSeconds % 3600) / 60)).padStart(2, '0')
  325. let seconds = String(totalSeconds % 60).padStart(2, '0')
  326. return `${hours}:${minutes}:${seconds}`
  327. }
  328. // 时分秒转换毫秒
  329. function hmsToMs(hms) {
  330. if (!hms) return 0
  331. const parts = hms.split(':').map((p) => parseFloat(p.replace(',', '.')))
  332. // 支持 hh:mm:ss 或 mm:ss
  333. let ms = 0
  334. if (parts.length === 3) {
  335. ms = (parts[0] * 3600 + parts[1] * 60 + parts[2]) * 1000
  336. } else if (parts.length === 2) {
  337. ms = (parts[0] * 60 + parts[1]) * 1000
  338. } else if (parts.length === 1) {
  339. ms = parts[0] * 1000
  340. }
  341. return ms
  342. }
  343. const nowTimesStr = Date.now()
  344. const outNowTimesStr = ref()
  345. const addClassPlan = (type) => {
  346. outNowTimesStr.value = Date.now()
  347. let progress = parseFloat((videoRef.value?.currentTime / videoRef.value?.duration) * 100)
  348. if (
  349. (progress || progress == 0) &&
  350. (initialtime.value || initialtime.value == 0) &&
  351. (videoRef.value.currentTime || videoRef.value.currentTime == 0)
  352. ) {
  353. classCentre.classPlanAdd({
  354. startTime: parseFloat(initialtime.value),
  355. endTime: Math.round(videoRef.value.currentTime * 1000),
  356. progress: Math.round(progress),
  357. hourId: classHourData.value?.id,
  358. stayTime: outNowTimesStr.value - nowTimesStr,
  359. type: type,
  360. funcType: 1,
  361. ...classDetailParams.value
  362. })
  363. }
  364. }
  365. const isLike = () => {
  366. classCentre
  367. .classCollectAdd(
  368. {
  369. courseId: route.query.id
  370. },
  371. classDetail.value.isCollect
  372. )
  373. .then(() => {
  374. classCentre.courseDetail({ courseId: route.query.id }).then((data) => {
  375. classDetail.value = data
  376. })
  377. })
  378. }
  379. const classDetailParams = computed(() => {
  380. return {
  381. hourName: classHourData.value.name,
  382. chapterName: classHourData.value.name,
  383. courseName: classDetail.value.courseName,
  384. hourId: classHourData.value.id,
  385. chapterId: selectedKeys.value[0],
  386. courseId: classDetail.value.courseId,
  387. fileId: classHourData.value.courseRelates.find((r) => r.funcType == 1)?.relateId,
  388. fileName: classHourData.value.courseRelates.find((r) => r.funcType == 1)?.name,
  389. filePath: classHourData.value.courseRelates.find((r) => r.funcType == 1)?.url
  390. }
  391. })
  392. //足迹
  393. const footprintClassAdd = () => {
  394. classCentre.footprintClassAdd({
  395. ...classDetailParams.value
  396. })
  397. }
  398. // 监听消息
  399. const stopListening = Broadcast.on('getClassDetail', (event) => {
  400. if (event.type == 1) {
  401. getClassData()
  402. }
  403. })
  404. const videoStopTime = (callback) => {
  405. videoRef.value.pause()
  406. callback && callback(videoRef.value.currentTime)
  407. }
  408. const webCon = ref([
  409. {
  410. title:'1.1 集合的概念',
  411. href:'/webEmpty'
  412. },
  413. {
  414. title:'1.2 集合间的基本关系',
  415. href:'/webEmpty'
  416. },
  417. {
  418. title:'1.3 集合的基本运算',
  419. href:'/webEmpty'
  420. },
  421. {
  422. title:'1.4 充分条件与必要条件',
  423. href:'/webEmpty'
  424. },
  425. {
  426. title:'1.5 全称量词与存在量词',
  427. href:'/webEmpty'
  428. },
  429. ])
  430. onMounted(() => {
  431. getClassData()
  432. })
  433. onBeforeUnmount(() => {
  434. stopListening()
  435. addClassPlan(1)
  436. })
  437. </script>
  438. <style scoped lang="less">
  439. .classTitle {
  440. height: 64px;
  441. width: 200px;
  442. font-size: 18px;
  443. color: #ccc;
  444. display: flex;
  445. justify-content: center;
  446. align-items: center;
  447. }
  448. .flex-between {
  449. display: flex;
  450. justify-content: space-between;
  451. }
  452. </style>