Recommend.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <script setup>
  2. import { ref, onMounted } from "vue";
  3. import { Refresh } from "@element-plus/icons-vue";
  4. import SvgIcon from "~/components/SvgIcon/index.vue";
  5. import * as topicApi from "~/api/topic";
  6. import { useRouter } from "vue-router";
  7. const router = useRouter();
  8. const list = ref([]);
  9. const page = ref(1);
  10. const total = ref(0);
  11. const last_page = ref(0);
  12. const __list__ = async () => {
  13. try {
  14. const { data } = await topicApi.list({
  15. page: page.value,
  16. limit: 10,
  17. is_recommend: 1,
  18. });
  19. list.value = data.list;
  20. total.value = data.total;
  21. last_page.value = data.last_page;
  22. } catch (error) {}
  23. };
  24. onMounted(__list__);
  25. //换一页
  26. const next = () => {
  27. if (last_page.value == 1) {
  28. ElMessage.warning({
  29. message: "当前已是最新页",
  30. type: "warning",
  31. });
  32. } else if (last_page.value == page.value) {
  33. page.value = 1;
  34. } else {
  35. page.value++;
  36. }
  37. __list__();
  38. };
  39. //跳转到该话题
  40. const topicinfo = (item) => {
  41. router.push({
  42. path: "/forum/topic/:id",
  43. query: {
  44. id: item.id,
  45. title:item.title,
  46. description:item.description
  47. },
  48. });
  49. };
  50. </script>
  51. <template>
  52. <div class="recommend-container">
  53. <div class="heade flex-row flex-aic flex-jc-sb">
  54. <div class="title flex-row flex-aic">
  55. <SvgIcon name="fire" :size="18" color="rgba(255, 81, 21, 1)" />
  56. 忆象推荐
  57. </div>
  58. <div class="more flex-row flex-aic" @click="next" style="cursor: pointer">
  59. <el-icon :size="16">
  60. <Refresh />
  61. </el-icon>
  62. 换一批
  63. </div>
  64. </div>
  65. <div class="main">
  66. <ul class="">
  67. <li
  68. @click="topicinfo(item)"
  69. v-for="(item, idx) in list"
  70. :key="idx"
  71. class="flex-row flex-aic"
  72. style="cursor: pointer"
  73. >
  74. <span :class="['idx', idx <= 2 ? `idx--${idx + 1}` : '']">{{
  75. 1 + idx
  76. }}</span>
  77. <div class="desc ellipsis">{{ item.title }}</div>
  78. </li>
  79. </ul>
  80. </div>
  81. </div>
  82. </template>
  83. <style lang="scss" scoped>
  84. .recommend-container {
  85. padding: 16px;
  86. background-color: #fff;
  87. border-radius: 6px;
  88. .heade {
  89. padding-top: 12px;
  90. padding-bottom: 16px;
  91. .title {
  92. font-weight: 500;
  93. color: #333333;
  94. line-height: 22px;
  95. }
  96. .more {
  97. font-size: 12px;
  98. font-weight: 400;
  99. color: #777777;
  100. line-height: 17px;
  101. .el-icon {
  102. margin-right: 3px;
  103. }
  104. }
  105. }
  106. .main {
  107. ul {
  108. list-style: none;
  109. padding: 0;
  110. margin: 0;
  111. }
  112. li {
  113. line-height: 38px;
  114. .idx {
  115. width: 16px;
  116. text-align: center;
  117. margin-right: 10px;
  118. font-size: 18px;
  119. font-weight: 600;
  120. color: #c0c0c0;
  121. &--1 {
  122. color: #e02020;
  123. }
  124. &--2 {
  125. color: #ff5115;
  126. }
  127. &--3 {
  128. color: #f7b500;
  129. }
  130. }
  131. .desc {
  132. width: 0;
  133. flex: 1;
  134. font-size: 14px;
  135. font-family: AppleColorEmoji;
  136. color: #444444;
  137. }
  138. }
  139. }
  140. }
  141. </style>