gio-miniprogram-sdk 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +4 -0
- package/.eslintignore +11 -0
- package/.eslintrc.js +120 -0
- package/.github/workflows/greetings.yml +13 -0
- package/.github/workflows/publish.yml +43 -0
- package/.prettierignore +19 -0
- package/.prettierrc.js +9 -0
- package/LICENSE +674 -0
- package/README.md +103 -0
- package/babel.config.js +6 -0
- package/bin/build/all.sh +38 -0
- package/bin/build/full.sh +32 -0
- package/bin/build/jd.sh +14 -0
- package/bin/build/ks.sh +14 -0
- package/bin/build/my.sh +14 -0
- package/bin/build/plugins.sh +5 -0
- package/bin/build/qq.sh +14 -0
- package/bin/build/quickapp.sh +14 -0
- package/bin/build/swan.sh +14 -0
- package/bin/build/taro.sh +18 -0
- package/bin/build/tb.sh +18 -0
- package/bin/build/tt.sh +14 -0
- package/bin/build/uniapp.sh +18 -0
- package/bin/build/wx.sh +14 -0
- package/dist/alipay.js +1 -0
- package/dist/baidu.js +1 -0
- package/dist/bytedance.js +1 -0
- package/dist/jingdong.js +1 -0
- package/dist/kuaishou.js +1 -0
- package/dist/plugins/gioABTest.js +1 -0
- package/dist/plugins/gioCompress.js +1 -0
- package/dist/plugins/gioEventAutoTracking.js +1 -0
- package/dist/plugins/gioImpressionTracking.js +1 -0
- package/dist/qq.js +1 -0
- package/dist/quickapp.js +1 -0
- package/dist/taobao.js +1 -0
- package/dist/taro.js +1 -0
- package/dist/uniapp.js +1 -0
- package/dist/wechat.js +1 -0
- package/package.json +144 -0
- package/rollup.config.js +92 -0
- package/rollup.plugins.config.js +76 -0
- package/src/constants/config.ts +136 -0
- package/src/constants/regex.ts +4 -0
- package/src/core/dataStore/eventContextBuilder.ts +70 -0
- package/src/core/dataStore/eventHooks/appEffects.ts +220 -0
- package/src/core/dataStore/eventHooks/index.ts +403 -0
- package/src/core/dataStore/eventHooks/minipPage.ts +132 -0
- package/src/core/dataStore/eventHooks/pageEffects.ts +168 -0
- package/src/core/dataStore/index.ts +543 -0
- package/src/core/growingIO.ts +433 -0
- package/src/core/plugins.ts +152 -0
- package/src/core/uploader.ts +219 -0
- package/src/core/userStore.ts +203 -0
- package/src/index.ts +68 -0
- package/src/minipInstance/base.ts +287 -0
- package/src/minipInstance/framework.ts +22 -0
- package/src/minipInstance/jd.ts +11 -0
- package/src/minipInstance/ks.ts +12 -0
- package/src/minipInstance/my.ts +53 -0
- package/src/minipInstance/qq.ts +12 -0
- package/src/minipInstance/quickapp.ts +230 -0
- package/src/minipInstance/swan.ts +20 -0
- package/src/minipInstance/tb.ts +53 -0
- package/src/minipInstance/tt.ts +12 -0
- package/src/minipInstance/wx.ts +12 -0
- package/src/platformConfig/base.ts +86 -0
- package/src/platformConfig/framework.ts +29 -0
- package/src/platformConfig/jd.ts +11 -0
- package/src/platformConfig/ks.ts +11 -0
- package/src/platformConfig/my.ts +15 -0
- package/src/platformConfig/qq.ts +13 -0
- package/src/platformConfig/quickapp.ts +48 -0
- package/src/platformConfig/swan.ts +11 -0
- package/src/platformConfig/tb.ts +29 -0
- package/src/platformConfig/tt.ts +11 -0
- package/src/platformConfig/wx.ts +20 -0
- package/src/pluginsOut/README.md +50 -0
- package/src/pluginsOut/frameworks/gioTaobaoAdapter.ts +195 -0
- package/src/pluginsOut/frameworks/gioTaroAdapter.ts +358 -0
- package/src/pluginsOut/frameworks/gioUniAppAdapter.ts +220 -0
- package/src/pluginsOut/ordinary/gioABTest.ts +254 -0
- package/src/pluginsOut/ordinary/gioCompress.ts +251 -0
- package/src/pluginsOut/ordinary/gioCustomTracking.ts +71 -0
- package/src/pluginsOut/ordinary/gioEventAutoTracking.ts +164 -0
- package/src/pluginsOut/ordinary/gioImpressionTracking.ts +298 -0
- package/src/types/base.ts +150 -0
- package/src/types/dataStore.ts +43 -0
- package/src/types/eventHooks.ts +141 -0
- package/src/types/gioCustomTracking.ts +9 -0
- package/src/types/gioEventTracking.ts +10 -0
- package/src/types/gioPerformance.ts +8 -0
- package/src/types/growingIO.ts +102 -0
- package/src/types/minipInstance.ts +126 -0
- package/src/types/platforms.ts +65 -0
- package/src/types/plugins.ts +24 -0
- package/src/types/uploader.ts +26 -0
- package/src/types/userStore.ts +22 -0
- package/src/utils/glodash.ts +423 -0
- package/src/utils/tools.ts +384 -0
- package/src/utils/verifiers.ts +76 -0
- package/tsconfig.json +32 -0
- package/typings/global.d.ts +92 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import {
|
|
2
|
+
find,
|
|
3
|
+
forEach,
|
|
4
|
+
head,
|
|
5
|
+
isArray,
|
|
6
|
+
isEmpty,
|
|
7
|
+
isFunction,
|
|
8
|
+
isNil,
|
|
9
|
+
isObject,
|
|
10
|
+
isString,
|
|
11
|
+
keys,
|
|
12
|
+
split,
|
|
13
|
+
startsWith,
|
|
14
|
+
toString
|
|
15
|
+
} from '@@/utils/glodash';
|
|
16
|
+
|
|
17
|
+
// 控制台打印提示信息,包含错误、警告和信息3种形式
|
|
18
|
+
export const consoleText = (
|
|
19
|
+
msg: string,
|
|
20
|
+
type?: 'info' | 'success' | 'error' | 'warn'
|
|
21
|
+
) => {
|
|
22
|
+
const styles = {
|
|
23
|
+
info: 'color: #3B82F6;',
|
|
24
|
+
error: 'color: #EF4444',
|
|
25
|
+
warn: 'color: #F59E0B',
|
|
26
|
+
success: 'color: #10B981'
|
|
27
|
+
};
|
|
28
|
+
console.log(`%c[GrowingIO]:${msg}`, styles[type] || '');
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// 失败提示
|
|
32
|
+
export const callError = (fn: string, type = true, msg = '参数不合法') =>
|
|
33
|
+
consoleText(`${type ? '调用' : '设置'} ${fn} 失败,${msg}!`, 'warn');
|
|
34
|
+
|
|
35
|
+
// 优化过的try...catch包裹体
|
|
36
|
+
export const niceTry = (fn: Function) => {
|
|
37
|
+
try {
|
|
38
|
+
return fn();
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// 封装过的调用callback的方法
|
|
45
|
+
export const niceCallback = (cb: Function, cbv?: any) => {
|
|
46
|
+
if (isFunction(cb)) {
|
|
47
|
+
try {
|
|
48
|
+
cb(cbv);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
consoleText(`回调执行失败!${error}`, 'error');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// 限制处理字符串
|
|
56
|
+
export const limitString = (s: string) => {
|
|
57
|
+
return isString(s) ? s.trim().substring(0, 100) : s;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// 埋点事件名校验
|
|
61
|
+
export const eventNameValidate = (eventName: string, callback: () => void) => {
|
|
62
|
+
if (
|
|
63
|
+
isString(eventName) &&
|
|
64
|
+
!isEmpty(eventName) &&
|
|
65
|
+
eventName.match(/^[a-zA-Z_][0-9a-zA-Z_]{0,100}$/)
|
|
66
|
+
) {
|
|
67
|
+
return callback();
|
|
68
|
+
} else {
|
|
69
|
+
consoleText(
|
|
70
|
+
'事件名格式不正确,只能包含数字、字母和下划线,且不能以数字开头,字符总长度不能超过100!',
|
|
71
|
+
'error'
|
|
72
|
+
);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// 生成uuid
|
|
78
|
+
export const guid = () => {
|
|
79
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
80
|
+
const r = (Math.random() * 16) | 0,
|
|
81
|
+
v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
82
|
+
return v.toString(16);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const getScreenHeight = (info) => {
|
|
87
|
+
if (info.pixelRatio) {
|
|
88
|
+
return Math.round(info.screenHeight * info.pixelRatio);
|
|
89
|
+
}
|
|
90
|
+
return info.screenHeight;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const getScreenWidth = (info) => {
|
|
94
|
+
if (info.pixelRatio) {
|
|
95
|
+
return Math.round(info.screenWidth * info.pixelRatio);
|
|
96
|
+
}
|
|
97
|
+
return info.screenWidth;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const getOS = (system: any, configName: string) => {
|
|
101
|
+
if (system) {
|
|
102
|
+
const lowsys = system.toLowerCase();
|
|
103
|
+
if (lowsys.indexOf('android') !== -1) {
|
|
104
|
+
return `${configName}-Android`;
|
|
105
|
+
} else if (lowsys.indexOf('ios') !== -1) {
|
|
106
|
+
return `${configName}-iOS`;
|
|
107
|
+
} else {
|
|
108
|
+
return system;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// 比较两个正式的版本号,v1>v2返回1,v1<v2返回-1,v1=v2返回0
|
|
114
|
+
export const compareVersion = (v1 = '', v2 = '') => {
|
|
115
|
+
const rpSpace = (s) => s.replace(/\s+/g, '');
|
|
116
|
+
const rpV = (s) => s.replace(/[vV]/g, '');
|
|
117
|
+
const nv1 = rpSpace(rpV(v1));
|
|
118
|
+
const nv2 = rpSpace(rpV(v2));
|
|
119
|
+
const nv1Array = nv1.split('.');
|
|
120
|
+
const nv2Array = nv2.split('.');
|
|
121
|
+
for (let i = 0; i < 3; i++) {
|
|
122
|
+
let na = Number(nv1Array[i]);
|
|
123
|
+
let nb = Number(nv2Array[i]);
|
|
124
|
+
if (na > nb) return 1;
|
|
125
|
+
if (nb > na) return -1;
|
|
126
|
+
if (!isNaN(na) && isNaN(nb)) return 1;
|
|
127
|
+
if (isNaN(na) && !isNaN(nb)) return -1;
|
|
128
|
+
}
|
|
129
|
+
return 0;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// 获取vue的主版本号
|
|
133
|
+
export const getVueVersion = (vue) => {
|
|
134
|
+
if (vue) {
|
|
135
|
+
const mv = Number.parseInt(head(split(vue.version, '.')), 10);
|
|
136
|
+
return Number.isNaN(mv) ? 0 : mv;
|
|
137
|
+
} else {
|
|
138
|
+
return 0;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const splitPath = (fullPath?: string): [string | undefined, string] => {
|
|
143
|
+
if (isString(fullPath)) {
|
|
144
|
+
const idx = fullPath.indexOf('?');
|
|
145
|
+
if (idx !== -1) {
|
|
146
|
+
const path = fullPath.substring(0, idx);
|
|
147
|
+
const query = fullPath.substring(idx + 1);
|
|
148
|
+
return [path, query];
|
|
149
|
+
} else {
|
|
150
|
+
return [fullPath, ''];
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
return ['', ''];
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export const normalPath = (path: string): string => {
|
|
158
|
+
if (isString(path)) {
|
|
159
|
+
return path.startsWith('/') ? path : `/${path}`;
|
|
160
|
+
} else {
|
|
161
|
+
return '';
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// 判断是否为Taro3环境
|
|
166
|
+
export const isTaro3 = (taro: any): boolean => {
|
|
167
|
+
const { Current, createComponent } = taro;
|
|
168
|
+
if (taro && Current && !createComponent) {
|
|
169
|
+
return true;
|
|
170
|
+
} else {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const getPlainMinip = (platform?: string) => {
|
|
176
|
+
return niceTry(() => {
|
|
177
|
+
switch (platform) {
|
|
178
|
+
// 指定平台获取实例
|
|
179
|
+
case 'wx':
|
|
180
|
+
return wx;
|
|
181
|
+
case 'my':
|
|
182
|
+
// 淘宝小程序和支付宝小程序共用my对象
|
|
183
|
+
case 'tb':
|
|
184
|
+
return my;
|
|
185
|
+
case 'swan':
|
|
186
|
+
return swan;
|
|
187
|
+
case 'tt':
|
|
188
|
+
return tt;
|
|
189
|
+
case 'qq':
|
|
190
|
+
return qq;
|
|
191
|
+
case 'ks':
|
|
192
|
+
return ks;
|
|
193
|
+
case 'jd':
|
|
194
|
+
return jd;
|
|
195
|
+
// 第三方框架下自动获取实例
|
|
196
|
+
// 百度等小程序中可能存在封装过的wx对象,因此wx要放在最后判断
|
|
197
|
+
default: {
|
|
198
|
+
let minip;
|
|
199
|
+
if (!minip) minip = niceTry(() => swan);
|
|
200
|
+
if (!minip) minip = niceTry(() => my);
|
|
201
|
+
if (!minip) minip = niceTry(() => tt);
|
|
202
|
+
if (!minip) minip = niceTry(() => qq);
|
|
203
|
+
if (!minip) minip = niceTry(() => ks);
|
|
204
|
+
if (!minip) minip = niceTry(() => jd);
|
|
205
|
+
if (!minip) minip = niceTry(() => wx);
|
|
206
|
+
return minip;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export const getPlainConfig = (platform?: string) => {
|
|
213
|
+
return niceTry(() => {
|
|
214
|
+
switch (platform) {
|
|
215
|
+
// 指定平台获取实例
|
|
216
|
+
case 'wx':
|
|
217
|
+
return __wxConfig;
|
|
218
|
+
case 'swan':
|
|
219
|
+
return appConfig;
|
|
220
|
+
case 'tt':
|
|
221
|
+
return __ttConfig;
|
|
222
|
+
case 'qq':
|
|
223
|
+
return __qqConfig;
|
|
224
|
+
case 'ks':
|
|
225
|
+
return __ksConfig;
|
|
226
|
+
case 'jd':
|
|
227
|
+
return __jdConfig;
|
|
228
|
+
// 第三方框架下自动获取实例
|
|
229
|
+
default:
|
|
230
|
+
// 支付宝和淘宝不存在可获取的全局对象
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// 在框架下自动获取当前平台值
|
|
237
|
+
export const getPlainPlatform = () => {
|
|
238
|
+
// 百度等小程序中可能存在封装过的wx对象,因此wx要放在最后判断
|
|
239
|
+
let platform;
|
|
240
|
+
if (!platform && niceTry(() => swan)) platform = 'swan';
|
|
241
|
+
if (!platform && niceTry(() => tt)) platform = 'tt';
|
|
242
|
+
if (!platform && niceTry(() => qq)) platform = 'qq';
|
|
243
|
+
if (!platform && niceTry(() => my.tb)) platform = 'tb';
|
|
244
|
+
if (!platform && niceTry(() => my)) platform = 'my';
|
|
245
|
+
if (!platform && niceTry(() => ks)) platform = 'ks';
|
|
246
|
+
if (!platform && niceTry(() => jd)) platform = 'jd';
|
|
247
|
+
if (!platform && niceTry(() => wx)) platform = 'wx';
|
|
248
|
+
if (!platform) {
|
|
249
|
+
const quickappExist = !!find(keys(global), (o) =>
|
|
250
|
+
toString(o).toLowerCase().includes('quickapp')
|
|
251
|
+
);
|
|
252
|
+
if (quickappExist) {
|
|
253
|
+
platform = 'quickapp';
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return platform;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// 获取当前分包在全局中的key值
|
|
260
|
+
export const getSubKeys = (app: any) => {
|
|
261
|
+
return keys(app)
|
|
262
|
+
.filter((o) => o.indexOf('__sub') > -1 && o.indexOf('gio__') > -1)
|
|
263
|
+
.sort();
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// 获取app实例
|
|
267
|
+
export const getAppInst = () => {
|
|
268
|
+
let app = niceTry(() => getApp({ allowDefault: true }));
|
|
269
|
+
// 阿里小程序中不支持getApp提前调用,所以只能把gio实例存在global当中
|
|
270
|
+
// 获取不到app实例的一律把gio实例存在global当中
|
|
271
|
+
if (!app) {
|
|
272
|
+
app = getGlobal();
|
|
273
|
+
}
|
|
274
|
+
return app;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export const getGlobal = () => {
|
|
278
|
+
return niceTry(() => $global) ?? global;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// Object参数限制
|
|
282
|
+
export const limitObject = (o: any) => {
|
|
283
|
+
const ob = {};
|
|
284
|
+
if (isObject(o)) {
|
|
285
|
+
forEach(o, (v, k) => {
|
|
286
|
+
const key = toString(k).slice(0, 100);
|
|
287
|
+
if (isObject(v)) {
|
|
288
|
+
ob[key] = limitObject(v);
|
|
289
|
+
} else if (isArray(v)) {
|
|
290
|
+
ob[key] = v.slice(0, 100);
|
|
291
|
+
ob[key] = ob[key].join('||').slice(0, 1000);
|
|
292
|
+
} else {
|
|
293
|
+
ob[key] = !isNil(v) ? toString(v).slice(0, 1000) : '';
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return ob;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// 批量获取存储中的数据,减少性能影响
|
|
301
|
+
export const batchGetStorageSync = (minipInstance: any, keys: string[]) => {
|
|
302
|
+
const batchFunction = () => {
|
|
303
|
+
return minipInstance.minip.batchGetStorageSync(keys);
|
|
304
|
+
};
|
|
305
|
+
const singleFunction = () => {
|
|
306
|
+
return keys.map((key: string) => minipInstance.getStorageSync(key));
|
|
307
|
+
};
|
|
308
|
+
// 优先使用批量接口(目前仅支持wx)
|
|
309
|
+
try {
|
|
310
|
+
if (minipInstance.minip.canIUse('batchGetStorageSync')) {
|
|
311
|
+
return batchFunction();
|
|
312
|
+
} else {
|
|
313
|
+
return singleFunction();
|
|
314
|
+
}
|
|
315
|
+
} catch (error) {
|
|
316
|
+
return singleFunction();
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// 批量存储数据,减少性能影响
|
|
321
|
+
export const batchSetStorageSync = (minipInstance: any, kvList: any[]) => {
|
|
322
|
+
const batchFunction = () => {
|
|
323
|
+
return minipInstance.minip.batchSetStorageSync(kvList);
|
|
324
|
+
};
|
|
325
|
+
const singleFunction = () => {
|
|
326
|
+
return kvList.map(({ key, value }: any) =>
|
|
327
|
+
minipInstance.setStorageSync(key, value)
|
|
328
|
+
);
|
|
329
|
+
};
|
|
330
|
+
// 优先使用批量接口(目前仅支持wx)
|
|
331
|
+
try {
|
|
332
|
+
if (minipInstance.minip.canIUse('batchSetStorageSync')) {
|
|
333
|
+
return batchFunction();
|
|
334
|
+
} else {
|
|
335
|
+
return singleFunction();
|
|
336
|
+
}
|
|
337
|
+
} catch (error) {
|
|
338
|
+
return singleFunction();
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// 将参数对象转为参数字符串
|
|
343
|
+
export const qsStringify = (query: any) => {
|
|
344
|
+
return keys(query || {})
|
|
345
|
+
.map((key) => {
|
|
346
|
+
if (key) {
|
|
347
|
+
return `${key}=${isNil(query[key]) ? '' : query[key]}`;
|
|
348
|
+
} else {
|
|
349
|
+
return '';
|
|
350
|
+
}
|
|
351
|
+
})
|
|
352
|
+
.join('&');
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// 解析参数
|
|
356
|
+
export const qsParse = (s: string) => {
|
|
357
|
+
if (startsWith(s, '?') || startsWith(s, '&')) {
|
|
358
|
+
s = s.slice(1, s.length);
|
|
359
|
+
}
|
|
360
|
+
const qsObject = {};
|
|
361
|
+
s.split('&').forEach((pairs: string) => {
|
|
362
|
+
const pair = pairs.split('=');
|
|
363
|
+
if (pair[0]) {
|
|
364
|
+
qsObject[pair[0]] = pair[1];
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
return qsObject;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// 将字符串转为hash
|
|
371
|
+
export const hashCode = (string) => {
|
|
372
|
+
let hash = 0;
|
|
373
|
+
if (isEmpty(string) || typeof string === 'boolean') {
|
|
374
|
+
return hash;
|
|
375
|
+
}
|
|
376
|
+
let i = 0;
|
|
377
|
+
while (i < string.length) {
|
|
378
|
+
const char = string.charCodeAt(i);
|
|
379
|
+
hash = (hash << 5) - hash + char;
|
|
380
|
+
hash = hash & hash; //Convert to 32bit integer
|
|
381
|
+
i++;
|
|
382
|
+
}
|
|
383
|
+
return hash;
|
|
384
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 代码中一些通用的或者业务上的校验器
|
|
3
|
+
*/
|
|
4
|
+
import { GrowingIOType } from '@@/types/growingIO';
|
|
5
|
+
import { compact, isNumber, isObject, isString, last } from '@@/utils/glodash';
|
|
6
|
+
import { consoleText } from '@@/utils/tools';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 一些id的合法性校验
|
|
10
|
+
* @param id // 只允许数字和字符串,不允许为空字符串、0、负数
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const verifyId = (o: string | number) =>
|
|
14
|
+
(isString(o) && (o as string).length > 0) ||
|
|
15
|
+
(isNumber(o) && (o as number) > 0);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 初始化时的一些合法性校验
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export const initPreCheck = (growingIO: GrowingIOType) => {
|
|
22
|
+
// 重复初始化校验
|
|
23
|
+
if (growingIO.vdsConfig || growingIO.gioSDKInitialized) {
|
|
24
|
+
consoleText(
|
|
25
|
+
'SDK重复初始化,请检查是否重复加载SDK或接入其他平台SDK导致冲突!',
|
|
26
|
+
'warn'
|
|
27
|
+
);
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 参数为空校验
|
|
34
|
+
export const paramsEmptyCheck = (args: any) => {
|
|
35
|
+
if (!compact(args)) {
|
|
36
|
+
consoleText(
|
|
37
|
+
'SDK初始化失败,请使用 gdp("init", "您的GrowingIO项目 accountId", "您项目的 dataSourceId", "你的应用 AppId", options); 进行初始化!',
|
|
38
|
+
'error'
|
|
39
|
+
);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// 基础参数校验(projectId、userOptions)
|
|
46
|
+
export const paramsBaseCheck = (args: any) => {
|
|
47
|
+
const projectId: string = args[0];
|
|
48
|
+
let userOptions: object = last(args);
|
|
49
|
+
// 参数校验(projectId)
|
|
50
|
+
if (!verifyId(projectId)) {
|
|
51
|
+
consoleText('SDK初始化失败,accountId 参数不合法!', 'error');
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// 参数校验(userOptions)
|
|
55
|
+
if (!isObject(userOptions) || !userOptions) {
|
|
56
|
+
userOptions = {};
|
|
57
|
+
}
|
|
58
|
+
return { projectId, userOptions };
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// 额外的参数校验(校验dataSourceId、AppId)
|
|
62
|
+
export const paramExtraCheck = (args: any) => {
|
|
63
|
+
// 参数校验(dataSourceId)
|
|
64
|
+
const dataSourceId: string = args[1];
|
|
65
|
+
let appId: any = args[2];
|
|
66
|
+
const options: any = last(args);
|
|
67
|
+
if (!dataSourceId || !isString(dataSourceId)) {
|
|
68
|
+
consoleText('SDK初始化失败,dataSourceId 参数不合法!', 'error');
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (!verifyId(appId)) {
|
|
72
|
+
consoleText('SDK初始化失败,appId 参数不合法!', 'error');
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return { dataSourceId, appId, options };
|
|
76
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"removeComments": true,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"allowUnreachableCode": true,
|
|
6
|
+
"baseUrl": "./",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"noImplicitAny": false,
|
|
9
|
+
"module": "es6",
|
|
10
|
+
"moduleResolution": "Node",
|
|
11
|
+
"preserveConstEnums": false,
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"strict": false,
|
|
14
|
+
"lib": ["DOM", "ES5", "ES6", "ES2016", "ES2017"],
|
|
15
|
+
"target": "ES6",
|
|
16
|
+
"types": ["node", "webpack-env"],
|
|
17
|
+
"paths": {
|
|
18
|
+
"@@/*": ["src/*"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"exclude": ["./node_modules", "./dist"],
|
|
22
|
+
"include": [
|
|
23
|
+
"./src/*.ts",
|
|
24
|
+
"./src/**/*.ts",
|
|
25
|
+
"./src/**/**/*.ts",
|
|
26
|
+
"./typings/*.d.ts"
|
|
27
|
+
],
|
|
28
|
+
"typedocOptions": {
|
|
29
|
+
"mode": "modules",
|
|
30
|
+
"out": "docs"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
declare interface Window {
|
|
2
|
+
gioSdkInstalled: boolean;
|
|
3
|
+
gio: any;
|
|
4
|
+
GioApp: any;
|
|
5
|
+
GioPage: any;
|
|
6
|
+
GioComponent: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare var global: any;
|
|
10
|
+
declare var $global: any;
|
|
11
|
+
declare var document: Document;
|
|
12
|
+
declare var App: any;
|
|
13
|
+
declare var Page: any;
|
|
14
|
+
declare var Component: any;
|
|
15
|
+
declare var Behavior: any;
|
|
16
|
+
declare var SelectorQuery: any;
|
|
17
|
+
declare var getApp: any;
|
|
18
|
+
|
|
19
|
+
// platform
|
|
20
|
+
declare var wx: any;
|
|
21
|
+
declare var swan: any;
|
|
22
|
+
declare var my: any;
|
|
23
|
+
declare var qq: any;
|
|
24
|
+
declare var tt: any;
|
|
25
|
+
declare var ks: any;
|
|
26
|
+
declare var jd: any;
|
|
27
|
+
declare var quickapp: any;
|
|
28
|
+
declare var __wxConfig: any;
|
|
29
|
+
declare var appConfig: any; // swan的全局配置
|
|
30
|
+
declare var __myConfig: any; // my的全局配置
|
|
31
|
+
declare var __ttConfig: any; // tt的全局配置
|
|
32
|
+
declare var __qqConfig: any; // qq的全局配置
|
|
33
|
+
declare var __ksConfig: any; // ks的全局配置
|
|
34
|
+
declare var __jdConfig: any; // jd的全局配置
|
|
35
|
+
declare var __proto__: any;
|
|
36
|
+
declare var Taro: any
|
|
37
|
+
declare var uni: any
|
|
38
|
+
|
|
39
|
+
declare module "__GIO_PLATFORM_CONFIG__" {
|
|
40
|
+
let module: any;
|
|
41
|
+
export default module;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare module "__GIO_PLATFORM_INSTANCE__" {
|
|
45
|
+
let module: any;
|
|
46
|
+
export default module;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare module "@system.app" {
|
|
50
|
+
let module: any;
|
|
51
|
+
export default module;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare module "@system.storage" {
|
|
55
|
+
let module: any;
|
|
56
|
+
export default module;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare module "@system.network" {
|
|
60
|
+
let module: any;
|
|
61
|
+
export default module;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare module "@system.device" {
|
|
65
|
+
let module: any;
|
|
66
|
+
export default module;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare module "@system.geolocation" {
|
|
70
|
+
let module: any;
|
|
71
|
+
export default module;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
declare module "@system.fetch" {
|
|
75
|
+
let module: any;
|
|
76
|
+
export default module;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare module "@system.router" {
|
|
80
|
+
let module: any;
|
|
81
|
+
export default module;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare module "@system.image" {
|
|
85
|
+
let module: any;
|
|
86
|
+
export default module;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare module "@system.share" {
|
|
90
|
+
let module: any;
|
|
91
|
+
export default module;
|
|
92
|
+
}
|