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

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