deming/static/js/common.js
2020-07-03 09:08:53 +08:00

34 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const common = {
/**
* 转义富文本标签
* @param { String } temp 后台返回需要处理的富文本
* @return { String } 处理好的富文本
*/
unescapeHTML(temp){
if(!temp) return '';
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'} = {}) {
if(!timestamp) return '';
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