cuiqian2004
2025-07-10 2db331628bbf94deee446d6e172e98f4db474a33
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
 
export function showModal(message, title = '提示', iscancel = true) {
    return new Promise((resolve) => {
        uni.showModal({
            title: title,
            content: message,
            showCancel: iscancel,
            confirmText: "确定",
            cancelText: "取消",
            success: function(res) {
                if (res.confirm) {
                    resolve(true)
                } else if (res.cancel) {
                    resolve(false)
                }
            }
        });
    })
}
 
export function showToast(title, icon) {
    uni.showToast({
        title: title,
        icon: icon ? icon : 'none'
    })
}
export function showLoading(title) {
 
    // #ifdef MP-WEIXIN
    uni.showLoading({
        title: title,
        mask: true
    })
    // #endif
    // #ifndef MP-WEIXIN
    uni.showLoading({
        title: title
    })
    // #endif
}
 
export function hideLoading() {
 
    uni.hideLoading()
}
 
 
//根据field获取数据
export function getData(thiz, field) {
    // 通过正则表达式  查找路径数据
    const regex = /([\w$]+)|\[(:\d)\]/g
    const patten = field.match(regex)
    let result = thiz // 指向调用的数据 如data
    // 遍历路径  逐级查找  最后一级用于直接赋值
    for (let i = 0; i < patten.length - 1; i++) {
        let key = patten[i]
        result = result[key]
    }
    return result[patten[patten.length - 1]]
}
//页面点击时对参数进行了转义,要进行反转义
export function getOption(option) {
    if (option !== null && typeof option === 'object') {
        for (let key in option) {
            option[key] = decodeURIComponent(option[key])
        }
    }
    return option
}
 
 
export function getCurUserId() {
    const data = getApp().globalData.userdata
    if (data)
        return data.user_login || ""
    else
        return ""
}
 
export function getCurUserName() {
    const data = getApp().globalData.userdata
    if (data)
        return data.user_name || ""
    else
        return ""
 
}
 
export function  getGuid() {
    function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    }
    return (S4() + S4() + "_" + S4() + "_" + S4() + "_" + S4() + "_" + S4() + S4() + S4());
}