courseManage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div>
  3. <!-- 顶部标题栏 -->
  4. <div>
  5. <div style="position: relative; display: flex; align-items: center; justify-content: center; height: 48px; background: #fff;">
  6. <span style="position: absolute; left: 16px; cursor: pointer;" @click="handleBack">
  7. <i class="el-icon-arrow-left" style="font-size: 20px; color: #333;"></i>
  8. </span>
  9. <span style="font-weight: bold; font-size: 16px;">课程管理</span>
  10. </div>
  11. <el-select
  12. v-model="courseId"
  13. placeholder="请点击选择课程"
  14. class="courseSelect"
  15. popper-class="courseSelectList"
  16. @visible-change="handleSelectOpen"
  17. @change="courseChange"
  18. ref="courseSelect"
  19. >
  20. <el-option
  21. v-for="item in courseList"
  22. :key="item.courseId"
  23. :label="item.courseName"
  24. :value="item.courseId">
  25. </el-option>
  26. <div
  27. v-if="courseQueryParams.hasNextPage"
  28. class="load-more"
  29. v-loading="courseQueryParams.loading"
  30. >
  31. <span v-if="!courseQueryParams.loading">加载更多</span>
  32. </div>
  33. </el-select>
  34. <el-input
  35. placeholder="请输入课程名称"
  36. v-model="videoQueryParams.keyword"
  37. class="videoSearch"
  38. @keyup.enter.native="handleSearch"
  39. >
  40. </el-input>
  41. </div>
  42. <!-- 列表 -->
  43. <div :class="extend ? 'infinite-list-wrapper-extend' : 'infinite-list-wrapper'" style="overflow:auto">
  44. <ul class="video-list" v-infinite-scroll="loadMoreVideo">
  45. <li v-for="item in videoList" :key="item.videoId" class="video-item">
  46. <div class="video-thumbnail">
  47. <img :src="item.thumbnail || defaultImage" alt="" @error="handleImgError">
  48. <div class="video-duration">{{formatDuration(item.duration)}}</div>
  49. </div>
  50. <div class="video-info">
  51. <div class="video-title">{{item.title}}</div>
  52. <div class="video-meta">
  53. <i class="el-icon-s-order" style="font-size: 18px;margin-right: 5px"></i>
  54. <span class="video-date">{{formatDate(item.createTime)}}</span>
  55. </div>
  56. </div>
  57. <div class="video-actions">
  58. <el-button
  59. type="primary"
  60. size="mini"
  61. round
  62. :loading="sharingVideoId === item.videoId"
  63. :disabled="sharingVideoId === item.videoId"
  64. @click="handleShare(item)">分享课程</el-button>
  65. </div>
  66. </li>
  67. </ul>
  68. <div v-if="videoList.length === 0 && !videoQueryParams.loading" class="empty-tip">
  69. <i class="el-icon-video-camera"></i>
  70. <p>暂无视频</p>
  71. </div>
  72. <div v-if="videoQueryParams.loading" class="loading-more">
  73. <i class="el-icon-loading"></i>
  74. <span>加载中...</span>
  75. </div>
  76. <div v-if="!videoQueryParams.hasNextPage && videoList.length > 0" class="no-more">
  77. <span>没有更多了</span>
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import {createMiniLink, getFsCourseListBySidebar, getFsCourseVideoListBySidebar} from "@/api/qw/im";
  84. export default {
  85. name: "courseManage",
  86. props: {
  87. userId: {
  88. type: Number,
  89. default: () => null
  90. },
  91. extend: {
  92. type: Boolean,
  93. default: false
  94. }
  95. },
  96. data() {
  97. return {
  98. courseId: null,
  99. courseQueryParams: {
  100. extId: this.userId,
  101. page: 1,
  102. limit: 10,
  103. hasNextPage: false,
  104. loading: false,
  105. },
  106. courseList: [],
  107. scrollEvent: null,
  108. videoQueryParams: {
  109. courseId: null,
  110. keyword: '',
  111. page: 1,
  112. limit: 10,
  113. hasNextPage: false,
  114. loading: false,
  115. },
  116. videoList: [],
  117. defaultImage: require('@/assets/image/default-image.png'),
  118. sharingVideoId: null
  119. }
  120. },
  121. created() {
  122. this.getFsCourseListBySidebar()
  123. },
  124. methods: {
  125. handleBack() {
  126. this.$emit('back')
  127. },
  128. getFsCourseListBySidebar() {
  129. this.courseQueryParams.loading = true;
  130. getFsCourseListBySidebar(this.courseQueryParams).then(response => {
  131. if (this.courseQueryParams.page === 1) {
  132. this.courseList = response.data.list;
  133. } else {
  134. this.courseList = [...this.courseList, ...response.data.list];
  135. }
  136. this.courseQueryParams.hasNextPage = response.data.hasNextPage;
  137. this.courseQueryParams.loading = false;
  138. }).catch(() => {
  139. this.courseQueryParams.loading = false;
  140. });
  141. },
  142. loadMore() {
  143. if (!this.courseQueryParams.hasNextPage || this.courseQueryParams.loading) return;
  144. this.courseQueryParams.page += 1;
  145. this.getFsCourseListBySidebar();
  146. },
  147. handleSelectOpen(visible) {
  148. if (visible) {
  149. // 下拉框打开时,添加滚动监听
  150. this.$nextTick(() => {
  151. const selectDropdown = document.querySelector('.el-select-dropdown.courseSelectList');
  152. if (selectDropdown) {
  153. const dropdownList = selectDropdown.querySelector('.el-select-dropdown__wrap');
  154. if (dropdownList) {
  155. // 移除之前可能存在的事件监听
  156. if (this.scrollEvent) {
  157. dropdownList.removeEventListener('scroll', this.scrollEvent);
  158. }
  159. // 添加新的滚动监听
  160. this.scrollEvent = () => {
  161. const { scrollTop, scrollHeight, clientHeight } = dropdownList;
  162. // 当滚动到距离底部20px时,加载更多
  163. if (scrollHeight - scrollTop - clientHeight < 20) {
  164. this.loadMore();
  165. }
  166. };
  167. dropdownList.addEventListener('scroll', this.scrollEvent);
  168. }
  169. }
  170. });
  171. } else {
  172. // 下拉框关闭时,移除滚动监听
  173. if (this.scrollEvent) {
  174. const selectDropdown = document.querySelector('.el-select-dropdown.courseSelectList');
  175. if (selectDropdown) {
  176. const dropdownList = selectDropdown.querySelector('.el-select-dropdown__wrap');
  177. if (dropdownList) {
  178. dropdownList.removeEventListener('scroll', this.scrollEvent);
  179. }
  180. }
  181. }
  182. }
  183. },
  184. courseChange(courseId) {
  185. this.videoQueryParams.courseId = courseId;
  186. this.handleSearch()
  187. },
  188. handleSearch() {
  189. if (!this.videoQueryParams.courseId) {
  190. return
  191. }
  192. this.videoQueryParams.page = 1;
  193. this.getFsCourseVideoListBySidebar()
  194. },
  195. getFsCourseVideoListBySidebar() {
  196. this.videoQueryParams.loading = true;
  197. getFsCourseVideoListBySidebar(this.videoQueryParams).then(response => {
  198. if (this.videoQueryParams.page === 1) {
  199. this.videoList = response.data.list;
  200. } else {
  201. this.videoList = [...this.videoList, ...response.data.list];
  202. }
  203. this.videoQueryParams.hasNextPage = response.data.hasNextPage;
  204. this.videoQueryParams.loading = false;
  205. console.log(this.videoList)
  206. }).catch(() => {
  207. this.videoQueryParams.loading = false;
  208. })
  209. },
  210. loadMoreVideo() {
  211. if (!this.videoQueryParams.hasNextPage || this.videoQueryParams.loading) return;
  212. this.videoQueryParams.page += 1;
  213. this.getFsCourseVideoListBySidebar()
  214. },
  215. handleImgError(e) {
  216. e.target.src = this.defaultImage;
  217. },
  218. formatDate(timestamp) {
  219. if (!timestamp) return '';
  220. const date = new Date(timestamp);
  221. return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
  222. },
  223. formatDuration(seconds) {
  224. if (!seconds) return '00:00';
  225. const minutes = Math.floor(seconds / 60);
  226. const remainingSeconds = seconds % 60;
  227. return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
  228. },
  229. handleShare(item) {
  230. const params = {
  231. extId: this.userId,
  232. courseId: item.courseId,
  233. videoId: item.videoId,
  234. title: item.title,
  235. }
  236. this.sharingVideoId = item.videoId;
  237. createMiniLink(params).then(response => {
  238. const {code, data} = response;
  239. if (code === 200) {
  240. this.$store.dispatch('qwIm/shareCourse', data)
  241. }
  242. this.sharingVideoId = null;
  243. }).catch(() => {
  244. this.$message.error('分享课程失败');
  245. this.sharingVideoId = null;
  246. })
  247. }
  248. }
  249. }
  250. </script>
  251. <style scoped>
  252. .courseSelect {
  253. width: 100%;
  254. }
  255. .courseSelectList li {
  256. text-align: center;
  257. }
  258. ::v-deep .courseSelect input {
  259. border: unset;
  260. text-align: center;
  261. }
  262. .load-more {
  263. text-align: center;
  264. height: 34px;
  265. line-height: 34px;
  266. color: #909399;
  267. font-size: 12px;
  268. cursor: pointer;
  269. background-color: #f5f7fa;
  270. }
  271. .load-more:hover {
  272. background-color: #e4e7ed;
  273. }
  274. .videoSearch {
  275. padding: 10px;
  276. border-radius: 8px;
  277. }
  278. ::v-deep .videoSearch input {
  279. border-radius: 22px;
  280. }
  281. .infinite-list-wrapper {
  282. height: calc(100vh - 200px);
  283. overflow-y: auto;
  284. padding: 0 10px;
  285. background-color: #f5f7fa;
  286. }
  287. .infinite-list-wrapper-extend {
  288. height: calc(100vh - 330px);
  289. overflow-y: auto;
  290. padding: 0 10px;
  291. background-color: #f5f7fa;
  292. }
  293. .video-list {
  294. list-style: none;
  295. padding: 0;
  296. margin: 0;
  297. }
  298. .video-item {
  299. display: flex;
  300. padding: 15px;
  301. margin-bottom: 5px;
  302. background-color: #fff;
  303. border-radius: 8px;
  304. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  305. transition: transform 0.2s;
  306. }
  307. .video-item:hover {
  308. transform: translateY(-2px);
  309. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  310. }
  311. .video-thumbnail {
  312. position: relative;
  313. flex: 0 0 120px;
  314. height: 80px;
  315. margin-right: 15px;
  316. border-radius: 4px;
  317. overflow: hidden;
  318. }
  319. .video-thumbnail img {
  320. width: 100%;
  321. height: 100%;
  322. object-fit: cover;
  323. }
  324. .video-duration {
  325. position: absolute;
  326. bottom: 5px;
  327. right: 5px;
  328. background-color: rgba(0, 0, 0, 0.7);
  329. color: #fff;
  330. padding: 2px 4px;
  331. border-radius: 2px;
  332. font-size: 12px;
  333. }
  334. .video-info {
  335. flex: 1;
  336. overflow: hidden;
  337. display: flex;
  338. flex-direction: column;
  339. justify-content: space-around;
  340. }
  341. .video-title {
  342. font-size: 16px;
  343. font-weight: 500;
  344. color: #303133;
  345. margin-bottom: 5px;
  346. overflow: hidden;
  347. text-overflow: ellipsis;
  348. white-space: nowrap;
  349. }
  350. .video-meta {
  351. display: flex;
  352. align-items: flex-end;
  353. font-size: 12px;
  354. color: #909399;
  355. margin-bottom: 5px;
  356. }
  357. .video-date {
  358. margin-right: 15px;
  359. }
  360. .video-actions {
  361. display: flex;
  362. flex-direction: column;
  363. justify-content: center;
  364. gap: 8px;
  365. margin-left: 10px;
  366. }
  367. .loading-more {
  368. text-align: center;
  369. padding: 15px 0;
  370. color: #909399;
  371. }
  372. .no-more {
  373. text-align: center;
  374. padding: 15px 0;
  375. color: #909399;
  376. font-size: 13px;
  377. }
  378. .empty-tip {
  379. display: flex;
  380. flex-direction: column;
  381. align-items: center;
  382. justify-content: center;
  383. padding: 40px 0;
  384. color: #909399;
  385. }
  386. .empty-tip i {
  387. font-size: 48px;
  388. margin-bottom: 10px;
  389. color: #dcdfe6;
  390. }
  391. </style>