//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:[], sub_list:[], show:1, uid:'', page_org:1, page_sub:1, total_org:0, total_sub:0, cycleId: 'day', value: ['日榜','周榜','月榜'], select:0, day:'', week:'', month: '', m_value:0, show_month:0, sub_value:0, week_h:0, casci_list:[], page_csi:1, total_csi: 0, yestoday:'', top_csi:0, keyword:'' }, onShow: function () { wx.hideNavigationBarLoading() }, onLoad: function () { var y = new Date().getFullYear() ,m=(new Date().getMonth() + 1) ,d=new Date().getDate(); m = m > 9 ? m : '0' + m; d = d > 9 ? d : '0' + d; this.setData({ day:y+'-'+m+'-'+d, month: y + '-' + m, yestoday1: y + '-' + m + '-' + (d - 1), yestoday: y + '-' + m + '-' + (d-1) }) this.getTimer() if (this.data.uid){ this.setData({ organizers: [], subjects: [], page_org: 1, page_sub: 1, total_org: 0, total_sub: 0 }) this.getData(); }else{ this.getData(); this.setData({ openid: app.globalData.openid }) wx.getStorage({ key: 'uid', success: res => { if (res.data) { this.setData({ show: 0, uid: res.data }) } }, fail:err=>{ wx.switchTab({ url: '../mine/mine', }) } }) } }, /** * 周期切换点击 * @param {*} e */ onTabItemClick: function onTabItemClick(e) { var id = e.currentTarget.dataset.tabs; this.setData({ select:id, page_csi:1, total_csi:0, casci_list:[], top_csi: 0 }) this.getcasci() }, //周榜 changeMonth:function(e){ var id = e.currentTarget.dataset.id; this.setData({ m_value: id }) }, monthSelect: function () { var week=this.data.columns[this.data.m_value] this.setData({ week: week, show_month:0, page_csi: 1, total_csi: 0, casci_list: [], top_csi: 0 }) this.getcasci() }, open: function () { this.setData({ show_month: 1, week_h: this.data.m_value*40 }) }, close:function(){ this.setData({ show_month: 0 }) }, // 日榜 bindDateChange:function(e){ this.setData({ yestoday: e.detail.value, page_csi: 1, total_csi: 0, casci_list: [], top_csi: 0 }) this.getcasci() }, //领域期刊 subChange:function(e){ this.setData({ sub_value: e.detail.value, page_csi: 1, total_csi: 0, casci_list: [], top_csi: 0 }) this.getcasci() }, //月榜 bindDateChange1: function (e) { this.setData({ month: e.detail.value, page_csi: 1, total_csi: 0, casci_list: [] }) this.getcasci() }, onGotUserInfo: function () { wx.getUserProfile({ desc: '用于完善会员资料', success: res=> { //获取基本信息 var data = { nickName: res.userInfo.nickName, avatarUrl: res.userInfo.avatarUrl } wx.showLoading({ title: '正在登陆', }) wx.setStorage({ key: 'userInfo', data: data, }) wx.request({ url: host + '/api/auth', method: 'POST', data: { nickname: data.nickName, avatar: data.avatarUrl, openid: app.globalData.openid, }, success: res => { wx.hideLoading() wx.setStorage({ key: 'uid', data: res.data.data.uid, }) this.setData({ show: 0, uid: res.data.data.uid }) this.getData() }, fail:error=>{ wx.hideLoading() wx.showLoading({ title: '登陆失败', }) } }) } }) }, //主办单位下一页 next_org:function(){ if(this.data.organizers.length < this.data.total_org){ const page = this.data.page_org+1 this.setData({ page_org: page }) this.getorg() } }, //领域期刊下一页 next_sub:function(){ if(this.data.subjects.length < this.data.total_sub){ const page = this.data.page_sub+1 this.setData({ page_sub: page }) this.getsub() } }, //指数下一页 next_csi: function () { if (this.data.casci_list.length < this.data.total_csi) { const page = this.data.page_csi + 1 this.setData({ page_csi: page }) this.getcasci() } }, //获取所有数据 getData:function(flag){ wx.showNavigationBarLoading() var that=this; if(!flag){ wx.request({ url: host+'/api/index/banners', method:'GET', success:function(res){ that.setData({ lb: res.data.data.banners }) }, fail: function () { wx.hideNavigationBarLoading() wx.showToast({ title: '服务器开小差啦!', icon: 'none' }) } }) // 全刊 wx.request({ url: host + '/api/index/journals', method: 'GET', success: function (res) { wx.hideNavigationBarLoading() that.setData({ journals: res.data.data.journals }) } }) } //全部数据 wx.request({ url: host + '/api/index/subjects', method: 'GET', data: { uid: this.data.uid, page_size:100000 }, success: res => { if (res.data.code == 0) { const list = res.data.data.list; list.unshift({ name:'全部学科', id:'' }) this.setData({ sub_list: list }) this.getcasci() } } }) this.getorg() this.getsub() }, //指数 getcasci:function(){ wx.showNavigationBarLoading() const casci_list = this.data.casci_list; var subject_id=this.data.sub_list[this.data.sub_value].id,date=''; if (this.data.select == 0){ date = this.data.yestoday } if (this.data.select == 1) { date = this.data.week.replace('至',',') } if (this.data.select == 2) { date = this.data.month } wx.request({ url: host + '/api/casci/list', method: 'GET', data: { uid: this.data.uid, date: date, signup_id: subject_id, page:this.data.page_csi, keyword: this.data.keyword // page_size:20 }, success: res => { wx.hideNavigationBarLoading() if (res.data.code == 0) { const list = res.data.data[1]; for (let i = 0; i < list.length; i++) { casci_list.push(list[i]) } this.setData({ casci_list: casci_list, total_csi: res.data.data[0] }) } } }) }, //主办单位 getorg:function(){ wx.showNavigationBarLoading() const organizers=this.data.organizers; wx.request({ url: host + '/api/index/organizers', method: 'GET', data: { uid: this.data.uid, page: this.data.page_org }, success: res=>{ wx.hideNavigationBarLoading() if(res.data.code == 0){ const list=res.data.data.list; for(let i=0;i{ wx.hideNavigationBarLoading() if(res.data.code == 0){ const list=res.data.data.list; for(let i=0;i{ wx.showToast({ title: '置顶成功', icon:'none' }) if (type == 'organizer'){ this.setData({ organizers:[], page_org:1 }) this.getorg() }else{ this.setData({ subjects: [], page_sub: 1 }) this.getsub() } } }) }, cancel_top: function (e) { var type = e.target.dataset.type; wx.request({ url: host + '/api/index/totop', method: 'PUT', data: { id: e.target.dataset.id, type: type, uid: this.data.uid, action:'cancel' }, success: res=> { wx.showToast({ title: '已取消', icon: 'none' }) if (type == 'organizer') { this.setData({ organizers: [], page_org: 1 }) this.getorg() } else { this.setData({ subjects: [], page_sub: 1 }) this.getsub() } } }) }, 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, }) }, 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, 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) { app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) }, toDetail:function(e){ // console.log(e) }, toBanner:function(e){ var url = e.target.dataset.id wx.navigateTo({ url: url, }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { wx.startPullDownRefresh() }, getTimer() { let time = new Date() // 获取当前时间 let nowTime = time.getTime() let day = time.getDay() let oneDayTime = 24 * 60 * 60 * 1000; // 一周的时间 let MondayTime = nowTime - (day - 1) * oneDayTime; //显示当前周一 let SundayTime = nowTime + (7 - day) * oneDayTime; //显示当前周日 let setlist = [] // 初始化一个空数组 准备装食物--你好骚啊 for (let i = 0; i < 365*3; i++) { // 这块我不知道怎么回事一直会有重复的push进去,后面做了去重,可以放心食用,当然也可以优化一下 setlist.push(this.setTime(MondayTime) + ' 至 ' + this.setTime(SundayTime)) // this.setTime()在下面 放心食用 // 重点 push完,赶紧让它获取上一周的时间 oneDayTime上面有写 time = new Date(time - oneDayTime) nowTime = time.getTime() day = time.getDay() MondayTime = nowTime - (day - 1) * oneDayTime; //显示当前周一 SundayTime = nowTime + (7 - day) * oneDayTime; //显示当前周日 } let list = [...new Set(setlist)] // 简单去重一下 list.shift() // console.log(list); this.setData({ columns: list, week: list[0] }) }, setTime(time) { // 将time时间戳 先格式化一下 let date = new Date(time) let yy = date.getFullYear() let m = date.getMonth() + 1 let day = date.getDate() let str = yy + '-' + (m < 10 ? '0' + m : m) + '-' + (day < 10 ? '0' + day : day) return str } })