@haluo/util 2.0.33-beta.1 → 2.0.33-beta.11

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/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ import upload from './modules/upload';
11
11
  import monitor from './modules/monitor';
12
12
  export * from './modules/monitor';
13
13
  export * from './modules/app-call';
14
+ export * from './modules/track';
14
15
  interface Modules {
15
16
  cookie: typeof cookie;
16
17
  date: typeof date;
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import upload from './modules/upload';
11
11
  import monitor from './modules/monitor';
12
12
  export * from './modules/monitor';
13
13
  export * from './modules/app-call';
14
+ export * from './modules/track';
14
15
  const modules = {
15
16
  cookie,
16
17
  date,
@@ -74,8 +74,10 @@ export class AppCallCoreClass {
74
74
  });
75
75
  }
76
76
  try {
77
+ console.log('this.isAndroid', this.isAndroid);
77
78
  if (this.isAndroid || this.isHarmonyos) {
78
79
  if (this.has(name)) {
80
+ console.log('has', name);
79
81
  data = window.NativeCall?.[name]?.apply(window.NativeCall, arr) || null;
80
82
  if (this.showTip && window.Toast) {
81
83
  window.Toast({
@@ -97,6 +99,7 @@ export class AppCallCoreClass {
97
99
  }
98
100
  }
99
101
  catch (error) {
102
+ console.log('error', error);
100
103
  if (this.showTip && window.Toast) {
101
104
  window.Toast({
102
105
  position: 'middle',
@@ -32,7 +32,7 @@ export function createAllExtensions(appCall, config) {
32
32
  uid: JSON.parse(window.localStorage?.user || '{}').uid || ''
33
33
  }) ||
34
34
  {};
35
- return appCall.call('pay', JSON.stringify(params), window.bridge.payCallback);
35
+ return appCall.call('pay', JSON.stringify(params), window.bridge.payCallback || function () { });
36
36
  },
37
37
  // 支付(新版本)
38
38
  payNew(params = {}) {
@@ -43,7 +43,7 @@ export function createAllExtensions(appCall, config) {
43
43
  wayCode: params.wayCode || ''
44
44
  }) ||
45
45
  {};
46
- return appCall.call('payNew', JSON.stringify(params), window.bridge.payNewCallback);
46
+ return appCall.call('payNew', JSON.stringify(params), window.bridge.payNewCallback || function () { });
47
47
  },
48
48
  // ========== 基础接口 ==========
49
49
  // 弹出提示
@@ -192,7 +192,7 @@ export function createAllExtensions(appCall, config) {
192
192
  let params = JSON.stringify(obj);
193
193
  params = JSON.parse(params);
194
194
  console.log('话题信息:', params);
195
- return appCall.call('newCircle', JSON.stringify(params), window.bridge.circleRelease);
195
+ return appCall.call('newCircle', JSON.stringify(params), window.bridge.circleRelease || function () { });
196
196
  })
197
197
  .catch((err) => {
198
198
  console.log(err);
@@ -202,7 +202,7 @@ export function createAllExtensions(appCall, config) {
202
202
  publishWatchExperience(obj) {
203
203
  let params = JSON.stringify(obj);
204
204
  params = JSON.parse(params);
205
- return appCall.call('newCircle', JSON.stringify(params), window.bridge.circleRelease);
205
+ return appCall.call('newCircle', JSON.stringify(params), window.bridge.circleRelease || function () { });
206
206
  },
207
207
  // 打开app指定页面
208
208
  navigate(action = {}) {
@@ -215,16 +215,17 @@ export function createAllExtensions(appCall, config) {
215
215
  relatedId: action.action || '',
216
216
  link: action.link || '',
217
217
  jumpUrl: fileToHttps(action.jumpUrl) || '',
218
- urlParam: action.urlParam || {}
218
+ urlParam: action.urlParam || {},
219
+ frompage: action.frompage || ''
219
220
  }, action);
220
221
  console.log(action);
221
- return appCall.call('navigate', JSON.stringify(action), window.bridge.navigateRelease);
222
+ return appCall.call('navigate', JSON.stringify(action), window.bridge.navigateRelease || function () { });
222
223
  },
223
224
  // 根据能量活动跳转指定页面
224
225
  navigateByEnergy(action) {
225
226
  if (action && action.type) {
226
227
  action.relationType = action.type;
227
- return appCall.call('navigateByEnergy', JSON.stringify(action), window.bridge.messageRelease);
228
+ return appCall.call('navigateByEnergy', JSON.stringify(action), window.bridge.messageRelease || function () { });
228
229
  }
229
230
  },
230
231
  // 跳转指定页面或链接,返回当前页面需告知H5
@@ -238,7 +239,7 @@ export function createAllExtensions(appCall, config) {
238
239
  orderNum: action.orderNum,
239
240
  shopId: action.shopId
240
241
  });
241
- return appCall.call('messageInteraction', JSON.stringify(action), window.bridge.messageRelease);
242
+ return appCall.call('messageInteraction', JSON.stringify(action), window.bridge.messageRelease || function () { });
242
243
  },
243
244
  // 获取预约价格
244
245
  getReservePrice(action = {}) {
@@ -311,7 +312,7 @@ export function createAllExtensions(appCall, config) {
311
312
  id: params.id,
312
313
  carId: params.carId
313
314
  };
314
- return appCall.call('openCarScore', JSON.stringify(params), window.bridge.openCarScoreRelease);
315
+ return appCall.call('openCarScore', JSON.stringify(params), window.bridge.openCarScoreRelease || function () { });
315
316
  },
316
317
  // 分享功能
317
318
  share(params = {}) {
@@ -373,10 +374,10 @@ export function createAllExtensions(appCall, config) {
373
374
  // 车辆认证
374
375
  vehicleCertification(params) {
375
376
  if (params) {
376
- return appCall.call('vehicleCertification', JSON.stringify(params), window.bridge.vehicleCertificationRelease);
377
+ return appCall.call('vehicleCertification', JSON.stringify(params), window.bridge.vehicleCertificationRelease || function () { });
377
378
  }
378
379
  else {
379
- return appCall.call('vehicleCertification', window.bridge.vehicleCertificationRelease);
380
+ return appCall.call('vehicleCertification', window.bridge.vehicleCertificationRelease || function () { });
380
381
  }
381
382
  },
382
383
  /**
@@ -385,12 +386,12 @@ export function createAllExtensions(appCall, config) {
385
386
  * num = 1个数 ,限制 1
386
387
  */
387
388
  iosOpenInput(params) {
388
- return appCall.call('iosOpenInput', window.bridge.iosOpenInputRelease);
389
+ return appCall.call('iosOpenInput', window.bridge.iosOpenInputRelease || function () { });
389
390
  },
390
391
  // 打开上传图片
391
392
  getOSPhotosWithCount(params) {
392
393
  if (isIOS) {
393
- return appCall.call('getOSPhotosWithCount', JSON.stringify(params), window.bridge.getOSPhotosWithCountRelease);
394
+ return appCall.call('getOSPhotosWithCount', JSON.stringify(params), window.bridge.getOSPhotosWithCountRelease || function () { });
394
395
  }
395
396
  else {
396
397
  return appCall.call('getOSPhotosWithCount', JSON.stringify(params));
@@ -402,13 +403,13 @@ export function createAllExtensions(appCall, config) {
402
403
  },
403
404
  // 调用原生评论
404
405
  goToComment(params) {
405
- return appCall.call('toComment', JSON.stringify(params), window.bridge.updataCircleRelease);
406
+ return appCall.call('toComment', JSON.stringify(params), window.bridge.updataCircleRelease || function () { });
406
407
  },
407
408
  // 发送各种详情接口
408
409
  informationData(detail) {
409
410
  const me = appCall;
410
411
  setTimeout(function () {
411
- return me.call('informationData', JSON.stringify(detail), window.bridge.updataCircleRelease);
412
+ return me.call('informationData', JSON.stringify(detail), window.bridge.updataCircleRelease || function () { });
412
413
  }, 100);
413
414
  },
414
415
  // 设置加密
@@ -435,15 +436,15 @@ export function createAllExtensions(appCall, config) {
435
436
  },
436
437
  // 上传视频操作
437
438
  uploadVideo(params) {
438
- return appCall.call('uploadVideo', JSON.stringify(params), window.bridge.uploadVideoRelease);
439
+ return appCall.call('uploadVideo', JSON.stringify(params), window.bridge.uploadVideoRelease || function () { });
439
440
  },
440
441
  // 调用app的选择省市
441
442
  getProvinces(params) {
442
- return appCall.call('getProvinces', JSON.stringify(params), window.bridge.provincesRelease);
443
+ return appCall.call('getProvinces', JSON.stringify(params), window.bridge.provincesRelease || function () { });
443
444
  },
444
445
  // 开启系统定位权限
445
446
  setLocationPermission() {
446
- return appCall.call('locationPermission', window.bridge.locationPermissionRelease);
447
+ return appCall.call('locationPermission', window.bridge.locationPermissionRelease || function () { });
447
448
  },
448
449
  // 通知app发送时长埋点
449
450
  postDurationTack(params) {
@@ -470,7 +471,7 @@ export function createAllExtensions(appCall, config) {
470
471
  },
471
472
  // 调app激励抽奖
472
473
  requestAdvideo(action = {}) {
473
- return appCall.call('requestAdvideo', JSON.stringify(action), window.bridge.adVideoPlayedRelease);
474
+ return appCall.call('requestAdvideo', JSON.stringify(action), window.bridge.adVideoPlayedRelease || function () { });
474
475
  },
475
476
  // 打开外部商品链接
476
477
  openMall(action = {}) {
@@ -510,7 +511,7 @@ export function createAllExtensions(appCall, config) {
510
511
  },
511
512
  // 跳转到发布文章(ugc 活动)
512
513
  jumpToReleaseStoryUgc(params = {}) {
513
- return appCall.call('jumpToReleaseStoryUgc', JSON.stringify(params), window.bridge.handleUGCRefreshPageEvent);
514
+ return appCall.call('jumpToReleaseStoryUgc', JSON.stringify(params), window.bridge.handleUGCRefreshPageEvent || function () { });
514
515
  },
515
516
  // 跳转到发布视频
516
517
  jumpToReleaseVideo(params = {}) {
@@ -615,11 +616,11 @@ export function createAllExtensions(appCall, config) {
615
616
  },
616
617
  // 浏览记录记录数量
617
618
  viewHistoryCount(day) {
618
- return appCall.call('viewHistoryCount', day, window.bridge.viewHistoryCountRelease);
619
+ return appCall.call('viewHistoryCount', day, window.bridge.viewHistoryCountRelease || function () { });
619
620
  },
620
621
  // 搜索记录数量
621
622
  searchHistoryCount() {
622
- return appCall.call('searchHistoryCount', window.bridge.searchHistoryCountRelease);
623
+ return appCall.call('searchHistoryCount', window.bridge.searchHistoryCountRelease || function () { });
623
624
  },
624
625
  // 摩宁定位导航
625
626
  mnPositionNavigation(params = {}) {
@@ -627,7 +628,7 @@ export function createAllExtensions(appCall, config) {
627
628
  },
628
629
  // 摩宁选址
629
630
  mnSiteSelection(params = {}) {
630
- return appCall.call('mnSiteSelection', JSON.stringify(params), window.bridge.mnSiteSelection);
631
+ return appCall.call('mnSiteSelection', JSON.stringify(params), window.bridge.mnSiteSelection || function () { });
631
632
  },
632
633
  // 跳转小程序
633
634
  jumpApplet(url = '') {
@@ -635,7 +636,7 @@ export function createAllExtensions(appCall, config) {
635
636
  },
636
637
  // 摩宁地图展示定位
637
638
  mnPositionSelection(params = {}) {
638
- return appCall.call('mnPositionSelection', JSON.stringify(params), window.bridge.mnPositionSelection);
639
+ return appCall.call('mnPositionSelection', JSON.stringify(params), window.bridge.mnPositionSelection || function () { });
639
640
  },
640
641
  // 点评官调到摩友圈桥
641
642
  commentOfficerTab(params = '') {
@@ -651,7 +652,7 @@ export function createAllExtensions(appCall, config) {
651
652
  },
652
653
  // 开启监听返回的桥
653
654
  interactivePopEnable(params = 2) {
654
- return appCall.call('interactivePopEnable', params, window.bridge.interactivePopEnableRelease);
655
+ return appCall.call('interactivePopEnable', params, window.bridge.interactivePopEnableRelease || function () { });
655
656
  },
656
657
  // ios开启监听返回的桥
657
658
  interactiveSideslip(params = 2) {
@@ -788,6 +789,8 @@ export function createAllExtensions(appCall, config) {
788
789
  }
789
790
  try {
790
791
  data = JSON.parse(data || '{}');
792
+ const info = window.localStorage && window.localStorage.deviceData;
793
+ const deviceDataInfo = JSON.parse(info !== 'undefined' ? info || '{}' : '{}');
791
794
  if (config.env) {
792
795
  const env = config.env;
793
796
  if (data.bundleId === env.emotofineBundleId) {
@@ -799,6 +802,7 @@ export function createAllExtensions(appCall, config) {
799
802
  window.isdronefine = true;
800
803
  }
801
804
  }
805
+ data.deviceId = data?.deviceId || deviceDataInfo?.deviceId || '';
802
806
  window.localStorage?.setItem('deviceData', JSON.stringify(data));
803
807
  console.log('deviceData', data);
804
808
  }
@@ -818,8 +822,8 @@ export function createAllExtensions(appCall, config) {
818
822
  params.needPermission = params.needPermission !== undefined ? params.needPermission : 1;
819
823
  setTimeout(() => {
820
824
  return appCall.isAppVersionGreatThan?.(version)
821
- ? appCall.call('getLocation', JSON.stringify(params), window.bridge.getLocationCallback)
822
- : appCall.call('getLocation', window.bridge.getLocationCallback);
825
+ ? appCall.call('getLocation', JSON.stringify(params), window.bridge.getLocationCallback || function () { })
826
+ : appCall.call('getLocation', window.bridge.getLocationCallback || function () { });
823
827
  }, 300);
824
828
  },
825
829
  // 获取客户端平台(1=Android,2=iOS,3=WAP,31=鸿蒙)
@@ -62,23 +62,6 @@ export function createOfflineAppCall(config = {}) {
62
62
  // window.AppCall = appCall
63
63
  // 扩展离线包特定的方法
64
64
  appCall.extend({
65
- // 展示地图导航
66
- showMapNavigation(params) {
67
- return appCall.call('showMapNavigation', JSON.stringify(params));
68
- },
69
- // 替换 JSON 值(用于处理特殊字符)
70
- replaceJsonValue(str) {
71
- const meta = {
72
- '\b': '\\b',
73
- '\t': '\\t',
74
- '\n': '\\n',
75
- '\f': '\\f',
76
- '\r': '\\r'
77
- };
78
- return String(str).replace(/[\b\t\n\f\r]/g, function (s) {
79
- return meta[s] || s;
80
- });
81
- },
82
65
  // 文章 HTML 操作
83
66
  articleHtmlAction(action = {}, callback) {
84
67
  ;
@@ -115,17 +98,6 @@ export function createOfflineAppCall(config = {}) {
115
98
  navigateMap(params = {}) {
116
99
  return appCall.call('navigateMap', JSON.stringify(params));
117
100
  },
118
- // 获取离线包版本
119
- getOfflinePackageVersion(action = {}, callback) {
120
- Object.assign((window.bridge = window.bridge || {}), {
121
- getOfflinePackageVersionCallback(res) {
122
- if (typeof callback === 'function') {
123
- callback(res);
124
- }
125
- }
126
- });
127
- return appCall.call('getOfflinePackageVersion', JSON.stringify(action), window.bridge.getOfflinePackageVersionCallback);
128
- },
129
101
  // 获取app信息
130
102
  getDeviceData(callback) {
131
103
  function _callback(data) {
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Track 埋点模块
3
+ * 统一封装各项目的埋点上报逻辑
4
+ *
5
+ * @example
6
+ * // 最简初始化(所有配置都有默认值)
7
+ * import { createTracker } from '@haluo/util/dist/modules/track'
8
+ *
9
+ * const tracker = createTracker({})
10
+ * // 或指定 appName
11
+ * const tracker2 = createTracker({ appName: 'emoto' })
12
+ *
13
+ * // 使用
14
+ * tracker.track('EVENT_ID', { key: 'value' })
15
+ * tracker.trackError({ err: 'error message' })
16
+ */
17
+ import type { TrackConfig, ErrorContent } from './types';
18
+ export * from './types';
19
+ /**
20
+ * 内置的 getChannel 方法
21
+ * 根据 UA 检测渠道:微信、QQ、微博等
22
+ */
23
+ declare function defaultGetChannel(): string;
24
+ /**
25
+ * Track 类
26
+ * 提供埋点上报功能
27
+ */
28
+ declare class Tracker {
29
+ private config;
30
+ constructor(config: TrackConfig);
31
+ /**
32
+ * 获取当前版本号
33
+ * 优先级:window.AppCall.getAppVersion() > 传入的 appCall > config.version
34
+ */
35
+ private getVersion;
36
+ /**
37
+ * 获取渠道号
38
+ * 优先使用自定义 getChannel,否则使用内置的默认方法
39
+ */
40
+ private getChannel;
41
+ /**
42
+ * 检查是否命中AB测试
43
+ */
44
+ private checkAbTest;
45
+ /**
46
+ * 构建埋点请求数据
47
+ */
48
+ private buildPostData;
49
+ /**
50
+ * 发送埋点请求
51
+ */
52
+ private sendRequest;
53
+ /**
54
+ * 核心埋点方法
55
+ * @param params 埋点参数
56
+ */
57
+ private trackUser;
58
+ /**
59
+ * 埋点上报
60
+ * @param eId 事件ID
61
+ * @param contentObj 事件内容对象
62
+ * @param isAbTest 是否AB测试(已废弃,保留兼容)
63
+ */
64
+ track(eId: string, contentObj?: Record<string, any>, isAbTest?: boolean): Promise<any>;
65
+ /**
66
+ * 错误上报
67
+ * @param contentObj 错误内容对象
68
+ */
69
+ trackError(contentObj?: Partial<ErrorContent>): Promise<any>;
70
+ /**
71
+ * 更新配置
72
+ */
73
+ updateConfig(config: Partial<TrackConfig>): void;
74
+ /**
75
+ * 获取当前配置
76
+ */
77
+ getConfig(): TrackConfig;
78
+ }
79
+ /**
80
+ * 创建 Tracker 实例
81
+ * @param config 配置项
82
+ * @returns Tracker 实例
83
+ *
84
+ * @example
85
+ * const tracker = createTracker({
86
+ * appName: 'emoto'
87
+ * // logUrl 可选,默认: https://log-center.58moto.com/am/log/v1/json
88
+ * // httpClient 可选,默认使用内置 fetch 实现
89
+ * })
90
+ *
91
+ * // 普通埋点
92
+ * tracker.track('EVENT_001', { page: 'home' })
93
+ *
94
+ * // 错误上报
95
+ * tracker.trackError({ err: 'Something went wrong' })
96
+ */
97
+ export declare function createTracker(config: TrackConfig): Tracker;
98
+ /**
99
+ * 创建简化版埋点方法
100
+ * 返回 postTrack 和 postTrackError 方法,与原有项目用法一致
101
+ *
102
+ * @example
103
+ * const { postTrack, postTrackError } = createTrackMethods({
104
+ * appName: 'moto'
105
+ * })
106
+ *
107
+ * // 等同于原来的 postJddTrack
108
+ * postTrack('EVENT_001', { page: 'home' })
109
+ *
110
+ * // 等同于原来的 postJddTrackError
111
+ * postTrackError({ err: 'error message' })
112
+ */
113
+ export declare function createTrackMethods(config: TrackConfig): {
114
+ /** 埋点上报方法 */
115
+ postTrack: (eId: string, contentObj?: Record<string, any>, isAbTest?: boolean) => Promise<any>;
116
+ /** 错误上报方法 */
117
+ postTrackError: (contentObj?: Partial<ErrorContent>) => Promise<any>;
118
+ /** Tracker 实例 */
119
+ tracker: Tracker;
120
+ };
121
+ export { defaultGetChannel as getChannel };
122
+ export default createTracker;