123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- // pages/index/index.js
- const app = getApp();
- const net = require('../../utils/net.js');
- const url = require('../../utils/url.js');
- const util = require('../../utils/util.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- file: url.file,
- list: [],
- lastTime: 0,
- animation: {},
- tabs: {
- width: 0,
- left: 0,
- list: [],
- current: 0,
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- //不使用群标识,支持长按转发
- wx.showShareMenu({
- withShareTicket: false
- })
- //获取分类列表
- this.getTagList();
- net.login();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- var offset = new Date().getTime() - this.data.lastTime;
- if (offset > 600000) {
- this.initList();
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- return {
- title: '总是被KO,不要啊!快来帮帮我!',
- path: '/pages/index/index',
- imageUrl: 'http://adminwxstore.xsbanruo.com/wxstore-admin/file/upload/2/8280/828020180831642627961906.jpg'
- }
- },
- setTabUnderLineAnimation: function(id){
- var animation = wx.createAnimation({
- duration: 400,
- timingFunction: 'ease',
- });
- var x = this.data.tabs.width * id + this.data.tabs.left;
- animation.translate(x, 0).step();
- this.setData({
- animation: animation.export()
- });
- },
- // 当tab切换时执行方法,修改tab样式,获取数据
- onTabChange: function(e) {
- var id = e.currentTarget.id;
- if (this.data.tabs.currentTabId === id) {
- return;
- }
- //执行tab下划线移动动画
- this.setTabUnderLineAnimation(id);
- //设置tab文字颜色变化
- this.data.tabs.list[this.data.tabs.current].class = '';
- this.data.tabs.list[id].class = 'active';
- this.data.tabs.current = id;
- this.setData({
- tabs: this.data.tabs
- });
- //当前列表无数据时,获取数据
- if (this.data.list[this.data.tabs.current].length <= 0) {
- this.getList();
- }
- },
- onSwiperChange: function(e) {
- //swiper为手动滑动
- if (e.detail.source === 'touch') {
- //tab发生变化,执行切换方法
- this.onTabChange({
- currentTarget: {
- id: e.detail.current
- }
- });
- }
- },
- initList: function(){
- //根据分类,初始化游戏列表
- var len = this.data.tabs.list.length;
- this.data.list = new Array(len);
- for (var i = 0; i < len; i++) {
- this.data.list[i] = [];
- }
- this.setData({
- list: this.data.list
- })
- //获取游戏列表
- this.getList();
- },
- getTagList: function() {
- this.data.lastTime = new Date().getTime();
- wx.showLoading({
- title: '',
- });
- net.request({
- url: url.tags,
- success: res => {
- //根据分类,初始化分类列表tabs
- this.data.tabs.list = res.data;
- this.data.tabs.list[0].class = 'active';
- var len = this.data.tabs.list.length;
- this.data.tabs.width = app.config.width / len;
- this.data.tabs.left = (this.data.tabs.width - app.config.width * 120 / 750) / 2;
- this.setTabUnderLineAnimation(0);
- this.setData({
- tabs: this.data.tabs
- });
- this.initList();
- },
- fail: err => {
- wx.showModal({
- title: '',
- content: '获取数据失败,请检查网络,重新获取',
- showCancel: false,
- success: res => {
- this.getTagList();
- }
- })
- }
- });
- },
- getList: function() {
- wx.showLoading({
- title: '',
- });
- net.request({
- url: url.list,
- data: {
- tagId: this.data.tabs.list[this.data.tabs.current].tagId
- },
- success: res => {
- this.data.lastTime = new Date().getTime();
- this.data.list[this.data.tabs.current] = res.data;
- this.setData({
- list: this.data.list
- })
- }
- });
- },
- toTask: function(e) {
- //进入详情页
- wx.showLoading({
- title: '',
- })
- const task = this.data.list[this.data.tabs.current][e.currentTarget.id];
- net.request({
- url: url.task,
- method: 'GET',
- data: {
- programId: task.programId
- },
- success: res => {
- const result = res.data || {
- gtaskId: 0,
- programId: task.programId,
- title: task.memo,
- jumpPath: '/pages/index/index',
- card: ''
- };
- result.appId = task.appId
- result.logo = task.logo
- result.appName = task.appName
- result.memo = task.memo
- result.playRefer = 1
- result.jumpPath = encodeURIComponent(result.jumpPath);
- var param = util.parseUrlParamByJson(result);
- wx.navigateTo({
- url: '/pages/task/task?' + param,
- });
- }
- });
- },
- })
|