jhzh
2025-04-03 db12897dc68c68d40c557aa59ad78022e2b30ac2
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import vue from 'vue';
import qs from 'qs'
import app from '@/app'
 
// 过去本地文件
let getFile = function (config) {
    return new Promise((ress, recs) => {
        // uni.showActionSheet({
        //     itemList: uni.getStorageSync('language')=='zh-CN'?['拍照', '从相册中选择']:['Camera', 'Album'],
        //     success(res) {
        //       console.log(res.tapIndex,)
        //       let sourceType ='camera'
        //       if (res.tapIndex == 0) {
        //        sourceType = 'camera'
        //       } else if (res.tapIndex == 1) {
        //        sourceType = 'album'
        //       }
        //       uni.chooseImage({
        //         count: config.config || 9,
        //           sourceType: [sourceType],
        //         success: (chooseImageRes) => {
        //             ress(chooseImageRes)
        //         },
        //         fail: () => {
        //             recs()
        //         }
        //       });
        //     }
        // })
        uni.chooseImage({
            count: config.config || 9,
            success: (chooseImageRes) => {
                ress(chooseImageRes)
            },
            fail: () => {
                recc()
            }
        });
    })
}
// 复制文本
function copy(txt) {
    uni.setClipboardData({
        data: txt,
        success: function () {
            uni.showToast({
                title: uni.getStorageSync('language')=='zh-CN'?'复制成功':'success',
                duration: 2000
            });
        }
    });
}
 
// 页面后退方法
vue.prototype.$back = (num = 1) => {
    uni.navigateBack(num)
    navFontColor()
}
 
// 标签过滤
function filterCode(str) {
    return str.replace(/<[^<>]+>/g, '').replace(/&nbsp;/ig, '')
}
 
// 解决uni-app slot 数组传递bug
vue.prototype.$list = function (obj) {
    return Object.entries(obj).filter(item => item[0] != '_i').map(item => item[1])
}
 
// 替换路由
vue.prototype._router = {
    push(path) {
        var url = '', query, animationType, animationDuration;
        if (typeof path == 'string') {
            url = path
        } else {
            url = path.path;
            query = qs.stringify(path.query);
            animationType = path.animationType
            animationDuration = path.animationDuration
        }
        uni.navigateTo({
            url: `${url}${url.includes('?') ? '&' : '?'}${query || ''}`,
            animationType,
            animationDuration
        });
        navFontColor()
    },
    replace(path) {
        var url = '', query, animationType, animationDuration;
        if (typeof path == 'string') {
            url = path
        } else {
            url = path.path || '';
            query = qs.stringify(path.query);
            animationType = path.animationType
            animationDuration = path.animationDuration
        }
        uni.redirectTo({
            url: `${url}${url.includes('?') ? '&' : '?'}${query || ''}`,
            animationType,
            animationDuration
        });
        navFontColor()
    }
}
function defaultTheme() {
    return `dark`
    // 获取当前时间
    let timeNow = new Date();
    // 获取当前小时
    let hours = timeNow.getHours();
    // 设置默认文字
    let state = ``;
    // 判断当前时间段
    if (hours >= 19 || hours <= 7) {
        state = `dark`;
    } else {
        state = `light`;
    }
    return state;
}
function navFontColor() {
    let theme = uni.getStorageSync('theme') || defaultTheme()
    setTimeout(() => {
        uni.setNavigationBarColor({
            frontColor: theme == 'light' ? '#000000' : '#ffffff',
            backgroundColor: '#cccccc',
        })
    }, 300)
}
function localImgUrl(name) {
    let theme = uni.getStorageSync('theme') || defaultTheme()
    let str = theme == 'light' ? 'static/img/light/' : 'static/img/'
    return str + name
}
vue.prototype.$imgUrl = app.imgUrl
vue.prototype.$baseUrl = app.baseUrl
vue.prototype.$getFile = getFile
vue.prototype.$copy = copy
vue.prototype.$filterCode = filterCode
vue.prototype.$navFontColor = navFontColor
vue.prototype.$localImgUrl = localImgUrl