reading-rank.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航栏 -->
  4. <view class="top-header">
  5. <view class="back-btn" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <view class="tabs-primary">
  9. <view
  10. class="tab-item"
  11. :class="{ active: currentBookType === 'ebook' }"
  12. @click="switchBookType('ebook')"
  13. >
  14. <text class="tab-text">电子书</text>
  15. </view>
  16. <view
  17. class="tab-item"
  18. :class="{ active: currentBookType === 'audiobook' }"
  19. @click="switchBookType('audiobook')"
  20. >
  21. <text class="tab-text">有声书</text>
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 第二行标签 -->
  26. <view class="tabs-secondary">
  27. <view
  28. class="tab-item-secondary"
  29. :class="{ active: currentPeriod === 'today' }"
  30. @click="switchPeriod('today')"
  31. >
  32. <text class="tab-text-secondary">今天</text>
  33. </view>
  34. <view
  35. class="tab-item-secondary"
  36. :class="{ active: currentPeriod === 'week' }"
  37. @click="switchPeriod('week')"
  38. >
  39. <text class="tab-text-secondary">本周</text>
  40. </view>
  41. </view>
  42. <scroll-view class="scroll-content" scroll-y>
  43. <!-- 前三名 -->
  44. <view class="top-three-section">
  45. <view
  46. class="top-three-item rank-2"
  47. >
  48. <image class="top-avatar" :src="topThree[0].avatar" mode="aspectFill"></image>
  49. <text class="top-name">{{ topThree[0].name }}</text>
  50. <text class="top-rank">{{ topThree[0].rank }}</text>
  51. </view>
  52. <view
  53. class="top-three-item rank-1"
  54. >
  55. <image class="top-avatar" :src="topThree[1].avatar" mode="aspectFill"></image>
  56. <text class="top-name">{{ topThree[1].name }}</text>
  57. <text class="top-rank">{{ topThree[1].rank }}</text>
  58. </view>
  59. <view
  60. class="top-three-item rank-3"
  61. >
  62. <image class="top-avatar" :src="topThree[2].avatar" mode="aspectFill"></image>
  63. <text class="top-name">{{ topThree[2].name }}</text>
  64. <text class="top-rank">{{ topThree[2].rank }}</text>
  65. </view>
  66. </view>
  67. <!-- 排名列表4-10 -->
  68. <view class="rank-list">
  69. <view
  70. class="rank-item"
  71. v-for="(user, index) in rankList"
  72. :key="index"
  73. >
  74. <text class="rank-number">{{ user.rank }}</text>
  75. <image class="rank-avatar" :src="user.avatar" mode="aspectFill"></image>
  76. <text class="rank-name">{{ user.name }}</text>
  77. <text class="rank-duration">{{ user.duration }}</text>
  78. </view>
  79. </view>
  80. <!-- 用户自己的排名 -->
  81. <view class="user-rank-section">
  82. <text class="user-rank-label">未上榜</text>
  83. <image class="user-rank-avatar" :src="userRank.avatar" mode="aspectFill"></image>
  84. <text class="user-rank-name">我</text>
  85. <text class="user-rank-duration">{{ userRank.duration }}</text>
  86. </view>
  87. </scroll-view>
  88. </view>
  89. </template>
  90. <script>
  91. export default {
  92. data() {
  93. const getRandomImage = (seed) => {
  94. return `https://picsum.photos/seed/${seed}/200/200`;
  95. };
  96. return {
  97. currentBookType: 'ebook', // ebook, audiobook
  98. currentPeriod: 'today', // today, week
  99. topThree: [
  100. {
  101. rank: 2,
  102. name: '郭德纲',
  103. avatar: getRandomImage('rank2')
  104. },
  105. {
  106. rank: 1,
  107. name: '郭德纲',
  108. avatar: getRandomImage('rank1')
  109. },
  110. {
  111. rank: 3,
  112. name: '郭德纲',
  113. avatar: getRandomImage('rank3')
  114. }
  115. ],
  116. rankList: [
  117. {
  118. rank: 4,
  119. name: '郭德纲',
  120. avatar: getRandomImage('rank4'),
  121. duration: '8小时'
  122. },
  123. {
  124. rank: 5,
  125. name: '郭德纲',
  126. avatar: getRandomImage('rank5'),
  127. duration: '8小时'
  128. },
  129. {
  130. rank: 6,
  131. name: '郭德纲',
  132. avatar: getRandomImage('rank6'),
  133. duration: '8小时'
  134. },
  135. {
  136. rank: 7,
  137. name: '郭德纲',
  138. avatar: getRandomImage('rank7'),
  139. duration: '8小时'
  140. },
  141. {
  142. rank: 8,
  143. name: '郭德纲',
  144. avatar: getRandomImage('rank8'),
  145. duration: '8小时'
  146. },
  147. {
  148. rank: 9,
  149. name: '郭德纲',
  150. avatar: getRandomImage('rank9'),
  151. duration: '8小时'
  152. },
  153. {
  154. rank: 10,
  155. name: '郭德纲',
  156. avatar: getRandomImage('rank10'),
  157. duration: '8小时'
  158. }
  159. ],
  160. userRank: {
  161. avatar: getRandomImage('user'),
  162. duration: '1小时'
  163. }
  164. }
  165. },
  166. methods: {
  167. goBack() {
  168. uni.navigateBack()
  169. },
  170. switchBookType(type) {
  171. this.currentBookType = type
  172. // 切换类型时可以重新加载数据
  173. this.loadRankData()
  174. },
  175. switchPeriod(period) {
  176. this.currentPeriod = period
  177. // 切换时间段时可以重新加载数据
  178. this.loadRankData()
  179. },
  180. loadRankData() {
  181. // 根据当前选择的类型和时间段加载排行榜数据
  182. // 这里可以调用API获取数据
  183. uni.showToast({
  184. title: `加载${this.currentBookType === 'ebook' ? '电子书' : '有声书'}${this.currentPeriod === 'today' ? '今天' : '本周'}排行榜`,
  185. icon: 'none'
  186. })
  187. }
  188. }
  189. }
  190. </script>
  191. <style scoped>
  192. .container {
  193. width: 100%;
  194. height: 100vh;
  195. background-color: #FFFFFF;
  196. display: flex;
  197. flex-direction: column;
  198. padding-top: 30px;
  199. box-sizing: border-box;
  200. }
  201. .top-header {
  202. display: flex;
  203. align-items: center;
  204. padding: 20rpx 30rpx;
  205. background-color: #81C784;
  206. position: relative;
  207. }
  208. .back-btn {
  209. width: 60rpx;
  210. height: 60rpx;
  211. display: flex;
  212. align-items: center;
  213. justify-content: center;
  214. margin-right: 20rpx;
  215. }
  216. .back-icon {
  217. font-size: 40rpx;
  218. color: #FFFFFF;
  219. font-weight: bold;
  220. }
  221. .tabs-primary {
  222. flex: 1;
  223. display: flex;
  224. background-color: rgba(255, 255, 255, 0.2);
  225. border-radius: 30rpx;
  226. padding: 4rpx;
  227. }
  228. .tab-item {
  229. flex: 1;
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. padding: 12rpx 0;
  234. border-radius: 26rpx;
  235. transition: all 0.3s;
  236. }
  237. .tab-item.active {
  238. background-color: #FFFFFF;
  239. }
  240. .tab-item.active .tab-text {
  241. color: #333333;
  242. font-weight: bold;
  243. }
  244. .tab-text {
  245. font-size: 28rpx;
  246. color: #FFFFFF;
  247. }
  248. .tabs-secondary {
  249. display: flex;
  250. background-color: #FFFFFF;
  251. padding: 0 30rpx;
  252. border-bottom: 1rpx solid #F0F0F0;
  253. }
  254. .tab-item-secondary {
  255. padding: 20rpx 40rpx;
  256. position: relative;
  257. }
  258. .tab-item-secondary.active .tab-text-secondary {
  259. color: #333333;
  260. font-weight: bold;
  261. }
  262. .tab-item-secondary.active::after {
  263. content: '';
  264. position: absolute;
  265. bottom: 0;
  266. left: 50%;
  267. transform: translateX(-50%);
  268. width: 60rpx;
  269. height: 4rpx;
  270. background-color: #81C784;
  271. border-radius: 2rpx;
  272. }
  273. .tab-text-secondary {
  274. font-size: 28rpx;
  275. color: #999999;
  276. }
  277. .scroll-content {
  278. flex: 1;
  279. width: 100%;
  280. background-color: #FFFFFF;
  281. padding-bottom: env(safe-area-inset-bottom);
  282. }
  283. .top-three-section {
  284. display: flex;
  285. justify-content: space-around;
  286. align-items: flex-end;
  287. padding: 60rpx 30rpx 40rpx;
  288. background-color: #FFFFFF;
  289. }
  290. .top-three-item {
  291. display: flex;
  292. flex-direction: column;
  293. align-items: center;
  294. }
  295. .top-three-item.rank-1 {
  296. order: 2;
  297. transform: scale(1.1);
  298. }
  299. .top-three-item.rank-2 {
  300. order: 1;
  301. }
  302. .top-three-item.rank-3 {
  303. order: 3;
  304. }
  305. .top-avatar {
  306. width: 140rpx;
  307. height: 140rpx;
  308. border-radius: 50%;
  309. margin-bottom: 20rpx;
  310. background-color: #F5F5F5;
  311. border: 4rpx solid #81C784;
  312. }
  313. .top-three-item.rank-1 .top-avatar {
  314. width: 160rpx;
  315. height: 160rpx;
  316. border-color: #FFD700;
  317. }
  318. .top-name {
  319. font-size: 28rpx;
  320. color: #333333;
  321. margin-bottom: 10rpx;
  322. font-weight: bold;
  323. }
  324. .top-rank {
  325. font-size: 36rpx;
  326. color: #333333;
  327. font-weight: bold;
  328. }
  329. .top-three-item.rank-1 .top-rank {
  330. font-size: 48rpx;
  331. color: #FFD700;
  332. }
  333. .rank-list {
  334. padding: 0 30rpx;
  335. background-color: #FFFFFF;
  336. }
  337. .rank-item {
  338. display: flex;
  339. align-items: center;
  340. padding: 25rpx 0;
  341. border-bottom: 1rpx solid #F0F0F0;
  342. }
  343. .rank-item:last-child {
  344. border-bottom: none;
  345. }
  346. .rank-number {
  347. font-size: 32rpx;
  348. font-weight: bold;
  349. color: #333333;
  350. width: 60rpx;
  351. text-align: center;
  352. }
  353. .rank-avatar {
  354. width: 80rpx;
  355. height: 80rpx;
  356. border-radius: 50%;
  357. margin-right: 20rpx;
  358. background-color: #F5F5F5;
  359. }
  360. .rank-name {
  361. flex: 1;
  362. font-size: 30rpx;
  363. color: #333333;
  364. }
  365. .rank-duration {
  366. font-size: 26rpx;
  367. color: #999999;
  368. }
  369. .user-rank-section {
  370. display: flex;
  371. align-items: center;
  372. padding: 30rpx;
  373. background-color: #F5F5F5;
  374. margin-top: 20rpx;
  375. }
  376. .user-rank-label {
  377. font-size: 28rpx;
  378. color: #666666;
  379. width: 120rpx;
  380. }
  381. .user-rank-avatar {
  382. width: 80rpx;
  383. height: 80rpx;
  384. border-radius: 50%;
  385. margin-right: 20rpx;
  386. background-color: #FFFFFF;
  387. }
  388. .user-rank-name {
  389. flex: 1;
  390. font-size: 30rpx;
  391. color: #333333;
  392. }
  393. .user-rank-duration {
  394. font-size: 26rpx;
  395. color: #999999;
  396. }
  397. </style>