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

271 lines
6.9 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
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. export default {
  69. data() {
  70. return {
  71. rankingData: [],
  72. defaultCover: '/static/images/default-book.png',
  73. };
  74. },
  75. onLoad() {
  76. this.getScreenConfig();
  77. },
  78. methods: {
  79. async getScreenConfig() {
  80. try {
  81. const res = await FetchInitScreenSetting({ libcode: '1201' });
  82. this.getReadRanking(res.data);
  83. } catch (err) {
  84. console.log(err)
  85. }
  86. },
  87. getFormattedDate(date) {
  88. const year = date.getFullYear();
  89. const month = date.getMonth() + 1;
  90. const day = date.getDate();
  91. return `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`;
  92. },
  93. getReadRanking(result) {
  94. const currentDate = new Date()
  95. currentDate.setDate(currentDate.getDate() - 30)
  96. const year = currentDate.getFullYear()
  97. const month = currentDate.getMonth() + 1
  98. const day = currentDate.getDate()
  99. const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`
  100. const params = {
  101. 'libcode': '1201',
  102. 'starttime': formattedDate,
  103. 'endtime': this.getFormattedDate(new Date()),
  104. 'rownum': 10,
  105. 'thirdAppid': result.open_lib_appId?.context || '',
  106. 'thirdSecret': result.open_lib_secret?.context || '',
  107. 'thirdUrl': result.open_lib_http?.context || ''
  108. }
  109. FetchBookRanking(params).then(res => {
  110. console.log('排行接口返回数据', res)
  111. const innerStr = res.data;
  112. const resultJson = JSON.parse(innerStr);
  113. console.log(resultJson)
  114. if (resultJson.success && resultJson.resultlist.length > 0) {
  115. // 按借阅次数降序
  116. this.rankingData = resultJson.resultlist.sort((a, b) => b.TOTALNUM - a.TOTALNUM);
  117. } else {
  118. this.rankingData = [];
  119. }
  120. }).catch(error => {
  121. console.error('排行接口错误', error)
  122. this.rankingData = [];
  123. })
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .ranking-header{
  130. position: relative;
  131. width: 100%;
  132. height: 150px;
  133. .ranking-heander-bg{
  134. width: 100%;
  135. height: 100%;
  136. }
  137. .ranking-header-txt{
  138. position: absolute;
  139. top: 0;
  140. left: 0;
  141. height: 150px;
  142. padding: 20px;
  143. display: flex;
  144. flex-direction: column;
  145. justify-content: flex-start;
  146. .ranking-title{
  147. display: flex;
  148. justify-content: flex-start;
  149. align-items: center;
  150. font-size: 26px;
  151. font-weight: bold;
  152. color: #1a1a1a;
  153. ::v-deep .uni-icons{
  154. color: #01a4fe !important;
  155. }
  156. .title-text{
  157. text-shadow: 0 2px 4px rgba(0, 0, 0, 0.15),
  158. 0 1px 2px rgba(0, 0, 0, 0.1);
  159. letter-spacing: 1px;
  160. margin-left: 8px;
  161. }
  162. }
  163. .ranking-header-tip,
  164. .ranking-num{
  165. color: #333;
  166. font-size: 14px;
  167. padding-top: 15px;
  168. }
  169. }
  170. }
  171. .ranking-list{
  172. position: relative;
  173. background-color: #fff;
  174. border-radius: 26px 26px 0 0;
  175. margin-top: -30px;
  176. z-index: 999;
  177. padding: 20px 0;
  178. min-height: 60vh;
  179. }
  180. /* 空状态 */
  181. .empty-box {
  182. display: flex;
  183. flex-direction: column;
  184. align-items: center;
  185. justify-content: center;
  186. height: 50vh;
  187. color: #999;
  188. font-size: 15px;
  189. }
  190. .ranking-item{
  191. position: relative;
  192. display: flex;
  193. justify-content: space-between;
  194. margin: 30px 20px 0 20px;
  195. padding: 10px;
  196. background-color: #f7f8fc;
  197. border-radius: 6px;
  198. .ranking-item-img{
  199. margin-right: 10px;
  200. .book-cover{
  201. width: 100px;
  202. height: 150px;
  203. border-radius: 10px;
  204. padding: 0 10px;
  205. background-color: #fff;
  206. }
  207. }
  208. .ranking-book-info{
  209. flex: 1;
  210. display: flex;
  211. flex-direction: column;
  212. font-size: 14px;
  213. color: #666;
  214. .book-info-title{
  215. font-size: 16px;
  216. font-weight: bold;
  217. color: #000;
  218. padding-top: 10px;
  219. }
  220. .book-info-name,
  221. .book-info-desc{
  222. padding-top: 10px;
  223. line-height: 24px;
  224. }
  225. }
  226. &.first-item{
  227. background-color: #fBF0BB;
  228. }
  229. &.two-item{
  230. background-color: #e9eff6;
  231. }
  232. &.three-item{
  233. background-color: #fBF0BB;
  234. }
  235. .ranking-icon{
  236. position: absolute;
  237. right: 10px;
  238. top: -10px;
  239. }
  240. .ranking-common-icon{
  241. position: absolute;
  242. right: 10px;
  243. top: -4px;
  244. .common-num{
  245. position: absolute;
  246. left: 0;
  247. top: 0;
  248. width: 28px;
  249. height: 28px;
  250. text-align: center;
  251. color: #fff;
  252. }
  253. }
  254. }
  255. </style>