60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
import Vue from 'vue'
|
|
|
|
// 日期格式化
|
|
export function formatterDate(date, flag = '-', mode = 'date') {
|
|
const year = new Date(date).getFullYear()
|
|
const month = new Date(date).getMonth() + 1
|
|
const day = new Date(date).getDate()
|
|
return `${year}${flag}${month > 9 ? month : '0' + month}${flag}${day > 9 ? day : '0' + day}`
|
|
}
|
|
|
|
export function formatContent(html) {
|
|
// 去掉img标签里的style、width、height属性
|
|
let contentData = html.replace(/<img[^>]*>/gi, function(match, capture) {
|
|
match = match.replace(`style=""`, '')
|
|
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '')
|
|
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '')
|
|
match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '')
|
|
return match
|
|
}) // 修改所有style里的width属性为max-width:100%
|
|
contentData = contentData.replace(/style="[^"]+"/gi, function(match, capture) {
|
|
match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;'); return match
|
|
}) // 去掉<br/>标签
|
|
contentData = contentData.replace(/<br[^>]*\/>/gi, '') // img标签添加style属性:max-width:100%;height:auto
|
|
contentData = contentData.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin:0 auto;"')
|
|
return contentData
|
|
}
|
|
|
|
/**
|
|
* desc: 监听页面访问次数
|
|
* auth: lifizer
|
|
* date: 2024-05-16
|
|
* @param key-页面唯一标识
|
|
* @param cb-回调函数
|
|
* @returns {null}
|
|
*/
|
|
export function pageToWatchShowCount(key, cb = '') {
|
|
if (Vue.prototype.$pageToWatchData[key]) {
|
|
Vue.prototype.$pageToWatchData[key].count++
|
|
} else {
|
|
Vue.prototype.$pageToWatchData[key] = {
|
|
count: 1,
|
|
timer: 0
|
|
}
|
|
}
|
|
cb && cb()
|
|
}
|
|
|
|
/**
|
|
* desc: 监听页面访问时长
|
|
* auth: lifizer
|
|
* date: 2024-05-16
|
|
* @param key-页面唯一标识
|
|
* @returns {null}
|
|
*/
|
|
export function pageToWatchShowTimer(key) {
|
|
if (Vue.prototype.$pageToWatchData[key]) {
|
|
Vue.prototype.$pageToWatchData[key].timer++
|
|
}
|
|
}
|