// pages/album/album.js import { imgUrl } from "../api/request" const baseUrl = "https://www.cqna.gov.cn/data/" const request = (options) => { return new Promise((resolve,reject) => { options.url = baseUrl + options.url wx.request({ // 配置 "wx.request" 请求参数 ...options, header: { 'content-type': 'application/json;charset=UTF-8' }, success: function (res) { // console.log("network-res=>", res); // 返回成功信息 resolve(res.data) }, fail: function (error) { // console.log("network-err=>", error); // 返回错误信息 reject(error) } }) }) } Page({ /** * 页面的初始数据 */ data: { // 图片前缀 imgUrl: imgUrl, baseUrl: baseUrl + '/', // 专辑列表 albumList: [], // 专辑标题 albumTitle: [], // 默认选中 currentTab: 0, // 分页参数 page: 1, // 专辑介绍 introduction: '专辑有论文专辑、音乐专辑等。论文专辑是指期刊的某一期专门对某一个大家关注的领域、问题、事件进行集中报道、讨论。', // 专辑内容 albumInfo: [], // 专辑内容全部加载完毕 loadComplete: false }, // 获取专辑列表 getAlbumList() { request({ url: '/yxna/getAlbumList', method: 'GET' }).then(res => { this.setData({ albumList: res.data }) this.getAlbumTitle(); this.getAlbumDetail(); }) }, // 获取专辑列表详细 getAlbumDetail() { if (!this.data.loadComplete) { request({ url: '/yxna/getAlbumById/' + this.data.albumList[this.data.currentTab].id, data: { page: this.data.page, limit: '6' }, method: 'GET' }).then(res => { let temp = this.data.albumInfo; if (temp.length >= res.count) { wx.showToast({ title: "没有更多了", icon: "none", duration: 1500 }) this.setData({ loadComplete: true }) } else { for (let i = 0; i < res.data.length; i++) { let time = res.data[i].vestingDate.split(" ")[0].split("-"); res.data[i].vestingDate = time[0] + " " + time[1] + "/" + time[2]; temp.push(res.data[i]); } this.setData({ albumInfo: temp, page: this.data.page + 1 }) } }) } }, // 获取专辑标题 getAlbumTitle() { let temp = []; let album = this.data.albumList[this.data.currentTab].name; for (let index = 0; index < album.length; index++) { temp.push(album.substr(index, 1)); } temp.push("专"); temp.push("辑"); this.setData({ albumTitle: temp }) }, // 切换专辑 tabNav(e) { let currentTab = e.currentTarget.dataset.index this.setData({ currentTab }) }, // 切换专辑 handleSwiper(e) { let { current, source } = e.detail if (source === 'autoplay' || source === 'touch') { const currentTab = current this.setData({ currentTab }) } this.setData({ albumInfo: [], loadComplete: false, page: 1 }) this.getAlbumTitle(); this.getAlbumDetail(); }, // 前往专辑内容详细界面 toYXNADetailInfo(data) { wx.navigateTo({ url: '/pagesPublic/pages/albumDetail/albumDetail?id=' + data.currentTarget.dataset.id, }) }, // 触底刷新 bindscrolltolower() { this.getAlbumDetail(); }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getAlbumList(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { return { title: '专辑' }; } })