1、微信小程序菜單內容左右聯動
如圖所以,左側是菜單欄,右側是主體內容,點擊左側菜單,右側滑動到相應的位置;右側滑動過程,也會改變左側菜單的選中狀態。本人的實現方案:
這樣還是存在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文件中修改: menuType:['food','dust','bowl','cages','toys','tools'], toView:'cages',
然后把下面函數修改一下: //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來保證數據安全。 |