//index.js //获取应用实例 const app = getApp() var host = app.globalData.host; Page({ data: { zimu_list: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'], scroll: '', //滚动到指定 id值的子元素 touchmove: 0,//给字母导航添加背景色 1 添加 0不添加 nav_height: '',//字母导航单个元素高度 nav_top:'', hiddenn: true,//hint_box 提示框 展示隐藏 nav_text: '',//hint_box 提示框里面的文本 lb:[], act:0, journals:[], organizers:[], subjects:[] }, onLoad: function () { this.getData(); }, //获取所有数据 getData:function(){ wx.showLoading({ title: '加载中', }) var that=this; wx.request({ url: host+'/api/index/banners', method:'GET', success:function(res){ that.setData({ lb: res.data.data.banners }) } }) // 全刊 wx.request({ url: host + '/api/index/journals', method: 'GET', success: function (res) { wx.hideLoading() that.setData({ journals: res.data.data.journals }) } }) // 主办单位 wx.request({ url: host + '/api/index/organizers', method: 'GET', success: function (res) { that.setData({ organizers: res.data.data.list }) } }) // 领域期刊 wx.request({ url: host + '/api/index/subjects', method: 'GET', success: function (res) { that.setData({ subjects: res.data.data.list }) } }) }, //置顶 top: function(e){ wx.request({ url: host+'/api/index/totop', method:'PUT', data:{ id:e.target.dataset.id, type:'subject' }, success:function(res){ console.log(res.data) } }) }, tab:function(e){ this.setData({ act: e.target.dataset.id }) }, swchange:function(e){ this.setData({ act: e.detail.current }) }, onReady: function () { this.get_height(); }, //事件处理函数 touchstart: function (e) { this.set_scroll(e) }, touchmove: function (e) { this.set_scroll(e) }, touchend: function () { this.setData({ touchmove: 0, hiddenn: true }) }, scroll(e){ var that = this this.setData({ scroll:e.target.dataset.id.toLowerCase(), }) }, set_scroll: function (e) { var page_y = e.changedTouches[0].pageY - this.data.nav_top; // console.log(page_y) var nav_height = +this.data.nav_height var idx = Math.floor(page_y / nav_height) var zimu = this.data.zimu_list[idx]; this.setData({ touchmove: 1, scroll: zimu.toLowerCase(), nav_text: zimu, hiddenn: false }) }, get_height: function () { var that = this var query = wx.createSelectorQuery(); query.select('#nav_item').boundingClientRect() wx.createSelectorQuery().select('#nav').boundingClientRect(function (rect) { that.setData({ nav_top: rect.top, }) }).exec() query.exec(function (res) { that.setData({ nav_height: res[0].height, }) }) }, getUserInfo: function(e) { console.log(e) app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) } })