gio-miniprogram-sdk 4.4.2 → 4.5.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/README.md +13 -11
- package/dist/alipay.js +1 -1
- package/dist/baidu.js +1 -1
- package/dist/bytedance.js +1 -1
- package/dist/jingdong.js +1 -1
- package/dist/kuaishou.js +1 -1
- package/dist/mpx.js +1 -0
- package/dist/plugins/gioABTest.js +1 -1
- package/dist/plugins/gioCompress.js +1 -1
- package/dist/plugins/gioEventAutoTracking.js +1 -1
- package/dist/plugins/gioImpressionTracking.js +1 -1
- package/dist/plugins/gioMultipleInstances.js +1 -1
- package/dist/plugins/gioPerformance.js +1 -1
- package/dist/qq.js +1 -1
- package/dist/quickapp.js +1 -1
- package/dist/taobao.js +1 -1
- package/dist/taro.js +1 -1
- package/dist/uniapp.js +1 -1
- package/dist/wechat.js +1 -1
- package/dist/xiaohongshu.js +1 -1
- package/package.json +13 -2
- package/.eslintignore +0 -11
- package/.eslintrc.js +0 -120
- package/.github/workflows/greetings.yml +0 -13
- package/.github/workflows/publish.yml +0 -45
- package/.prettierignore +0 -19
- package/.prettierrc.js +0 -9
- package/babel.config.js +0 -6
- package/rollup.config.js +0 -100
- package/rollup.plugins.config.js +0 -84
- package/src/adapters/gioTaobaoAdapter.ts +0 -202
- package/src/adapters/gioTaroAdapter.ts +0 -467
- package/src/adapters/gioUniAppAdapter.ts +0 -431
- package/src/constants/config.ts +0 -170
- package/src/constants/emitMsg.ts +0 -24
- package/src/constants/regex.ts +0 -18
- package/src/core/dataStore/eventContextBuilder.ts +0 -95
- package/src/core/dataStore/eventHooks/appEffects.ts +0 -218
- package/src/core/dataStore/eventHooks/index.ts +0 -468
- package/src/core/dataStore/eventHooks/minipPage.ts +0 -221
- package/src/core/dataStore/eventHooks/pageEffects.ts +0 -189
- package/src/core/dataStore/index.ts +0 -661
- package/src/core/growingIO.ts +0 -637
- package/src/core/pluginsInstance/base.ts +0 -157
- package/src/core/pluginsInstance/taro.ts +0 -15
- package/src/core/pluginsInstance/tb.ts +0 -15
- package/src/core/pluginsInstance/uniapp.ts +0 -15
- package/src/core/uploader.ts +0 -272
- package/src/core/userStore.ts +0 -267
- package/src/index.ts +0 -77
- package/src/minipInstance/base.ts +0 -352
- package/src/minipInstance/framework.ts +0 -24
- package/src/minipInstance/jd.ts +0 -11
- package/src/minipInstance/ks.ts +0 -12
- package/src/minipInstance/my.ts +0 -131
- package/src/minipInstance/qq.ts +0 -12
- package/src/minipInstance/quickapp.ts +0 -233
- package/src/minipInstance/swan.ts +0 -20
- package/src/minipInstance/tb.ts +0 -58
- package/src/minipInstance/tt.ts +0 -12
- package/src/minipInstance/wx.ts +0 -27
- package/src/minipInstance/xhs.ts +0 -20
- package/src/platformConfig/base.ts +0 -82
- package/src/platformConfig/framework.ts +0 -31
- package/src/platformConfig/jd.ts +0 -11
- package/src/platformConfig/ks.ts +0 -11
- package/src/platformConfig/my.ts +0 -16
- package/src/platformConfig/qq.ts +0 -13
- package/src/platformConfig/quickapp.ts +0 -48
- package/src/platformConfig/swan.ts +0 -11
- package/src/platformConfig/tb.ts +0 -29
- package/src/platformConfig/tt.ts +0 -11
- package/src/platformConfig/wx.ts +0 -20
- package/src/platformConfig/xhs.ts +0 -27
- package/src/plugins/gioABTest.ts +0 -348
- package/src/plugins/gioCompress.ts +0 -253
- package/src/plugins/gioEventAutoTracking.ts +0 -310
- package/src/plugins/gioImpressionTracking.ts +0 -386
- package/src/plugins/gioMultipleInstances.ts +0 -189
- package/src/plugins/gioPerformance/exception.ts +0 -152
- package/src/plugins/gioPerformance/monitor.ts +0 -284
- package/src/plugins/gioPerformance/network.ts +0 -197
- package/src/plugins/gioPerformance.ts +0 -131
- package/src/types/base.ts +0 -167
- package/src/types/dataStore.ts +0 -62
- package/src/types/eventHooks.ts +0 -146
- package/src/types/gioCustomTracking.ts +0 -9
- package/src/types/gioEventTracking.ts +0 -10
- package/src/types/gioPerformance.ts +0 -8
- package/src/types/growingIO.ts +0 -137
- package/src/types/minipInstance.ts +0 -133
- package/src/types/platforms.ts +0 -64
- package/src/types/plugins.ts +0 -24
- package/src/types/uploader.ts +0 -30
- package/src/types/userStore.ts +0 -28
- package/src/utils/glodash.ts +0 -430
- package/src/utils/tools.ts +0 -511
- package/src/utils/verifiers.ts +0 -52
- package/tsconfig.json +0 -32
- package/typings/global.d.ts +0 -105
package/src/utils/tools.ts
DELETED
|
@@ -1,511 +0,0 @@
|
|
|
1
|
-
import { IMP_EVENTNAME_REG } from '@@/constants/regex';
|
|
2
|
-
import {
|
|
3
|
-
compact,
|
|
4
|
-
find,
|
|
5
|
-
forEach,
|
|
6
|
-
formatDate,
|
|
7
|
-
has,
|
|
8
|
-
head,
|
|
9
|
-
isArray,
|
|
10
|
-
isDate,
|
|
11
|
-
isEmpty,
|
|
12
|
-
isFunction,
|
|
13
|
-
isNil,
|
|
14
|
-
isObject,
|
|
15
|
-
isString,
|
|
16
|
-
keys,
|
|
17
|
-
split,
|
|
18
|
-
startsWith,
|
|
19
|
-
toString,
|
|
20
|
-
unset
|
|
21
|
-
} from '@@/utils/glodash';
|
|
22
|
-
|
|
23
|
-
// 控制台打印提示信息,包含错误、警告和信息3种形式
|
|
24
|
-
export const consoleText = (
|
|
25
|
-
msg: string,
|
|
26
|
-
type?: 'info' | 'success' | 'error' | 'warn'
|
|
27
|
-
) => {
|
|
28
|
-
const styles = {
|
|
29
|
-
info: 'color: #3B82F6;',
|
|
30
|
-
error: 'color: #EF4444',
|
|
31
|
-
warn: 'color: #F59E0B',
|
|
32
|
-
success: 'color: #10B981'
|
|
33
|
-
};
|
|
34
|
-
console.log(`%c[GrowingIO]:${msg}`, styles[type] || '');
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// 失败提示
|
|
38
|
-
export const callError = (fn: string, type = true, msg = '参数不合法') =>
|
|
39
|
-
consoleText(`${type ? '调用' : '设置'} ${fn} 失败,${msg}!`, 'warn');
|
|
40
|
-
|
|
41
|
-
// 优化过的try...catch包裹体
|
|
42
|
-
export const niceTry = (fn: Function) => {
|
|
43
|
-
try {
|
|
44
|
-
return fn();
|
|
45
|
-
} catch (e) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// 封装过的调用callback的方法
|
|
51
|
-
export const niceCallback = (cb: Function, cbv?: any) => {
|
|
52
|
-
if (isFunction(cb)) {
|
|
53
|
-
try {
|
|
54
|
-
cb(cbv);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
consoleText(`回调执行失败!${error}`, 'error');
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// 限制处理字符串
|
|
62
|
-
export const limitString = (s: string) => {
|
|
63
|
-
return isString(s) ? s.trim().substring(0, 100) : s;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// 埋点事件名校验
|
|
67
|
-
export const eventNameValidate = (eventName: string, callback: () => void) => {
|
|
68
|
-
if (
|
|
69
|
-
isString(eventName) &&
|
|
70
|
-
!isEmpty(eventName) &&
|
|
71
|
-
eventName.match(IMP_EVENTNAME_REG)
|
|
72
|
-
) {
|
|
73
|
-
return callback();
|
|
74
|
-
} else {
|
|
75
|
-
consoleText(
|
|
76
|
-
'事件名格式不正确,只能包含数字、字母和下划线,且不能以数字开头,字符总长度不能超过100!',
|
|
77
|
-
'error'
|
|
78
|
-
);
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// 获取动态属性的值
|
|
84
|
-
export const getDynamicAttributes = (properties: any) => {
|
|
85
|
-
if (!isNil(properties)) {
|
|
86
|
-
keys(properties).forEach((k: string) => {
|
|
87
|
-
if (isFunction(properties[k])) {
|
|
88
|
-
properties[k] = niceTry(() => properties[k]());
|
|
89
|
-
} else if (isObject(properties[k])) {
|
|
90
|
-
unset(properties, k);
|
|
91
|
-
} else if (!isArray(properties[k])) {
|
|
92
|
-
properties[k] = toString(properties[k]);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return properties;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// 生成uuid
|
|
100
|
-
export const guid = () => {
|
|
101
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
102
|
-
const r = (Math.random() * 16) | 0,
|
|
103
|
-
v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
104
|
-
return v.toString(16);
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export const getScreenHeight = (info) => {
|
|
109
|
-
if (info.pixelRatio) {
|
|
110
|
-
return Math.round(info.screenHeight * info.pixelRatio);
|
|
111
|
-
}
|
|
112
|
-
return info.screenHeight;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export const getScreenWidth = (info) => {
|
|
116
|
-
if (info.pixelRatio) {
|
|
117
|
-
return Math.round(info.screenWidth * info.pixelRatio);
|
|
118
|
-
}
|
|
119
|
-
return info.screenWidth;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export const getOS = (system: any, configName: string) => {
|
|
123
|
-
if (system) {
|
|
124
|
-
const lowsys = system.toLowerCase();
|
|
125
|
-
if (lowsys.indexOf('android') !== -1) {
|
|
126
|
-
return `${configName}-Android`;
|
|
127
|
-
} else if (lowsys.indexOf('ios') !== -1) {
|
|
128
|
-
return `${configName}-iOS`;
|
|
129
|
-
} else if (
|
|
130
|
-
lowsys.indexOf('harmonyos') !== -1 ||
|
|
131
|
-
lowsys.indexOf('ohos') !== -1
|
|
132
|
-
) {
|
|
133
|
-
return `${configName}-HarmonyOS`;
|
|
134
|
-
} else {
|
|
135
|
-
return `${configName}-${system}`;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// 比较两个正式的版本号,v1>v2返回1,v1<v2返回-1,v1=v2返回0
|
|
141
|
-
export const compareVersion = (v1 = '', v2 = '') => {
|
|
142
|
-
const rpSpace = (s) => s.replace(/\s+/g, '');
|
|
143
|
-
const rpV = (s) => s.replace(/[vV]/g, '');
|
|
144
|
-
const nv1 = rpSpace(rpV(v1));
|
|
145
|
-
const nv2 = rpSpace(rpV(v2));
|
|
146
|
-
const nv1Array = nv1.split('.');
|
|
147
|
-
const nv2Array = nv2.split('.');
|
|
148
|
-
for (let i = 0; i < 3; i++) {
|
|
149
|
-
let na = Number(nv1Array[i]);
|
|
150
|
-
let nb = Number(nv2Array[i]);
|
|
151
|
-
if (na > nb) return 1;
|
|
152
|
-
if (nb > na) return -1;
|
|
153
|
-
if (!isNaN(na) && isNaN(nb)) return 1;
|
|
154
|
-
if (isNaN(na) && !isNaN(nb)) return -1;
|
|
155
|
-
}
|
|
156
|
-
return 0;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// 获取vue的主版本号
|
|
160
|
-
export const getVueVersion = (vue) => {
|
|
161
|
-
if (vue) {
|
|
162
|
-
const mv = Number(head(split(vue.version, '.')));
|
|
163
|
-
return Number.isNaN(mv) ? 0 : mv;
|
|
164
|
-
} else {
|
|
165
|
-
return 0;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
export const splitPath = (fullPath?: string): [string | undefined, string] => {
|
|
170
|
-
if (isString(fullPath)) {
|
|
171
|
-
const idx = fullPath.indexOf('?');
|
|
172
|
-
if (idx !== -1) {
|
|
173
|
-
const path = fullPath.substring(0, idx);
|
|
174
|
-
const query = fullPath.substring(idx + 1);
|
|
175
|
-
return [path, query];
|
|
176
|
-
} else {
|
|
177
|
-
return [fullPath, ''];
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
return ['', ''];
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export const normalPath = (path: string): string => {
|
|
185
|
-
if (isString(path)) {
|
|
186
|
-
return path.startsWith('/') ? path : `/${path}`;
|
|
187
|
-
} else {
|
|
188
|
-
return '';
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
// 判断是否为Taro3环境
|
|
193
|
-
export const isTaro3 = (taro: any): boolean => {
|
|
194
|
-
const { Current, createComponent } = taro;
|
|
195
|
-
if (taro && Current && !createComponent) {
|
|
196
|
-
return true;
|
|
197
|
-
} else {
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
export const getPlainMinip = (platform?: string) => {
|
|
203
|
-
return niceTry(() => {
|
|
204
|
-
switch (platform) {
|
|
205
|
-
// 指定平台获取实例
|
|
206
|
-
case 'wx':
|
|
207
|
-
return wx;
|
|
208
|
-
case 'my':
|
|
209
|
-
// 淘宝小程序和支付宝小程序共用my对象
|
|
210
|
-
case 'tb':
|
|
211
|
-
return my;
|
|
212
|
-
case 'swan':
|
|
213
|
-
return swan;
|
|
214
|
-
case 'tt':
|
|
215
|
-
return tt;
|
|
216
|
-
case 'qq':
|
|
217
|
-
return qq;
|
|
218
|
-
case 'ks':
|
|
219
|
-
return ks;
|
|
220
|
-
case 'jd':
|
|
221
|
-
return jd;
|
|
222
|
-
case 'xhs':
|
|
223
|
-
return xhs;
|
|
224
|
-
// 第三方框架下自动获取实例
|
|
225
|
-
// 百度等小程序中可能存在封装过的wx对象,因此wx要放在最后判断
|
|
226
|
-
default: {
|
|
227
|
-
let minip;
|
|
228
|
-
if (!minip) minip = niceTry(() => xhs);
|
|
229
|
-
if (!minip) minip = niceTry(() => swan);
|
|
230
|
-
if (!minip) minip = niceTry(() => my);
|
|
231
|
-
if (!minip) minip = niceTry(() => tt);
|
|
232
|
-
if (!minip) minip = niceTry(() => qq);
|
|
233
|
-
if (!minip) minip = niceTry(() => ks);
|
|
234
|
-
if (!minip) minip = niceTry(() => jd);
|
|
235
|
-
if (!minip) minip = niceTry(() => wx);
|
|
236
|
-
return minip;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
export const getPlainConfig = (platform?: string) => {
|
|
243
|
-
return niceTry(() => {
|
|
244
|
-
switch (platform) {
|
|
245
|
-
// 指定平台获取实例
|
|
246
|
-
case 'wx':
|
|
247
|
-
return __wxConfig;
|
|
248
|
-
case 'swan':
|
|
249
|
-
return appConfig;
|
|
250
|
-
case 'tt':
|
|
251
|
-
return (
|
|
252
|
-
niceTry(() => __ttConfig) ||
|
|
253
|
-
global?.TMAConfig ||
|
|
254
|
-
globalThis?.TMAConfig
|
|
255
|
-
); // 可能会拿不到
|
|
256
|
-
case 'qq':
|
|
257
|
-
return __qqConfig;
|
|
258
|
-
case 'ks':
|
|
259
|
-
return __ksConfig; // 新版快手小程序已经拿不到了
|
|
260
|
-
case 'jd':
|
|
261
|
-
return __jdConfig;
|
|
262
|
-
case 'xhs':
|
|
263
|
-
return __MP_APP_JSON_MIGRATION__ ?? __MP_APP_JSON__;
|
|
264
|
-
// 第三方框架下自动获取实例
|
|
265
|
-
default:
|
|
266
|
-
// 支付宝和淘宝不存在可获取的全局对象
|
|
267
|
-
return undefined;
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
export const getPlainAppCode = (platform?: string) => {
|
|
273
|
-
return niceTry(() => {
|
|
274
|
-
switch (platform) {
|
|
275
|
-
// 指定平台获取实例
|
|
276
|
-
case 'wx':
|
|
277
|
-
case 'qq':
|
|
278
|
-
return __wxAppCode__;
|
|
279
|
-
case 'tt':
|
|
280
|
-
return __allConfig__;
|
|
281
|
-
case 'ks':
|
|
282
|
-
return __module__;
|
|
283
|
-
case 'jd':
|
|
284
|
-
return __jdAppCode__;
|
|
285
|
-
default:
|
|
286
|
-
return undefined;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
// 在框架下自动获取当前平台值
|
|
292
|
-
export const getPlainPlatform = () => {
|
|
293
|
-
// 百度等小程序中可能存在封装过的wx对象,因此wx要放在最后判断
|
|
294
|
-
let platform;
|
|
295
|
-
if (!platform && niceTry(() => xhs)) platform = 'xhs';
|
|
296
|
-
if (!platform && niceTry(() => swan)) platform = 'swan';
|
|
297
|
-
if (!platform && niceTry(() => tt)) platform = 'tt';
|
|
298
|
-
if (!platform && niceTry(() => qq)) platform = 'qq';
|
|
299
|
-
if (!platform && niceTry(() => my.tb)) platform = 'tb';
|
|
300
|
-
if (!platform && niceTry(() => my)) platform = 'my';
|
|
301
|
-
if (!platform && niceTry(() => ks)) platform = 'ks';
|
|
302
|
-
if (!platform && niceTry(() => jd)) platform = 'jd';
|
|
303
|
-
if (!platform && niceTry(() => wx)) platform = 'wx';
|
|
304
|
-
if (!platform) {
|
|
305
|
-
const quickappExist = !!find(keys(global), (o) =>
|
|
306
|
-
toString(o).toLowerCase().includes('quickapp')
|
|
307
|
-
);
|
|
308
|
-
if (quickappExist) {
|
|
309
|
-
platform = 'quickapp';
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return platform;
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
// 获取当前分包在全局中的key值
|
|
316
|
-
export const getSubKeys = (app: any) => {
|
|
317
|
-
return keys(app)
|
|
318
|
-
.filter((o) => o.indexOf('__sub') > -1 && o.indexOf('gio__') > -1)
|
|
319
|
-
.sort();
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
// 获取app实例
|
|
323
|
-
export const getAppInst = () => {
|
|
324
|
-
let app = niceTry(() => getApp({ allowDefault: true }));
|
|
325
|
-
// 阿里小程序中不支持getApp提前调用,所以只能把gio实例存在global当中
|
|
326
|
-
// 获取不到app实例的一律把gio实例存在global当中
|
|
327
|
-
if (!app) {
|
|
328
|
-
app = getGlobal();
|
|
329
|
-
}
|
|
330
|
-
return app;
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
export const getGlobal = () => {
|
|
334
|
-
return (
|
|
335
|
-
niceTry(() => niceTry(() => niceTry(() => $global) ?? global) ?? window) ??
|
|
336
|
-
globalThis
|
|
337
|
-
);
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
// Object参数限制
|
|
341
|
-
export const limitObject = (o: any) => {
|
|
342
|
-
const ob = {};
|
|
343
|
-
if (isObject(o)) {
|
|
344
|
-
// 移除预置的'&&sendTo'字段
|
|
345
|
-
unset(o, '&&sendTo');
|
|
346
|
-
forEach(o, (v, k) => {
|
|
347
|
-
const key = toString(k).slice(0, 100);
|
|
348
|
-
if (isObject(v)) {
|
|
349
|
-
ob[key] = limitObject(v);
|
|
350
|
-
} else if (isArray(v)) {
|
|
351
|
-
ob[key] = compact(v.slice(0, 100), true);
|
|
352
|
-
ob[key] = ob[key].join('||').slice(0, 1000);
|
|
353
|
-
} else if (isDate(v)) {
|
|
354
|
-
ob[key] = formatDate(v);
|
|
355
|
-
} else {
|
|
356
|
-
ob[key] = !isNil(v) ? toString(v).slice(0, 1000) : '';
|
|
357
|
-
}
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
return ob;
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// 批量获取存储中的数据,减少性能影响
|
|
364
|
-
export const batchGetStorageSync = (minipInstance: any, keys: string[]) => {
|
|
365
|
-
const batchFunction = () => {
|
|
366
|
-
return minipInstance.minip.batchGetStorageSync(keys);
|
|
367
|
-
};
|
|
368
|
-
const singleFunction = () => {
|
|
369
|
-
return keys.map((key: string) => minipInstance.getStorageSync(key));
|
|
370
|
-
};
|
|
371
|
-
// 优先使用批量接口(目前仅支持wx)
|
|
372
|
-
try {
|
|
373
|
-
if (minipInstance.minip.canIUse('batchGetStorageSync')) {
|
|
374
|
-
return batchFunction();
|
|
375
|
-
} else {
|
|
376
|
-
return singleFunction();
|
|
377
|
-
}
|
|
378
|
-
} catch (error) {
|
|
379
|
-
return singleFunction();
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
// 批量存储数据,减少性能影响
|
|
384
|
-
export const batchSetStorageSync = (minipInstance: any, kvList: any[]) => {
|
|
385
|
-
const batchFunction = () => {
|
|
386
|
-
return minipInstance.minip.batchSetStorageSync(kvList);
|
|
387
|
-
};
|
|
388
|
-
const singleFunction = () => {
|
|
389
|
-
return kvList.map(({ key, value }: any) =>
|
|
390
|
-
minipInstance.setStorageSync(key, value)
|
|
391
|
-
);
|
|
392
|
-
};
|
|
393
|
-
// 优先使用批量接口(目前仅支持wx)
|
|
394
|
-
try {
|
|
395
|
-
if (minipInstance.minip.canIUse('batchSetStorageSync')) {
|
|
396
|
-
return batchFunction();
|
|
397
|
-
} else {
|
|
398
|
-
return singleFunction();
|
|
399
|
-
}
|
|
400
|
-
} catch (error) {
|
|
401
|
-
return singleFunction();
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
// 将参数对象转为参数字符串
|
|
406
|
-
export const qsStringify = (query: any) => {
|
|
407
|
-
return keys(query || {})
|
|
408
|
-
.map((key) => {
|
|
409
|
-
if (key) {
|
|
410
|
-
return `${key}=${isNil(query[key]) ? '' : query[key]}`;
|
|
411
|
-
} else {
|
|
412
|
-
return '';
|
|
413
|
-
}
|
|
414
|
-
})
|
|
415
|
-
.join('&');
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
// 解析参数
|
|
419
|
-
export const qsParse = (s: string) => {
|
|
420
|
-
if (startsWith(s, '?') || startsWith(s, '&')) {
|
|
421
|
-
s = s.slice(1, s.length);
|
|
422
|
-
}
|
|
423
|
-
const qsObject = {};
|
|
424
|
-
s.split('&').forEach((pairs: string) => {
|
|
425
|
-
const pair = pairs.split('=');
|
|
426
|
-
if (pair[0]) {
|
|
427
|
-
qsObject[pair[0]] = pair[1];
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
return qsObject;
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
// 将字符串转为hash
|
|
434
|
-
export const hashCode = (string: string, abs = false) => {
|
|
435
|
-
let hash = 0;
|
|
436
|
-
if (isEmpty(string) || typeof string === 'boolean') {
|
|
437
|
-
return hash;
|
|
438
|
-
}
|
|
439
|
-
let i = 0;
|
|
440
|
-
while (i < string.length) {
|
|
441
|
-
const char = string.charCodeAt(i);
|
|
442
|
-
hash = (hash << 5) - hash + char;
|
|
443
|
-
hash = hash & hash; //Convert to 32bit integer
|
|
444
|
-
i++;
|
|
445
|
-
}
|
|
446
|
-
return abs ? Math.abs(hash) : hash;
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
export const getExtraData = (data: any) => {
|
|
450
|
-
if (isString(data)) {
|
|
451
|
-
return niceTry(() => JSON.parse(data)) ?? {};
|
|
452
|
-
} else {
|
|
453
|
-
return data ?? {};
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* 清理参数中的非法字段
|
|
459
|
-
* @param originQuery 原始查询参数,可以是对象或参数字符串
|
|
460
|
-
* @param extraData 额外数据,可以是对象或参数字符串
|
|
461
|
-
* @returns 清理后的纯净参数对象
|
|
462
|
-
*/
|
|
463
|
-
const dirtyKey = [
|
|
464
|
-
'wxShoppingListScene',
|
|
465
|
-
'$taroTimestamp',
|
|
466
|
-
'gdpCircleRoomCollectUrl'
|
|
467
|
-
];
|
|
468
|
-
export const getPureParams = (originQuery: any = {}, extraData: any = {}) => {
|
|
469
|
-
// 处理originQuery可能是字符串的情况
|
|
470
|
-
const parsedOriginQuery =
|
|
471
|
-
typeof originQuery === 'string' ? qsParse(originQuery) : originQuery || {};
|
|
472
|
-
|
|
473
|
-
// 递归清理函数
|
|
474
|
-
function cleanObject(obj, needCompare) {
|
|
475
|
-
if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
|
|
476
|
-
return obj;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
const result = {};
|
|
480
|
-
|
|
481
|
-
keys(obj).forEach((key) => {
|
|
482
|
-
// 检查key是否包含dirtyKey中的任何字符串
|
|
483
|
-
const isKeyDirty = dirtyKey.some((dirty) => key.includes(dirty));
|
|
484
|
-
const isKeyExist = has(parsedOriginQuery, key);
|
|
485
|
-
|
|
486
|
-
if (!isKeyDirty && (needCompare ? !isKeyExist : true)) {
|
|
487
|
-
const value = obj[key];
|
|
488
|
-
|
|
489
|
-
// 检查value是否是字符串且包含dirtyKey中的任何字符串
|
|
490
|
-
if (typeof value === 'string') {
|
|
491
|
-
const isValueDirty = dirtyKey.some((dirty) => value.includes(dirty));
|
|
492
|
-
if (!isValueDirty) {
|
|
493
|
-
result[key] = value;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
// 如果是数字和布尔值,直接保留,其他类型丢弃
|
|
497
|
-
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
498
|
-
result[key] = value;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
return result;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
return Object.assign(
|
|
507
|
-
{},
|
|
508
|
-
cleanObject(parsedOriginQuery, false),
|
|
509
|
-
cleanObject(extraData, true)
|
|
510
|
-
);
|
|
511
|
-
};
|
package/src/utils/verifiers.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 代码中一些通用的或者业务上的校验器
|
|
3
|
-
*/
|
|
4
|
-
import { consoleText } from '@@/utils/tools';
|
|
5
|
-
import { GrowingIOType } from '@@/types/growingIO';
|
|
6
|
-
import { isNumber, isString, toString } from '@@/utils/glodash';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 一些id的合法性校验
|
|
10
|
-
* @param id // 只允许数字和字符串,不允许为空字符串、0、负数、短横线字符串null,undefined
|
|
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
|
-
!['-', 'null', 'undefined'].includes(o as string);
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 初始化时的一些合法性校验
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
export const initialCheck = (growingIO: GrowingIOType, args: any) => {
|
|
23
|
-
// ?重复初始化由init方法内部判断
|
|
24
|
-
const projectId = toString(args[0]);
|
|
25
|
-
const dataSourceId = toString(args[1]);
|
|
26
|
-
// 参数为空校验
|
|
27
|
-
const userOptions = (args.length === 4 ? args[3] : args[2]) || {};
|
|
28
|
-
if (!projectId || !dataSourceId) {
|
|
29
|
-
consoleText(
|
|
30
|
-
'SDK初始化失败,请使用 gdp("init", "您的GrowingIO项目 accountId", "您项目的 dataSourceId", "您的小程序 AppId(可选)", options: { serverUrl: "您的数据上报地址" }); 进行初始化!',
|
|
31
|
-
'error'
|
|
32
|
-
);
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
const gioSDKInitialized = growingIO.dataStore.initializedTrackingIds.some(
|
|
36
|
-
(tid: string, index: number) => {
|
|
37
|
-
const vds =
|
|
38
|
-
index === 0 ? growingIO.vdsConfig : growingIO.subInstance[tid];
|
|
39
|
-
return vds.projectId === projectId && vds.dataSourceId === dataSourceId;
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
if (gioSDKInitialized) {
|
|
43
|
-
consoleText('SDK初始化失败,重复初始化,请检查初始化参数!', 'error');
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
projectId,
|
|
48
|
-
dataSourceId,
|
|
49
|
-
appId: toString(args.length === 4 ? args[2] : ''),
|
|
50
|
-
userOptions
|
|
51
|
-
};
|
|
52
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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": "ES5",
|
|
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
|
-
}
|
package/typings/global.d.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
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 xhs: any;
|
|
28
|
-
declare var quickapp: any;
|
|
29
|
-
declare var __wxAppCode__: any;
|
|
30
|
-
declare var __wxConfig: any;
|
|
31
|
-
declare var appConfig: any; // swan的全局配置
|
|
32
|
-
declare var __myConfig: any; // my的全局配置
|
|
33
|
-
declare var TMAConfig: any; // tt的全局配置
|
|
34
|
-
declare var __ttConfig: any; // tt的全局配置
|
|
35
|
-
declare var __allConfig__: any;
|
|
36
|
-
declare var __qqConfig: any; // qq的全局配置
|
|
37
|
-
declare var __ksConfig: any; // ks的全局配置
|
|
38
|
-
declare var __module__: any;
|
|
39
|
-
declare var __jdConfig: any; // jd的全局配置
|
|
40
|
-
declare var __jdAppCode__: any;
|
|
41
|
-
declare var __MP_APP_JSON_MIGRATION__: any; // xhs的全局配置
|
|
42
|
-
declare var __MP_APP_JSON__: any; // xhs的全局配置
|
|
43
|
-
declare var __proto__: any;
|
|
44
|
-
declare var Taro: any
|
|
45
|
-
declare var uni: any
|
|
46
|
-
|
|
47
|
-
declare module "__GIO_PLATFORM_CONFIG__" {
|
|
48
|
-
let module: any;
|
|
49
|
-
export default module;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
declare module "__GIO_PLATFORM_INSTANCE__" {
|
|
53
|
-
let module: any;
|
|
54
|
-
export default module;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
declare module "__GIO_PLUGIN_INSTANCE__" {
|
|
58
|
-
let module: any;
|
|
59
|
-
export default module;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
declare module "@system.app" {
|
|
63
|
-
let module: any;
|
|
64
|
-
export default module;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare module "@system.storage" {
|
|
68
|
-
let module: any;
|
|
69
|
-
export default module;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
declare module "@system.network" {
|
|
73
|
-
let module: any;
|
|
74
|
-
export default module;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
declare module "@system.device" {
|
|
78
|
-
let module: any;
|
|
79
|
-
export default module;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
declare module "@system.geolocation" {
|
|
83
|
-
let module: any;
|
|
84
|
-
export default module;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
declare module "@system.fetch" {
|
|
88
|
-
let module: any;
|
|
89
|
-
export default module;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
declare module "@system.router" {
|
|
93
|
-
let module: any;
|
|
94
|
-
export default module;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
declare module "@system.image" {
|
|
98
|
-
let module: any;
|
|
99
|
-
export default module;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
declare module "@system.share" {
|
|
103
|
-
let module: any;
|
|
104
|
-
export default module;
|
|
105
|
-
}
|