小程序模板网

微信小程序开发问答《五十》实现点击返回顶层 & md5加密 ... ...

发布时间:2018-04-21 09:55 所属栏目:小程序开发教程

1、如何实现点击返回顶层?

最近在研究微信小程序,被这个返回顶层给坑了一波,下面贴代码

wxml代码:

<scroll-view scroll-y style="height: 1000rpx;" scroll-top="50" enable-back-to-top="true" scroll-top="{{scrollTop.scroll_top}}" bindscroll="scrollTopFun">
<block wx:for="{{sortArr}}">
<template is="spL" data="{{item}}">template>
block>
scroll-view> 

<view class="findOur fliexBox"><contact-button type="default-light" size="15" session-from="weapp">contact-button>客服view>

<view class="callOur fliexBox" bindtap="call">电话view>
<view class="fliexBox" style=" bottom: 150rpx; border: solid 1px green;" wx:if="{{scrollTop.goTop_show}}" catchtap="goTopFun">顶层view>

js代码:

var app = getApp();
Page({
data: {
hidden: true,
list: [],
scrollTop: {
scroll_top: 0,
goTop_show: false
},
scrollHeight: 0,
floorstatus:true,
sortArr:[
{
id: 1,
img: "../../images/2.jpg",
title: "君御豪园住宅",
introduction: "杭州不限购不限贷口住宅",
money: 5000,
vperson: 115,
tperson: 0
}
],
},
scrollTopFun: function (e) {
console.log(e.detail);
if (e.detail.scrollTop > 300) {//触发gotop的显示条件 
this.setData({
'scrollTop.goTop_show': true
});
} else {
this.setData({
'scrollTop.goTop_show': false
});
}
},
goTopFun: function (e) {
var _top = this.data.scrollTop.scroll_top;//发现设置scroll-top值不能和上一次的值一样,否则无效,所以这里加了个判断 
if (_top == 0) {
_top = 1;
} else {
_top = 0;
}
this.setData({
'scrollTop.scroll_top': _top
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.getSystemInfo({
success: function (res) {
that.setData({
scrollHeight: res.windowHeight
});
}
});
},

})

wxss代码:

.fliexBox{
width: 100rpx;
height: 50rpx;
background-color: #5db13b;
color: #ffffff;
text-align: center;
position: fixed;
right: 0rpx;
bottom: 85rpx;
border-radius: 20rpx 0rpx 0rpx 20rpx;
font-size: 26rpx;
line-height: 50rpx;
opacity: .6;
}
.callOur{
bottom: 20rpx;
}
contact-button{
opacity: 0;
position: absolute;
}

主要是需要把scroll-view 组件的高度设置起来而且不能是百分比 如100%这样,可以是rpx,这样才可以监测到滑动的距离。

 

2、微信小程序md5加密 

/* 
* 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)) 
} 

/* 
* These functions implement the four basic operations the algorithm uses. 
*/ 
function cmn(q, a, b, x, s, t) 
{ 
return safe_add(rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b) 
} 
function ff(a, b, c, d, x, s, t) 
{ 
return cmn((b & c) | ((~b) & d), a, b, x, s, t) 
} 
function gg(a, b, c, d, x, s, t) 
{ 
return cmn((b & d) | (c & (~d)), a, b, x, s, t) 
} 
function hh(a, b, c, d, x, s, t) 
{ 
return cmn(b ^ c ^ d, a, b, x, s, t) 
} 
function ii(a, b, c, d, x, s, t) 
{ 
return cmn(c ^ (b | (~d)), a, b, x, s, t) 
} 

/* 
* Calculate the MD5 of an array of little-endian words, producing an array 
* of little-endian words. 
*/ 
function coreMD5(x) 
{ 
var a = 1732584193 
var b = -271733879 
var c = -1732584194 
var d = 271733878 

for(var i = 0; i < x.length; i += 16) 
{ 
var olda = a 
var oldb = b 
var oldc = c 
var oldd = d 

a = ff(a, b, c, d, x[i+ 0], 7 , -680876936) 
d = ff(d, a, b, c, x[i+ 1], 12, -389564586) 
c = ff(c, d, a, b, x[i+ 2], 17, 606105819) 
b = ff(b, c, d, a, x[i+ 3], 22, -1044525330) 
a = ff(a, b, c, d, x[i+ 4], 7 , -176418897) 
d = ff(d, a, b, c, x[i+ 5], 12, 1200080426) 
c = ff(c, d, a, b, x[i+ 6], 17, -1473231341) 
b = ff(b, c, d, a, x[i+ 7], 22, -45705983) 
a = ff(a, b, c, d, x[i+ 8], 7 , 1770035416) 
d = ff(d, a, b, c, x[i+ 9], 12, -1958414417) 
c = ff(c, d, a, b, x[i+10], 17, -42063) 
b = ff(b, c, d, a, x[i+11], 22, -1990404162) 
a = ff(a, b, c, d, x[i+12], 7 , 1804603682) 
d = ff(d, a, b, c, x[i+13], 12, -40341101) 
c = ff(c, d, a, b, x[i+14], 17, -1502002290) 
b = ff(b, c, d, a, x[i+15], 22, 1236535329) 

a = gg(a, b, c, d, x[i+ 1], 5 , -165796510) 
d = gg(d, a, b, c, x[i+  


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/23858.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询