export default { install(app) { const clearStorageSync = () => { let oneStart = uni.getStorageSync('oneStart') uni.clearStorageSync() uni.setStorageSync('oneStart', oneStart) } // 时间格式化 const formatDate = (date, fmt = 'YYYY-MM-DD HH:mm:ss') => { if (!date) return '' // 解决iOS时间格式兼容问题 if (typeof date === 'string') { date = date.replace(/-/g, '/') } const d = new Date(date) if (isNaN(d.getTime())) return '' const o = { 'M+': d.getMonth() + 1, // 月份 'D+': d.getDate(), // 日 'H+': d.getHours(), // 小时 'm+': d.getMinutes(), // 分 's+': d.getSeconds(), // 秒 'q+': Math.floor((d.getMonth() + 3) / 3), // 季度 'S': d.getMilliseconds() // 毫秒 } if (/(Y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (d.getFullYear() + '').substr(4 - RegExp.$1.length)) } for (const k in o) { if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[ k]).length))) } } return fmt } // 图片显示 const showFullImg = (img) => { if (!img) return ' ' return 'https://jiashikang.cn/images/' + img // return 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg' } app.config.globalProperties.$formatDate = formatDate app.provide('formatDate', formatDate) app.config.globalProperties.$showFullImg = showFullImg app.provide('showFullImg', showFullImg) app.provide('clearStorageSync', clearStorageSync) } }