123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- // 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: '专辑'
- };
- }
- })
|