//获取cookie、
export const getCookie=(name)=>{
let arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
if (arr = document.cookie.match(reg))
return (arr[2]);
else
return null;
};
//设置cookie,增加到vue实例方便全局调用
export const setCookie=(c_name, value, expiredays)=>{
let exdate = new Date();
exdate.setDate(exdate.getDate() + expiredays);
document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
};
//删除cookie
export const delCookie=(name)=>{
let exp = new Date();
exp.setTime(exp.getTime() - 1);
let cval = getCookie(name);
if (cval != null)
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
};
//导出excel
export const exportExcel = (table, name)=>{
let tableHtml;
if(table.refs);
let header=table.refs.body.querySelector('tbody').outerHTML;
tableHtml=header+body;
}else {
tableHtml=table.innerHTML;
}
let uri = 'data:application/vnd.ms-excel;base64,',
template = <html> <head><meta charset="UTF-8"></head> <body><table border="1">${tableHtml}</table></body> </html>
;
let a=document.createElement('a');
a.href=uri + window.btoa(unescape(encodeURIComponent(template)));
a.download=name;
a.click();
document.removeChild(a);
};
网友评论