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) => {
//处理token失效的情况
if (res.data.hasOwnProperty('data')) {
if (res.data.err_code === 501 || res.data.errcode === 501) {
wx.navigateTo({
wx.redirectTo({
url: '/pages/person/login/index'
});
} else {
......@@ -55,7 +55,7 @@ const getData = (url, type, param, callBack, loading, isheader, istoken) => {
}
} else {
if (res.data.err_code === 501 || res.data.errcode === 501) {
wx.navigateTo({
wx.redirectTo({
url: '/pages/person/login/index'
});
} else {
......@@ -144,13 +144,17 @@ const chooseImg = (url, num, callback) => {
}
})
};
const tips = (text) => {
wx.showToast({
title: text,
icon: 'none',
duration: 2000
});
}
};
const changeTime = (str) => {
let date = new Date(str);
let Hours = date.getHours();
......@@ -161,7 +165,9 @@ const changeTime = (str) => {
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);
return time;
}
};
const randomFun = () => {
let str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let newStr = "";
......@@ -170,7 +176,9 @@ const randomFun = () => {
newStr += str.substr(randomNum, 1)
}
return newStr
}
};
const sort = (arr) => {
for (let j = 0; j < arr.length; j++) {
for (let i = 0; i < arr.length - 1 - j; i++) {
......@@ -180,7 +188,9 @@ const sort = (arr) => {
}
}
return arr;
}
};
const encodeUTF8 = (s) => {
var i, r = [],
c, x;
......@@ -196,6 +206,8 @@ const encodeUTF8 = (s) => {
};
return r;
};
const sha1 = (s) => {
var data = new Uint8Array(encodeUTF8(s))
var i, j, t;
......@@ -207,20 +219,20 @@ const sha1 = (s) => {
s[l - 1] = data.length << 3;
var w = [],
f = [
function() {
function () {
return m[1] & m[2] | ~m[1] & m[3];
},
function() {
function () {
return m[1] ^ m[2] ^ m[3];
},
function() {
function () {
return m[1] & m[2] | m[1] & m[3] | m[2] & m[3];
},
function() {
function () {
return m[1] ^ m[2] ^ m[3];
}
],
rol = function(n, c) {
rol = function (n, c) {
return n << c | n >>> (32 - c);
},
k = [1518500249, 1859775393, -1894007588, -899497514],
......@@ -237,11 +249,13 @@ const sha1 = (s) => {
t = new DataView(new Uint32Array(m).buffer);
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);
}).join("");
return hex;
};
const dataEncryption = () => {
let timestamp = Date.parse(new Date()) / 1000;
let randomStr = randomFun();
......@@ -253,25 +267,27 @@ const dataEncryption = () => {
singnatrueStr: singnatrueStr,
timestampStr: timestamp
}
}
};
const judgeToken = (boolen) => {
let token = wx.getStorageSync('access_token');
if(token){
if (token) {
return true
}else{
if(boolen){
} else {
if (boolen) {
wx.redirectTo({
url: '/pages/person/login/index',
url: '/pages/person/login/index'
})
}
return false;
}
}
};
module.exports = {
getData: getData,
chooseImg: chooseImg,
tips: tips,
changeTime: changeTime,
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