You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
6.8 KiB

8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
8 months ago
7 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
7 months ago
8 months ago
8 months ago
8 months ago
  1. <template>
  2. <div class="main">
  3. <div class="mainContent" v-for="article in diarylist">
  4. <a-badge-ribbon :text=article.typename color="black">
  5. <a-card hoverable>
  6. <h2>{{ article.diarytitle }}</h2>
  7. <div class="tag-group">
  8. <a-tag color="#E6E6FA">
  9. <template #icon>
  10. <component :is=iconComponents.RiLiLined />
  11. </template>
  12. {{ article.create_at }}
  13. </a-tag>
  14. <a-tag color="#6495ED">
  15. <template #icon>
  16. <component :is=iconComponents.YanJingLined />
  17. </template>
  18. {{ article.readnum }}
  19. </a-tag>
  20. <a-tag color="#B0C4DE">
  21. <template #icon>
  22. <component :is=iconComponents.XieZiLined />
  23. </template>
  24. 字数{{ article.wordcount }}
  25. </a-tag>
  26. <a-tag color="#20B2AA">
  27. <template #icon>
  28. <component :is=iconComponents.YueDuLined />
  29. </template>
  30. 阅读时长{{ article.readminite }}
  31. </a-tag>
  32. </div>
  33. <div class="blog-content">
  34. <div class="image-container">
  35. <a-image :preview="false" :src=article.imglink class="responsive-image"/>
  36. </div>
  37. </div>
  38. <div class="read-button">
  39. <a-button type="primary" shape="round" @click="readMore(article.id)">阅读全文</a-button>
  40. </div>
  41. </a-card>
  42. </a-badge-ribbon>
  43. </div>
  44. <div class="pagination" v-if="diarystore.isPage">
  45. <a-pagination v-model:current="current" v-if="dataLoaded" v-model:page-size="pageSizeRef"
  46. :page-size-options="pageSizeOptions" :total="total" show-size-changer @change="onShowSizeChange">
  47. <template #buildOptionText="props">
  48. <span v-if="props.value !== '50'">{{ props.value }}/</span>
  49. <span v-else>全部</span>
  50. </template>
  51. </a-pagination>
  52. </div>
  53. <div class="is-null" v-if="diarystore.isEmpty">
  54. <a-card hoverable>
  55. <a-empty description="没有数据" />
  56. </a-card>
  57. </div>
  58. </div>
  59. </template>
  60. <script setup lang='ts'>
  61. import { onMounted, ref } from 'vue';
  62. import iconComponents from '@/assets';
  63. import dayjs from 'dayjs';
  64. import type { diaryInterface } from '@/api/admin';
  65. import { get,put } from "@/tools/request"
  66. import { diaryStore } from "@/stores"
  67. import router from '@/router';
  68. const diarystore = diaryStore()
  69. const dataLoaded = ref(false);
  70. // 分页
  71. const pageSizeOptions = ref<string[]>(['10', '20', '30', '40', '50']);
  72. const current = ref(1);
  73. const total = ref();
  74. const pageSizeRef = ref(10);
  75. const onShowSizeChange = (page: number) => {
  76. current.value = page;
  77. diaryList(page, pageSizeRef.value)
  78. };
  79. const diaryCount=async (id:any)=>{
  80. await put(`/diarys/update/${id}/readnum`)
  81. }
  82. const diarylist = ref<diaryInterface[]>([])
  83. const diaryList = async (page: number, pageSize: number) => {
  84. try {
  85. const response = await get('/diarys/list', {
  86. page,
  87. page_size: pageSize,
  88. });
  89. diarylist.value = response.data.data.diarys.map((items: any, index: number) => ({
  90. id: items.id,
  91. key: items.key,
  92. diarytitle: items.diarytitle,
  93. diarycontent: items.diarycontent,
  94. typename: items.typename,
  95. wordcount: items.diarycontent.length,
  96. create_at: dayjs(items.create_at).format('YYYY-MM-DD HH:mm:ss'),
  97. update_at: dayjs(items.update_at).format('YYYY-MM-DD HH:mm:ss'),
  98. readnum: items.readnum,
  99. readminite: Math.round(items.diarycontent.length/ 200),
  100. imglink: items.imglink || 'http://www.wuruilin.cn/personself/暂无图片.jpg',
  101. }));
  102. total.value = response.data.data.total; // 更新总数
  103. if (response.data.data.total===0) {
  104. diarystore.isEmpty=true,
  105. diarystore.isPage=false
  106. }else{
  107. diarystore.isEmpty=false,
  108. diarystore.isPage=true
  109. }
  110. pageSizeRef.value = pageSize; // 更新页大小,如果需要从接口返回页大小也可以改为 response.data.data.page_size
  111. dataLoaded.value = true
  112. } catch (error) {
  113. console.error('Failed to fetch data', error);
  114. }
  115. };
  116. const readMore = (id: any) => {
  117. router.push(`/diary/${id}`)
  118. diaryCount(id)
  119. }
  120. onMounted(() => {
  121. diaryList(current.value, pageSizeRef.value);
  122. });
  123. </script>
  124. <style scoped>
  125. .main {
  126. width: 45%;
  127. margin: 0 24px;
  128. }
  129. /* .main h2 {
  130. text-align: center;
  131. } */
  132. .main .mainContent {
  133. margin-bottom: 24px;
  134. }
  135. .main h2 {
  136. text-align: center;
  137. }
  138. .main .tag-group {
  139. display: flex;
  140. justify-content: center;
  141. }
  142. .main .tag-group>* {
  143. color: black;
  144. margin: 0 12px;
  145. }
  146. .main .blog-content {
  147. display: flex;
  148. margin: 48px;
  149. }
  150. .main .blog-content>:first-child {
  151. padding: 4px;
  152. border: 2px solid #ccc;
  153. display: inline-block;
  154. border-radius: 10px;
  155. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  156. }
  157. .main .blog-content>:nth-child(2) {
  158. overflow: hidden;
  159. text-overflow: ellipsis;
  160. white-space: pre-wrap;
  161. /* 防止文本换行 */
  162. }
  163. .diarys .image-container {
  164. width: 1000px;
  165. }
  166. .diarys .responsive-image {
  167. width: 100%;
  168. height: auto;
  169. }
  170. .main .read-button {
  171. display: flex;
  172. justify-content: center;
  173. }
  174. .main .read-button button {
  175. color: #fff;
  176. border: none;
  177. cursor: pointer;
  178. background-color: #007bff;
  179. /* 初始背景颜色 */
  180. animation: colorChange 3s infinite alternate;
  181. /* 添加颜色变化的动画 */
  182. }
  183. .custom-line {
  184. border: 0;
  185. height: 1px;
  186. background: #d9d6d6;
  187. margin: 48px 0 24px 0;
  188. }
  189. @keyframes colorChange {
  190. 0% {
  191. background-color: #007bff;
  192. /* 初始颜色 */
  193. }
  194. 50% {
  195. background-color: #ff7e5f;
  196. /* 中间颜色 */
  197. }
  198. 100% {
  199. background-color: #feb47b;
  200. /* 结束颜色 */
  201. }
  202. }
  203. .main .text-container {
  204. text-overflow: ellipsis;
  205. display: -webkit-box;
  206. -webkit-box-orient: vertical;
  207. -webkit-line-clamp: 6;
  208. word-wrap: break-word;
  209. overflow-wrap: break-word;
  210. line-height: 2;
  211. margin-left: 24px;
  212. }
  213. .pagination {
  214. margin-bottom: 24px;
  215. display: flex;
  216. justify-content: right;
  217. }
  218. </style>