多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ## 1. onLoad与onShow 1. onLoad负责页面数据加载初始化,onShow页面展现调用,两者都可用于页面初始化 2. onLoad先于onShow执行 3. onShow只要打开页面就会执行,而onLoad只会在页面初始化的时候执行。利用onShow,可以做返回页面刷新。 4. 返回和tabbar切换都不会引起页面初始化,所以onLoad不会执行,onShow会执行 ## 2. 上下拉刷新 onPullDownRefresh和onReachBottom两个事件函数监听下拉和上拉事件函数 ~~~ data: { enterpriseList: [], pageNo: 1, //页数 pageSize: 10, // 条数 }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { this.setData({ //刷新操作初始化数据 pageNo: 1, list: [], isEmpty: true }) this.queryData(); //查询数据 }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { var pageNum = this.data.pageNo; if (pageNum < this.data.totalPageCnt) { this.setData({ pageNo: pageNum + 1 //设置下一页 }) this.queryData(); //查询数据 } else { wx.showToast({ title: "没有更多数据了", duration: 1000, icon: 'none', mask: true }) } }, // 查询数据方法 //查询数据 queryData: function() { var that = this; var pageNo = this.data.pageNo; var pageSize = this.data.pageSize; wx.showLoading({ title: '加载中...', }); wx.request({ url: app.globalData.pubSiteUrl + 'pubsite-company/companylist', //上线的话必须是https,没有appId的本地请求貌似不受影响 ... }, // 设置请求的 header data: { pageIndex: pageNo, pageSize: pageSize }, success: function(res) { wx.hideLoading(); //隐藏加载中提示 }, fail: function() { wx.hideLoading(); //隐藏加载中提示 wx.showToast({ title: "请求失败!", duration: 1000, icon: 'none', mask: true }) }, complete: function() { // complete } }) }, ~~~ ## 3. MD5加密 密码加密 1. md5.js(放入小程序项目) ~~~ /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Version 1.1 Copyright (C) Paul Johnston 1999 - 2002. * Code also contributed by Greg Holt * See http://pajhome.org.uk/site/legal.html for details. */ /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ function safe_add(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF) var msw = (x >> 16) + (y >> 16) + (lsw >> 16) return (msw << 16) | (lsw & 0xFFFF) } /* * Bitwise rotate a 32-bit number to the left. */ function rol(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)) } ... /* * External interface */ function hexMD5(str) { return binl2hex(coreMD5(str2binl(str))) } function hexMD5w(str) { return binl2hex(coreMD5(strw2binl(str))) } function b64MD5(str) { return binl2b64(coreMD5(str2binl(str))) } function b64MD5w(str) { return binl2b64(coreMD5(strw2binl(str))) } /* Backward compatibility */ function calcMD5(str) { return binl2hex(coreMD5(str2binl(str))) } module.exports = { // 暴露接口,并执行调用名 md5: hexMD5 } ~~~ 1. 使用md5.js 在对应页面的js文件当中: 1. 连接md5.js文件 var utilMd5 = require('../../../utils/md5.js'); 2. 调用 utilMd5.md5(oldPwd);