Collection.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="collection">
  3. <div class="gap10 title">
  4. <div class="line_vertical"></div>
  5. <div class="">{{ $t('personalCenter.myCollection') }}</div>
  6. </div>
  7. <div class="collection-list">
  8. <div @click.prevent="toDetail(item)" class="flex-center-between li" v-for="(item, index) in list" :key="index">
  9. <img class="image" :src="item.coverImageUrl" alt="">
  10. <div class="collection-list-main">
  11. <div class="collection-list-main-left">
  12. <div class="titles">{{ item.courseTitle }}</div>
  13. <div class="gap10 tag">
  14. <el-button type="primary" size="large" plain>{{ item.skillTag }}</el-button>
  15. </div>
  16. <div class="">{{ item.courseIntro }}</div>
  17. </div>
  18. <div @click.stop.prevent="cancelCollect(item, index)" class="btn flex-center active">
  19. <img src="/src/assets/imgs/my/star@2x.png" alt="">
  20. <div class="">{{ $t('common.cancelCollect') }}</div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <template v-if="list.length">
  26. <Pagination :total="form.total" :page-size="form.pageSize" :current-page="form.pageNum"
  27. @page-change="handlePageChange" />
  28. </template>
  29. <el-empty v-else :description="$t('common.empty')" />
  30. </div>
  31. </template>
  32. <script setup lang="ts">
  33. import Pagination from '@/components/Pagination.vue'
  34. import { ref, onMounted } from 'vue'
  35. import { collectList } from '@/api/my.js'
  36. import { collect } from '@/api/course'
  37. import DGTMessage from '@/utils/message'
  38. import { useI18n } from 'vue-i18n'
  39. const { t } = useI18n()
  40. import { useRouter } from 'vue-router'
  41. const router = useRouter()
  42. const form = ref({
  43. pageNum: 1,
  44. pageSize: 10,
  45. total: 0,
  46. orderByColumn: 'create_time',
  47. isAsc: 'desc'
  48. })
  49. const list = ref([])
  50. // 取消收藏
  51. const cancelCollect = async (item, index) => {
  52. let res = await collect({ objectId: item.objectId });
  53. DGTMessage.success(`${t('common.unCollect')}${t('common.success')}`)
  54. getList()
  55. }
  56. const getList = async () => {
  57. let res = await collectList(form.value);
  58. form.value.total = res.total;
  59. list.value = res.rows
  60. }
  61. const handlePageChange = (page, pageSize) => {
  62. list.value = []
  63. form.value.pageNum = page;
  64. if(pageSize)form.value.pageSize = pageSize;
  65. getList()
  66. }
  67. // 跳转详情
  68. const toDetail = (item: any) => {
  69. router.push({
  70. path: `/learning-system/detail/${item.objectId}/course/${item.objectId}`,
  71. query: {
  72. courseId: item.objectId,
  73. metaTitle: item.courseTitle || '课程详情'
  74. }
  75. })
  76. }
  77. onMounted(() => {
  78. getList()
  79. })
  80. </script>
  81. <style scoped lang="scss">
  82. .collection {
  83. padding-bottom: 20px;
  84. .title {
  85. height: 60px;
  86. font-size: 20px;
  87. font-weight: bold;
  88. color: #333333;
  89. }
  90. .collection-list {
  91. .li {
  92. padding: 16px;
  93. margin-bottom: 16px;
  94. background: #F5F7FA;
  95. border-radius: 16px;
  96. &:last-child {
  97. margin-bottom: 0;
  98. }
  99. .image {
  100. width: 213px;
  101. height: 120px;
  102. object-fit: cover;
  103. border-radius: 8px;
  104. margin-right: 16px;
  105. }
  106. .collection-list-main {
  107. flex: 1;
  108. display: flex;
  109. align-items: center;
  110. justify-content: space-between;
  111. .collection-list-main-left {
  112. flex: 1;
  113. margin-right: 16px;
  114. .titles {
  115. font-size: 18px;
  116. font-weight: bold;
  117. color: #333333;
  118. }
  119. .tag {
  120. margin: 8px 0;
  121. }
  122. .content {
  123. color: #666666;
  124. font-size: 14px;
  125. line-height: 22px;
  126. }
  127. }
  128. .btn {
  129. width: 120px;
  130. height: 32px;
  131. color: #FFFFFF;
  132. font-size: 14px;
  133. cursor: pointer;
  134. background: linear-gradient(270deg, #0055FE 0%, #C832FA 100%);
  135. border-radius: 4px;
  136. &:hover {
  137. opacity: 0.7;
  138. }
  139. img {
  140. width: 14px;
  141. height: 14px;
  142. margin-right: 4px;
  143. }
  144. }
  145. .active {
  146. background: #FFFFFF;
  147. color: #2D71FF;
  148. }
  149. }
  150. }
  151. }
  152. }
  153. </style>