Collection.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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) => {
  62. list.value = []
  63. form.value.pageNum = page;
  64. getList()
  65. }
  66. // 跳转详情
  67. const toDetail = (item: any) => {
  68. router.push({
  69. path: `/learning-system/detail/${item.objectId}/course/${item.objectId}`,
  70. query: {
  71. courseId: item.objectId,
  72. metaTitle: item.courseTitle || '课程详情'
  73. }
  74. })
  75. }
  76. onMounted(() => {
  77. getList()
  78. })
  79. </script>
  80. <style scoped lang="scss">
  81. .collection {
  82. padding-bottom: 20px;
  83. .title {
  84. height: 60px;
  85. font-size: 20px;
  86. font-weight: bold;
  87. color: #333333;
  88. }
  89. .collection-list {
  90. .li {
  91. padding: 16px;
  92. margin-bottom: 16px;
  93. background: #F5F7FA;
  94. border-radius: 16px;
  95. &:last-child {
  96. margin-bottom: 0;
  97. }
  98. .image {
  99. width: 213px;
  100. height: 120px;
  101. object-fit: cover;
  102. border-radius: 8px;
  103. margin-right: 16px;
  104. }
  105. .collection-list-main {
  106. flex: 1;
  107. display: flex;
  108. align-items: center;
  109. justify-content: space-between;
  110. .collection-list-main-left {
  111. flex: 1;
  112. margin-right: 16px;
  113. .titles {
  114. font-size: 18px;
  115. font-weight: bold;
  116. color: #333333;
  117. }
  118. .tag {
  119. margin: 8px 0;
  120. }
  121. .content {
  122. color: #666666;
  123. font-size: 14px;
  124. line-height: 22px;
  125. }
  126. }
  127. .btn {
  128. width: 120px;
  129. height: 32px;
  130. color: #FFFFFF;
  131. font-size: 14px;
  132. cursor: pointer;
  133. background: linear-gradient(270deg, #0055FE 0%, #C832FA 100%);
  134. border-radius: 4px;
  135. &:hover {
  136. opacity: 0.7;
  137. }
  138. img {
  139. width: 14px;
  140. height: 14px;
  141. margin-right: 4px;
  142. }
  143. }
  144. .active {
  145. background: #FFFFFF;
  146. color: #2D71FF;
  147. }
  148. }
  149. }
  150. }
  151. }
  152. </style>