schangxiang@126.com
2025-05-14 f2643367f79a7136c9ddd92b68922112b5c06ef3
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
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:字典集合码
    返回:字典列表
 */
export function getDicList(store,code) {
    let res = [];
    let dicDataSource = store.getters['system/getEnum'];
    if (dicDataSource) {
        res=dicDataSource.filter(item=>item.code==code)
    } 
    return res.length>0?res[0]:[];
}
 
/* 
  解析字典值
        code:字典集合码
        value:字典值
    返回:字典值对应名称
 */
export function parseDic(store,code,value){
    let res = '';
    let dicDataSource = store.getters['system/getEnum'];
    if (dicDataSource) {
        let _arr = dicDataSource.filter(item=>item.code==code)
        if (_arr.length>0) {
            res=_arr[0]?.sysDictDatas.filter(item=>item.code==value)
            res=res.length>0?res[0].value:''
            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)
    }
};
 
export function getObjectType(obj){
    if (typeof obj !== 'object') {
        return null;
    } else {
        let objTypeStr = Object.prototype.toString.call(obj).toLowerCase().trim();
        objTypeStr = objTypeStr.substr(1,objTypeStr.length-2)
        let tempA = objTypeStr.split(" ");
        return tempA[1];
    }    
}
 
export function getUserDefaultArea($store,arr,valueField='code'){
  let res = ''
  const _default = $store.getters['user/getUserInfo']['workShopType']
  for (let i=0;i<arr.length;i++){
    if (String(arr[i][valueField])===Sring(_default)) {
      res = _default
      break;
    }
  }
  return res
}
 
export function getUserDefaultLine($store,arr,valueField='productionlineId'){
  let res = ''
  const _default = $store.getters['user/getUserInfo']['productionlineId']
  for (let i=0;i<arr.length;i++){
    if (arr[i][valueField]===_default) {
      res = _default
      break;
    }
  }
    return res
}