@haluo/util 2.0.32 → 2.0.33-beta.2

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 (37) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +2 -0
  3. package/dist/modules/app-call/configs.d.ts +9 -0
  4. package/dist/modules/app-call/configs.js +39 -0
  5. package/dist/modules/app-call/core.d.ts +53 -0
  6. package/dist/modules/app-call/core.js +166 -0
  7. package/dist/modules/app-call/extensions.d.ts +186 -0
  8. package/dist/modules/app-call/extensions.js +1226 -0
  9. package/dist/modules/app-call/index.d.ts +16 -0
  10. package/dist/modules/app-call/index.js +84 -0
  11. package/dist/modules/app-call/offline.d.ts +12 -0
  12. package/dist/modules/app-call/offline.js +211 -0
  13. package/dist/modules/app-call/partner-bridge.d.ts +5 -0
  14. package/dist/modules/app-call/partner-bridge.js +68 -0
  15. package/dist/modules/app-call/types.d.ts +53 -0
  16. package/dist/modules/app-call/types.js +4 -0
  17. package/dist/modules/open-app/index.d.ts +2 -7
  18. package/dist/modules/tools/index.d.ts +3 -3
  19. package/dist/modules/upload/aliOss.js +3 -1
  20. package/dist/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +3 -2
  22. package/dist/types/modules/cookie/index.d.ts +0 -27
  23. package/dist/types/modules/date/index.d.ts +0 -52
  24. package/dist/types/modules/dom/index.d.ts +0 -28
  25. package/dist/types/modules/filter/index.d.ts +0 -24
  26. package/dist/types/modules/format/index.d.ts +0 -15
  27. package/dist/types/modules/match/index.d.ts +0 -12
  28. package/dist/types/modules/monitor/index.d.ts +0 -3
  29. package/dist/types/modules/monitor/lib/jsError.d.ts +0 -1
  30. package/dist/types/modules/monitor/lib/timing.d.ts +0 -1
  31. package/dist/types/modules/monitor/lib/xhr.d.ts +0 -1
  32. package/dist/types/modules/monitor/utils/onload.d.ts +0 -1
  33. package/dist/types/modules/monitor/utils/tracker.d.ts +0 -7
  34. package/dist/types/modules/number/index.d.ts +0 -41
  35. package/dist/types/modules/sentry/index.d.ts +0 -15
  36. package/dist/types/modules/tools/index.d.ts +0 -166
  37. package/dist/types/types/index.d.ts +0 -3
