import Vue from 'vue' import { pushSystemStatic } from '@/api/public' import { pageViewDataCacheKey } from '@/config/index' // 日期格式化 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(/]*>/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 }) // 去掉
标签 contentData = contentData.replace(/]*\/>/gi, '') // img标签添加style属性:max-width:100%;height:auto contentData = contentData.replace(/\ { const userInfo = uni.getStorageSync('userInfo') if (!userInfo) { return } let statsData = [] for (const key in Vue.prototype.$pageToWatchData) { if (Vue.prototype.$pageToWatchData[key]) { statsData = statsData.concat(Vue.prototype.$pageToWatchData[key]) } } if (statsData.length < 1) { console.log('*************没有页面埋点数据则不用上报,节约网络请求') return } // 设备类型phone、pad、pc、unknow const deviceType = uni.getSystemInfoSync().deviceType // 系统名称ios、android const osName = uni.getSystemInfoSync().osName console.log(deviceType) console.log(osName) const postData = { uid: userInfo.uid, deviceType: deviceType === 'phone' ? osName : 'unknown', statsData } console.log('开始上报数据-------------------') pushSystemStatic(postData).then(res => { const { success } = res if (success) { // 上报成功之后清空上一次的页面埋点数据 for (const key in Vue.prototype.$pageToWatchData) { Vue.prototype.$pageToWatchData[key] = [] } console.log('*************清除上次未登录缓存的页面埋点数据') uni.removeStorageSync(pageViewDataCacheKey) } }).catch(err => { console.log(err) }) }, 30 * 1000) }