@kbapp/js-bridge 0.3.4-alpha.0 → 0.4.0-alpha.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 CHANGED
@@ -51,6 +51,29 @@ defineComponents({
51
51
 
52
52
  ## Api
53
53
 
54
+ ### 总览
55
+
56
+ | 方法 | 说明 |
57
+ | --------------------- | ------------------------------ |
58
+ | checkForNewVersion | 检测是否有新版本 |
59
+ | closeWebView | 关闭当前 webview |
60
+ | definePermissionUsage | 定义隐私权限协议文案 |
61
+ | getDeviceInfo | 获取设备信息 |
62
+ | runAction | 执行 action |
63
+ | saveImageToLocal | 保存图片到本地 |
64
+ | saveVideoToLocal | 保存视频到本地 |
65
+ | setWebViewTitle | 设置网页标题 |
66
+ | defineShareModel | 设置当前页面分享时显示卡片样式 |
67
+ | defineShareModelState | 定义分享面板控件布局 |
68
+ | invokeShareModal | 主动唤起更多分享模态框 |
69
+ | sharePoster | 分享海报 |
70
+ | getAppLoginInfo | 获取用户登录信息 |
71
+
72
+ | 枚举 | 说明 |
73
+ | ------------- | ---------------- |
74
+ | JSBridgeCode | kbapp 桥接状态码 |
75
+ | AppLoginModel | 登录信息 model |
76
+
54
77
  ### saveImageToLocal
55
78
 
56
79
  > 保存图片到本地
@@ -99,7 +122,11 @@ Promise<{ errCode: JSBridgeCode }>
99
122
 
100
123
  ---
101
124
 
102
- ### invokeMoreShareModal
125
+ ### defineShareModelState
126
+
127
+ ---
128
+
129
+ ### invokeShareModal
103
130
 
104
131
  > 唤起分享更多模态框
105
132
 
@@ -243,7 +270,7 @@ if (await canIUse('sharePoster')) {
243
270
 
244
271
  ---
245
272
 
246
- ### defineShareAppMessage
273
+ ### defineShareModel
247
274
 
248
275
  > 定义当前页面分享文案
249
276
 
@@ -302,7 +329,7 @@ Promise<{
302
329
 
303
330
  ### triggerAppLogin
304
331
 
305
- > 唤起app登录. 如果已登录,将直接返回登录信息
332
+ > 唤起 app 登录. 如果已登录,将直接返回登录信息
306
333
 
307
334
  #### 请求参数
308
335
 
@@ -1,22 +1,8 @@
1
- /** 桥接 */
2
- export declare const $bridge: {
3
- registerHandler: (name: any, registerCallback: any) => void;
4
- callHandler: (name: any, params: any, callback: any) => void;
5
- } | {
6
- default: undefined;
7
- /** 桥接 */
8
- callHandler: (method: any, args: any, cb: any) => any;
9
- register: (name: any, fun: any, asyn: any) => void;
10
- registerHandler: (name: any, fun: any) => void;
11
- } | {
12
- registerHandler(name: string, cb: (data: unknown, cb: (data: Record<string, any>) => void) => void): void;
13
- callHandler(name: string, params: any, callback: (...params: any) => void): void;
14
- };
15
1
  /**
16
2
  *
17
3
  * @description 注册事件 提供给native端调用
18
4
  */
19
- export declare const registerHandler: (name: string, cb: (data: unknown, cb: (data: Record<string, any>) => void) => void) => void;
5
+ export declare const registerHandler: <Data = unknown>(name: string, cb: (data: Data, cb: (data: Record<string, any>) => void) => void) => void;
20
6
  /**
21
7
  *
22
8
  * @description 主动触发 触发native端任务
@@ -12,12 +12,12 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  var _a;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.callHandlerPromise = exports.callHandler = exports.registerHandler = exports.$bridge = void 0;
15
+ exports.callHandlerPromise = exports.callHandler = exports.registerHandler = void 0;
16
16
  var js_bridge_1 = require("./lib/js-bridge");
17
17
  var ds_bridge_1 = require("./lib/ds-bridge");
18
18
  var flutter_ds_bridge_1 = require("./lib/flutter-ds-bridge");
19
19
  /** 桥接 */
20
- exports.$bridge = (function (user_agent) {
20
+ var $bridge = (function (user_agent) {
21
21
  if (!/(kb)/i.test(user_agent)) {
22
22
  return {
23
23
  registerHandler: function (name, cb) {
@@ -40,13 +40,13 @@ exports.$bridge = (function (user_agent) {
40
40
  *
41
41
  * @description 注册事件 提供给native端调用
42
42
  */
43
- exports.registerHandler = exports.$bridge.registerHandler;
43
+ exports.registerHandler = $bridge.registerHandler;
44
44
  /**
45
45
  *
46
46
  * @description 主动触发 触发native端任务
47
47
  */
48
48
  var callHandler = function (data) {
49
- exports.$bridge.callHandler(data.name, data.params, function (res) {
49
+ $bridge.callHandler(data.name, data.params, function (res) {
50
50
  var _a, _b, _c;
51
51
  var result;
52
52
  try {
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  export * from './lib/can-i-use';
2
2
  export * from './lib/check-for-new-version';
3
3
  export * from './lib/close-webview';
4
- export * from './lib/define-share-app-message';
4
+ export * from './lib/share-model';
5
5
  export * from './lib/get-device-info';
6
- export * from './lib/invoke-more-share-modal';
7
6
  export * from './lib/js-bridge-code';
8
7
  export * from './lib/run-action';
9
8
  export * from './lib/save-image-to-local';
@@ -11,3 +10,4 @@ export * from './lib/save-video-to-local';
11
10
  export * from './lib/set-webview-title';
12
11
  export * from './lib/share-poster';
13
12
  export * from './lib/trigger-login';
13
+ export * from './lib/define-permission-usage';
package/dist/index.js CHANGED
@@ -17,9 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./lib/can-i-use"), exports);
18
18
  __exportStar(require("./lib/check-for-new-version"), exports);
19
19
  __exportStar(require("./lib/close-webview"), exports);
20
- __exportStar(require("./lib/define-share-app-message"), exports);
20
+ __exportStar(require("./lib/share-model"), exports);
21
21
  __exportStar(require("./lib/get-device-info"), exports);
22
- __exportStar(require("./lib/invoke-more-share-modal"), exports);
23
22
  __exportStar(require("./lib/js-bridge-code"), exports);
24
23
  __exportStar(require("./lib/run-action"), exports);
25
24
  __exportStar(require("./lib/save-image-to-local"), exports);
@@ -27,3 +26,4 @@ __exportStar(require("./lib/save-video-to-local"), exports);
27
26
  __exportStar(require("./lib/set-webview-title"), exports);
28
27
  __exportStar(require("./lib/share-poster"), exports);
29
28
  __exportStar(require("./lib/trigger-login"), exports);
29
+ __exportStar(require("./lib/define-permission-usage"), exports);
@@ -1,4 +1,4 @@
1
- type JSBridgeMethod = 'invokeMoreShareModal' | 'saveImageToLocal' | 'saveVideoToLocal' | 'sharePoster' | 'setWebViewTitle' | 'checkForNewVersion';
1
+ type JSBridgeMethod = 'invokeShareModal' | 'saveImageToLocal' | 'saveVideoToLocal' | 'sharePoster' | 'setWebViewTitle' | 'checkForNewVersion' | 'defineShareModelState';
2
2
  /**
3
3
  *
4
4
  * @description 判断某个桥接能否在当前app版本中使用
@@ -60,6 +60,8 @@ function canIUse(/** 方法名 */ method) {
60
60
  case 'saveVideoToLocal':
61
61
  case 'saveImageToLocal':
62
62
  return [2 /*return*/, deviceInfo.vcode >= 69011];
63
+ case 'defineShareModelState':
64
+ return [2 /*return*/, deviceInfo.vcode >= 70601];
63
65
  default:
64
66
  return [2 /*return*/, true];
65
67
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ *
3
+ * @description 相关权限
4
+ */
5
+ declare enum PermissionUsage {
6
+ /** 麦克风 */
7
+ MICROPHONE = "microphone",
8
+ /** 摄像机 */
9
+ CAMERA = "camera",
10
+ /** 地理位置 */
11
+ LOCATION = "location"
12
+ }
13
+ /**
14
+ *
15
+ * @description 定义相关隐私政策文案, 用于网页授权相关权限时候, 提醒用户
16
+ * @example ```js
17
+ definePermissionUsage({
18
+ microphone: { description: '用于发帖上传音频' },
19
+ location: { description: '获取你选择的位置信息,用于线下导航服务' },
20
+ camera: { description: '收集你选中的照片或视频信息 ,用于 发表评论、分享视频' },
21
+ })
22
+ ```
23
+ */
24
+ export declare function definePermissionUsage(config: Partial<Record<PermissionUsage, {
25
+ description: string;
26
+ }>>): void;
27
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.definePermissionUsage = void 0;
5
+ var core_1 = require("../core");
6
+ /**
7
+ *
8
+ * @description 相关权限
9
+ */
10
+ var PermissionUsage;
11
+ (function (PermissionUsage) {
12
+ /** 麦克风 */
13
+ PermissionUsage["MICROPHONE"] = "microphone";
14
+ /** 摄像机 */
15
+ PermissionUsage["CAMERA"] = "camera";
16
+ /** 地理位置 */
17
+ PermissionUsage["LOCATION"] = "location";
18
+ })(PermissionUsage || (PermissionUsage = {}));
19
+ var SelfPermissionUsageDescription = (_a = {},
20
+ _a[PermissionUsage.MICROPHONE] = { description: '用于发帖上传音频' },
21
+ _a[PermissionUsage.LOCATION] = { description: '获取你选择的位置信息,用于线下导航服务' },
22
+ _a[PermissionUsage.CAMERA] = { description: '收集你选中的照片或视频信息 ,用于 发表评论、分享视频' },
23
+ _a);
24
+ /**
25
+ *
26
+ * @description 定义相关隐私政策文案, 用于网页授权相关权限时候, 提醒用户
27
+ * @example ```js
28
+ definePermissionUsage({
29
+ microphone: { description: '用于发帖上传音频' },
30
+ location: { description: '获取你选择的位置信息,用于线下导航服务' },
31
+ camera: { description: '收集你选中的照片或视频信息 ,用于 发表评论、分享视频' },
32
+ })
33
+ ```
34
+ */
35
+ function definePermissionUsage(config) {
36
+ Object.assign(SelfPermissionUsageDescription, config);
37
+ (0, core_1.registerHandler)('getPermissionUsage', function (data, callback) {
38
+ callback(SelfPermissionUsageDescription[data.permission]);
39
+ });
40
+ }
41
+ exports.definePermissionUsage = definePermissionUsage;
@@ -4,5 +4,7 @@
4
4
  */
5
5
  export declare enum JSBridgeCode {
6
6
  /** 当前版本不支持 */
7
- UNSUPPORTED_VERSION = 1001
7
+ UNSUPPORTED_VERSION = 1001,
8
+ /** 未登录 */
9
+ UN_LOGIN = 1002
8
10
  }
@@ -9,4 +9,6 @@ var JSBridgeCode;
9
9
  (function (JSBridgeCode) {
10
10
  /** 当前版本不支持 */
11
11
  JSBridgeCode[JSBridgeCode["UNSUPPORTED_VERSION"] = 1001] = "UNSUPPORTED_VERSION";
12
+ /** 未登录 */
13
+ JSBridgeCode[JSBridgeCode["UN_LOGIN"] = 1002] = "UN_LOGIN";
12
14
  })(JSBridgeCode || (exports.JSBridgeCode = JSBridgeCode = {}));
@@ -0,0 +1,69 @@
1
+ /**
2
+ *
3
+ * @description 设置当前页面 分享时 显示的文案内容封面等
4
+ *
5
+ * **示例代码**
6
+ ```js
7
+ import { defineShareModel } from '@kbapp/js-bridge';
8
+
9
+ defineShareModel({
10
+ title: '分享标题',
11
+ content: '分享内容',
12
+ imgUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png', // 分享图片
13
+ url: 'http://www.kaiba315.com.cn/' // 分享网页地址
14
+ })
15
+ ```
16
+ */
17
+ export declare function defineShareModel(data: {
18
+ /** 标题 */
19
+ title: string;
20
+ /** 内容 */
21
+ content: string;
22
+ /** 封面图片 */
23
+ imgUrl: string;
24
+ /** url */
25
+ url: string;
26
+ /** qqUrl */
27
+ qqUrl?: string;
28
+ /** 天目打点 */
29
+ tmuTrack?: any;
30
+ }): void;
31
+ /**
32
+ *
33
+ * @description 定义页面右上角分享更多按钮显示以及分享面板
34
+ *
35
+ */
36
+ export declare function defineShareModelState(params: {
37
+ /** 显示右上角 ...菜单. 默认true */
38
+ showMenu: boolean;
39
+ /** 显示分享面板布局, 0:正常显示. 1:只显示复制链接,浏览器打开相关. 2:只显示分享微信、QQ等. 默认 0 */
40
+ panelStyle: 0 | 1 | 2;
41
+ }): void;
42
+ /**
43
+ *
44
+ * @description 主动唤起更多分享模态框
45
+ *
46
+ *
47
+ * **示例代码**
48
+ ```js
49
+ import { invokeShareModal } from '@kbapp/js-bridge';
50
+
51
+ invokeShareModal({
52
+ title: '开吧分享',
53
+ content: '开吧,开汽车上新生活!',
54
+ url: 'http://www.kaiba315.com.cn/',
55
+ imageUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png'
56
+ })
57
+ ```
58
+ *
59
+ */
60
+ export declare function invokeShareModal(data: {
61
+ /** 分享出去的h5地址 */
62
+ url: string;
63
+ /** 分享出去的标题 */
64
+ title: string;
65
+ /** 分享出去的正文内容 */
66
+ content: string;
67
+ /** 分享出去的封面图片 */
68
+ imageUrl: string;
69
+ }): void;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.invokeShareModal = exports.defineShareModelState = exports.defineShareModel = void 0;
4
+ var core_1 = require("../core");
5
+ /**
6
+ *
7
+ * @description 设置当前页面 分享时 显示的文案内容封面等
8
+ *
9
+ * **示例代码**
10
+ ```js
11
+ import { defineShareModel } from '@kbapp/js-bridge';
12
+
13
+ defineShareModel({
14
+ title: '分享标题',
15
+ content: '分享内容',
16
+ imgUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png', // 分享图片
17
+ url: 'http://www.kaiba315.com.cn/' // 分享网页地址
18
+ })
19
+ ```
20
+ */
21
+ function defineShareModel(data) {
22
+ (0, core_1.registerHandler)('CommonShare', function (_, callback) {
23
+ callback({
24
+ type: 12,
25
+ data: data,
26
+ });
27
+ });
28
+ (0, core_1.registerHandler)('CommonRequest', function (_, callback) {
29
+ callback({
30
+ type: 12,
31
+ data: data,
32
+ });
33
+ });
34
+ }
35
+ exports.defineShareModel = defineShareModel;
36
+ /**
37
+ *
38
+ * @description 定义页面右上角分享更多按钮显示以及分享面板
39
+ *
40
+ */
41
+ function defineShareModelState(params) {
42
+ (0, core_1.callHandler)({
43
+ name: 'OpenActRequest',
44
+ params: {
45
+ type: 68,
46
+ data: {
47
+ show: params.showMenu || true,
48
+ showActionMode: params.panelStyle || 0
49
+ },
50
+ },
51
+ });
52
+ }
53
+ exports.defineShareModelState = defineShareModelState;
54
+ /**
55
+ *
56
+ * @description 主动唤起更多分享模态框
57
+ *
58
+ *
59
+ * **示例代码**
60
+ ```js
61
+ import { invokeShareModal } from '@kbapp/js-bridge';
62
+
63
+ invokeShareModal({
64
+ title: '开吧分享',
65
+ content: '开吧,开汽车上新生活!',
66
+ url: 'http://www.kaiba315.com.cn/',
67
+ imageUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png'
68
+ })
69
+ ```
70
+ *
71
+ */
72
+ function invokeShareModal(data) {
73
+ (0, core_1.callHandler)({
74
+ name: 'OpenActRequest',
75
+ params: {
76
+ type: 58,
77
+ data: data,
78
+ },
79
+ });
80
+ }
81
+ exports.invokeShareModal = invokeShareModal;
@@ -2,11 +2,11 @@
2
2
  *
3
3
  * @description 登录信息
4
4
  */
5
- export type AppLoginInfo = {
5
+ export declare class AppLoginModel {
6
6
  /** 车牌号:例如浙A999999 */
7
- carNo: string;
7
+ carNo?: string;
8
8
  /** 未知 */
9
- role: number;
9
+ role?: number;
10
10
  /** 手机号 */
11
11
  mobile: string;
12
12
  /** 性别 */
@@ -20,44 +20,44 @@ export type AppLoginInfo = {
20
20
  /** 用户id */
21
21
  userId: number;
22
22
  /** 用户名 */
23
- userName: string;
24
- };
23
+ userName?: string;
24
+ }
25
25
  /**
26
26
  *
27
27
  * @description 获取用户登录信息.如果未登录返回null
28
28
  */
29
- export declare function getAppLoginInfo(): Promise<AppLoginInfo | null>;
29
+ export declare function getAppLoginInfo(): Promise<AppLoginModel | null>;
30
30
  /**
31
31
  *
32
- * @description 登录完成会触发回调函数,调用该时将会立刻检测当前是否登录
33
- * @param {(loginInfo: AppLoginInfo) => void} callback 登录成功回调
34
- * @returns {() => void} 调用该函数取消监听
32
+ * @description 触发登录
33
+ * 如果已登录,将直接返回登录信息, 请通过 `watchAppLoginSuccess` 监听登录成功事件
35
34
  *
36
35
  * **示例代码**
37
36
  ```js
38
- import { watchAppLoginSuccess } from '@kbapp/js-bridge';
39
-
40
- const handle = watchAppLoginSuccess(() => {
41
- console.log('登录成功')
42
- })
43
-
44
- // handle() 停止监听
37
+ import { triggerAppLogin } from '@kbapp/js-bridge';
45
38
 
39
+ const onTapLoginButton = async () => {
40
+ await triggerAppLogin()
41
+ // app已登录
42
+ }
46
43
  ```
47
44
  */
48
- export declare const watchAppLoginSuccess: (callback: (loginInfo: AppLoginInfo) => void) => () => void;
45
+ export declare function triggerAppLogin(): Promise<AppLoginModel>;
49
46
  /**
50
47
  *
51
- * @description 触发登录.如果未登录,将会唤起登录弹窗,已登录则返回登录信息
52
- * @param {(loginInfo: AppLoginInfo) => void} [callback] 可选 登录成功回调,通过 onAppLoginSuccess 实现
53
- *
54
- * 该函数返回结果未采用返回promise值,原因在于避免多次进入promise阻塞挂起状态,待登录完成后,无法避免触发多次的情况
48
+ * @description 注册监听app登录成功, 注册时,立刻执行检测一次
49
+ * @param {(loginInfo: AppLoginModel) => void} callback 登录成功回调
50
+ * @returns {() => void} 调用该函数取消监听
55
51
  *
56
52
  * **示例代码**
57
53
  ```js
58
- import { triggerAppLogin } from '@kbapp/js-bridge';
54
+ import { watchAppLoginSuccess } from '@kbapp/js-bridge';
59
55
 
60
- triggerAppLogin()
56
+ const handle = watchAppLoginSuccess(() => {
57
+ console.log('登录成功')
58
+ })
59
+
60
+ // handle() 停止监听
61
61
  ```
62
62
  */
63
- export declare function triggerAppLogin(callback?: (loginInfo: AppLoginInfo) => void): Promise<void>;
63
+ export declare const watchAppLoginSuccess: (callback: (loginInfo: AppLoginModel) => void) => () => void;
@@ -36,8 +36,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.triggerAppLogin = exports.watchAppLoginSuccess = exports.getAppLoginInfo = void 0;
39
+ exports.watchAppLoginSuccess = exports.triggerAppLogin = exports.getAppLoginInfo = exports.AppLoginModel = void 0;
40
+ var js_bridge_code_1 = require("./js-bridge-code");
40
41
  var core_1 = require("../core");
42
+ /**
43
+ *
44
+ * @description 登录信息
45
+ */
46
+ var AppLoginModel = /** @class */ (function () {
47
+ function AppLoginModel() {
48
+ }
49
+ return AppLoginModel;
50
+ }());
51
+ exports.AppLoginModel = AppLoginModel;
41
52
  /**
42
53
  *
43
54
  * @description 获取用户登录信息.如果未登录返回null
@@ -103,7 +114,7 @@ var watchAppLoginSuccessTask = (function () {
103
114
  };
104
115
  })();
105
116
  return {
106
- /** 监听登录信息,纯粹监听 */
117
+ /** 注册监听事件(需要通过triggerCheckTask触发检测任务) */
107
118
  addTask: function (callback) {
108
119
  watchHandles.add(callback);
109
120
  },
@@ -114,7 +125,7 @@ var watchAppLoginSuccessTask = (function () {
114
125
  resetCheckTask.stop();
115
126
  }
116
127
  },
117
- /** 触发定时检测任务 */
128
+ /** 触发定时检测是否登录成功任务 */
118
129
  triggerCheckTask: function () {
119
130
  resetCheckTask.start();
120
131
  },
@@ -122,8 +133,55 @@ var watchAppLoginSuccessTask = (function () {
122
133
  })();
123
134
  /**
124
135
  *
125
- * @description 登录完成会触发回调函数,调用该时将会立刻检测当前是否登录
126
- * @param {(loginInfo: AppLoginInfo) => void} callback 登录成功回调
136
+ * @description 触发登录
137
+ * 如果已登录,将直接返回登录信息, 请通过 `watchAppLoginSuccess` 监听登录成功事件
138
+ *
139
+ * **示例代码**
140
+ ```js
141
+ import { triggerAppLogin } from '@kbapp/js-bridge';
142
+
143
+ const onTapLoginButton = async () => {
144
+ await triggerAppLogin()
145
+ // app已登录
146
+ }
147
+ ```
148
+ */
149
+ function triggerAppLogin() {
150
+ return __awaiter(this, void 0, void 0, function () {
151
+ var loginInfo;
152
+ return __generator(this, function (_a) {
153
+ switch (_a.label) {
154
+ case 0: return [4 /*yield*/, getAppLoginInfo()];
155
+ case 1:
156
+ loginInfo = _a.sent();
157
+ if (loginInfo) {
158
+ return [2 /*return*/, loginInfo];
159
+ }
160
+ watchAppLoginSuccessTask.triggerCheckTask();
161
+ /**
162
+ * 当reqiureLogin为true时用户取消登录或者, 第三方登录, 均不会触发回调
163
+ * 只有当用户完成登录流程(第三方不支持)才会回调
164
+ */
165
+ (0, core_1.callHandler)({
166
+ name: 'OpenActRequest',
167
+ params: { type: 31, data: { requireLogin: true } },
168
+ success: function (result) {
169
+ var _a;
170
+ if ((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) {
171
+ watchAppLoginSuccessTask.triggerCheckTask();
172
+ }
173
+ },
174
+ });
175
+ return [2 /*return*/, Promise.reject({ errCode: js_bridge_code_1.JSBridgeCode.UN_LOGIN })];
176
+ }
177
+ });
178
+ });
179
+ }
180
+ exports.triggerAppLogin = triggerAppLogin;
181
+ /**
182
+ *
183
+ * @description 注册监听app登录成功, 注册时,立刻执行检测一次
184
+ * @param {(loginInfo: AppLoginModel) => void} callback 登录成功回调
127
185
  * @returns {() => void} 调用该函数取消监听
128
186
  *
129
187
  * **示例代码**
@@ -135,7 +193,6 @@ const handle = watchAppLoginSuccess(() => {
135
193
  })
136
194
 
137
195
  // handle() 停止监听
138
-
139
196
  ```
140
197
  */
141
198
  var watchAppLoginSuccess = function (callback) {
@@ -146,42 +203,3 @@ var watchAppLoginSuccess = function (callback) {
146
203
  };
147
204
  };
148
205
  exports.watchAppLoginSuccess = watchAppLoginSuccess;
149
- /**
150
- *
151
- * @description 触发登录.如果未登录,将会唤起登录弹窗,已登录则返回登录信息
152
- * @param {(loginInfo: AppLoginInfo) => void} [callback] 可选 登录成功回调,通过 onAppLoginSuccess 实现
153
- *
154
- * 该函数返回结果未采用返回promise值,原因在于避免多次进入promise阻塞挂起状态,待登录完成后,无法避免触发多次的情况
155
- *
156
- * **示例代码**
157
- ```js
158
- import { triggerAppLogin } from '@kbapp/js-bridge';
159
-
160
- triggerAppLogin()
161
- ```
162
- */
163
- function triggerAppLogin(callback) {
164
- if (callback === void 0) { callback = function () { }; }
165
- return __awaiter(this, void 0, void 0, function () {
166
- return __generator(this, function (_a) {
167
- watchAppLoginSuccessTask.addTask(callback);
168
- watchAppLoginSuccessTask.triggerCheckTask();
169
- /**
170
- * 当reqiureLogin为true时用户取消登录或者, 第三方登录, 均不会触发回调
171
- * 只有当用户完成登录流程(第三方不支持)才会回调
172
- */
173
- (0, core_1.callHandler)({
174
- name: 'OpenActRequest',
175
- params: { type: 31, data: { requireLogin: true } },
176
- success: function (result) {
177
- var _a;
178
- if ((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) {
179
- watchAppLoginSuccessTask.triggerCheckTask();
180
- }
181
- },
182
- });
183
- return [2 /*return*/];
184
- });
185
- });
186
- }
187
- exports.triggerAppLogin = triggerAppLogin;
package/package.json CHANGED
@@ -3,9 +3,9 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.4-alpha.0",
6
+ "version": "0.4.0-alpha.0",
7
7
  "description": "开吧客户端桥接",
8
8
  "main": "./dist/index.js",
9
9
  "author": "along",
10
- "gitHead": "30e2b8314727020101c27a63f10379b6dc8b70de"
10
+ "gitHead": "0f9df8812c66dd6ba1488e82d2a8dd18f6975521"
11
11
  }
@@ -1,30 +0,0 @@
1
- /**
2
- *
3
- * @description 设置当前页面 分享时 显示的文案内容封面等
4
- *
5
- * **示例代码**
6
- ```js
7
- import { defineShareAppMessage } from '@kbapp/js-bridge';
8
-
9
- defineShareAppMessage({
10
- title: '分享标题',
11
- content: '分享内容',
12
- imgUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png', // 分享图片
13
- url: 'http://www.kaiba315.com.cn/' // 分享网页地址
14
- })
15
- ```
16
- */
17
- export declare function defineShareAppMessage(data: {
18
- /** 标题 */
19
- title: string;
20
- /** 内容 */
21
- content: string;
22
- /** 封面图片 */
23
- imgUrl: string;
24
- /** url */
25
- url: string;
26
- /** qqUrl */
27
- qqUrl?: string;
28
- /** 天目打点 */
29
- tmuTrack?: any;
30
- }): void;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineShareAppMessage = void 0;
4
- var core_1 = require("../core");
5
- /**
6
- *
7
- * @description 设置当前页面 分享时 显示的文案内容封面等
8
- *
9
- * **示例代码**
10
- ```js
11
- import { defineShareAppMessage } from '@kbapp/js-bridge';
12
-
13
- defineShareAppMessage({
14
- title: '分享标题',
15
- content: '分享内容',
16
- imgUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png', // 分享图片
17
- url: 'http://www.kaiba315.com.cn/' // 分享网页地址
18
- })
19
- ```
20
- */
21
- function defineShareAppMessage(data) {
22
- (0, core_1.registerHandler)('CommonShare', function (_, callback) {
23
- callback({
24
- type: 12,
25
- data: data,
26
- });
27
- });
28
- (0, core_1.registerHandler)('CommonRequest', function (_, callback) {
29
- callback({
30
- type: 12,
31
- data: data,
32
- });
33
- });
34
- }
35
- exports.defineShareAppMessage = defineShareAppMessage;
@@ -1,28 +0,0 @@
1
- /**
2
- *
3
- * @description 唤起更多分享模态框
4
- *
5
- *
6
- * **示例代码**
7
- ```js
8
- import { invokeMoreShareModal } from '@kbapp/js-bridge';
9
-
10
- invokeMoreShareModal({
11
- title: '开吧分享',
12
- content: '开吧,开汽车上新生活!',
13
- url: 'http://www.kaiba315.com.cn/',
14
- imageUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png'
15
- })
16
- ```
17
- *
18
- */
19
- export declare function invokeMoreShareModal(data: {
20
- /** 分享出去的h5地址 */
21
- url: string;
22
- /** 分享出去的标题 */
23
- title: string;
24
- /** 分享出去的正文内容 */
25
- content: string;
26
- /** 分享出去的封面图片 */
27
- imageUrl: string;
28
- }): void;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.invokeMoreShareModal = void 0;
4
- var core_1 = require("../core");
5
- /**
6
- *
7
- * @description 唤起更多分享模态框
8
- *
9
- *
10
- * **示例代码**
11
- ```js
12
- import { invokeMoreShareModal } from '@kbapp/js-bridge';
13
-
14
- invokeMoreShareModal({
15
- title: '开吧分享',
16
- content: '开吧,开汽车上新生活!',
17
- url: 'http://www.kaiba315.com.cn/',
18
- imageUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png'
19
- })
20
- ```
21
- *
22
- */
23
- function invokeMoreShareModal(data) {
24
- (0, core_1.callHandler)({
25
- name: 'OpenActRequest',
26
- params: {
27
- type: 58,
28
- data: data,
29
- },
30
- });
31
- }
32
- exports.invokeMoreShareModal = invokeMoreShareModal;