@@ -0,0 +1,16 @@
1
+ import { createProjectConfig, projectConfigs } from './configs';
2
+ import type { AppCallConfig, AppCallInstance } from './types';
3
+ /**
4
+ * 创建 AppCall 实例
5
+ */
6
+ export declare function createAppCall(config: AppCallConfig): AppCallInstance;
7
+ /**
8
+ * 快速创建项目 AppCall(使用预设配置)
9
+ */
10
+ export declare function createProjectAppCall(projectType: keyof typeof projectConfigs, overrides?: Partial<AppCallConfig>): AppCallInstance;
11
+ /**
12
+ * 导出配置和类型
13
+ */
14
+ export { projectConfigs, createProjectConfig };
15
+ export { createOfflineAppCall, initOfflineAppCall } from './offline';
16
+ export type { AppCallConfig, AppCallInstance, AppCallCore } from './types';
@@ -0,0 +1,84 @@
1
+ /**
2
+ * AppCall 统一模块
3
+ * H5调用APP方法的统一接口
4
+ */
5
+ import { AppCallCoreClass } from './core';
6
+ import { createAllExtensions } from './extensions';
7
+ import { createProjectConfig, projectConfigs } from './configs';
8
+ /**
9
+ * 创建 AppCall 实例
10
+ */
11
+ export function createAppCall(config) {
12
+ const core = new AppCallCoreClass(config);
13
+ const appCall = core;
14
+ appCall.__core = core;
15
+ // 添加所有扩展方法(所有项目共享)
16
+ appCall.extend(createAllExtensions(appCall, config));
17
+ // 添加初始化方法
18
+ appCall.init = function () {
19
+ return new Promise((resolve) => {
20
+ if (!core.getIsClient()) {
21
+ resolve();
22
+ return;
23
+ }
24
+ if (window.isIOS) {
25
+ // iOS Bridge 初始化
26
+ window.setupWebViewJavascriptBridge = function (callback) {
27
+ if (window.WebViewJavascriptBridge) {
28
+ return typeof callback === 'function' && callback(window.WebViewJavascriptBridge);
29
+ }
30
+ if (window.WVJBCallbacks) {
31
+ return window.WVJBCallbacks.push(callback);
32
+ }
33
+ window.WVJBCallbacks = [callback];
34
+ const WVJBIframe = document.createElement('iframe');
35
+ WVJBIframe.style.display = 'none';
36
+ WVJBIframe.src = 'motor://__BRIDGE_LOADED__';
37
+ document.documentElement.appendChild(WVJBIframe);
38
+ setTimeout(() => {
39
+ document.documentElement.removeChild(WVJBIframe);
40
+ }, 0);
41
+ };
42
+ appCall.callIOSHandler('getInterface', [], (data) => {
43
+ core.setIOSInterface(data);
44
+ if (window.location.href.includes('machine-verification')) {
45
+ resolve();
46
+ return;
47
+ }
48
+ appCall.getUserData(() => {
49
+ resolve();
50
+ });
51
+ appCall.getDeviceData();
52
+ });
53
+ }
54
+ else if (window.isAndroid || window.isHarmonyos) {
55
+ if (window.location.href.includes('machine-verification')) {
56
+ resolve();
57
+ return;
58
+ }
59
+ appCall.getUserData(() => {
60
+ resolve();
61
+ });
62
+ appCall.getDeviceData();
63
+ }
64
+ else {
65
+ resolve();
66
+ }
67
+ });
68
+ };
69
+ // 挂载到 window
70
+ window.AppCall = appCall;
71
+ return appCall;
72
+ }
73
+ /**
74
+ * 快速创建项目 AppCall(使用预设配置)
75
+ */
76
+ export function createProjectAppCall(projectType, overrides) {
77
+ const config = createProjectConfig(projectType, overrides);
78
+ return createAppCall(config);
79
+ }
80
+ /**
81
+ * 导出配置和类型
82
+ */
83
+ export { projectConfigs, createProjectConfig };
84
+ export { createOfflineAppCall, initOfflineAppCall } from './offline';
@@ -0,0 +1,12 @@
1
+ import type { AppCallConfig, AppCallInstance } from './types';
2
+ /**
3
+ * 创建离线包专用的 AppCall
4
+ * @param config 配置项
5
+ */
6
+ export declare function createOfflineAppCall(config?: Partial<AppCallConfig>): AppCallInstance;
7
+ /**
8
+ * 初始化离线包 AppCall
9
+ * 注意:全局变量已在 AppCallCoreClass 构造函数中通过 initGlobalVars() 初始化
10
+ * 这里直接使用已初始化的全局变量,避免重复计算和设置
11
+ */
12
+ export declare function initOfflineAppCall(appCall: AppCallInstance): Promise<void>;
@@ -0,0 +1,211 @@
1
+ /**
2
+ * AppCall for offline package
3
+ * 离线包专用的 AppCall,不依赖项目特定的配置
4
+ */
5
+ import { AppCallCoreClass } from './core';
6
+ import { createAllExtensions } from './extensions';
7
+ /**
8
+ * 将获取到的设备信息放到本地存储
9
+ */
10
+ const setDeviceinfo = (devicedata = '') => {
11
+ if (devicedata && typeof devicedata === 'string') {
12
+ devicedata = devicedata.replace('undefined', '');
13
+ devicedata = JSON.parse(devicedata || '{}');
14
+ }
15
+ devicedata && window.localStorage.setItem('deviceData', JSON.stringify(devicedata));
16
+ };
17
+ /**
18
+ * 创建离线包专用的 AppCall
19
+ * @param config 配置项
20
+ */
21
+ export function createOfflineAppCall(config = {}) {
22
+ const offlineConfig = {
23
+ projectName: config.projectName || '摩托范',
24
+ domain: config.domain || '58moto.com',
25
+ defaultImage: config.defaultImage || 'https://wap.58moto.com/static/img/common/motuofan_small.png',
26
+ defaultDesc: config.defaultDesc || '摩托范,摩托发烧友的交流的平台,摩托维修、保养、配件等知识与经验分享社区。',
27
+ supportHarmonyos: config.supportHarmonyos ?? true,
28
+ showTip: config.showTip ?? false,
29
+ env: config.env || {},
30
+ // 离线包不需要这些依赖,提供空函数
31
+ getCircleIdByName: () => Promise.resolve({ id: 0, type: '' }),
32
+ setUserinfo: (data) => {
33
+ console.log('setUserinfo', data);
34
+ if (data && typeof data === 'string') {
35
+ data = JSON.parse(data || '{}');
36
+ }
37
+ if (data && data.token) {
38
+ window.localStorage.setItem('user', JSON.stringify(data));
39
+ window.localStorage.setItem('token', data.token);
40
+ }
41
+ },
42
+ fileToHttps: config.fileToHttps || ((url) => {
43
+ if (url.includes('file://')) {
44
+ const suffix = location.href.split('html#')[1];
45
+ return `https://wap.58moto.com${suffix}`;
46
+ }
47
+ return url;
48
+ }),
49
+ ...config
50
+ };
51
+ // 直接使用核心类创建实例,避免循环依赖
52
+ const core = new AppCallCoreClass(offlineConfig);
53
+ const appCall = core;
54
+ appCall.__core = core;
55
+ // 添加所有扩展方法(所有项目共享)
56
+ appCall.extend(createAllExtensions(appCall, offlineConfig));
57
+ // 添加初始化方法(简化版,离线包不需要完整的 init)
58
+ appCall.init = function () {
59
+ return Promise.resolve();
60
+ };
61
+ // 挂载到 window(离线包会在外部再次挂载,这里先不挂载)
62
+ // window.AppCall = appCall
63
+ // 扩展离线包特定的方法
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
+ // 文章 HTML 操作
83
+ articleHtmlAction(action = {}, callback) {
84
+ ;
85
+ window.enableBridgeLog = false;
86
+ window.enableBridgeLog && appCall.alert('1.1、articleHtmlAction');
87
+ Object.assign((window.bridge = window.bridge || {}), {
88
+ articleHtmlActionCallback(res = {}) {
89
+ console.log('articleHtmlActionCallback', res);
90
+ window.enableBridgeLog && appCall.alert('1.2、articleHtmlActionCallback');
91
+ if (typeof res === 'string') {
92
+ try {
93
+ // 直接使用已初始化的全局变量,避免重复计算
94
+ if ((window.isAndroid || window.isHarmonyos) && action.action === 'getDetail') {
95
+ res = appCall.replaceJsonValue(res);
96
+ }
97
+ res = JSON.parse(res);
98
+ window.enableBridgeLog && appCall.alert('1.3、articleHtmlAction JSON.parse');
99
+ }
100
+ catch (error) {
101
+ res = null;
102
+ console.log(error.message);
103
+ appCall.alert('html:' + error.message);
104
+ window.enableBridgeLog && appCall.alert('1.4、articleHtmlAction error' + error.message);
105
+ }
106
+ }
107
+ if (typeof callback === 'function') {
108
+ callback(res);
109
+ }
110
+ }
111
+ });
112
+ return appCall.call('articleHtmlAction', JSON.stringify(action), window.bridge.articleHtmlActionCallback);
113
+ },
114
+ // 地图导航
115
+ navigateMap(params = {}) {
116
+ return appCall.call('navigateMap', JSON.stringify(params));
117
+ },
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
+ // 获取app信息
130
+ getDeviceData(callback) {
131
+ function _callback(data) {
132
+ // 直接使用已初始化的全局变量
133
+ if (window.isIOS) {
134
+ if (data) {
135
+ data = data.replace(/\n/g, '').replace(/\s*/g, '');
136
+ data = JSON.parse(data) || '';
137
+ window.localStorage.setItem('deviceData', JSON.stringify(data));
138
+ }
139
+ }
140
+ typeof callback === 'function' && callback(data);
141
+ }
142
+ const deviceData = appCall.call('getDeviceData', _callback);
143
+ // 安卓没有触发回调,所以自己调用设置一下
144
+ if (window.isAndroid || window.isHarmonyos) {
145
+ setDeviceinfo(deviceData);
146
+ }
147
+ return deviceData;
148
+ },
149
+ login(params = {}) {
150
+ // 非客户端环境,跳转H5登录
151
+ if (!window.isClient) {
152
+ return (window.location.href = '/login');
153
+ }
154
+ appCall.call('login', JSON.stringify(params));
155
+ },
156
+ });
157
+ return appCall;
158
+ }
159
+ /**
160
+ * 初始化离线包 AppCall
161
+ * 注意:全局变量已在 AppCallCoreClass 构造函数中通过 initGlobalVars() 初始化
162
+ * 这里直接使用已初始化的全局变量,避免重复计算和设置
163
+ */
164
+ export function initOfflineAppCall(appCall) {
165
+ return new Promise((resolve) => {
166
+ // 获取 core 实例(全局变量已在构造函数中初始化)
167
+ const core = appCall.__core;
168
+ if (!core) {
169
+ resolve();
170
+ return;
171
+ }
172
+ // 直接使用已初始化的全局变量,避免重复计算
173
+ const isClient = core.getIsClient();
174
+ if (isClient) {
175
+ if (window.isIOS) {
176
+ // iOS Bridge 初始化(与 index.ts 中的逻辑保持一致)
177
+ window.setupWebViewJavascriptBridge = function (callback) {
178
+ if (window.WebViewJavascriptBridge) {
179
+ return typeof callback === 'function' && callback(window.WebViewJavascriptBridge);
180
+ }
181
+ if (window.WVJBCallbacks) {
182
+ return window.WVJBCallbacks.push(callback);
183
+ }
184
+ window.WVJBCallbacks = [callback];
185
+ const WVJBIframe = document.createElement('iframe');
186
+ WVJBIframe.style.display = 'none';
187
+ WVJBIframe.src = 'motor://__BRIDGE_LOADED__';
188
+ document.documentElement.appendChild(WVJBIframe);
189
+ setTimeout(() => {
190
+ document.documentElement.removeChild(WVJBIframe);
191
+ }, 0);
192
+ };
193
+ appCall.callIOSHandler('getInterface', [], (data) => {
194
+ appCall.getUserData(() => {
195
+ resolve();
196
+ });
197
+ appCall.getDeviceData();
198
+ });
199
+ }
200
+ else if (window.isAndroid || window.isHarmonyos) {
201
+ appCall.getUserData(() => {
202
+ resolve();
203
+ });
204
+ appCall.getDeviceData();
205
+ }
206
+ }
207
+ else {
208
+ resolve();
209
+ }
210
+ });
211
+ }
@@ -0,0 +1,5 @@
1
+ import type { AppCallConfig, AppCallInstance } from './types';
2
+ /**
3
+ * 创建简化版的 AppCall(用于外部对接)
4
+ */
5
+ export declare function createPartnerBridge(config?: Partial<AppCallConfig>): AppCallInstance;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Partner Bridge - 外部对接使用的简化版 AppCall
3
+ */
4
+ import { createAppCall } from './index';
5
+ /**
6
+ * 创建简化版的 AppCall(用于外部对接)
7
+ */
8
+ export function createPartnerBridge(config = {}) {
9
+ const bridgeConfig = {
10
+ projectName: config.projectName || '摩托范',
11
+ domain: config.domain || '58moto.com',
12
+ supportHarmonyos: config.supportHarmonyos ?? true,
13
+ ...config
14
+ };
15
+ const appCall = createAppCall(bridgeConfig);
16
+ // 添加外部对接专用的方法
17
+ appCall.extend({
18
+ /**
19
+ * 唤醒阿里金融的实名认证
20
+ * -- 调用接口:expands/realuser/getToken 获取token
21
+ * -- faceAuthback 回调接收 res: { token, bizId }
22
+ */
23
+ faceAuth(params = {}) {
24
+ window.bridge = window.bridge || {};
25
+ window.bridge.faceAuthback = window.bridge.faceAuthback || function () { };
26
+ return appCall.call('faceAuth', JSON.stringify(params), window.bridge.faceAuthback);
27
+ },
28
+ /**
29
+ * 获取app设备信息(Promise 版本)
30
+ */
31
+ getDeviceData() {
32
+ return new Promise((resolve, reject) => {
33
+ const _callback = (data) => {
34
+ const ua = navigator.userAgent.toLowerCase();
35
+ const isIOS = ua.indexOf('mac') > -1;
36
+ if (data && typeof data === 'string') {
37
+ if (isIOS) {
38
+ data = data.replace(/\n/g, '').replace(/\s*/g, '');
39
+ }
40
+ try {
41
+ data = JSON.parse(data || '{}');
42
+ }
43
+ catch (e) {
44
+ reject('解析失败');
45
+ return;
46
+ }
47
+ }
48
+ data ? resolve(data) : reject('获取失败');
49
+ };
50
+ appCall.call('getDeviceData', _callback);
51
+ });
52
+ },
53
+ /**
54
+ * 获取定位信息(Promise 版本)
55
+ */
56
+ getLocation(params = {}) {
57
+ return new Promise((resolve, reject) => {
58
+ window.bridge = window.bridge || {};
59
+ window.bridge.getLocationCallback = (data) => {
60
+ data ? resolve(data) : reject('获取失败');
61
+ };
62
+ params.needPermission = params.needPermission !== undefined ? params.needPermission : 1;
63
+ appCall.call('getLocation', JSON.stringify(params), window.bridge.getLocationCallback);
64
+ });
65
+ }
66
+ });
67
+ return appCall;
68
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * AppCall 类型定义
3
+ */
4
+ export interface AppCallConfig {
5
+ /** 项目名称,用于默认标题等 */
6
+ projectName: string;
7
+ /** 项目域名 */
8
+ domain: string;
9
+ /** 默认图片URL */
10
+ defaultImage?: string;
11
+ /** 默认描述 */
12
+ defaultDesc?: string;
13
+ /** BundleId */
14
+ bundleId?: string;
15
+ /** iOS Scheme */
16
+ iosScheme?: string;
17
+ /** Android Scheme */
18
+ androidScheme?: string;
19
+ /** App Store 链接 */
20
+ appStoreUrl?: string;
21
+ /** Android 应用市场链接 */
22
+ androidStoreUrl?: string;
23
+ /** 是否支持鸿蒙系统 */
24
+ supportHarmonyos?: boolean;
25
+ /** 是否显示调试提示 */
26
+ showTip?: boolean;
27
+ /** 环境配置对象(从 config/env 导入) */
28
+ env: any;
29
+ /** 项目依赖函数:根据圈子名称获取圈子id */
30
+ getCircleIdByName?: (params: {
31
+ title: string;
32
+ }) => Promise<{
33
+ id: number;
34
+ type: string;
35
+ }>;
36
+ /** 项目依赖函数:设置用户信息 */
37
+ setUserinfo?: (data: any) => void;
38
+ /** 项目依赖函数:文件路径转https */
39
+ fileToHttps?: (url: string) => string;
40
+ }
41
+ export interface BridgeCallback {
42
+ [key: string]: (...args: any[]) => any;
43
+ }
44
+ export interface AppCallCore {
45
+ call: (name: string, ...args: any[]) => any;
46
+ has: (name: string) => boolean;
47
+ extend: (obj: Record<string, any>) => AppCallCore;
48
+ callIOSHandler: (name: string, params: any[], callback?: Function) => boolean;
49
+ allParamsToString: (params: Record<string, any>) => Record<string, string>;
50
+ }
51
+ export interface AppCallInstance extends AppCallCore {
52
+ [key: string]: any;
53
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * AppCall 类型定义
3
+ */
4
+ export {};
@@ -1,11 +1,6 @@
1
1
  declare global {
2
2
  interface Window {
3
- AppCall?: {
4
- has: (method: string) => boolean;
5
- openOtherAppUrlRouter: (params: {
6
- appUrlRouter: string;
7
- }) => void;
8
- };
3
+ AppCall?: any;
9
4
  }
10
5
  }
11
6
  interface EnvConfig {
@@ -74,7 +69,7 @@ declare class OpenAppClass {
74
69
  /**
75
70
  * 打开APP主流程
76
71
  */
77
- invoke(): void;
72
+ invoke(): any;
78
73
  getUrl(): string | undefined;
79
74
  /**
80
75
  * 获取打开 app sechma url
@@ -51,13 +51,13 @@ declare class ToolsClass {
51
51
  * @param {String} url
52
52
  * @return {Promise}
53
53
  */
54
- loadJs(url: string): Error | Promise<unknown>;
54
+ loadJs(url: string): Promise<unknown> | Error;
55
55
  /**
56
56
  * 动态加载样式
57
57
  * @param {String} url
58
58
  * @return {Promise}
59
59
  */
60
- loadCss(url: string): Error | Promise<unknown>;
60
+ loadCss(url: string): Promise<unknown> | Error;
61
61
  /**
62
62
  * 蒙层显示后,html禁止滚动操作
63
63
  * @param {String} className
@@ -76,7 +76,7 @@ declare class ToolsClass {
76
76
  * @param {String} str
77
77
  * @return {String}
78
78
  */
79
- clipboard(str: string): Error | Promise<void>;
79
+ clipboard(str: string): Promise<void> | Error;
80
80
  /**
81
81
  * 首字母大写
82
82
  * @param {String} str
@@ -225,14 +225,16 @@ export class AliOssClass {
225
225
  let { size } = params;
226
226
  let result = {};
227
227
  try {
228
+ let docType = file.name?.split('.').reverse()[0] || file.type; // 兼容 *.*.* 这种后缀(必传)
228
229
  if (!size && this.isImageFile(file)) {
229
230
  const image = await this.getImageInfo(file);
230
231
  size = `_${image?.width}_${image?.height}`;
232
+ docType = file.type?.split('/').reverse()[0] || file.type; // 如果是图片文件格式如png(必传)
231
233
  }
232
234
  // 步骤 1:请求后端获取所有签名字段
233
235
  const signResponse = await this.apiConfig.getSts({
234
236
  businessType: businessType,
235
- docType: file.type?.split('/')[1] || file.type,
237
+ docType,
236
238
  size: size, // _1024_567(可选)
237
239
  });
238
240
  if (signResponse.data.code !== 0) {