网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序開發問答《六十六》 菜單內容左右聯動 & MD5加密 ...

發布時間:2018-04-23 12:17 所屬欄目:小程序開發教程
1、微信小程序菜單內容左右聯動
 

小程序無法獲取元素的寬高,位置信息,只能通過后臺計算,但是存在較大的機器誤差,不知有啥好的解決方案?git地址:https://github.com/Panfen/lumm

如圖所以,左側是菜單欄,右側是主體內容,點擊左側菜單,右側滑動到相應的位置;右側滑動過程,也會改變左側菜單的選中狀態。本人的實現方案:

  • 所有元素大小單位用rpx;

  • 通過scrollbind(e) 的 e.detail.scrollHeight獲取右側滑動區域的總高度(單位px)

  • 通過物品高度和標題高度的比值,計算出各自的實際高度(單位px)

  • 通過修改scrollTop(單位px)改變主體內容位置

這樣還是存在1px-100px的誤差,物品越多,后面的累計誤差會越大,有沒有更好的解決辦法呢?

 

答:測試了一下,的確用scroll-view的scroll-to-view特性可以解決:

 

wxml中修改:


<scroll-view scroll-y style="height: 31.5em" class="goods" bindscroll="goodsScrollAct"  scroll-into-view="{{toView}}" >
  <view class="box" id="{{item.viewId}}"  wx:for="{{allGoods}}" wx:key="unique" wx:for-index="typeId">

js文件中修改:
page data中增加:


menuType:['food','dust','bowl','cages','toys','tools'],
toView:'cages',

然后把下面函數修改一下:
selectMenuAct: function (e) {


//typename
var id = e.target.dataset.id;
var tType=this.data.menuType[id];
console.log(e),
this.setData({
  scrollNum: id,
  toView: tType
  //scrollTop: this.data.heightList[id]
});

},
測試環境下通過。

 

scroll-into-view值應為某子元素id(id不能以數字開頭)。設置哪個方向可滾動,則在哪個方向滾動到該元素。

 

2、微信小程序MD5加密

一般很多語言都有MD5加密的庫。

如果你指的是數據加密,怕數據明文不安全,我建議使用base64 + 一些前綴或者后綴進行加密,然后將數據傳到服務器,服務器再進行解密后去掉這些前后綴。比如,明文是abc,你可以加一下前綴,變成123abc,然后加密成為MTIzYWJj再發出去,然后再解密就行了。

一般MD5加密是不可逆的。而base64可以編碼解碼,如下:


package main

import (
    "fmt"
    "github.com/hunterhug/GoSpider/util"
)

func main() {
    s := "abc"
    prefix := "123"
    base64e := util.Base64E(prefix + s)
    fmt.Println("加密:" + base64e)
    fmt.Println("再解密:" + util.Base64D(base64e))
}

結果


加密:MTIzYWJj
再解密:123abc

百度百科介紹:Base64編碼可用于在HTTP環境下傳遞較長的標識信息。例如,在Java Persistence系統Hibernate中,就采用了Base64來將一個較長的唯一標識符(一般為128-bit的UUID)編碼為一個字符串,用作HTTP表單和HTTP GET URL中的參數。在其他應用程序中,也常常需要把二進制數據編碼為適合放在URL(包括隱藏表單域)中的形式。此時,采用Base64編碼不僅比較簡短,同時也具有不可讀性,即所編碼的數據不會被人用肉眼所直接看到。

我的Golang語言自己封裝的加密庫一般是這樣的:


/*
Copyright 2017 by GoSpider author.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package util

import (
    "crypto/hmac"
    "crypto/md5"
    "crypto/sha256"
    "encoding/base64"
    "encoding/hex"
    "fmt"
    "net/url"
    "strings"
)

// HMAC with the SHA256  http://blog.csdn.net/js_sky/article/details/49024959
func ComputeHmac256(message string, secret string) string {
    key := []byte(secret)
    h := hmac.New(sha256.New, key)
    h.Write([]byte(message))
    return base64.StdEncoding.EncodeToString(h.Sum(nil))
}

// create md5 string
func Strtomd5(s string) string {
    h := md5.New()
    h.Write([]byte(s))
    rs := hex.EncodeToString(h.Sum(nil))
    return rs
}

func Md5(str string) string {
    return Strtomd5(str)
}

// 字符串base64加密
func Base64E(urlstring string) string {
    str := []byte(urlstring)
    data := base64.StdEncoding.EncodeToString(str)
    return data
}

// 字符串base64解密
func Base64D(urlxxstring string) string {
    data, err := base64.StdEncoding.DecodeString(urlxxstring)
    if err != nil {
        return ""
    }
    s := fmt.Sprintf("%q", data)
    s = strings.Replace(s, "\"", "", -1)
    return s
}

//url轉義
func UrlE(s string) string {
    return url.QueryEscape(s)
}

//url解義
func UrlD(s string) string {
    s, e := url.QueryUnescape(s)
    if e != nil {
        return e.Error()
    } else {
        return s
    }
}

現在大部分站點都開啟https來保證數據安全。



易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/23941.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×