baotian
2024-06-04 b959135a1139fb66646523d92e5bd20c5910f283
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
import colorModule from './modules/color.js'
import regModule from './modules/regexValidate.js'
 
export let color = colorModule;
export let regexValidate = regModule;
/* 生成随机uuid
*    n:uuid的长度
* type:类型(0-大小写字母+数字,1-小写字母+数字,2-纯数字,3-大小写字母,4-小写字母)
*/
export function uuid(n=6,type=0){
    let res='', uType=0;
    const __uuidLetter = function(){
        const __tempArr = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
        return __tempArr[Math.floor(Math.random()*26)];
    }
    for (let i=0;i<n;i++) {
        switch(type) {
            case 1:
                uType = Math.floor(Math.random()*2);
                if (uType===0) {
                    res += Math.floor(Math.random()*10).toString()
                } else {
                    res += __uuidLetter()
                }
                break;
            case 2:
                res += Math.floor(Math.random()*10).toString()
                break;
            case 3:
                uType = Math.floor(Math.random()*2);
                if (uType===0) {
                    res += __uuidLetter()
                } else {
                    res += __uuidLetter().toUpperCase()
                }
                break;
            case 4:
                res += __uuidLetter()
                break;
            default:
                uType = Math.floor(Math.random()*3);
                if (uType===0) {
                    res += Math.floor(Math.random()*10).toString()
                } else if (uType===1) {
                    res += __uuidLetter()
                } else {
                    res += __uuidLetter().toUpperCase()
                }
                break;
        }
    }
    return res;
}
export function $alert(msg,title="系统提示",callback){
    uni.showModal({
        title:title,
        content:msg,
        showCancel:false,
        confirmText:'确定',
        success:function(res){
            if (res.confirm) {
                callback && callback()
            }
        }
    })
}
export function $successInfo(info){
    uni.showToast({
        title:info,
        mask:true,
        icon:'success'
    })
};
 
/* 
  解析字典值
        code:字典集合码
        value:字典值
    返回:字典值对应名称
 */
export function parseDic(store,code,value){
    let res = '';
    let dicDataSource = store.getters['system/getEnum'];
    if (dicDataSource) {
        let _arr = [];
        for (let i=0;i<dicDataSource.length;i++) {
            if (dicDataSource[i].code===code) {
                _arr = dicDataSource[i].children || [];
                break;
            }
        }
        if (_arr.length>0) {
            for (let j=0;j<_arr.length;j++) {
                if (_arr[j].code==value) {
                    res = _arr[j].name;
                    break;
                }
            }
            if (!res) res = '无此字典'
        } else {
            res = '无此字典'
        }
    } else {
        res = 'Failed'
    }
    return res;
};
 
/* 
  下载更新
 */
export function downloadApk($config){
    try{
        const _downFun = function(){
            try{
                plus.runtime.openURL($config.downUrl, function(res) {console.log(res);});  
            }catch(ex){
                console.log('_downFun Error!')
                console.log(ex)
            }
            setTimeout(()=>{
                uni.hideLoading();
            },10000)
        }
        
        uni.showLoading({
            title: '开启下载...',
            mask:true
        });
        if (plus.networkinfo.getCurrentType() != 3){
            uni.hideLoading();
            uni.showModal({
                title:'系统提示',
                content:'当前非WIFI环境,确认继续下载吗?',
                success:(res)=>{
                    if (res.confirm) {
                        uni.showLoading({
                            title: '开启下载...',
                            mask:true
                        });
                        _downFun()
                    }
                }
            })
        } else {
            _downFun()
        }
    } catch(e){
        uni.hideLoading();
        uni.showModal({
            title:'系统提示',
            content:'下载失败',
            showCancel:false
        })
        console.log('DownloadApk Error!')
        console.log(e)
    }
};