zjk
2026-08-31 0284ff93129252683da82ed01f0e60f81839761c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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)
    }
}