|
|
@ -15,150 +15,150 @@ const exts = { |
|
|
|
// 各个站点首页的路径
|
|
|
|
// 各个站点首页的路径
|
|
|
|
const indexPath = ['/home', '/sfel', '/estate/index', '/iasf'] |
|
|
|
const indexPath = ['/home', '/sfel', '/estate/index', '/iasf'] |
|
|
|
const util = { |
|
|
|
const util = { |
|
|
|
local: _local, |
|
|
|
local: _local, |
|
|
|
//返回格式化时间,传参例如:"yyyy-MM-dd hh:mm:ss"
|
|
|
|
//返回格式化时间,传参例如:"yyyy-MM-dd hh:mm:ss"
|
|
|
|
formatDate(fmt, date) { |
|
|
|
formatDate (fmt, date) { |
|
|
|
var date = date ? date : new Date(); |
|
|
|
var date = date ? date : new Date(); |
|
|
|
var o = { |
|
|
|
var o = { |
|
|
|
"M+": date.getMonth() + 1, //月份
|
|
|
|
"M+": date.getMonth() + 1, //月份
|
|
|
|
"d+": date.getDate(), //日
|
|
|
|
"d+": date.getDate(), //日
|
|
|
|
"h+": date.getHours(), //小时
|
|
|
|
"h+": date.getHours(), //小时
|
|
|
|
"m+": date.getMinutes(), //分
|
|
|
|
"m+": date.getMinutes(), //分
|
|
|
|
"s+": date.getSeconds(), //秒
|
|
|
|
"s+": date.getSeconds(), //秒
|
|
|
|
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
|
|
|
|
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
|
|
|
|
"S": date.getMilliseconds() //毫秒
|
|
|
|
"S": date.getMilliseconds() //毫秒
|
|
|
|
}; |
|
|
|
}; |
|
|
|
if (/(y+)/.test(fmt)) { |
|
|
|
if (/(y+)/.test(fmt)) { |
|
|
|
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); |
|
|
|
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); |
|
|
|
} |
|
|
|
} |
|
|
|
for (var k in o) { |
|
|
|
for (var k in o) { |
|
|
|
if (new RegExp("(" + k + ")").test(fmt)) { |
|
|
|
if (new RegExp("(" + k + ")").test(fmt)) { |
|
|
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); |
|
|
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return fmt; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入文件后缀判断是否是视频
|
|
|
|
|
|
|
|
isVideo(ext) { |
|
|
|
|
|
|
|
if (exts.video.includes(ext)) return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入文件后缀判断是否是音频
|
|
|
|
|
|
|
|
isAudio(ext) { |
|
|
|
|
|
|
|
if (exts.audio.includes(ext)) return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入文件后缀判断是否是图片
|
|
|
|
|
|
|
|
isImg(ext) { |
|
|
|
|
|
|
|
if (exts.img.includes(ext)) return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入文件后缀判断是否是pdf以外的文档
|
|
|
|
|
|
|
|
isDoc(ext) { |
|
|
|
|
|
|
|
if (exts.doc.includes(ext)) return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入文件名和路径,下载图片视频,支持跨域,a标签加download不支持跨域
|
|
|
|
|
|
|
|
downloadFile(fileName, url) { |
|
|
|
|
|
|
|
var x = new XMLHttpRequest(); |
|
|
|
|
|
|
|
x.open("GET", url, true); |
|
|
|
|
|
|
|
x.responseType = "blob"; |
|
|
|
|
|
|
|
x.onload = function(e) { |
|
|
|
|
|
|
|
var url = window.URL.createObjectURL(x.response); |
|
|
|
|
|
|
|
var a = document.createElement("a"); |
|
|
|
|
|
|
|
a.href = url; |
|
|
|
|
|
|
|
a.download = fileName; |
|
|
|
|
|
|
|
a.click(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
x.send(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入文件名和数据,下载文件
|
|
|
|
|
|
|
|
downloadFileDirect(fileName,data) { |
|
|
|
|
|
|
|
if ('download' in document.createElement('a')) { // 非IE下载
|
|
|
|
|
|
|
|
const elink = document.createElement('a') |
|
|
|
|
|
|
|
elink.download = fileName |
|
|
|
|
|
|
|
elink.style.display = 'none' |
|
|
|
|
|
|
|
elink.href = URL.createObjectURL(data) |
|
|
|
|
|
|
|
document.body.appendChild(elink) |
|
|
|
|
|
|
|
elink.click() |
|
|
|
|
|
|
|
URL.revokeObjectURL(elink.href) // 释放URL 对象
|
|
|
|
|
|
|
|
document.body.removeChild(elink) |
|
|
|
|
|
|
|
} else { // IE10+下载
|
|
|
|
|
|
|
|
navigator.msSaveBlob(data, fileName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 成功提示
|
|
|
|
|
|
|
|
successMsg(message, duration = 3000) { |
|
|
|
|
|
|
|
Message.closeAll(); |
|
|
|
|
|
|
|
return Message.success({ |
|
|
|
|
|
|
|
message, |
|
|
|
|
|
|
|
showClose: true, |
|
|
|
|
|
|
|
duration |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 警告提示
|
|
|
|
|
|
|
|
warningMsg(message, duration = 3000) { |
|
|
|
|
|
|
|
Message.closeAll(); |
|
|
|
|
|
|
|
return Message.warning({ |
|
|
|
|
|
|
|
message, |
|
|
|
|
|
|
|
showClose: true, |
|
|
|
|
|
|
|
duration |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 错误提示
|
|
|
|
|
|
|
|
errorMsg(message, duration = 3000) { |
|
|
|
|
|
|
|
Message.closeAll(); |
|
|
|
|
|
|
|
return Message.error({ |
|
|
|
|
|
|
|
message, |
|
|
|
|
|
|
|
showClose: true, |
|
|
|
|
|
|
|
duration |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 去掉html里的标签及空格
|
|
|
|
|
|
|
|
removeTag(list, prop = 'mainBody') { |
|
|
|
|
|
|
|
list.map(e => { |
|
|
|
|
|
|
|
// 有摘要取摘要,没有摘要就去掉正文里的标签空格(也可以通过正则去除html标签,不过富文本里会有插入IE注释的情况下,直接创建一个元素取text比较简单)
|
|
|
|
|
|
|
|
const text = e.summary || e[prop].replace(/(<p class="img-des">[^>]+<\/p>)|(( )+)/g , '') |
|
|
|
|
|
|
|
const el = document.createElement('div') |
|
|
|
|
|
|
|
el.innerHTML = text |
|
|
|
|
|
|
|
// e.mainBody = e.summary || e[prop].replace(/(<p class="img-des">[^>]+<\/p>)|(<\!--[^-->]+-->)|(<[^>]+>)|(( )+)/g , '')
|
|
|
|
|
|
|
|
e.mainBody = el.innerText |
|
|
|
|
|
|
|
e.releaseTime = e.releaseTime.split(' ')[0] |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return list |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 获取url里的参数
|
|
|
|
|
|
|
|
getQuery(name) { |
|
|
|
|
|
|
|
let url = window.location.href |
|
|
|
|
|
|
|
let param = new Object() |
|
|
|
|
|
|
|
if (url.indexOf("?") != -1) { |
|
|
|
|
|
|
|
let str = url.split('?')[1] |
|
|
|
|
|
|
|
let strs = str.split("&") |
|
|
|
|
|
|
|
for(var i = 0; i < strs.length; i ++) { |
|
|
|
|
|
|
|
param[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return param[name] || null |
|
|
|
} |
|
|
|
}, |
|
|
|
return fmt; |
|
|
|
// 是否是各个站点的首页,首页的导航样式不一样,所以要单独判断
|
|
|
|
}, |
|
|
|
isIndex() { |
|
|
|
// 传入文件后缀判断是否是视频
|
|
|
|
return indexPath.includes(Router.app.$route.path) |
|
|
|
isVideo (ext) { |
|
|
|
}, |
|
|
|
if (exts.video.includes(ext)) return true; |
|
|
|
// 传入站点id,判断是否英文
|
|
|
|
return false; |
|
|
|
isEn(id) { |
|
|
|
}, |
|
|
|
return Setting.enIds.includes(+id) |
|
|
|
// 传入文件后缀判断是否是音频
|
|
|
|
}, |
|
|
|
isAudio (ext) { |
|
|
|
// 传入站点id,判断是否英文
|
|
|
|
if (exts.audio.includes(ext)) return true; |
|
|
|
getLang(id) { |
|
|
|
return false; |
|
|
|
let siteId = util.getQuery('siteId') |
|
|
|
}, |
|
|
|
return Setting.enIds.includes(siteId ? +siteId : store.state.content.site) ? 'en' : 'zh' |
|
|
|
// 传入文件后缀判断是否是图片
|
|
|
|
}, |
|
|
|
isImg (ext) { |
|
|
|
// rsa加密
|
|
|
|
if (exts.img.includes(ext)) return true; |
|
|
|
rsa(data) { |
|
|
|
return false; |
|
|
|
const jse = new JSEncrypt(); // 实例化一个 jsEncrypt 对象
|
|
|
|
}, |
|
|
|
jse.setPublicKey(Setting.publicKey); //配置公钥
|
|
|
|
// 传入文件后缀判断是否是pdf以外的文档
|
|
|
|
return jse.encrypt(JSON.stringify(data)) |
|
|
|
isDoc (ext) { |
|
|
|
}, |
|
|
|
if (exts.doc.includes(ext)) return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入文件名和路径,下载图片视频,支持跨域,a标签加download不支持跨域
|
|
|
|
|
|
|
|
downloadFile (fileName, url) { |
|
|
|
|
|
|
|
var x = new XMLHttpRequest(); |
|
|
|
|
|
|
|
x.open("GET", url, true); |
|
|
|
|
|
|
|
x.responseType = "blob"; |
|
|
|
|
|
|
|
x.onload = function (e) { |
|
|
|
|
|
|
|
var url = window.URL.createObjectURL(x.response); |
|
|
|
|
|
|
|
var a = document.createElement("a"); |
|
|
|
|
|
|
|
a.href = url; |
|
|
|
|
|
|
|
a.download = fileName; |
|
|
|
|
|
|
|
a.click(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
x.send(); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入文件名和数据,下载文件
|
|
|
|
|
|
|
|
downloadFileDirect (fileName, data) { |
|
|
|
|
|
|
|
if ('download' in document.createElement('a')) { // 非IE下载
|
|
|
|
|
|
|
|
const elink = document.createElement('a') |
|
|
|
|
|
|
|
elink.download = fileName |
|
|
|
|
|
|
|
elink.style.display = 'none' |
|
|
|
|
|
|
|
elink.href = URL.createObjectURL(data) |
|
|
|
|
|
|
|
document.body.appendChild(elink) |
|
|
|
|
|
|
|
elink.click() |
|
|
|
|
|
|
|
URL.revokeObjectURL(elink.href) // 释放URL 对象
|
|
|
|
|
|
|
|
document.body.removeChild(elink) |
|
|
|
|
|
|
|
} else { // IE10+下载
|
|
|
|
|
|
|
|
navigator.msSaveBlob(data, fileName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 成功提示
|
|
|
|
|
|
|
|
successMsg (message, duration = 3000) { |
|
|
|
|
|
|
|
Message.closeAll(); |
|
|
|
|
|
|
|
return Message.success({ |
|
|
|
|
|
|
|
message, |
|
|
|
|
|
|
|
showClose: true, |
|
|
|
|
|
|
|
duration |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 警告提示
|
|
|
|
|
|
|
|
warningMsg (message, duration = 3000) { |
|
|
|
|
|
|
|
Message.closeAll(); |
|
|
|
|
|
|
|
return Message.warning({ |
|
|
|
|
|
|
|
message, |
|
|
|
|
|
|
|
showClose: true, |
|
|
|
|
|
|
|
duration |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 错误提示
|
|
|
|
|
|
|
|
errorMsg (message, duration = 3000) { |
|
|
|
|
|
|
|
Message.closeAll(); |
|
|
|
|
|
|
|
return Message.error({ |
|
|
|
|
|
|
|
message, |
|
|
|
|
|
|
|
showClose: true, |
|
|
|
|
|
|
|
duration |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 去掉html里的标签及空格
|
|
|
|
|
|
|
|
removeTag (list, prop = 'mainBody') { |
|
|
|
|
|
|
|
list.map(e => { |
|
|
|
|
|
|
|
// 有摘要取摘要,没有摘要就去掉正文里的标签空格(也可以通过正则去除html标签,不过富文本里会有插入IE注释的情况下,直接创建一个元素取text比较简单)
|
|
|
|
|
|
|
|
const text = e.summary || e[prop].replace(/(<p class="img-des">[^>]+<\/p>)|(( )+)/g, '') |
|
|
|
|
|
|
|
const el = document.createElement('div') |
|
|
|
|
|
|
|
el.innerHTML = text |
|
|
|
|
|
|
|
// e.mainBody = e.summary || e[prop].replace(/(<p class="img-des">[^>]+<\/p>)|(<\!--[^-->]+-->)|(<[^>]+>)|(( )+)/g , '')
|
|
|
|
|
|
|
|
e.mainBody = el.innerText |
|
|
|
|
|
|
|
e.releaseTime = e.releaseTime.split(' ')[0] |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
return list |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 获取url里的参数
|
|
|
|
|
|
|
|
getQuery (name) { |
|
|
|
|
|
|
|
let url = window.location.href |
|
|
|
|
|
|
|
let param = new Object() |
|
|
|
|
|
|
|
if (url.indexOf("?") != -1) { |
|
|
|
|
|
|
|
let str = url.split('?')[1] |
|
|
|
|
|
|
|
let strs = str.split("&") |
|
|
|
|
|
|
|
for (var i = 0; i < strs.length; i++) { |
|
|
|
|
|
|
|
param[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return param[name] || null |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 是否是各个站点的首页,首页的导航样式不一样,所以要单独判断
|
|
|
|
|
|
|
|
isIndex () { |
|
|
|
|
|
|
|
return indexPath.includes(Router.app.$route.path) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入站点id,判断是否英文
|
|
|
|
|
|
|
|
isEn (id) { |
|
|
|
|
|
|
|
return Setting.enIds.includes(+id) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 传入站点id,判断是否英文
|
|
|
|
|
|
|
|
getLang (id) { |
|
|
|
|
|
|
|
let siteId = util.getQuery('siteId') || 2 |
|
|
|
|
|
|
|
return Setting.enIds.includes(siteId ? +siteId : store.state.content.site) ? 'en' : 'zh' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// rsa加密
|
|
|
|
|
|
|
|
rsa (data) { |
|
|
|
|
|
|
|
const jse = new JSEncrypt(); // 实例化一个 jsEncrypt 对象
|
|
|
|
|
|
|
|
jse.setPublicKey(Setting.publicKey); //配置公钥
|
|
|
|
|
|
|
|
return jse.encrypt(JSON.stringify(data)) |
|
|
|
|
|
|
|
}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export default util; |
|
|
|
export default util; |