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.
Files changed (103) hide show
  1. package/.babelrc +4 -0
  2. package/.eslintignore +11 -0
  3. package/.eslintrc.js +120 -0
  4. package/.github/workflows/greetings.yml +13 -0
  5. package/.github/workflows/publish.yml +43 -0
  6. package/.prettierignore +19 -0
  7. package/.prettierrc.js +9 -0
  8. package/LICENSE +674 -0
  9. package/README.md +103 -0
  10. package/babel.config.js +6 -0
  11. package/bin/build/all.sh +38 -0
  12. package/bin/build/full.sh +32 -0
  13. package/bin/build/jd.sh +14 -0
  14. package/bin/build/ks.sh +14 -0
  15. package/bin/build/my.sh +14 -0
  16. package/bin/build/plugins.sh +5 -0
  17. package/bin/build/qq.sh +14 -0
  18. package/bin/build/quickapp.sh +14 -0
  19. package/bin/build/swan.sh +14 -0
  20. package/bin/build/taro.sh +18 -0
  21. package/bin/build/tb.sh +18 -0
  22. package/bin/build/tt.sh +14 -0
  23. package/bin/build/uniapp.sh +18 -0
  24. package/bin/build/wx.sh +14 -0
  25. package/dist/alipay.js +1 -0
  26. package/dist/baidu.js +1 -0
  27. package/dist/bytedance.js +1 -0
  28. package/dist/jingdong.js +1 -0
  29. package/dist/kuaishou.js +1 -0
  30. package/dist/plugins/gioABTest.js +1 -0
  31. package/dist/plugins/gioCompress.js +1 -0
  32. package/dist/plugins/gioEventAutoTracking.js +1 -0
  33. package/dist/plugins/gioImpressionTracking.js +1 -0
  34. package/dist/qq.js +1 -0
  35. package/dist/quickapp.js +1 -0
  36. package/dist/taobao.js +1 -0
  37. package/dist/taro.js +1 -0
  38. package/dist/uniapp.js +1 -0
  39. package/dist/wechat.js +1 -0
  40. package/package.json +144 -0
  41. package/rollup.config.js +92 -0
  42. package/rollup.plugins.config.js +76 -0
  43. package/src/constants/config.ts +136 -0
  44. package/src/constants/regex.ts +4 -0
  45. package/src/core/dataStore/eventContextBuilder.ts +70 -0
  46. package/src/core/dataStore/eventHooks/appEffects.ts +220 -0
  47. package/src/core/dataStore/eventHooks/index.ts +403 -0
  48. package/src/core/dataStore/eventHooks/minipPage.ts +132 -0
  49. package/src/core/dataStore/eventHooks/pageEffects.ts +168 -0
  50. package/src/core/dataStore/index.ts +543 -0
  51. package/src/core/growingIO.ts +433 -0
  52. package/src/core/plugins.ts +152 -0
  53. package/src/core/uploader.ts +219 -0
  54. package/src/core/userStore.ts +203 -0
  55. package/src/index.ts +68 -0
  56. package/src/minipInstance/base.ts +287 -0
  57. package/src/minipInstance/framework.ts +22 -0
  58. package/src/minipInstance/jd.ts +11 -0
  59. package/src/minipInstance/ks.ts +12 -0
  60. package/src/minipInstance/my.ts +53 -0
  61. package/src/minipInstance/qq.ts +12 -0
  62. package/src/minipInstance/quickapp.ts +230 -0
  63. package/src/minipInstance/swan.ts +20 -0
  64. package/src/minipInstance/tb.ts +53 -0
  65. package/src/minipInstance/tt.ts +12 -0
  66. package/src/minipInstance/wx.ts +12 -0
  67. package/src/platformConfig/base.ts +86 -0
  68. package/src/platformConfig/framework.ts +29 -0
  69. package/src/platformConfig/jd.ts +11 -0
  70. package/src/platformConfig/ks.ts +11 -0
  71. package/src/platformConfig/my.ts +15 -0
  72. package/src/platformConfig/qq.ts +13 -0
  73. package/src/platformConfig/quickapp.ts +48 -0
  74. package/src/platformConfig/swan.ts +11 -0
  75. package/src/platformConfig/tb.ts +29 -0
  76. package/src/platformConfig/tt.ts +11 -0
  77. package/src/platformConfig/wx.ts +20 -0
  78. package/src/pluginsOut/README.md +50 -0
  79. package/src/pluginsOut/frameworks/gioTaobaoAdapter.ts +195 -0
  80. package/src/pluginsOut/frameworks/gioTaroAdapter.ts +358 -0
  81. package/src/pluginsOut/frameworks/gioUniAppAdapter.ts +220 -0
  82. package/src/pluginsOut/ordinary/gioABTest.ts +254 -0
  83. package/src/pluginsOut/ordinary/gioCompress.ts +251 -0
  84. package/src/pluginsOut/ordinary/gioCustomTracking.ts +71 -0
  85. package/src/pluginsOut/ordinary/gioEventAutoTracking.ts +164 -0
  86. package/src/pluginsOut/ordinary/gioImpressionTracking.ts +298 -0
  87. package/src/types/base.ts +150 -0
  88. package/src/types/dataStore.ts +43 -0
  89. package/src/types/eventHooks.ts +141 -0
  90. package/src/types/gioCustomTracking.ts +9 -0
  91. package/src/types/gioEventTracking.ts +10 -0
  92. package/src/types/gioPerformance.ts +8 -0
  93. package/src/types/growingIO.ts +102 -0
  94. package/src/types/minipInstance.ts +126 -0
  95. package/src/types/platforms.ts +65 -0
  96. package/src/types/plugins.ts +24 -0
  97. package/src/types/uploader.ts +26 -0
  98. package/src/types/userStore.ts +22 -0
  99. package/src/utils/glodash.ts +423 -0
  100. package/src/utils/tools.ts +384 -0
  101. package/src/utils/verifiers.ts +76 -0
  102. package/tsconfig.json +32 -0
  103. package/typings/global.d.ts +92 -0
