cshenfu
2024-05-21 09d8c671d5e6e6045677bfb5218a5fb78c26aa0f
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
const formatTime = date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()
 
    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
 
const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : '0' + n
}
 
const durationForHuman = duration => {
    let minutes = parseInt(duration / 60);
    let seconds = duration % 10;
    // console.log(duration, minutes, seconds);
    if (minutes.length === 0) {
        minutes = '0' + minutes.toString();
    }
    if (seconds.length === 0) {
        seconds = '0' + seconds.toString();
    }
    return minutes + '分钟' + seconds + '秒';
}
 
const loginCheck = () => {
    if (!uni.getStorageSync('access_token')) {
        uni.showModal({
            title: "提示",
            content: "登录后内容更精彩,是否前往登录?",
            success(res) {
                if (res.confirm) {
                    uni.navigateTo({
                        url: '/pages/auth/login',
                    })
                }
            }
        })
    }
}
 
const go = (page, auth = false) => {
    if (auth && !uni.vk.callFunctionUtil.checkToken()) {
 
        // #ifdef MP
        uni.showModal({
            title: "提示",
            content: "登录后内容更精彩,是否前往登录?",
            success(res) {
                if (res.confirm) {
                    uni.navigateTo({
                        url: '/pages/login/index/index?redirect=' + encodeURIComponent(page),
                    })
                }
            }
        })
        // #endif
 
        // #ifndef MP
        uni.navigateTo({
            url: '/pages/login/index/index?redirect=' + encodeURIComponent(page),
        })
        // #endif
 
        return
    }
 
    uni.navigateTo({
        url: page,
    })
}
 
const isIos = () => {
    let info = uni.getSystemInfoSync();
    return info.platform === 'ios';
}
 
const platform = () => {
    let platform = '';
    // #ifdef APP-PLUS
    platform = 'APP';
    // #endif
 
    // #ifdef H5
    if (isWechat()) {
        platform = 'WECHAT-H5';
    } else {
        platform = 'H5';
    }
    // #endif
 
    // #ifdef MP
    platform = 'MP-ALIPAY';
    // #endif
 
    // #ifdef MP-WEIXIN
    platform = 'MP-WEIXIN';
    // #endif
 
    // #ifdef MP-ALIPAY
    platform = 'MP-ALIPAY';
    // #endif
 
    return platform;
}
 
const getWeiXinLoginPlatfo = () => {
    let platform = undefined;
 
    // #ifdef APP-PLUS
    platform = 'app-plus';
    // #endif
 
    // #ifdef H5
    if (isWechat()) {
        platform = 'h5-weixin';
    }
    // #endif
 
    // #ifdef MP-WEIXIN
    platform = 'mp-weixin';
    // #endif
 
    return platform;
}
 
const isIosWechatMini = () => {
    let systemInfo = uni.getSystemInfoSync();
    return process.env.VUE_APP_PLATFORM === 'mp-weixin' && systemInfo.platform === 'ios';
}
const isWechatMini = () => {
    return process.env.VUE_APP_PLATFORM === 'mp-weixin';
}
const isH5 = () => {
    return process.env.VUE_APP_PLATFORM === 'h5';
}
const isIosApp = () => {
    let i = false;
    // #ifdef APP-PLUS
    i = uni.getSystemInfoSync().platform === 'ios';
    // #endif
    return i;
}
const isWechat = () => {
    if (typeof window === 'undefined') {
        return false;
    }
    let ua = window.navigator.userAgent.toLowerCase();
    return /micromessenger/.test(ua) ? true : false;
}
const get = (key) => {
    if (typeof window === 'undefined') {
        return null;
    }
    let url = window.location.href.split('?');
    let query = url.length === 1 ? '' : url[1];
    let vars = query.split("&");
    for (let i = 0; i < vars.length; i++) {
        let pair = vars[i].split("=");
        if (pair[0] == key) {
            return pair[1];
        }
    }
    return null;
}
const chunk = (array, subGroupLength) => {
    var index = 0;
    var newArray = [];
 
    while (index < array.length) {
        newArray.push(array.slice(index, index += subGroupLength));
    }
 
    return newArray;
}
const random = (minNum, maxNum) => {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * minNum + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
            break;
        default:
            return 0;
            break;
    }
}
 
const transOrderType = (type) => {
    var constType = {
        "course": "点播课",
        "articel": "资讯",
        "pay-article": "图文",
        "free-live-course": "公开课",
        "q-bank": "题库",
        "bbs": "问答",
    }
 
    return constType[type] || "未知的订单类型"
}
 
const transOrderStatus = (code) => {
    var payStatus = [{
        "label": "待付款",
        "value": 1
    }, {
        "label": "已付款",
        "value": 2
    }, {
        "label": "退款审核中",
        "value": 3
    }, {
        "label": "退款中",
        "value": 4
    }, {
        "label": "已退款",
        "value": 5
    }, {
        "label": "已取消付款/退款",
        "value": -1
    }, {
        "label": "退款拒绝",
        "value": -2
    }, {
        "label": "退款失败",
        "value": -3
    }]
    let status = payStatus.find(v => v.value == code)
    if (!status) {
        status = {
            "label": "未知状态",
            "value": code
        }
    }
    let color = '#606266'
    switch (code) {
        case 2:
            color = '#42b983'
            break
        case 5:
            color = 'red'
            break
    }
    return { ...status, color }
}
 
module.exports = {
    formatTime: formatTime,
    durationForHuman: durationForHuman,
    loginCheck: loginCheck,
    go: go,
    isIos: isIos,
    platform: platform,
    getWeiXinLoginPlatfo: getWeiXinLoginPlatfo,
    isIosWechatMini: isIosWechatMini,
    isWechatMini: isWechatMini,
    isH5: isH5,
    isIosApp: isIosApp,
    isWechat: isWechat,
    get: get,
    chunk: chunk,
    random: random,
    transOrderType: transOrderType,
    transOrderStatus: transOrderStatus
}