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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import nettyApi from '@/constants/api/ms-netty/netty.api';
import InterFaceFactory from '@/public/factory/InterFaceFactory';
import systemApi from '@/constants/api/ms-system/system.api';
/**
* 工具类
*/
const Public = {
/**
* 获取地理位置信息(同步方法)
* @return {Object} {lng, lat, address} 当前位置信息的经度、纬度、地理位置
*/
getLocation() {
let locInfos;
if (window.plus && window.plus.os.name === 'iOS') {
locInfos = this.parseLocation(window.plus.iOSMapNav.getLocation());
} else if (window.plus && window.plus.os.name === 'Android') {
locInfos = this.parseLocation((window as any).SMMP.getLocation('2'));
} else {
locInfos = {
lng: '#',
lat: '#',
address: '暂无位置信息'
};
}
return locInfos;
},
/**
* 获取当前位置信息(异步方法),支持iOS设备
* @param {Function} successCallback 成功回调
* @param {Function} errorCallback 失败回调
*/
getCurrentPosition(successCallback: any, errorCallback: any) {
if (window.plus) {
if (window.plus.os.name === 'iOS') {
window.plus.iOSMapNav.getCurrentPosition(
function(result: any) {
let locInfos = result.split('◆');
let newResult = {};
let myPosition;
if (locInfos.length === 2) {
myPosition = locInfos[1];
} else {
myPosition = locInfos[0];
}
// 经度
(newResult as any).lng = myPosition.split('▓')[1];
// 维度
(newResult as any).lat = myPosition.split('▓')[2];
// 地址
(newResult as any).address = myPosition.split('▓')[3];
if (typeof successCallback === 'function') {
successCallback(newResult);
}
},
function(result: any) {
console.debug(result);
if (typeof errorCallback === 'function') {
errorCallback(result);
}
}
);
}
}
},
/**
* 解析位置信息
* @param {String} locInfoStr 位置信息,格式:2020-08-13 14:22:33▓113.356552▓22.946032▓中国广东省广州市番禺区北丽园六街◆2020-08-13 14:27:33▓113.356552▓22.946032▓中国广东省广州市番禺区北丽园六街
* @return {Object} {lng, lat, address} 当前位置信息的经度、纬度、地理位置
*/
parseLocation(locInfoStr: any) {
let newResult = {};
if (typeof locInfoStr === 'string') {
let locInfos = locInfoStr.split('◆');
let curPosition;
if (locInfos.length === 2) {
curPosition = locInfos[1];
} else {
curPosition = locInfos[0];
}
// 经度
(newResult as any).lng = curPosition.split('▓')[1];
// 维度
(newResult as any).lat = curPosition.split('▓')[2];
// 地址
(newResult as any).address = curPosition.split('▓')[3];
}
return newResult;
},
/**
* 检测距离
* @param {String} curDistance 当前距离
* @param {String} targerDistance 目标距离
*/
detectDistance(curDistance: any, targerDistance: any) {
if (curDistance < targerDistance) {
return true;
}
return false;
},
/**
* 获取两点距离
* @author liuxiaoyu
* @param {String} curLon 当前经度
* @param {String} curLat 当前纬度
* @param {String} oldLon 上次经度
* @param {String} oldLat 上次纬度
*/
getLongDistance(curLon: any, curLat: any, oldLon: any, oldLat: any) {
let ew1,
ns1,
ew2,
ns2,
distance,
DEF_PI180 = 0.01745329252, //PI / 180
DEF_R = 6371003.5; //地球半径
// 角度转换为弧度
ew1 = curLon * DEF_PI180;
ns1 = curLat * DEF_PI180;
ew2 = oldLon * DEF_PI180;
ns2 = oldLat * DEF_PI180;
// 求大圆劣弧与球心所夹的角(弧度)
distance = Math.sin(ns1) * Math.sin(ns2) + Math.cos(ns1) * Math.cos(ns2) * Math.cos(ew1 - ew2);
// 调整到[-1..1]范围内,避免溢出
if (distance > 1.0) distance = 1.0;
else if (distance < -1.0) distance = -1.0;
// 求大圆劣弧长度
distance = (DEF_R * Math.acos(distance)) / 1000;
return distance.toFixed(2);
},
/** 格式化金额*/
formatMoney: function(s: any, split: any) {
if (isNaN(s)) return;
if (typeof s == 'undefined' || s == null || s == '') return '';
if (s == 0) return '0.00';
s = parseFloat(s);
if (typeof s != 'number') return '';
s = s.toFixed(2).toString();
if (!split) split = ',';
var l = s
.split('.')[0]
.split('')
.reverse(),
r = s.split('.')[1];
var t = '';
for (var i = 0; i < l.length; i++) {
t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? ',' : '');
}
return (
t
.split('')
.reverse()
.join('') +
'.' +
r
);
},
/**计算年龄 */
getAge: function(identityCard: any) {
var len = (identityCard + '').length;
if (len == 0) {
return 0;
} else {
if (len != 15 && len != 18) {
//身份证号码只能为15位或18位其它不合法
return 0;
}
}
var strBirthday = '';
if (len == 18) {
//处理18位的身份证号码从号码中得到生日和性别代码
strBirthday = identityCard.substr(6, 4) + '/' + identityCard.substr(10, 2) + '/' + identityCard.substr(12, 2);
}
if (len == 15) {
strBirthday =
'19' + identityCard.substr(6, 2) + '/' + identityCard.substr(8, 2) + '/' + identityCard.substr(10, 2);
}
//时间字符串里,必须是“/”
var birthDate = new Date(strBirthday);
var nowDateTime = new Date();
var age = nowDateTime.getFullYear() - birthDate.getFullYear();
//再考虑月、天的因素;.getMonth()获取的是从0开始的,这里进行比较,不需要加1
if (
nowDateTime.getMonth() < birthDate.getMonth() ||
(nowDateTime.getMonth() == birthDate.getMonth() && nowDateTime.getDate() < birthDate.getDate())
) {
age--;
}
return age;
},
/**
* 16进制转字符串
* @author zhangmk
* @time 2021年11月17日10:39:58
*/
hexToString: function(hex: any) {
var encoding = 'utf-8';
var trimedStr = hex.trim();
var rawStr = trimedStr.substr(0, 2).toLowerCase() === '0x' ? trimedStr.substr(2) : trimedStr;
var len = rawStr.length;
if (len % 2 !== 0) {
return '';
}
var curCharCode;
var resultStr = [];
for (var i = 0; i < len; i = i + 2) {
curCharCode = parseInt(rawStr.substr(i, 2), 16);
resultStr.push(curCharCode);
}
// encoding为空时默认为utf-8
var bytesView = new Uint8Array(resultStr);
var str = new TextDecoder(encoding).decode(bytesView);
return str;
},
/**ahtuor:pd
* 工商证件类型码值转换
* 2021年11月25日12:17:24
*/
getGScode(code: any) {
const tycode = '202'; //统一信用代码--工商
const zzcode = '200'; //组织机构代码--工商
if (code == '26') {
//信贷统一信用代码
return tycode;
} else if (code == '20') {
//组织机构代码--信贷
return zzcode;
} else {
return code;
}
},
/**
*author:pd
*组装交易编号SvrCode
*/
getSvrCode(tc: any) {
return this.getProdId() + '_' + tc;
},
/**
*author:pd
*ProdId产品编号
*/
getProdId() {
const ProdId = 'MCEP';
return ProdId;
},
/**
*
*author:zhangmk
*判断是否分支行
*/
getIfBranch() {
var NO = sessionStorage.getItem('branchNo') || '';
var array = ['9100', '9200', '9300', '2222', '0000', '9999'];
//从登录返回的数据中获取机构后调整
if (NO.length == 9) {
NO = NO.substring(5, NO.length);
if (array.indexOf(NO) != -1) {
return false;
} else return true;
} else {
if (NO.substring(0, 4) == '9999') {
return false;
} else {
if (NO.substring(0, 4) == '9999') {
return false;
} else {
return true;
}
}
}
},
/**
* zhangmingkun
* 2021年12月08日10:39:18
* 查询树结构内容
* treedicField:树结构名称: 行业:STD_GB_4754-2011
* treedicKey: 值
* 案例:Public.getTreeValue('STD_GB_4754-2002', '0330', function(res) {
console.log(res);
});
*/
getTreeValue(treedicField: any, treedicKey: any, callback: any) {
let param = {
tc: 'MCEP',
treedictField: treedicField,
treedictKey: treedicKey
};
InterFaceFactory.transferDataInter(systemApi.treeRq, param).then((res: any) => {
if (res.code == '1') {
let dataDic = res.data;
callback(dataDic);
}
});
},
/**
*@Desc 功能描述:根据图片路径将图片转file格式
*@Author XWH
*Date 2022/2/19 17:29
*/
imgUrlToFile(imgUrl: any, fileName: string){
const canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d")!,
img = new Image();
img.setAttribute("crossOrigin", "*");
let dataURL = "";
img.onload = () => {
canvas.height = img.height;
canvas.width = img.width;
ctx.drawImage(img, 0, 0);
dataURL = canvas.toDataURL("image/jpg");
// console.log(dataURL); //Base64码 一般用这个就行
return this.base64toFile(dataURL, fileName);
};
img.src = imgUrl;
},
/**
*@Desc 功能描述:base64格式图片转file
*@Author XWH
*Date 2022/2/19 17:30
*/
base64toFile(url: any, fileName: string){
let arr = url.split(','), //dataUrl是传入的base64格式数据
mime = arr[0].match(/:(.*?);/)[1],
suffix = mime.split('/')[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
let file = new File([u8arr],`${fileName}.${suffix}`,{ //${fileName}为传入的参数,写死为file
type: mime
});
return file
},
/**
*@Description 功能描述:根据父id获取菜单
*@Author XWH
*@Date 2022/1/17 16:21
*/
getMenuBySuperID(superID: any, menuType: any) {
let menuList: any = sessionStorage.getItem('menuType'),
menuData = JSON.parse(menuList),
menuArr = [];
for (let data of menuData) {
const obj: any = {};
if (data.menuSupId == superID) {
obj.name = data.frontMenuName;
obj.path = data.menuUrl;
obj.iconName = data.menuIcon;
obj.menuId = data.menuId;
if (data.moveMenuType == menuType) {
if (menuType == 'CommonFunctions' || menuType == 'CommonUpcoming') {
obj.iconName = require('@/assets/images/' + obj.iconName + '.png');
} else if (menuType == 'secondRow') {
obj.info = '当前待处理';
obj.num = 0;
}
menuArr.push(obj);
}
}
}
return menuArr;
}
};
export default Public;