Commit 6ee28efc by 梁建民

js

parent e1cec561
Showing with 36 additions and 19 deletions
...@@ -47,7 +47,7 @@ const getData = (url, type, param, callBack, loading, isheader, istoken) => { ...@@ -47,7 +47,7 @@ const getData = (url, type, param, callBack, loading, isheader, istoken) => {
//处理token失效的情况 //处理token失效的情况
if (res.data.hasOwnProperty('data')) { if (res.data.hasOwnProperty('data')) {
if (res.data.err_code === 501 || res.data.errcode === 501) { if (res.data.err_code === 501 || res.data.errcode === 501) {
wx.navigateTo({ wx.redirectTo({
url: '/pages/person/login/index' url: '/pages/person/login/index'
}); });
} else { } else {
...@@ -55,7 +55,7 @@ const getData = (url, type, param, callBack, loading, isheader, istoken) => { ...@@ -55,7 +55,7 @@ const getData = (url, type, param, callBack, loading, isheader, istoken) => {
} }
} else { } else {
if (res.data.err_code === 501 || res.data.errcode === 501) { if (res.data.err_code === 501 || res.data.errcode === 501) {
wx.navigateTo({ wx.redirectTo({
url: '/pages/person/login/index' url: '/pages/person/login/index'
}); });
} else { } else {
...@@ -144,13 +144,17 @@ const chooseImg = (url, num, callback) => { ...@@ -144,13 +144,17 @@ const chooseImg = (url, num, callback) => {
} }
}) })
}; };
const tips = (text) => { const tips = (text) => {
wx.showToast({ wx.showToast({
title: text, title: text,
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}); });
} };
const changeTime = (str) => { const changeTime = (str) => {
let date = new Date(str); let date = new Date(str);
let Hours = date.getHours(); let Hours = date.getHours();
...@@ -161,7 +165,9 @@ const changeTime = (str) => { ...@@ -161,7 +165,9 @@ const changeTime = (str) => {
let time = date.getFullYear() + "-" + (Month < 10 ? "0" + Month : Month) + "-" + (Day < 10 ? "0" + Day : Day) + " " + let time = date.getFullYear() + "-" + (Month < 10 ? "0" + Month : Month) + "-" + (Day < 10 ? "0" + Day : Day) + " " +
(Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds); (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds);
return time; return time;
} };
const randomFun = () => { const randomFun = () => {
let str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; let str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let newStr = ""; let newStr = "";
...@@ -170,7 +176,9 @@ const randomFun = () => { ...@@ -170,7 +176,9 @@ const randomFun = () => {
newStr += str.substr(randomNum, 1) newStr += str.substr(randomNum, 1)
} }
return newStr return newStr
} };
const sort = (arr) => { const sort = (arr) => {
for (let j = 0; j < arr.length; j++) { for (let j = 0; j < arr.length; j++) {
for (let i = 0; i < arr.length - 1 - j; i++) { for (let i = 0; i < arr.length - 1 - j; i++) {
...@@ -180,7 +188,9 @@ const sort = (arr) => { ...@@ -180,7 +188,9 @@ const sort = (arr) => {
} }
} }
return arr; return arr;
} };
const encodeUTF8 = (s) => { const encodeUTF8 = (s) => {
var i, r = [], var i, r = [],
c, x; c, x;
...@@ -196,6 +206,8 @@ const encodeUTF8 = (s) => { ...@@ -196,6 +206,8 @@ const encodeUTF8 = (s) => {
}; };
return r; return r;
}; };
const sha1 = (s) => { const sha1 = (s) => {
var data = new Uint8Array(encodeUTF8(s)) var data = new Uint8Array(encodeUTF8(s))
var i, j, t; var i, j, t;
...@@ -207,20 +219,20 @@ const sha1 = (s) => { ...@@ -207,20 +219,20 @@ const sha1 = (s) => {
s[l - 1] = data.length << 3; s[l - 1] = data.length << 3;
var w = [], var w = [],
f = [ f = [
function() { function () {
return m[1] & m[2] | ~m[1] & m[3]; return m[1] & m[2] | ~m[1] & m[3];
}, },
function() { function () {
return m[1] ^ m[2] ^ m[3]; return m[1] ^ m[2] ^ m[3];
}, },
function() { function () {
return m[1] & m[2] | m[1] & m[3] | m[2] & m[3]; return m[1] & m[2] | m[1] & m[3] | m[2] & m[3];
}, },
function() { function () {
return m[1] ^ m[2] ^ m[3]; return m[1] ^ m[2] ^ m[3];
} }
], ],
rol = function(n, c) { rol = function (n, c) {
return n << c | n >>> (32 - c); return n << c | n >>> (32 - c);
}, },
k = [1518500249, 1859775393, -1894007588, -899497514], k = [1518500249, 1859775393, -1894007588, -899497514],
...@@ -237,11 +249,13 @@ const sha1 = (s) => { ...@@ -237,11 +249,13 @@ const sha1 = (s) => {
t = new DataView(new Uint32Array(m).buffer); t = new DataView(new Uint32Array(m).buffer);
for (var i = 0; i < 5; i++) m[i] = t.getUint32(i << 2); for (var i = 0; i < 5; i++) m[i] = t.getUint32(i << 2);
var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function(e) { var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) {
return (e < 16 ? "0" : "") + e.toString(16); return (e < 16 ? "0" : "") + e.toString(16);
}).join(""); }).join("");
return hex; return hex;
}; };
const dataEncryption = () => { const dataEncryption = () => {
let timestamp = Date.parse(new Date()) / 1000; let timestamp = Date.parse(new Date()) / 1000;
let randomStr = randomFun(); let randomStr = randomFun();
...@@ -253,25 +267,27 @@ const dataEncryption = () => { ...@@ -253,25 +267,27 @@ const dataEncryption = () => {
singnatrueStr: singnatrueStr, singnatrueStr: singnatrueStr,
timestampStr: timestamp timestampStr: timestamp
} }
} };
const judgeToken = (boolen) => { const judgeToken = (boolen) => {
let token = wx.getStorageSync('access_token'); let token = wx.getStorageSync('access_token');
if(token){ if (token) {
return true return true
}else{ } else {
if(boolen){ if (boolen) {
wx.redirectTo({ wx.redirectTo({
url: '/pages/person/login/index', url: '/pages/person/login/index'
}) })
} }
return false; return false;
} }
} };
module.exports = { module.exports = {
getData: getData, getData: getData,
chooseImg: chooseImg, chooseImg: chooseImg,
tips: tips, tips: tips,
changeTime: changeTime, changeTime: changeTime,
dataEncryption: dataEncryption, dataEncryption: dataEncryption,
judgeToken:judgeToken judgeToken: judgeToken
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment