演示项目-图书馆
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

113 lines
3.3 KiB

export const Urlencode = str => {
str = (str + '').toString();
return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}
export const isIPhoneX = () => {
let u = navigator.userAgent;
let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if (isIOS) {
if (screen.height == 812 && screen.width == 375) {
return true;
}
else {
return false;
}
}
}
//获取url 参数值,并解码
export const getUnescapeUrlParam = (name) => {
let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
let localUrl = window.location.href.split("?")[1]
let r = localUrl.match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
// 截取时间
export const cutTime = (val) => {
if (val == null) {
return val
} else {
return val.slice(0, val.indexOf("T"))
}
}
// 判断是否登录才可操作
export const isLogin = (proxy,$dialog) => {
let userData = localStorage.getItem('userData') || "";
// clientType主要是鉴别当前用户的类型
// ClientType = 1 普通用户
// ClientType = 0 白名单用户
if (JSON.parse(userData).clientType === 0) {
proxy.$dialog.confirm({
title: '',
message: '该功能需要登录账号!',
})
.then(() => {
proxy.$router.push('/Login');
})
.catch(() => {
console.log('用户点击取消');
});
return false;
}
}
// 时间格式化1 val时间戳数字
export const formatDateDay = (val) => {
let date = new Date(val);
let YY = date.getFullYear() + '-';
let MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
let DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
return YY + MM + + DD
}
// 时间格式化2 val时间戳数字
export const formatDateMin = (val) => {
let date = new Date(val);
let YY = date.getFullYear() + '-';
let MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
let DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
let hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
let mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
let ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
return YY + MM + DD +" "+ hh + mm + ss;
}
// 判断是否微信浏览器
export const isWeiXin = () => {
let ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
return true;
}else{
return false;
}
}
//获取url 参数值 (原封不动获取url 参数, 不解码)
const getUrlParam = (name) => {
let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
let localUrl = window.location.href.split("?")[1]
let r = localUrl.match(reg);
if (r != null) {
return r[2];
}
return null;
}
//检测是否是移动端
const isMobile = () => {
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
return true;
} else {
return false;
}
}