@@ -0,0 +1,287 @@
1
+ import { GrowingIOType } from '@@/types/growingIO';
2
+ import {
3
+ AppSource,
4
+ Location,
5
+ MinipInstanceType,
6
+ NavigateToMiniProgramOption,
7
+ SystemInfo
8
+ } from '@@/types/minipInstance';
9
+ import { PLATFORMS } from '@@/types/platforms';
10
+ import { isFunction, isObject, isString, last } from '@@/utils/glodash';
11
+ import {
12
+ limitString,
13
+ niceTry,
14
+ getPlainMinip,
15
+ getPlainPlatform,
16
+ getPlainConfig
17
+ } from '@@/utils/tools';
18
+
19
+ // 此基础实现类仅包含所有小程序,快应用所有方法全部单独实现
20
+ class BaseInstance implements MinipInstanceType {
21
+ readonly minip: any = getPlainMinip('__GIO_PLATFORM__');
22
+ public platform: PLATFORMS;
23
+ public scnPrefix: string;
24
+ public location: Location;
25
+ public appSource: AppSource;
26
+ public systemInfo: any;
27
+ public network: any;
28
+
29
+ constructor(public growingIO: GrowingIOType) {
30
+ const {
31
+ platformConfig: { platform, scnPrefix }
32
+ } = this.growingIO;
33
+ this.platform = platform;
34
+ this.scnPrefix = scnPrefix;
35
+ this.growingIO.emitter.on('OPTION_INITIALIZED', () => {
36
+ this.getNetworkType().then(() =>
37
+ this.growingIO.dataStore?.eventReleaseInspector()
38
+ );
39
+ this.getSystemInfo().then(() =>
40
+ this.growingIO.dataStore?.eventReleaseInspector()
41
+ );
42
+ });
43
+ }
44
+
45
+ // 通过hook setNavigationBarTitle方法优雅地获取客户设置的当前页面标题
46
+ hookSetTitle = () => {
47
+ const originSetter = this.minip?.setNavigationBarTitle;
48
+ const self = this;
49
+ if (originSetter) {
50
+ Object.defineProperty(this.minip, 'setNavigationBarTitle', {
51
+ writable: true,
52
+ enumerable: true,
53
+ configurable: true,
54
+ value: function () {
55
+ if (self.growingIO.gioSDKInitialized) {
56
+ // 这个currentPath一般认为是在onLoad中获取的当前小程序页面的path,此时SDK还没有parse,保存的还是上一个页面的信息
57
+ const currentPath = self.getCurrentPath();
58
+ const { title } = arguments[0] || {};
59
+ self.growingIO.dataStore.eventHooks.currentPage.settedTitle[
60
+ currentPath
61
+ ] = title;
62
+ }
63
+ return originSetter.apply(this, arguments);
64
+ }
65
+ });
66
+ }
67
+ };
68
+
69
+ // -----以下为除快应用以外的小程序通用的实现,由各平台端继承并差异化实现-----
70
+
71
+ /**
72
+ * 业务相关
73
+ */
74
+ // 保留当前页面,跳转到应用内的某个页面
75
+ navigateTo = (opt: {
76
+ url: string;
77
+ fail: () => void;
78
+ success: () => void;
79
+ complete: () => void;
80
+ }) => this.minip?.navigateTo(opt);
81
+
82
+ // 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
83
+ switchTab = (opt: {
84
+ url: string;
85
+ fail: () => void;
86
+ success: () => void;
87
+ complete: () => void;
88
+ }) => {
89
+ this.minip?.switchTab(opt);
90
+ };
91
+
92
+ // 打开另一个小程序
93
+ navigateToMiniProgram = (opt: NavigateToMiniProgramOption) =>
94
+ this.minip?.navigateToMiniProgram(opt);
95
+
96
+ // 获取图片信息
97
+ getImageInfo = ({ src, success, fail, complete }: any) =>
98
+ this.minip?.getImageInfo({ src, success, fail, complete });
99
+
100
+ // 采集曝光事件
101
+ initImpression = (collectPage: any) => {
102
+ this.growingIO.plugins?.gioImpressionTracking?.main(
103
+ collectPage,
104
+ 'observeAll'
105
+ );
106
+ };
107
+
108
+ /**
109
+ * 页面相关
110
+ */
111
+ // 获取当前页面栈
112
+ getCurrentPage = (): any => {
113
+ // @ts-ignore 小程序自带api
114
+ return niceTry(() => last(getCurrentPages())) || {};
115
+ };
116
+
117
+ // 获取当前页面路由
118
+ getCurrentPath = () => {
119
+ const currentPage = this.getCurrentPage();
120
+ // wx/my取route; swan取uri; tt取__route__; qq无值
121
+ return (
122
+ currentPage?.route || currentPage?.uri || currentPage?.__route__ || ''
123
+ );
124
+ };
125
+
126
+ // 获取页面标题
127
+ getPageTitle = (page) => {
128
+ let title = '';
129
+ const instConfig = getPlainConfig(getPlainPlatform());
130
+ try {
131
+ // 第一优先级在base中的hook setNavigationBarTitle设置的值
132
+ // 第二优先级支持客户自己在页面中设置页面title
133
+ const data = page?.data || page.$data || {};
134
+ title = isString(data?.gioPageTitle) ? data?.gioPageTitle : '';
135
+ // 第三优先级取页面的navigationBarTitleText
136
+ if (title.length === 0) {
137
+ const pageInfo =
138
+ instConfig.page[page.route] || instConfig.page[`${page.route}.html`];
139
+ if (pageInfo) {
140
+ title = pageInfo.window.navigationBarTitleText;
141
+ } else {
142
+ title = instConfig.global.window.navigationBarTitleText;
143
+ }
144
+ }
145
+ // 第四优先级取tabBar配置
146
+ if (title.length === 0) {
147
+ const tabPage = instConfig?.tabBar?.list?.find((p) => {
148
+ return (
149
+ p.pagePath === page.route || p.pagePath === `${page.route}.html`
150
+ );
151
+ });
152
+ title = tabPage?.text || '';
153
+ }
154
+ } catch (e) {
155
+ return '';
156
+ }
157
+ return limitString(title);
158
+ };
159
+
160
+ /**
161
+ * 存储相关
162
+ */
163
+ // 同步获取存储数据
164
+ getStorageSync = (key: string): any => {
165
+ let value = this.minip?.getStorageSync(key);
166
+ if (isObject(value) && value.expiredAt) {
167
+ if (value.expiredAt < Date.now()) {
168
+ return '';
169
+ } else {
170
+ return value.value;
171
+ }
172
+ }
173
+ return value;
174
+ };
175
+
176
+ // 异步获取存储数据
177
+ getStorage = (key: string): Promise<string> => {
178
+ return new Promise((resolve) => {
179
+ this.minip?.getStorage({
180
+ key,
181
+ success: ({ data }) => resolve(data),
182
+ fail: () => resolve('')
183
+ });
184
+ });
185
+ };
186
+
187
+ // 同步存储数据
188
+ setStorageSync = (key: string, value: any, expiredAt?: string | number) => {
189
+ if (expiredAt) {
190
+ value = { value, expiredAt };
191
+ }
192
+ this.minip?.setStorageSync(key, value);
193
+ };
194
+
195
+ // 异步存储数据
196
+ setStorage = (key: string, value: any) => {
197
+ this.minip?.setStorage({ key, data: value });
198
+ };
199
+
200
+ // 同步移除指定数据
201
+ removeStorageSync = (key: string) => {
202
+ this.minip?.removeStorageSync(key);
203
+ };
204
+
205
+ // 异步移除指定数据
206
+ removeStorage = (key: string) => {
207
+ this.minip?.removeStorage(key);
208
+ };
209
+
210
+ /**
211
+ * 网络相关
212
+ */
213
+ // 获取网络类型
214
+ getNetworkType = (): Promise<{ networkType: string }> => {
215
+ const self = this;
216
+ return new Promise((resolve) => {
217
+ this.minip?.getNetworkType({
218
+ success: (r) => {
219
+ self.network = r;
220
+ resolve(r);
221
+ },
222
+ fail: () => resolve(null)
223
+ });
224
+ });
225
+ };
226
+
227
+ // 发起请求
228
+ request = ({
229
+ url,
230
+ data,
231
+ header,
232
+ timeout,
233
+ method,
234
+ success,
235
+ fail,
236
+ complete
237
+ }) => {
238
+ const requestTask = this.minip?.request({
239
+ url,
240
+ data,
241
+ // 微信小程序和其他小程序里叫header
242
+ header,
243
+ // 支付宝小程序里叫headers
244
+ headers: header,
245
+ timeout,
246
+ method,
247
+ success,
248
+ fail,
249
+ complete
250
+ });
251
+ // 设置超时中断请求
252
+ let t = setTimeout(() => {
253
+ if (requestTask?.abort && isFunction(requestTask?.abort)) {
254
+ requestTask?.abort();
255
+ }
256
+ clearTimeout(t);
257
+ t = null;
258
+ }, (timeout || 10000) + 10);
259
+ return requestTask;
260
+ };
261
+
262
+ /**
263
+ * 系统相关
264
+ */
265
+ // 获取小程序系统信息
266
+ getSystemInfo = (): Promise<SystemInfo> => {
267
+ const self = this;
268
+ return new Promise((resolve) => {
269
+ this.minip?.getSystemInfo({
270
+ success: (r) => {
271
+ self.systemInfo = r;
272
+ resolve(r);
273
+ },
274
+ fail: () => resolve(null)
275
+ });
276
+ });
277
+ };
278
+
279
+ // 获取小程序设置
280
+ getSetting = () => {
281
+ return new Promise((resolve) => {
282
+ this.minip?.getSetting({ success: resolve, fail: resolve });
283
+ });
284
+ };
285
+ }
286
+
287
+ export default BaseInstance;
@@ -0,0 +1,22 @@
1
+ import { getPlainPlatform } from '@@/utils/tools';
2
+
3
+ import JingDong from './jd';
4
+ import KuaiShou from './ks';
5
+ import Alipay from './my';
6
+ import QQ from './qq';
7
+ import Baidu from './swan';
8
+ import Bytedance from './tt';
9
+ import Weixin from './wx';
10
+
11
+ const plainPlatform = getPlainPlatform();
12
+ const INST = {
13
+ wx: Weixin,
14
+ swan: Baidu,
15
+ my: Alipay,
16
+ qq: QQ,
17
+ tt: Bytedance,
18
+ ks: KuaiShou,
19
+ jd: JingDong
20
+ };
21
+
22
+ export default INST[plainPlatform];
@@ -0,0 +1,11 @@
1
+ import { GrowingIOType } from '@@/types/growingIO';
2
+ import BaseImplements from './base';
3
+
4
+ class JingDong extends BaseImplements {
5
+ constructor(public growingIO: GrowingIOType) {
6
+ super(growingIO);
7
+ this.hookSetTitle();
8
+ }
9
+ }
10
+
11
+ export default JingDong;
@@ -0,0 +1,12 @@
1
+ import { GrowingIOType } from '@@/types/growingIO';
2
+
3
+ import BaseImplements from './base';
4
+
5
+ class KuaiShou extends BaseImplements {
6
+ constructor(public growingIO: GrowingIOType) {
7
+ super(growingIO);
8
+ this.hookSetTitle();
9
+ }
10
+ }
11
+
12
+ export default KuaiShou;
@@ -0,0 +1,53 @@
1
+ import { GrowingIOType } from '@@/types/growingIO';
2
+ import BaseImplements from './base';
3
+
4
+ class Alipay extends BaseImplements {
5
+ constructor(public growingIO: GrowingIOType) {
6
+ super(growingIO);
7
+ this.hookSetTitle();
8
+ }
9
+
10
+ hookSetTitle = () => {
11
+ const originSetter = this.minip?.setNavigationBar;
12
+ const self = this;
13
+ if (originSetter) {
14
+ Object.defineProperty(this.minip, 'setNavigationBar', {
15
+ writable: true,
16
+ enumerable: true,
17
+ configurable: true,
18
+ value: function () {
19
+ if (self.growingIO.gioSDKInitialized) {
20
+ // 这个currentPath一般认为是在onLoad中获取的当前小程序页面的path,此时SDK还没有parse,保存的还是上一个页面的信息
21
+ const currentPath = self.getCurrentPath();
22
+ const { title } = arguments[0] || {};
23
+ self.growingIO.dataStore.eventHooks.currentPage.settedTitle[
24
+ currentPath
25
+ ] = title;
26
+ }
27
+ return originSetter.apply(this, arguments);
28
+ }
29
+ });
30
+ }
31
+ };
32
+
33
+ // 采集曝光事件
34
+ initImpression = (collectPage: any) => {
35
+ this.growingIO.plugins?.gioImpressionTracking?.main(
36
+ collectPage,
37
+ 'selectAll'
38
+ );
39
+ };
40
+
41
+ // 同步获取存储数据(支付宝小程序返回值与其他平台不同)
42
+ getStorageSync = (key: string) => {
43
+ const { data } = my.getStorageSync({ key });
44
+ return data;
45
+ };
46
+
47
+ // 同步存储数据(支付宝小程序参数与其他平台不同)
48
+ setStorageSync = (key: string, value: any) => {
49
+ this.minip?.setStorageSync({ key, data: value });
50
+ };
51
+ }
52
+
53
+ export default Alipay;
@@ -0,0 +1,12 @@
1
+ import { GrowingIOType } from '@@/types/growingIO';
2
+
3
+ import BaseImplements from './base';
4
+
5
+ class QQ extends BaseImplements {
6
+ constructor(public growingIO: GrowingIOType) {
7
+ super(growingIO);
8
+ this.hookSetTitle();
9
+ }
10
+ }
11
+
12
+ export default QQ;
@@ -0,0 +1,230 @@
1
+ import { GrowingIOType } from '@@/types/growingIO';
2
+ import { SystemInfo } from '@@/types/minipInstance';
3
+ import { isString, last } from '@@/utils/glodash';
4
+ import { limitString } from '@@/utils/tools';
5
+ import app from '@system.app';
6
+ import device from '@system.device';
7
+ import fetch from '@system.fetch';
8
+ import image from '@system.image';
9
+ import network from '@system.network';
10
+ import router from '@system.router';
11
+ import share from '@system.share';
12
+ import storage from '@system.storage';
13
+
14
+ import BaseImplements from './base';
15
+
16
+ class QuickApp extends BaseImplements {
17
+ constructor(public growingIO: GrowingIOType) {
18
+ super(growingIO);
19
+ this.growingIO.emitter.on('minipLifecycle', ({ event }) => {
20
+ switch (event) {
21
+ case 'App onCreate':
22
+ {
23
+ this.getNetworkType().then(() =>
24
+ this.growingIO.dataStore?.eventReleaseInspector()
25
+ );
26
+ this.getSystemInfo().then(() =>
27
+ this.growingIO.dataStore?.eventReleaseInspector()
28
+ );
29
+ }
30
+ break;
31
+ case 'App onCreateEnd':
32
+ {
33
+ this.setStorage = (key: string, value: string) => {
34
+ storage?.set({ key, value });
35
+ };
36
+ }
37
+ break;
38
+ default:
39
+ break;
40
+ }
41
+ });
42
+ }
43
+
44
+ /**
45
+ * 业务相关
46
+ */
47
+ // 获取应用来源
48
+ getAppSource = () => {
49
+ const { source } = app.getInfo();
50
+ this.appSource = source || {};
51
+ return this.appSource;
52
+ };
53
+
54
+ // 保留当前页面,跳转到应用内的某个页面(重写为空)
55
+ navigateTo = () => {}; // eslint-disable-line
56
+
57
+ // 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面(重写为空)
58
+ switchTab = () => {}; // eslint-disable-line
59
+
60
+ // 打开另一个小程序(重写为空)
61
+ navigateToMiniProgram = () => {}; // eslint-disable-line
62
+
63
+ // 监听小程序切前台事件(重写为空)
64
+ onAppShow = () => {}; // eslint-disable-line
65
+
66
+ // 监听小程序切后台事件(重写为空)
67
+ onAppHide = () => {}; // eslint-disable-line
68
+
69
+ // 获取图片信息
70
+ getImageInfo = ({ src, success, fail, complete }: any) => {
71
+ return image?.getImageInfo({ uri: src, success, fail, complete });
72
+ };
73
+
74
+ // 采集曝光事件
75
+ initImpression = () => {}; // eslint-disable-line
76
+
77
+ // 初始化分享
78
+ initShareAppMessage = (growingIO: GrowingIOType) => {
79
+ const { vdsConfig, platformConfig } = growingIO;
80
+ try {
81
+ this.growingIO.shareAppMessage = function () {
82
+ const params = arguments[0];
83
+ if (
84
+ params &&
85
+ params.type &&
86
+ !/^text.*/.test(params.type) &&
87
+ params.data
88
+ ) {
89
+ if (vdsConfig.followShare) {
90
+ if (params.data.indexOf('?') === -1) {
91
+ params.data = params.data + '?suid=' + growingIO.userStore.uid;
92
+ } else {
93
+ params.data = params.data + '&suid=' + growingIO.userStore.uid;
94
+ }
95
+ }
96
+ }
97
+ share?.share(params);
98
+ growingIO?.eventTracking?.pageEffects(
99
+ this,
100
+ platformConfig.listeners.page.shareApp as any,
101
+ arguments
102
+ );
103
+ };
104
+ } catch (e) {
105
+ //
106
+ }
107
+ };
108
+
109
+ /**
110
+ * 页面相关
111
+ */
112
+ // 获取当前页面栈
113
+ getCurrentPage = () => {
114
+ if (router?.getPages) {
115
+ return last(router?.getPages());
116
+ }
117
+ return {};
118
+ };
119
+
120
+ // 获取当前页面路由
121
+ getCurrentPath = () => {
122
+ const route = router?.getState();
123
+ return route?.path;
124
+ };
125
+
126
+ // 获取页面标题(除wx以外其他平台)
127
+ getPageTitle = (page) => {
128
+ let title = '';
129
+ try {
130
+ // this.$page.setTitleBar是只读方法,不能hook
131
+ // 第一优先级支持客户自己在页面中设置页面title
132
+ title = isString(page?.gioPageTitle) ? page?.gioPageTitle : '';
133
+ // 第三优先级取页面的titleBarText
134
+ if (!title) {
135
+ const instConfig = page?.$app?.$def?.manifast?.display?.pages ?? {};
136
+ const pageInfo = instConfig?.[page.route];
137
+ if (pageInfo) {
138
+ title = pageInfo.titleBarText;
139
+ }
140
+ }
141
+ // 第四优先级取router状态
142
+ if (!title) {
143
+ const route = router?.getState();
144
+ title = route?.name || '';
145
+ }
146
+ } catch (e) {
147
+ return '';
148
+ }
149
+ return limitString(title);
150
+ };
151
+
152
+ /**
153
+ * 存储相关
154
+ */
155
+ // 同步获取存储数据
156
+ getStorageSync = () => '';
157
+
158
+ // 异步获取存储数据
159
+ getStorage = async (key: string): Promise<string> => {
160
+ return await new Promise((resolve) => {
161
+ storage?.get({
162
+ key,
163
+ success: (res) => resolve(res),
164
+ fail: () => resolve(null)
165
+ });
166
+ });
167
+ };
168
+
169
+ // 同步存储数据
170
+ setStorageSync = () => {}; // eslint-disable-line
171
+
172
+ // 异步存储数据
173
+ setStorage = (key: string, value: string) => {}; // eslint-disable-line
174
+
175
+ // 同步移除指定数据
176
+ removeStorageSync = () => {}; // eslint-disable-line
177
+
178
+ // 异步移除指定数据
179
+ removeStorage = (key: string) => {
180
+ storage?.delete({ key });
181
+ };
182
+
183
+ /**
184
+ * 网络相关
185
+ */
186
+ // 获取网络类型
187
+ getNetworkType = async (): Promise<{
188
+ networkType: string;
189
+ }> => {
190
+ const self = this;
191
+ return await new Promise((resolve) => {
192
+ network?.getType({
193
+ success: (res) => {
194
+ self.network = res;
195
+ resolve(res);
196
+ },
197
+ fail: () => resolve(null)
198
+ });
199
+ });
200
+ };
201
+
202
+ // 发起请求
203
+ request = ({ url, header, method, data, success, fail, complete }) => {
204
+ return fetch?.fetch({ url, header, method, data, success, fail, complete });
205
+ };
206
+
207
+ /**
208
+ * 系统相关
209
+ */
210
+ // 获取设备系统信息
211
+ getSystemInfo = async (): Promise<SystemInfo> => {
212
+ const self = this;
213
+ return await new Promise((resolve) => {
214
+ device?.getInfo({
215
+ success: (res) => {
216
+ const info = {
217
+ ...res,
218
+ version: res.platformVersionName,
219
+ platform: res.osType
220
+ };
221
+ self.systemInfo = info;
222
+ resolve(info);
223
+ },
224
+ fail: () => resolve(null)
225
+ });
226
+ });
227
+ };
228
+ }
229
+
230
+ export default QuickApp;
@@ -0,0 +1,20 @@
1
+ import { GrowingIOType } from '@@/types/growingIO';
2
+
3
+ import BaseImplements from './base';
4
+
5
+ class Baidu extends BaseImplements {
6
+ constructor(public growingIO: GrowingIOType) {
7
+ super(growingIO);
8
+ this.hookSetTitle();
9
+ }
10
+
11
+ // 采集曝光事件
12
+ initImpression = (collectPage: any) => {
13
+ this.growingIO.plugins?.gioImpressionTracking?.main(
14
+ collectPage,
15
+ 'selectAll'
16
+ );
17
+ };
18
+ }
19
+
20
+ export default Baidu;
@@ -0,0 +1,53 @@
1
+ import { GrowingIOType } from '@@/types/growingIO';
2
+ import BaseImplements from './base';
3
+
4
+ class Taobao extends BaseImplements {
5
+ constructor(public growingIO: GrowingIOType) {
6
+ super(growingIO);
7
+ this.hookSetTitle();
8
+ }
9
+
10
+ hookSetTitle = () => {
11
+ const originSetter = this.minip?.setNavigationBar;
12
+ const self = this;
13
+ if (originSetter) {
14
+ Object.defineProperty(this.minip, 'setNavigationBar', {
15
+ writable: true,
16
+ enumerable: true,
17
+ configurable: true,
18
+ value: function () {
19
+ if (self.growingIO.gioSDKInitialized) {
20
+ // 这个currentPath一般认为是在onLoad中获取的当前小程序页面的path,此时SDK还没有parse,保存的还是上一个页面的信息
21
+ const currentPath = self.getCurrentPath();
22
+ const { title } = arguments[0] || {};
23
+ self.growingIO.dataStore.eventHooks.currentPage.settedTitle[
24
+ currentPath
25
+ ] = title;
26
+ }
27
+ return originSetter.apply(this, arguments);
28
+ }
29
+ });
30
+ }
31
+ };
32
+
33
+ // 采集曝光事件
34
+ initImpression = (collectPage: any) => {
35
+ this.growingIO.plugins?.gioImpressionTracking?.main(
36
+ collectPage,
37
+ 'selectAll'
38
+ );
39
+ };
40
+
41
+ // 同步获取存储数据(支付宝小程序返回值与其他平台不同)
42
+ getStorageSync = (key: string) => {
43
+ const { data } = my.getStorageSync({ key });
44
+ return data;
45
+ };
46
+
47
+ // 同步存储数据(支付宝小程序参数与其他平台不同)
48
+ setStorageSync = (key: string, value: any) => {
49
+ this.minip?.setStorageSync({ key, data: value });
50
+ };
51
+ }
52
+
53
+ export default Taobao;