//获取cookie、 export function getCookie(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return (arr[2]); else return null; } //设置cookie export function setCookie(c_name, value, expiredays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); }; //删除cookie export function delCookie(name){ var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = getCookie(name); if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString(); }; //格式化日期 yyyy-mm-dd export function formatDate(ns) { var date = new Date(ns * 1000); var y = date.getFullYear(); var m = date.getMonth() + 1; var d = date.getDate(); if (m < 10) { m = "0" + m; } if (d < 10) { d = "0" + d; } return y + "-" + m + "-" + d; } //格式化日期 export function timestampToTime(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 var Y = date.getFullYear(); var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1); var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()); var h = date.getHours(); var m = date.getMinutes(); var s = date.getSeconds(); h = h < 10 ? "0" + h : h; m = m < 10 ? "0" + m : m; s = s < 10 ? "0" + s : s; return Y + "-" + M + "-" + D + ' ' + h + ':' + m + ':'+ s; } /** 转换时间戳为指定格式 * @param {Number} timestamp 时间戳:10位就*1000, 13位或标准时间字符串保留,不是就默认转当前时间 * @param {String} type 格式类型:支持8种格式。默认格式 年月日时分秒 * @param {String} joinStr 连字符:"-", "/"等等。 默认 "-" 连接年月日 */ export function getFormatDate(timestamp, type, joinStr) { function addZero(n) { return Number(n) < 10 ? "0" + n : n; } if((timestamp).toString().length == 10) { date = new Date(timestamp * 1000); }else if((timestamp).toString().length >= 13){ date = new Date(timestamp); }else { date = new Date(); } if(!type) { type = "ymdhms"; } if(!joinStr) { joinStr = "-"; } var date; var time; var Y = date.getFullYear(); var M = addZero(date.getMonth() + 1); var D = addZero(date.getDate()); var h = addZero(date.getHours()); var m = addZero(date.getMinutes()); var s = addZero(date.getSeconds()); time = Y + joinStr + M + joinStr + D + ' ' + h + ':' + m + ':'+ s; //年月日 if(type == "ymd") { time = Y + joinStr + M + joinStr + D; } //年月 if(type == "ym") { time = Y + joinStr + M; } //月日 if(type == "md") { time = M + joinStr + D; } //时分秒 if(type == "hms") { time = h + ':' + m + ':'+ s; } //时分 if(type == "hm") { time = h + ':' + m; } //年月日 时分秒 if(type == "ymdhms") { time = Y + joinStr + M + joinStr + D + ' ' + h + ':' + m + ':'+ s; } //年月日 时分 if(type == "ymdhm") { time = Y + joinStr + M + joinStr + D + ' ' + h + ':' + m; } //月日 时分 if(type == "mdhm") { time = M + joinStr + D + ' ' + h + ':' + m; } return time; } //获取当前用户品牌列表 export function getBrandList(e,token) { let list let data = e.$http.get("/brand_list?AdminToken=" + token + '&type=auth').then( success => { list = success.data.list return list }, error => { console.log(error) } ) return data } // 获取详细权限 export function getAuthority(target,params){ target.$http.post("/navbar/fun",{ AdminToken:this.getCookie("token"), Classify_ID:params }).then(success=>{ if(success.data.status == "0"){ // console.log(success) let myData = success.data.data.Function_list; myData.forEach((v,i)=>{ let ID = v.ID return target.detailAuthority[ID] = ID }) } },error=>{ console.log(error) }) }
//复制内容到剪切板
//id: 要复制的内容的标签id,例如'#copy-content'
export function copyContent(id){
let range;
if (document.selection) {
//IE
range = document.body.createTextRange();
range.moveToElementText(document.getElementById('selectable'));
range.select();
}else if (window.getSelection) {
range = document.createRange();
let content = document.querySelector(id);
range.selectNode(content);
let selection = window.getSelection();
if(selection.rangeCount > 0) {
selection.removeAllRanges();
}
selection.addRange(range);
}
document.execCommand('copy');
};