小说网站前端代码仓库
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.

376 lines
12 KiB

  1. <template>
  2. <div class="ranking-container">
  3. <div class="content-wrapper">
  4. <!-- 左侧榜单导航 -->
  5. <div class="ranking-sidebar">
  6. <ul class="ranking-nav">
  7. <li v-for="(name, id) in rankingTypes" :key="id" :class="{ active: id === currentRankingType }"
  8. @click="switchRankingType(id)">
  9. {{ name }}
  10. </li>
  11. </ul>
  12. </div>
  13. <!-- 右侧内容区 -->
  14. <div class="ranking-content">
  15. <!-- 顶部分类导航 -->
  16. <div class="category-tabs">
  17. <ul class="category-nav">
  18. <li v-for="(name, id) in categoryMap" :key="id" :class="{ active: id === currentCategoryId }"
  19. @click="switchCategory(id)">
  20. {{ name }}
  21. </li>
  22. </ul>
  23. </div>
  24. <!-- 书籍列表 -->
  25. <div class="book-list-container">
  26. <div v-for="(book, index) in books" :key="index" class="book-item">
  27. <div class="rank-number" :class="{
  28. 'rank-first': index === 0,
  29. 'rank-second': index === 1,
  30. 'rank-third': index === 2
  31. }">{{ index + 1 }}</div>
  32. <book-card :book="book" />
  33. </div>
  34. </div>
  35. <!-- 分页 -->
  36. <div class="pagination-container">
  37. <el-pagination v-model:current-page="currentPage" :page-size="pageSize" :total="total"
  38. layout="prev, pager, next" @current-change="handlePageChange" />
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. import { ref, reactive, onMounted, computed } from 'vue';
  46. import { useRoute, useRouter } from 'vue-router';
  47. import BookCard from '@/components/common/BookCard.vue';
  48. export default {
  49. name: 'RankingView',
  50. components: {
  51. BookCard
  52. },
  53. setup() {
  54. const route = useRoute();
  55. const router = useRouter();
  56. const categoryId = computed(() => route.params.id);
  57. const currentCategoryId = ref(categoryId.value || '1');
  58. // 计算是否有路由ID参数
  59. const hasRouteId = computed(() => !!categoryId.value);
  60. // 分页相关
  61. const currentPage = ref(1);
  62. const pageSize = ref(20);
  63. const total = ref(100);
  64. // 分类名称映射
  65. const categoryMap = {
  66. '1': '武侠',
  67. '2': '都市',
  68. '3': '玄幻',
  69. '4': '历史',
  70. '5': '浪漫青春',
  71. '6': '短篇',
  72. '7': '言情',
  73. '8': '小说'
  74. };
  75. // 榜单类型
  76. const rankingTypes = {
  77. '1': '推荐榜',
  78. '2': '完本榜',
  79. '3': '阅读榜',
  80. '4': '口碑榜',
  81. '5': '新书榜',
  82. '6': '高分榜'
  83. };
  84. const currentRankingType = ref('1');
  85. // 计算当前分类名称
  86. const categoryName = computed(() => categoryMap[currentCategoryId.value] || '玄幻类');
  87. // 模拟书籍数据
  88. const books = reactive([
  89. {
  90. id: '1',
  91. title: '大宋好厨夫',
  92. author: '祝家大郎',
  93. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  94. description: '书友群:638781087智慧老猿经过了北宋水浒世界,变成了那个被孙二娘三拳打死的张青',
  95. status: '已完结'
  96. },
  97. {
  98. id: '2',
  99. title: '重生日本当厨神',
  100. author: '千回转',
  101. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  102. description: '作死一次安然,宁原吃料理到撑死的复仇,来到一个他完全陌生的食林之中',
  103. status: '已完结'
  104. },
  105. {
  106. id: '3',
  107. title: '罗修炎月儿武道大帝',
  108. author: '忘情至尊',
  109. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  110. description: '关于武道大帝:少年罗修出身寒微,天赋一般,却意外觅得奇遇本末逆转',
  111. status: '已完结'
  112. },
  113. {
  114. id: '4',
  115. title: '神豪无极限',
  116. author: '匿名',
  117. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  118. description: '穿越到平行时空的陆安打了个响指,开启了全新的生活方式,他说,其实掐的',
  119. status: '已完结'
  120. },
  121. {
  122. id: '5',
  123. title: '顾道长生',
  124. author: '睡觉变白',
  125. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  126. description: '本以为是写实的都市生活,结果一言不合就修仙!灵气复苏,道法重现,这',
  127. status: '已完结'
  128. },
  129. {
  130. id: '6',
  131. title: '魔天记',
  132. author: '忘语',
  133. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  134. description: '一名在无数岁月中中长大的亡魂少年,一个与魂并立的时代,一个个可以仿佛',
  135. status: '已完结'
  136. },
  137. {
  138. id: '7',
  139. title: '二十面骰子',
  140. author: '赛斯',
  141. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  142. description: '在整千七朝由感转化的时代,新大陆的出现成为各种族冒险争夺的乐园,延',
  143. status: '已完结'
  144. },
  145. {
  146. id: '8',
  147. title: '苏莫是什么小说',
  148. author: '半代溜王',
  149. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  150. description: '苏莫少年苏莫,突破逆天武魂,却被认为是最低级的垃圾武魂,受尽屈辱…',
  151. status: '已完结'
  152. },
  153. {
  154. id: '9',
  155. title: '重生大明当暴君',
  156. author: '圆溜溜',
  157. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  158. description: '你以为你请我建设好,联不如意?你以为你随商宰,联不如意?东南富庶,而',
  159. status: '已完结'
  160. },
  161. {
  162. id: '10',
  163. title: '重生大明当暴君',
  164. author: '圆溜溜',
  165. cover: 'https://bookcover.yuewen.com/qdbimg/349573/1041637443/150.webp',
  166. description: '你以为你请我建设好,联不如意?你以为你随商宰,联不如意?东南富庶,而',
  167. status: '已完结'
  168. }
  169. ]);
  170. // 切换分类
  171. const switchCategory = (id) => {
  172. currentCategoryId.value = id;
  173. currentPage.value = 1;
  174. // 实际应用中这里应该调用API获取对应分类的书籍
  175. console.log('切换到分类:', id);
  176. };
  177. // 切换榜单类型
  178. const switchRankingType = (id) => {
  179. currentRankingType.value = id;
  180. currentPage.value = 1;
  181. // 实际应用中这里应该调用API获取对应榜单的书籍
  182. console.log('切换到榜单:', id);
  183. };
  184. const handlePageChange = (page) => {
  185. currentPage.value = page;
  186. // 这里应该调用API获取对应页码的数据
  187. console.log('切换到页码:', page);
  188. };
  189. onMounted(() => {
  190. if (categoryId.value) {
  191. currentCategoryId.value = categoryId.value;
  192. }
  193. // 实际应用中这里应该根据分类ID从API获取书籍列表
  194. console.log('加载分类ID:', currentCategoryId.value);
  195. });
  196. return {
  197. categoryName,
  198. categoryMap,
  199. books,
  200. currentPage,
  201. pageSize,
  202. total,
  203. handlePageChange,
  204. currentCategoryId,
  205. switchCategory,
  206. hasRouteId,
  207. rankingTypes,
  208. currentRankingType,
  209. switchRankingType
  210. };
  211. }
  212. };
  213. </script>
  214. <style lang="scss" scoped>
  215. @use '@/assets/styles/variables.scss' as vars;
  216. .ranking-container {
  217. width: 100%;
  218. background-color: #fff;
  219. }
  220. .content-wrapper {
  221. display: flex;
  222. gap: 20px;
  223. }
  224. // 左侧榜单导航
  225. .ranking-sidebar {
  226. width: 120px;
  227. flex-shrink: 0;
  228. background-color: #f8f8f8;
  229. border-radius: 4px;
  230. .ranking-nav {
  231. list-style: none;
  232. padding: 0;
  233. margin: 0;
  234. li {
  235. padding: 12px 15px;
  236. font-size: 14px;
  237. cursor: pointer;
  238. border-left: 3px solid transparent;
  239. transition: all 0.3s;
  240. &:hover {
  241. background-color: #f0f0f0;
  242. color: vars.$primary-color;
  243. }
  244. &.active {
  245. background-color: #e8f1ff;
  246. color: vars.$primary-color;
  247. border-left-color: vars.$primary-color;
  248. font-weight: bold;
  249. }
  250. }
  251. }
  252. }
  253. // 右侧内容区
  254. .ranking-content {
  255. flex: 1;
  256. min-width: 0;
  257. }
  258. // 顶部分类导航
  259. .category-tabs {
  260. width: 100%;
  261. background-color: #fff;
  262. border-bottom: 1px solid #eee;
  263. padding: 0 20px;
  264. .category-nav {
  265. list-style: none;
  266. padding: 0;
  267. margin: 0;
  268. display: flex;
  269. flex-wrap: wrap;
  270. li {
  271. padding: 15px 20px;
  272. font-size: 16px;
  273. cursor: pointer;
  274. position: relative;
  275. transition: all 0.3s;
  276. &:hover {
  277. color: vars.$primary-color;
  278. }
  279. &.active {
  280. color: vars.$primary-color;
  281. font-weight: bold;
  282. &::after {
  283. content: '';
  284. position: absolute;
  285. bottom: 0;
  286. left: 50%;
  287. transform: translateX(-50%);
  288. width: 30px;
  289. height: 3px;
  290. background-color: vars.$primary-color;
  291. }
  292. }
  293. }
  294. }
  295. }
  296. .book-list-container {
  297. display: flex;
  298. flex-direction: column;
  299. gap: 15px;
  300. margin-bottom: 30px;
  301. padding: 20px;
  302. }
  303. .book-item {
  304. display: flex;
  305. align-items: center;
  306. border-bottom: 1px solid #f0f0f0;
  307. padding-bottom: 15px;
  308. position: relative;
  309. }
  310. .rank-number {
  311. width: 24px;
  312. height: 24px;
  313. display: flex;
  314. justify-content: center;
  315. align-items: center;
  316. background-color: #ddd;
  317. color: #fff;
  318. font-weight: bold;
  319. border-radius: 4px;
  320. margin-right: 15px;
  321. flex-shrink: 0;
  322. // 前三名特殊样式
  323. &.rank-first {
  324. background-color: #e74c3c;
  325. }
  326. &.rank-second {
  327. background-color: #f39c12;
  328. }
  329. &.rank-third {
  330. background-color: #2ecc71;
  331. }
  332. }
  333. .pagination-container {
  334. display: flex;
  335. justify-content: center;
  336. padding: 20px 0;
  337. }
  338. </style>