helper.class.js
4.38 KB
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
/**
* 定义常用方法类
*/
// 引入组件
import CallApp from 'callapp-lib';
export default class Helper {
// 构造函数
constructor(context) {
// 设置上下文
this.context = context;
}
/**
* 设置唤起App弹窗
* @param {object} param [唤起App定向页面参数]
* @param {function} callback [回调函数]
*/
schemeLayer = function(param, callback) {
// 唤起App操作
function _doApp(callApp, path, param) {
callApp.open({
path: path,
param: param
});
}
// 设置平台固定参数
let path = this.context.isiPhone.value ? "ios-path" : "shop/schemaFilter";
let intentPackage = this.context.mode == "prod" ? "com.cnlive.strike" : "com.cnlive.strike.debug";
let universalHost = this.context.mode == "prod" ? "applelinkstest.cnlive.com" : "applelinkstest.cnlive.com";
// H5唤起App参数
let options = {
scheme: {
protocol: "cnlive"
},
intent: {
package: intentPackage,
scheme: "cnlive"
},
universal: {
host: universalHost + "/app_store.html",
pathKey: "page"
},
appstore: "https://sj.qq.com/myapp/detail.htm?apkName=com.cnlive.strike",
yingyongbao: "https://sj.qq.com/myapp/detail.htm?apkName=com.cnlive.strike",
fallback: "http://wjjh5.cnlive.com/apkdownload.php"
}
// 实例化对象
let callApp = new CallApp(options);
// 回调
if (typeof callback === "function") {
// 点击确定执行数据
let options = {
success: _doApp,
success_params: {
callApp, path, param
}
}
// 回调函数
callback(options);
}
}
/**
* 正则校验URL
* @param {string} strURL [URL地址]
*/
checkURL = function(strURL) {
// 校验参数
if (strURL) {
// 正则
let reg = /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
// 校验匹配
if (reg.test(strURL)) {
return true;
}
}
return false;
}
/* 加密/解密算法 开始 */
/**
* 加密算法
* @param {string} word [原文]
*/
encrypt = function(word) {
let CryptoJS = require("crypto-js/crypto-js");
// KEY和IV
const KEY = CryptoJS.enc.Utf8.parse("cnlive!$@cnlive_");
const IV = CryptoJS.enc.Utf8.parse("yrEpH8Nx6umBLc1f");
// 明文编码
let srcs = CryptoJS.enc.Utf8.parse(word);
// crypt加密
var encrypted = CryptoJS.AES.encrypt(srcs, KEY, {
iv: IV,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
/**
* 解密算法
* @param {string} word [密文]
*/
decrypt = function(word) {
let CryptoJS = require("crypto-js/crypto-js");
// KEY和IV
const KEY = CryptoJS.enc.Utf8.parse("cnlive!$@cnlive_");
const IV = CryptoJS.enc.Utf8.parse("yrEpH8Nx6umBLc1f");
let srcs = word;
// let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
// let srcs = CryptoJS.enc.Base64.stringify(word);
let decrypt = CryptoJS.AES.decrypt(srcs, KEY, { iv: IV, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
return decryptedStr.toString();
}
/* 加密/解密算法 结束 */
/* 数字格式化 开始 */
/**
* 获取输入数字的整数部分
*/
getInteger() {
return (number) => {
return parseInt(number);
}
}
/**
* 获取输入数字的小数部分
*/
getDecimal() {
return (number) => {
// 拆分数字
let numberArr = number.toString().split(".");
// 判断是否有效数部分
if (numberArr.length === 2) {
return numberArr[1];
} else {
return "00";
}
}
}
/* 数字格式化 结束 */
/* 数据格式处理 开始 */
/**
* 对象内指定字符串内容替换
* @param {Object} o [目标对象]
* @param {String} key [目标字段名]
* @param {String} oldString [原始字符串]
* @param {String} newString [新字符串]
*/
objectStringReplaceAll(o, key, oldString, newString) {
// 判断对象是否为数组
if (typeof o === "object" && o !== null && o.length) {
// 遍历数组,替换内容
for (let i = 0; i < o.length; i++) {
o[i][key] = o[i][key].replace(new RegExp(oldString, "gm"), newString);
}
}
}
/* 数据格式处理 结束 */
}