cuiqian2004
4 天以前 2af5f043b60c1f7ac38ecccc8f5bf44743134325
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
import {
    sendEmail as sendEmailAndroid
} from './utils-android.js';
import {
    sendEmail as sendEmailiOS
} from './utils-ios.js';
 
const SESSION_SUFFIX = "diniu_app_"
 
export function showModal({
    content,
    title = '',
    showCancel = true,
    confirmText,
    cancelText
}) {
    return new Promise((resolve) => {
        uni.showModal({
            title,
            content,
            showCancel,
            confirmText,
            cancelText,
            success: function(res) {
                if (res.confirm) {
                    resolve(true)
                } else if (res.cancel) {
                    resolve(false)
                }
            }
        });
    })
}
 
export function showToast(ex) {
    if (!ex)
        return
    let tip = ex
    // console.log(ex);
    if (typeof ex !== "string") {
        let exStr = JSON.stringify(ex)
        if (exStr == "{}")
            exStr = ex
        tip = typeof ex.errMsg == "string" ? ex.errMsg : typeof ex.msg == "string" ? ex.msg : typeof ex.message ==
            "string" ? ex.message : exStr
    }
    plus.nativeUI.toast(tip, {
        duration: "short",
        verticalAlign: "center"
    });
    // uni.showToast({
    //     title: title,
    //     icon: icon ? icon : 'none'
    // })
}
export function showInfo(ex) {
    if (!ex)
        return
    let tip = ex
    // console.log(ex);
    if (typeof ex !== "string") {
        let exStr = JSON.stringify(ex)
        if (exStr == "{}")
            exStr = ex
        tip = typeof ex.errMsg == "string" ? ex.errMsg : typeof ex.msg == "string" ? ex.msg : typeof ex.message ==
            "string" ? ex.message : exStr
    }
    // plus.nativeUI.toast(tip, {
    //     duration: "short",
    //     verticalAlign:"center"
    // });
    return uni.showModal({
        // title: "提示",
        content: tip,
        showCancel: false
    });
}
 
export function showError(ex, title = "") {
    if (!ex)
        return
    let tip = ex
    if (typeof ex !== "string") {
        let exStr = JSON.stringify(ex)
        if (exStr == "{}")
            exStr = ex
        tip = typeof ex.errMsg == "string" ? ex.errMsg : typeof ex.msg == "string" ? ex.msg : typeof ex.message ==
            "string" ? ex.message : exStr
    }
    console.log(ex, tip)
    //plus.nativeUI.alert(tip,title);
    return uni.showModal({
        title: title || "",
        content: tip,
        showCancel: false
    });
}
export function showLoading(title) {
    uni.showLoading({
        title: title,
        mask: true
    })
}
 
 
export function hexToRGBA(hex, alpha) {
    const r = parseInt(hex.slice(1, 3), 16);
    const g = parseInt(hex.slice(3, 5), 16);
    const b = parseInt(hex.slice(5, 7), 16);
 
    return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}
 
export function hideLoading() {
 
    uni.hideLoading()
}
// 1. 把任意数据写成 txt 文件
export function saveAndSendEmail(data, fileName = 'report.txt') {
    const fullPath = `_esgo/${fileName}`; // 沙盒内路径
    plus.io.requestFileSystem(plus.io.PRIVATE_DOC, fs => {
        fs.root.getFile(fullPath, {
            create: true
        }, fileEntry => {
            fileEntry.createWriter(writer => {
                writer.onwrite = () => {
                    // 写完立即发邮件
                    sendEmailWithAttach(fileEntry.fullPath);
                };
                writer.write(data); // data 可以是字符串/JSON
            });
        });
    });
}
//带附件调起系统邮件客户端
export function sendEmailWithAttach(absPath) {
    const platform = uni.getSystemInfoSync().platform;
    if (platform === 'android') {
        sendEmailAndroid(absPath);
    } else if (platform === 'ios') {
        sendEmailiOS(absPath);
    }
}
 
let session = {
    setValue(key, value) {
        let suffixStr = SESSION_SUFFIX
        if (value == null) {
            uni.removeStorageSync(suffixStr + key)
        } else {
            uni.setStorageSync(suffixStr + key, value);
        }
    },
 
    getValue(key) {
        let suffixStr = SESSION_SUFFIX
        return uni.getStorageSync(suffixStr + key) || null;
    },
 
    clearValue(key) {
        let suffixStr = SESSION_SUFFIX
        return uni.removeStorageSync(suffixStr + key);
    },
}
export {
    session
}