123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- //index.js
- //获取应用实例
- import http from '../../utils/http'
- import api from '../../utils/api'
- const app = getApp()
- Page({
- data: {
- motto: 'Hello World',
- userInfo: {},
- hasUserInfo: false,
- canIUse: wx.canIUse('button.open-type.getUserInfo'),
- keyword: '',
- page: 1,
- list: [],
- touchBottom: false
- },
- //事件处理函数
- bindViewTap: function() {
- wx.navigateTo({
- url: '../logs/logs'
- })
- },
- onShow: function() {
- this.setData({
- list: []
- })
- this.getList();
- api.getByName(this, 'getUserInfo', 'userInfo', {}, function(res) {
- app.updateUserInfo(res);
- });
- },
- onLoad: function () {
- if (app.globalData.userInfo) {
- this.setData({
- userInfo: app.globalData.userInfo,
- hasUserInfo: true
- })
- } else if (this.data.canIUse){
- // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
- // 所以此处加入 callback 以防止这种情况
- app.userInfoReadyCallback = res => {
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- }
- } else {
- // 在没有 open-type=getUserInfo 版本的兼容处理
- wx.getUserInfo({
- success: res => {
- app.globalData.userInfo = res.userInfo
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- }
- })
- }
- },
- navigate: function(e) {
- wx.navigateTo({
- url: e.currentTarget.dataset.url,
- })
- },
- updateInput: function(e) {
- var name = e.currentTarget.dataset.name
- this.setData({
- [name]: e.detail.value
- })
- },
- search: function() {
- this.setData({
- list: [],
- page: 1
- })
- this.getList()
- },
- getList: function() {
- if(this.data.touchBottom) return false;
- var that = this
- http({
- url: 'projects/get',
- data: {
- page: this.data.page,
- name: this.data.keyword
- },
- success: function(res) {
- if(res.code == 0) {
- var list = that.data.list.concat(res.data)
- that.setData({
- touchBottom: res.data.length == 0,
- list: list
- })
- }
- }
- })
- },
- getUserInfo: function(e) {
- console.log(e)
- app.globalData.userInfo = e.detail.userInfo
- this.setData({
- userInfo: e.detail.userInfo,
- hasUserInfo: true
- })
- },
- onReachBottom: function() {
- if(!this.data.touchBottom) {
- this.setData({
- page: this.data.page + 1
- })
- this.getList()
- } else {
- wx.showToast({
- icon: 'none',
- title: '没有更多了',
- })
- }
- }
- })
|