Collection.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. <ul class="collection-list">
  8. <li class="flex-center-between" 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="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. </li>
  24. </ul>
  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. const form = ref({
  41. pageNum: 1,
  42. pageSize: 10,
  43. total: 0
  44. })
  45. const list = ref([])
  46. // 取消收藏
  47. const cancelCollect = async (item, index) => {
  48. let res = await collect({ objectId: item.objectId });
  49. DGTMessage.success(`${t('common.unCollect')}${t('common.success')}`)
  50. getList()
  51. }
  52. const getList = async () => {
  53. let res = await collectList(form.value);
  54. console.log(res);
  55. form.value.total = res.total;
  56. list.value = res.rows
  57. }
  58. const handlePageChange = (page) => {
  59. list.value = []
  60. form.value.pageNum = page;
  61. getList()
  62. }
  63. onMounted(() => {
  64. getList()
  65. })
  66. </script>
  67. <style scoped lang="scss">
  68. .collection {
  69. padding-bottom: 20px;
  70. .title {
  71. height: 60px;
  72. font-size: 20px;
  73. font-weight: bold;
  74. color: #333333;
  75. }
  76. .collection-list {
  77. li {
  78. padding: 16px;
  79. margin-bottom: 16px;
  80. background: #F5F7FA;
  81. border-radius: 16px;
  82. &:last-child {
  83. margin-bottom: 0;
  84. }
  85. .image {
  86. width: 213px;
  87. height: 120px;
  88. object-fit: cover;
  89. border-radius: 8px;
  90. margin-right: 16px;
  91. }
  92. .collection-list-main {
  93. flex: 1;
  94. display: flex;
  95. align-items: center;
  96. justify-content: space-between;
  97. .collection-list-main-left {
  98. flex: 1;
  99. margin-right: 16px;
  100. .titles {
  101. font-size: 18px;
  102. font-weight: bold;
  103. color: #333333;
  104. }
  105. .tag {
  106. margin: 8px 0;
  107. }
  108. .content {
  109. color: #666666;
  110. font-size: 14px;
  111. line-height: 22px;
  112. }
  113. }
  114. .btn {
  115. width: 120px;
  116. height: 32px;
  117. color: #FFFFFF;
  118. font-size: 14px;
  119. cursor: pointer;
  120. background: linear-gradient(270deg, #0055FE 0%, #C832FA 100%);
  121. border-radius: 4px;
  122. &:hover {
  123. opacity: 0.7;
  124. }
  125. img {
  126. width: 14px;
  127. height: 14px;
  128. margin-right: 4px;
  129. }
  130. }
  131. .active {
  132. background: #FFFFFF;
  133. color: #2D71FF;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. </style>