/* 判空
|
*null, undefined, {}, [],"" 这五类都判定为空
|
*/
|
export function isEmpty(a) {
|
if (typeof a === 'string') { // 检验空字符串
|
const reg = /^\s+|\s+$/g
|
if (a.replace(reg, '') === '') {
|
return true
|
} else {
|
return false
|
}
|
} else {
|
if (a === 'null') return true // 检验字符串类型的null
|
if (a === 'undefined') return true // 检验字符串类型的 undefined
|
if (!a && a !== 0 && a !== '') return true // 检验 undefined 和 null
|
if (Object.prototype.toString.call(a) === '[object Array]' && a.length === 0) return true // 检验空数组
|
if (Object.prototype.toString(a) === '[object Object]' && Object.keys(a).length === 0) return true // 检验空对象
|
}
|
return false
|
}
|
|
// 获取cookie
|
export function getCookieValue(name) {
|
let result = document.cookie.match("(^|[^;]+)\\s*" + name + "\\s*=\\s*([^;]+)")
|
return result ? result.pop() : ""
|
}
|
|
// 设置cookie
|
// val = ets-app=token;path=/;expires=Fri, 31 Dec 9999 23:59:59 GMT
|
export function setCookieValue(val) {
|
return document.cookie = val;
|
}
|