deming/static/js/common.js

34 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-07-01 09:32:36 +00:00
const common = {
/**
* 转义富文本标签
* @param { String } temp 后台返回需要处理的富文本
* @return { String } 处理好的富文本
*/
unescapeHTML(temp){
2020-07-03 01:08:53 +00:00
if(!temp) return '';
2020-07-01 09:32:36 +00:00
temp = "" + temp;
return temp.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
},
/**
* php时间戳转为格式化日期
* @param { String } timestamp 必填 php返回的时间戳
* @param { String } spacer 可选 日期间隔符,默认 '-'
* @param { String } end 可选 年月日时分秒截止位置默认 day可传 second
* @return { String } 格式化日期
*/
timestampToDate({timestamp, spacer = '-', end = 'day'} = {}) {
2020-07-03 01:08:53 +00:00
if(!timestamp) return '';
2020-07-01 09:32:36 +00:00
const newDate = new Date(parseInt(timestamp) * 1000);
// const year = newDate.getUTCFullYear();
const year = newDate.getFullYear();
const month = newDate.getMonth() + 1;
const nowday = newDate.getDate();
const hours = newDate.getHours();
const minutes = newDate.getMinutes();
const seconds = newDate.getSeconds();
return end == 'day'
? year + spacer + month + spacer + nowday
: year + spacer + month + spacer + nowday + spacer + hours + spacer + minutes + spacer + seconds;
}
}
export default common