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