70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
class utils {
|
|
|
|
random(len) {
|
|
len = len || 32;
|
|
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
|
|
/****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
|
|
var maxPos = $chars.length;
|
|
var pwd = '';
|
|
for (var i = 0; i < len; i++) {
|
|
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
|
|
}
|
|
return pwd;
|
|
}
|
|
|
|
time(time) {
|
|
var d = time ? new Date(time) : new Date();
|
|
var year = d.getFullYear();
|
|
var month = d.getMonth() + 1;
|
|
var day = d.getDate();
|
|
var hours = d.getHours();
|
|
var min = d.getMinutes();
|
|
var seconds = d.getSeconds();
|
|
|
|
if (month < 10) month = '0' + month;
|
|
if (day < 10) day = '0' + day;
|
|
if (hours < 0) hours = '0' + hours;
|
|
if (min < 10) min = '0' + min;
|
|
if (seconds < 10) seconds = '0' + seconds;
|
|
|
|
return (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);
|
|
}
|
|
|
|
checkPhone(phone) {
|
|
return /^1[3456789]\d{9}$/.test(phone)
|
|
}
|
|
|
|
checkIsLogin() {
|
|
const isLogin = wx.getStorageSync('user')
|
|
// 如果已经登录,那么直接跳转首页
|
|
if (typeof isLogin == "object") {
|
|
return true;
|
|
} else {
|
|
wx.showModal({
|
|
title: '',
|
|
content: '未登录,请先登录!',
|
|
showCancel: false,
|
|
success (res) {
|
|
if (res.confirm) {
|
|
wx.redirectTo({ url: '/pages/account/account' })
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
showToast(options) {
|
|
const duration = options.duration || 2000
|
|
wx.showToast(options)
|
|
if (options.close) {
|
|
setTimeout(() => { options.close('hideToast') }, duration)
|
|
}
|
|
}
|
|
|
|
test() {
|
|
console.log("工具函数");
|
|
}
|
|
|
|
}
|
|
|
|
export default new utils(); |