album.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // pages/album/album.js
  2. import {
  3. imgUrl
  4. } from "../api/request"
  5. const baseUrl = "https://www.cqna.gov.cn/data/"
  6. const request = (options) => {
  7. return new Promise((resolve,reject) => {
  8. options.url = baseUrl + options.url
  9. wx.request({
  10. // 配置 "wx.request" 请求参数
  11. ...options,
  12. header: {
  13. 'content-type': 'application/json;charset=UTF-8'
  14. },
  15. success: function (res) {
  16. // console.log("network-res=>", res);
  17. // 返回成功信息
  18. resolve(res.data)
  19. },
  20. fail: function (error) {
  21. // console.log("network-err=>", error);
  22. // 返回错误信息
  23. reject(error)
  24. }
  25. })
  26. })
  27. }
  28. Page({
  29. /**
  30. * 页面的初始数据
  31. */
  32. data: {
  33. // 图片前缀
  34. imgUrl: imgUrl,
  35. baseUrl: baseUrl + '/',
  36. // 专辑列表
  37. albumList: [],
  38. // 专辑标题
  39. albumTitle: [],
  40. // 默认选中
  41. currentTab: 0,
  42. // 分页参数
  43. page: 1,
  44. // 专辑介绍
  45. introduction: '专辑有论文专辑、音乐专辑等。论文专辑是指期刊的某一期专门对某一个大家关注的领域、问题、事件进行集中报道、讨论。',
  46. // 专辑内容
  47. albumInfo: [],
  48. // 专辑内容全部加载完毕
  49. loadComplete: false
  50. },
  51. // 获取专辑列表
  52. getAlbumList() {
  53. request({
  54. url: '/yxna/getAlbumList',
  55. method: 'GET'
  56. }).then(res => {
  57. this.setData({
  58. albumList: res.data
  59. })
  60. this.getAlbumTitle();
  61. this.getAlbumDetail();
  62. })
  63. },
  64. // 获取专辑列表详细
  65. getAlbumDetail() {
  66. if (!this.data.loadComplete) {
  67. request({
  68. url: '/yxna/getAlbumById/' + this.data.albumList[this.data.currentTab].id,
  69. data: {
  70. page: this.data.page,
  71. limit: '6'
  72. },
  73. method: 'GET'
  74. }).then(res => {
  75. let temp = this.data.albumInfo;
  76. if (temp.length >= res.count) {
  77. wx.showToast({
  78. title: "没有更多了",
  79. icon: "none",
  80. duration: 1500
  81. })
  82. this.setData({
  83. loadComplete: true
  84. })
  85. } else {
  86. for (let i = 0; i < res.data.length; i++) {
  87. let time = res.data[i].vestingDate.split(" ")[0].split("-");
  88. res.data[i].vestingDate = time[0] + " " + time[1] + "/" + time[2];
  89. temp.push(res.data[i]);
  90. }
  91. this.setData({
  92. albumInfo: temp,
  93. page: this.data.page + 1
  94. })
  95. }
  96. })
  97. }
  98. },
  99. // 获取专辑标题
  100. getAlbumTitle() {
  101. let temp = [];
  102. let album = this.data.albumList[this.data.currentTab].name;
  103. for (let index = 0; index < album.length; index++) {
  104. temp.push(album.substr(index, 1));
  105. }
  106. temp.push("专");
  107. temp.push("辑");
  108. this.setData({
  109. albumTitle: temp
  110. })
  111. },
  112. // 切换专辑
  113. tabNav(e) {
  114. let currentTab = e.currentTarget.dataset.index
  115. this.setData({
  116. currentTab
  117. })
  118. },
  119. // 切换专辑
  120. handleSwiper(e) {
  121. let {
  122. current,
  123. source
  124. } = e.detail
  125. if (source === 'autoplay' || source === 'touch') {
  126. const currentTab = current
  127. this.setData({
  128. currentTab
  129. })
  130. }
  131. this.setData({
  132. albumInfo: [],
  133. loadComplete: false,
  134. page: 1
  135. })
  136. this.getAlbumTitle();
  137. this.getAlbumDetail();
  138. },
  139. // 前往专辑内容详细界面
  140. toYXNADetailInfo(data) {
  141. wx.navigateTo({
  142. url: '/pagesPublic/pages/albumDetail/albumDetail?id=' + data.currentTarget.dataset.id,
  143. })
  144. },
  145. // 触底刷新
  146. bindscrolltolower() {
  147. this.getAlbumDetail();
  148. },
  149. /**
  150. * 生命周期函数--监听页面加载
  151. */
  152. onLoad(options) {
  153. this.getAlbumList();
  154. },
  155. /**
  156. * 生命周期函数--监听页面初次渲染完成
  157. */
  158. onReady() {
  159. },
  160. /**
  161. * 生命周期函数--监听页面显示
  162. */
  163. onShow() {
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide() {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload() {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh() {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom() {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage() {
  189. return {
  190. title: '专辑'
  191. };
  192. }
  193. })