helper.class.js
2.86 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
/**
* 定义常用方法类
*/
// 引入组件
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.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);
}
}
/**
* 数组中根据二级分类的key查找一级分类对象
* @param {array} arr [原始数组]
* @param {string} key [查找的key]
* @param {any} value [要查找的值]
* @param {boolean} index [获取索引]
* @returns {any}
*/
findItemBySubItemKeyValue = function(arr, key, value, index = false) {
// 返回值
let result = null;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].child.length; j++) {
if (arr[i].child[j][key] == value) {
result = index ? i : arr[i];
break;
}
}
if (result !== null) {
break;
}
}
return result;
}
/**
* 数组中根据key查找对象
* @param {array} arr [原始数组]
* @param {string} key [查找的key]
* @param {any} value [要查找的值]
* @param {boolean} index [获取索引]
* @returns {any}
*/
findObjectByKeyValue = function(arr, key, value, index = false) {
// 返回值
let result = null;
for (let i = 0; i < arr.length; i++) {
if (arr[i][key] == value) {
result = index ? i : arr[i];
break;
}
}
return result;
}
}