图书馆小程序
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.

272 lines
7.0 KiB

2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
  1. <template>
  2. <view>
  3. <view class="ranking-header">
  4. <image
  5. class="ranking-heander-bg"
  6. src="@/static/images/ranking-bg.png"
  7. mode="aspectFill"
  8. />
  9. <view class="ranking-header-txt">
  10. <view class="ranking-title">
  11. <uni-icons custom-prefix="iconfont" type="icon-paihangbang2" size="20"></uni-icons>
  12. <text class="title-text">读者借阅排行</text>
  13. </view>
  14. <text class="ranking-header-tip">由本图书馆近30天读者借阅次数生成排行榜单</text>
  15. </view>
  16. </view>
  17. <view class="ranking-list">
  18. <!-- 空状态 -->
  19. <view class="empty-box" v-if="rankingData.length === 0">
  20. <uni-icons type="cube" size="70" color="#ccc"></uni-icons>
  21. <text>暂无读者排行数据</text>
  22. </view>
  23. <view
  24. class="ranking-item"
  25. :class="[
  26. index === 0 ? 'first-item' : '',
  27. index === 1 ? 'two-item' : '',
  28. index === 2 ? 'three-item' : ''
  29. ]"
  30. v-for="(item, index) in rankingData"
  31. :key="index"
  32. >
  33. <!-- 第一名 -->
  34. <uni-icons class="ranking-icon" v-if="index === 0" custom-prefix="iconfont" type="icon-TOP2" size="26" color="#E6CB97"></uni-icons>
  35. <!-- 第二名 -->
  36. <uni-icons class="ranking-icon" v-if="index === 1" custom-prefix="iconfont" type="icon-TOP" size="26" color="#a2b2c3"></uni-icons>
  37. <!-- 第三名 -->
  38. <uni-icons class="ranking-icon" v-if="index === 2" custom-prefix="iconfont" type="icon-TOP1" size="26" color="#D0BA9D"></uni-icons>
  39. <!-- 4~10 显示数字 -->
  40. <view v-if="index >= 3" class="ranking-common-icon">
  41. <uni-icons custom-prefix="iconfont" type="icon-tag" size="28" color="#8899ab"></uni-icons>
  42. <text class="common-num">{{ index + 1 }}</text>
  43. </view>
  44. <!-- 书籍封面 -->
  45. <view class="ranking-item-img">
  46. <image
  47. class="book-cover"
  48. :src="item.cover || defaultCover"
  49. mode="scaleToFill"
  50. @error="onImgError"
  51. />
  52. </view>
  53. <!-- 书籍信息 -->
  54. <view class="ranking-book-info">
  55. <text class="book-info-title">{{ item.TITLE || '暂无书名' }}</text>
  56. <text class="book-info-name">{{ item.AUTHOR || '佚名' }}</text>
  57. <text class="book-info-desc line-clamp-3">
  58. 借阅次数{{ item.TOTALNUM || 0 }}
  59. </text>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import { FetchInitScreenSetting } from '@/api/user';
  67. import { FetchBookRanking } from '@/api/book';
  68. import config from '@/utils/config';
  69. export default {
  70. data() {
  71. return {
  72. rankingData: [],
  73. defaultCover: '/static/images/default-book.png',
  74. };
  75. },
  76. onLoad() {
  77. this.getScreenSetting();
  78. },
  79. methods: {
  80. async getScreenSetting() {
  81. try {
  82. const res = await FetchInitScreenSetting({ libcode: config.LIB_CODE });
  83. this.getReadRanking(res.data);
  84. } catch (err) {
  85. console.error('获取屏幕配置失败:', err);
  86. }
  87. },
  88. getFormattedDate(date) {
  89. const year = date.getFullYear();
  90. const month = date.getMonth() + 1;
  91. const day = date.getDate();
  92. return `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;
  93. },
  94. getReadRanking(result) {
  95. const currentDate = new Date()
  96. currentDate.setDate(currentDate.getDate() - 30)
  97. const year = currentDate.getFullYear()
  98. const month = currentDate.getMonth() + 1
  99. const day = currentDate.getDate()
  100. const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
  101. const params = {
  102. 'libcode': config.LIB_CODE,
  103. 'starttime': formattedDate,
  104. 'endtime': this.getFormattedDate(new Date()),
  105. 'rownum': 10,
  106. 'thirdAppid': result.open_lib_appId?.context || '',
  107. 'thirdSecret': result.open_lib_secret?.context || '',
  108. 'thirdUrl': result.open_lib_http?.context || ''
  109. }
  110. FetchBookRanking(params).then(res => {
  111. // console.log('排行接口返回数据', res)
  112. const innerStr = res.data;
  113. const resultJson = JSON.parse(innerStr);
  114. // console.log(resultJson)
  115. if (resultJson.success && resultJson.resultlist.length > 0) {
  116. // 按借阅次数降序
  117. this.rankingData = resultJson.resultlist.sort((a, b) => b.TOTALNUM - a.TOTALNUM);
  118. } else {
  119. this.rankingData = [];
  120. }
  121. }).catch(error => {
  122. console.error('排行接口错误', error)
  123. this.rankingData = [];
  124. })
  125. }
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .ranking-header{
  131. position: relative;
  132. width: 100%;
  133. height: 150px;
  134. .ranking-heander-bg{
  135. width: 100%;
  136. height: 100%;
  137. }
  138. .ranking-header-txt{
  139. position: absolute;
  140. top: 0;
  141. left: 0;
  142. height: 150px;
  143. padding: 20px;
  144. display: flex;
  145. flex-direction: column;
  146. justify-content: flex-start;
  147. .ranking-title{
  148. display: flex;
  149. justify-content: flex-start;
  150. align-items: center;
  151. font-size: 26px;
  152. font-weight: bold;
  153. color: #1a1a1a;
  154. ::v-deep .uni-icons{
  155. color: #01a4fe !important;
  156. }
  157. .title-text{
  158. text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15),
  159. 0 1px 2px rgba(0, 0, 0, 0.1);
  160. letter-spacing: 1px;
  161. margin-left: 8px;
  162. }
  163. }
  164. .ranking-header-tip,
  165. .ranking-num{
  166. color: #333;
  167. font-size: 14px;
  168. padding-top: 15px;
  169. }
  170. }
  171. }
  172. .ranking-list{
  173. position: relative;
  174. background-color: #fff;
  175. border-radius: 26px 26px 0 0;
  176. margin-top: -30px;
  177. z-index: 999;
  178. padding: 20px 0;
  179. min-height: 60vh;
  180. }
  181. /* 空状态 */
  182. .empty-box {
  183. display: flex;
  184. flex-direction: column;
  185. align-items: center;
  186. justify-content: center;
  187. height: 50vh;
  188. color: #999;
  189. font-size: 15px;
  190. }
  191. .ranking-item{
  192. position: relative;
  193. display: flex;
  194. justify-content: space-between;
  195. margin: 30px 20px 0 20px;
  196. padding: 10px;
  197. background-color: #f7f8fc;
  198. border-radius: 6px;
  199. .ranking-item-img{
  200. margin-right: 10px;
  201. .book-cover{
  202. width: 100px;
  203. height: 150px;
  204. border-radius: 10px;
  205. padding: 0 10px;
  206. background-color: #fff;
  207. }
  208. }
  209. .ranking-book-info{
  210. flex: 1;
  211. display: flex;
  212. flex-direction: column;
  213. font-size: 14px;
  214. color: #666;
  215. .book-info-title{
  216. font-size: 16px;
  217. font-weight: bold;
  218. color: #000;
  219. padding-top: 10px;
  220. }
  221. .book-info-name,
  222. .book-info-desc{
  223. padding-top: 10px;
  224. line-height: 24px;
  225. }
  226. }
  227. &.first-item{
  228. background-color: #fBF0BB;
  229. }
  230. &.two-item{
  231. background-color: #e9eff6;
  232. }
  233. &.three-item{
  234. background-color: #fBF0BB;
  235. }
  236. .ranking-icon{
  237. position: absolute;
  238. right: 10px;
  239. top: -10px;
  240. }
  241. .ranking-common-icon{
  242. position: absolute;
  243. right: 10px;
  244. top: -4px;
  245. .common-num{
  246. position: absolute;
  247. left: 0;
  248. top: 0;
  249. width: 28px;
  250. height: 28px;
  251. text-align: center;
  252. color: #fff;
  253. }
  254. }
  255. }
  256. </style>