isNull =
(value)=> {
return typeof value ==
'undefined' || value ==
"" || value ==
null || value ==
undefined|| value ==
"null";
};
current =
(str) => {
var _d =
new Date();
var _s = _d.getFullYear() +
'-' + (_d.getMonth() +
1) +
'-' + _d.getDate();
if (str) {
_s +=
' ' + _d.getHours() +
':' + _d.getMinutes() +
':' + _d.getSeconds();
}
return _s;
};
const viewport = {
width: $(
window).width(),
height: $(
window).height()
};
getPageName =
() => {
var href =
window.location.href;
var index = href.indexOf(
'?');
if (index >
0) {
href = href.substr(
0, index);
}
index = href.lastIndexOf(
'\/');
if (index >
0) {
href = href.substr(index +
1);
}
ret
setLocalStorage =
(key, value, isJson) => {
if (
window.localStorage) {
if (isJson) {
value =
JSON.stringify(value);
}
window.localStorage[key] = value;
}
else {
e.log(
"当前浏览器不支持localStorage");
}
};
getLocalStorage =
(key, isJson) => {
if (
window.localStorage) {
var value =
window.localStorage[key] ||
"";
if (isJson && value) {
value =
JSON.parse(value);
}
return value;
}
else {
e.log(
"当前浏览器不支持localStorage");
}
};
removelocalStorage =
(key)=> {
if (
window.localStorage) {
window.localStorage.removeItem(key);
}
};
setSessionStorage =
(key, content)=> {
if (
window.sessionStorage) {
window.sessionStorage[key] = content;
}
else {
e.log(
'您的浏览器不支持setSessionStorage方法');
}
};
getSessionStorage =
(key)=> {
if (
window.sessionStorage) {
return window.sessionStorage[key] ||
'';
}
else {
e.log(
'您的浏览器不支持getSessionStorage方法');
}
};
removeSessionStorage =
(key) =>{
if (
window.sessionStorage) {
window.sessionStorage.removeItem(key);
}
};
getCookie =
(cookie_name, decode)=> {
if (
'ACCESS_TOKEN' == cookie_name) {
return e.getLocalStorage(
'ACCESS_TOKEN');
}
decode = decode ||
true;
var allcookies =
document.cookie;
var cookie_pos = allcookies.indexOf(cookie_name);
var value =
'';
if (cookie_pos >
-1) {
cookie_pos += cookie_name.length +
1;
var cookie_end = allcookies.indexOf(
";", cookie_pos);
if (cookie_end ==
-1) {
cookie_end = allcookies.length;
}
value = allcookies.substring(cookie_pos, cookie_end);
if (decode) {
try {
value =
decodeURIComponent(value);
}
catch (e) {
console.log(e);
return "";
}
}
}
return value;
};
setCookie =
(cookie_name, cookie_value, domain, isencode, expTime)=> {
var exp =
new Date();
var expires =
"";
if (expTime) {
exp.setTime(exp.getTime() + expTime);
expires =
";expires=" + exp.toGMTString();
}
if (!domain) {
domain =
document.domain;
if (
/^[a-z]/i.test(
document.domain)) {
domain =
document.domain.substring(
document.domain.indexOf(
"."));
}
}
isencode =
typeof isencode ==
'undefined' ?
true : isencode;
if (isencode) {
cookie_value =
encodeURIComponent(cookie_value);
}
if (
'ACCESS_TOKEN' == cookie_name) {
e.setLocalStorage(
'ACCESS_TOKEN', cookie_value);
document.cookie = cookie_name +
"=" + cookie_value +
"; path=/; domain=" + domain +
";" + expires;
}
else {
document.cookie = cookie_name +
"=" + cookie_value +
"; path=/; domain=" + domain +
";" + expires;
}
};
getQueryString =
(names, urls, cn)=> {
if (urls) {
if (urls.indexOf(
'?') >
-1) {
urls = urls.substring(urls.indexOf(
'?') +
1);
}
else {
return '';
}
}
else {
urls =
window.location.search.substr(
1);
}
var reg =
new RegExp(
"(^|&)" + names +
"=([^&]*)(&|$)",
"i");
var r = urls.match(reg);
if (r && r[
2]) {
var ms = r[
2].match(
/(\<)|(\>)|(<)|(>)/g);
if (ms && ms.length >=
4) {
r[
2] = r[
2].replace(
/(\<)|(<)/g,
'');
}
if (cn) {
return r[
2];
}
return unescape(r[
2]);
}
return '';
};
function getPlatform (){
var platforms = {
amazon_fireos:
/cordova-amazon-fireos/,
android:
/Android/,
ios:
/(iPad)|(iPhone)|(iPod)/,
blackberry10:
/(BB10)/,
blackberry:
/(PlayBook)|(BlackBerry)/,
windows8:
/MSAppHost/,
windowsphone:
/Windows Phone/
};
for (
var key
in platforms) {
if (platforms[key].exec(navigator.userAgent)) {
return key;
}
}
return "";
};
isAndroidApp =
()=> {
var result =
false;
if (
window.javaBridgeInterface &&
window.javaBridgeInterface.getClientOS(
"android").toLocaleLowerCase() ===
'android') {
e.log(
'当前运行环境是在Android壳子中运行');
result =
true;
}
if (!result)
{
if(getPlatform() ==
"android" && isApp())
{
result =
true;
}
else
{
result =
false;
}
}
return result;
}();
isiPhoneApp =
()=> {
var result = e.getCookie(
'isiPhoneApp',
false) ||
"false";
if (result !=
"true") {
if (
typeof(getClientOS) ==
'function' && getClientOS().toLocaleLowerCase() ==
'ios') {
result =
"true";
e.log(
'当前运行环境是在iOS壳子中运行');
}
else if (
window.navigator.userAgent.indexOf(
",cpic_zt_ios") >
-1) {
result =
"true";
}
else {
result = (e.getQueryString(
"e") ==
"1").toString();
}
}
if (result !=
"true")
{
if(getPlatform() ==
"ios" && isApp())
{
result =
"true";
}
else
{
result =
"false";
}
}
e.setCookie(
'isiPhoneApp', result, getDomain());
return result ==
"true" ?
true :
false;
}();
isRunByApp =()=》 {
return isAndroidApp() || e.isiPhoneApp();
}();
function isApp()
{
var result =
true;
var userAgent =
window.navigator.userAgent;
if(userAgent.indexOf(
'Safari') >=
0)
{
result =
false;
}
if(result)
{
if(userAgent.indexOf(
'MicroMessenger') >=
0)
{
result =
false;
}
}
if(result)
{
if(userAgent.indexOf(
'QQ') >=
0)
{
result =
false;
}
}
if(result)
{
if(userAgent.indexOf(
'AliApp') >=
0)
{
result =
false;
}
}
if(result)
{
if(ua.indexOf(
"Weibo") >=
0 && ua.indexOf(
"_weibo_") >=
0)
{
result =
false;
}
}
return result;
}
formatDateTime =
(date)=> {
var y = date.getFullYear();
var m = date.getMonth() +
1;
m = m <
10 ? (
'0' + m) : m;
var d = date.getDate();
d = d <
10 ? (
'0' + d) : d;
var h = date.getHours();
var minute = date.getMinutes();
var seconds = date.getSeconds();
minute = minute <
10 ? (
'0' + minute) : minute;
return y +
'-' + m +
'-' + d+
' '+h+
':'+minute;
};
formatDateTimeNew =
(str)=> {
if(!str)
return;
var date =
new Date(str);
var y = date.getFullYear();
var m = date.getMonth() +
1;
m = m <
10 ? (
'0' + m) : m;
var d = date.getDate();
d = d <
10 ? (
'0' + d) : d;
return y +
'-' + m +
'-' + d;
};
getCurrentTime =
()=> {
var date =
new Date();
var seperator1 =
"-";
var seperator2 =
":";
var month = date.getMonth() +
1;
var strDate = date.getDate();
if (month >=
1 && month <=
9) {
month =
"0" + month;
}
if (strDate >=
0 && strDate <=
9) {
strDate =
"0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+
" " + date.getHours() + seperator2 + date.getMinutes();
return currentdate;
}
isWeixin =
()=>{
var ua = navigator.userAgent.toLowerCase();
if(ua.match(
/MicroMessenger/i) ==
"micromessenger") {
return true;
}
else {
return false;
}
}
function getDomain()
{
if (
/^\d/.test(
document.domain))
{
return document.domain;
}
else if (
/^[a-z]/i.test(
document.domain))
{
return document.domain.substring(
document.domain.indexOf(
"."));
}
return document.domain;
}
```