@docoi/mys-sdk 1.0.3 → 1.1.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 +212 -0
- package/dist/api/basic.d.ts +208 -111
- package/dist/api/biz.d.ts +153 -30
- package/dist/api/router/index.d.ts +68 -0
- package/dist/api/router/launch.d.ts +3 -0
- package/dist/api/router/legacy.d.ts +22 -0
- package/dist/api/router/routes.d.ts +732 -0
- package/dist/bridge.d.ts +48 -9
- package/dist/constants/code.d.ts +10 -2
- package/dist/index.d.ts +21 -42
- package/dist/index.mjs +1240 -312
- package/dist/transport/legacy.d.ts +27 -0
- package/dist/types/base.d.ts +77 -5
- package/dist/types/enums.d.ts +36 -23
- package/dist/types/index.d.ts +2 -3
- package/dist/types/params.d.ts +131 -97
- package/dist/types/results.d.ts +200 -55
- package/dist/types/router.d.ts +231 -0
- package/dist/utils/app.d.ts +30 -0
- package/dist/utils/data.d.ts +39 -0
- package/package.json +9 -9
- package/LICENSE +0 -21
package/dist/types/results.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PermissionStatus, PermissionType, ShareImageAction } from './enums';
|
|
2
2
|
/** chooseMedia 返回值 */
|
|
3
3
|
export interface ChooseMediaResult {
|
|
4
4
|
/** 本地临时媒体文件列表 */
|
|
@@ -6,7 +6,7 @@ export interface ChooseMediaResult {
|
|
|
6
6
|
}
|
|
7
7
|
/** chooseMedia 临时媒体文件 */
|
|
8
8
|
export interface ChooseMediaFile {
|
|
9
|
-
/**
|
|
9
|
+
/** 临时文件路径,如 mysFile://temp/xxxx.png,可用于 img / video 预览,也可传给 uploadFiles 上传 */
|
|
10
10
|
tempFilePath: string;
|
|
11
11
|
/** 文件大小,单位 KB */
|
|
12
12
|
size?: number;
|
|
@@ -49,40 +49,67 @@ export interface UploadFilesProgressFile {
|
|
|
49
49
|
/** 当前文件进度,范围 0-100 */
|
|
50
50
|
progress: number;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* uploadFiles 上传进度回调,仅 H5 侧生效。
|
|
54
|
+
*
|
|
55
|
+
* @param progress 本次上传各文件的进度
|
|
56
|
+
*/
|
|
57
|
+
export type UploadFilesProgressCallback = (progress: UploadFilesProgress) => void;
|
|
52
58
|
/** getClipboardData 返回值 */
|
|
53
59
|
export interface GetClipboardDataResult {
|
|
54
60
|
/** 剪贴板内容 */
|
|
55
61
|
data: string;
|
|
56
62
|
}
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
63
|
+
/**
|
|
64
|
+
* App 基础信息,即 UA 中 #webBaseInfo{...}# 规整后的结果,getAppBaseInfo 的返回类型。
|
|
65
|
+
*
|
|
66
|
+
* 字段名和取值以 Native 上报的 UA 为准,原样保留 snake_case,不另起一套命名。
|
|
67
|
+
* app_version 必填(缺失或格式不对时 getAppBaseInfo 整体返回 null),其余字段 UA 里缺失时为空,读取时按需判空。
|
|
68
|
+
*/
|
|
69
|
+
export interface AppBaseInfo {
|
|
70
|
+
/** App 版本号,含构建号,如 4.4.0.452 */
|
|
71
|
+
app_version: string;
|
|
72
|
+
/** 渠道,如 docoi、Appstore */
|
|
73
|
+
channel?: string;
|
|
74
|
+
/** 设备 ID */
|
|
75
|
+
device_id?: string;
|
|
76
|
+
/** 设备型号,如 V2453A、iPhone16,1 */
|
|
77
|
+
device_model?: string;
|
|
78
|
+
/** 设备类型,如 Phone、iPhone */
|
|
79
|
+
device_type?: string;
|
|
80
|
+
/** 当前环境标识,如 test,App 4.2.0 起支持 */
|
|
81
|
+
env?: string;
|
|
82
|
+
/** 页面类型:1 普通 H5,2 小程序,4 沉浸式 */
|
|
83
|
+
h5Type?: number;
|
|
84
|
+
/** 安卓是否为加速版:'0' 为普通版,其他为加速版,仅 Android 上报,App 4.2.0 起支持 */
|
|
85
|
+
jsNum?: string;
|
|
86
|
+
/** 网络类型,Android 为 NETWORK_WIFI 形式,iOS 为 WiFi 形式 */
|
|
87
|
+
network_type?: string;
|
|
88
|
+
/** 操作系统,Android 或 iOS */
|
|
89
|
+
os?: string;
|
|
77
90
|
/** 操作系统版本 */
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
|
|
91
|
+
os_version?: string;
|
|
92
|
+
/** 状态栏高度(px),iOS 为 CSS 逻辑像素,Android 为物理像素 */
|
|
93
|
+
status_bar_height?: number;
|
|
94
|
+
/** WebView 类型:0 默认 H5,1 首页,App 4.1.0 起支持 */
|
|
95
|
+
webviewType?: number;
|
|
81
96
|
}
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
97
|
+
/**
|
|
98
|
+
* getSystemInfo 返回值:UA 的 App 基础信息,再加 H5 侧从 window 补充的字段。
|
|
99
|
+
*
|
|
100
|
+
* 浏览器里(不在 App 内)没有 UA 信息,只有 H5 侧补充的字段,所以 app_version 在这里是可选的。
|
|
101
|
+
*/
|
|
102
|
+
export interface SystemInfoResult extends Partial<AppBaseInfo> {
|
|
103
|
+
/** 设备像素比,H5 侧补充,UA 里没有 */
|
|
104
|
+
pixelRatio?: number;
|
|
105
|
+
/** 屏幕宽度(px),H5 侧补充,UA 里没有 */
|
|
106
|
+
screenWidth?: number;
|
|
107
|
+
/** 屏幕高度(px),H5 侧补充,UA 里没有 */
|
|
108
|
+
screenHeight?: number;
|
|
109
|
+
/** 可使用窗口宽度(px),H5 侧补充,UA 里没有 */
|
|
110
|
+
windowWidth?: number;
|
|
111
|
+
/** 可使用窗口高度(px),H5 侧补充,UA 里没有 */
|
|
112
|
+
windowHeight?: number;
|
|
86
113
|
}
|
|
87
114
|
/** checkPermission 返回值 */
|
|
88
115
|
export interface CheckPermissionResult {
|
|
@@ -91,47 +118,73 @@ export interface CheckPermissionResult {
|
|
|
91
118
|
/** 权限检查结果 */
|
|
92
119
|
result: PermissionStatus;
|
|
93
120
|
}
|
|
121
|
+
/** openApp 返回值 */
|
|
122
|
+
export interface OpenAppResult {
|
|
123
|
+
/** 处理结果:1 未安装,已触发下载;2 已打开 App */
|
|
124
|
+
type?: 1 | 2;
|
|
125
|
+
}
|
|
126
|
+
/** getBeforeInfo 返回值:上一个页面的埋点信息,字段由 Native 决定 */
|
|
127
|
+
export type BeforeInfoResult = Record<string, unknown>;
|
|
128
|
+
/** 页面显示/可见性事件回调,无 payload */
|
|
129
|
+
export type PageEventCallback = () => void;
|
|
94
130
|
/**
|
|
95
131
|
* 键盘高度变化回调。
|
|
96
132
|
*
|
|
97
|
-
*
|
|
133
|
+
* @param height 键盘高度,单位为 CSS 逻辑像素,可直接用于页面布局
|
|
98
134
|
*/
|
|
99
135
|
export type KeyboardHeightChangeCallback = (height: number) => void;
|
|
100
|
-
/**
|
|
101
|
-
* 评论区面板状态变化事件 payload。
|
|
102
|
-
*
|
|
103
|
-
* 事件监听直接返回该业务对象,不包装 code/msg/result。
|
|
104
|
-
*/
|
|
136
|
+
/** 评论区面板状态变化事件的数据 */
|
|
105
137
|
export interface CommentPanelChangeResult {
|
|
106
138
|
/** 评论区面板是否可见 */
|
|
107
139
|
visible: boolean;
|
|
108
140
|
/** 评论区面板状态变化原因 */
|
|
109
141
|
reason: string;
|
|
110
142
|
}
|
|
111
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* 评论区面板状态变化回调。
|
|
145
|
+
*
|
|
146
|
+
* @param res 评论区面板的状态
|
|
147
|
+
*/
|
|
112
148
|
export type CommentPanelChangeCallback = (res: CommentPanelChangeResult) => void;
|
|
113
|
-
/**
|
|
114
|
-
export interface
|
|
115
|
-
/**
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
|
|
149
|
+
/** startRecordAudio 的 onEnd 回调的数据 */
|
|
150
|
+
export interface RecordAudioEndResult {
|
|
151
|
+
/** 录音文件的临时路径,如 mysFile://temp/xxxx,可用于 audio 播放,也可传给 uploadFiles 上传 */
|
|
152
|
+
tempFilePath: string;
|
|
153
|
+
/** 录音时长,单位秒 */
|
|
154
|
+
duration: number;
|
|
155
|
+
/** 文件大小,单位 KB */
|
|
156
|
+
size: number;
|
|
157
|
+
/** 录音文件格式,由宿主 App 决定,如 m4a */
|
|
158
|
+
fileType: string;
|
|
123
159
|
}
|
|
160
|
+
/** startRecordAudio 的 onProgress 回调的数据 */
|
|
161
|
+
export interface RecordAudioProgressResult {
|
|
162
|
+
/** 当前音量,单位分贝 0-100 */
|
|
163
|
+
decibel: number;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 录音结束回调。
|
|
167
|
+
*
|
|
168
|
+
* @param res 录音文件信息
|
|
169
|
+
*/
|
|
170
|
+
export type RecordAudioEndCallback = (res: RecordAudioEndResult) => void;
|
|
171
|
+
/**
|
|
172
|
+
* 录音音量回调。
|
|
173
|
+
*
|
|
174
|
+
* @param res 当前音量,不包含录音文件
|
|
175
|
+
*/
|
|
176
|
+
export type RecordAudioProgressCallback = (res: RecordAudioProgressResult) => void;
|
|
124
177
|
/** login 返回值 */
|
|
125
178
|
export interface LoginResult {
|
|
126
|
-
/**
|
|
127
|
-
readonly
|
|
128
|
-
/** 用户信息 */
|
|
129
|
-
readonly userInfo?: UserInfo;
|
|
179
|
+
/** 是否已登录;App 4.4.0 以下 Native 只保证登录动作被处理,该字段不一定返回 */
|
|
180
|
+
readonly isLogin?: boolean;
|
|
130
181
|
}
|
|
131
182
|
/** getToken 返回值 */
|
|
132
183
|
export interface GetTokenResult {
|
|
133
|
-
/** 登录 Token */
|
|
184
|
+
/** 登录 Token,未登录时为空字符串 */
|
|
134
185
|
readonly token: string;
|
|
186
|
+
/** 游客 Token */
|
|
187
|
+
readonly visitor_token?: string;
|
|
135
188
|
}
|
|
136
189
|
/** shareImage 返回值 */
|
|
137
190
|
export interface ShareImageResult {
|
|
@@ -142,8 +195,100 @@ export interface ShareImageResult {
|
|
|
142
195
|
export interface GetCircleInfoResult {
|
|
143
196
|
/** 服务器 ID */
|
|
144
197
|
readonly serverId: string;
|
|
145
|
-
/** 社群/圈子名称 */
|
|
146
|
-
readonly name: string;
|
|
147
|
-
/** 社群/圈子图标 URL */
|
|
148
|
-
readonly icon: string;
|
|
149
198
|
}
|
|
199
|
+
/** 投票选项 */
|
|
200
|
+
export interface VoteItem {
|
|
201
|
+
/** 选项 ID */
|
|
202
|
+
vote_id?: string;
|
|
203
|
+
/** 选项内容,文字选项为文案,图片选项为图片地址 */
|
|
204
|
+
content?: string;
|
|
205
|
+
/** 选项名称 */
|
|
206
|
+
name?: string;
|
|
207
|
+
/** 1:文字 2:图片 */
|
|
208
|
+
content_type?: number;
|
|
209
|
+
/** 投票数量 */
|
|
210
|
+
count?: number;
|
|
211
|
+
/** 是否已投票 */
|
|
212
|
+
is_vote?: boolean;
|
|
213
|
+
/** 0:正常 1:已删除 */
|
|
214
|
+
status?: number;
|
|
215
|
+
/** 得票占比 */
|
|
216
|
+
percent?: number;
|
|
217
|
+
}
|
|
218
|
+
/** 投票数据,voteAction 的入参与返回值共用 */
|
|
219
|
+
export interface VoteData {
|
|
220
|
+
/** 投票模式 1:单选 2:多选 */
|
|
221
|
+
vote_mode?: number;
|
|
222
|
+
/** 投票状态 1:未开始 2:进行中 3:已结束 */
|
|
223
|
+
vote_status?: number;
|
|
224
|
+
/** 用户参与投票数量 */
|
|
225
|
+
user_vote_count?: number;
|
|
226
|
+
/** 投票开始时间 */
|
|
227
|
+
start_time?: number;
|
|
228
|
+
/** 投票结束时间 */
|
|
229
|
+
end_time?: number;
|
|
230
|
+
/** 总票数 */
|
|
231
|
+
vote_total?: number;
|
|
232
|
+
/** 投票选项 */
|
|
233
|
+
votes?: VoteItem[];
|
|
234
|
+
}
|
|
235
|
+
/** 动态操作信息 */
|
|
236
|
+
export interface DynamicHandle {
|
|
237
|
+
/** 操作类型:1 置顶/取消置顶,2 精华/取消精华,3 推流/取消推流,4 推荐/取消推荐,5 修改板块,6 评论权限,7 可见性,8 删除 */
|
|
238
|
+
type: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
239
|
+
/** 操作附带数据,结构随 type 变化 */
|
|
240
|
+
data?: unknown;
|
|
241
|
+
}
|
|
242
|
+
/** onShared 事件 payload */
|
|
243
|
+
export interface SharedResult {
|
|
244
|
+
/**
|
|
245
|
+
* 分享渠道:1 微信,2 朋友圈,3 QQ,4 QQ 空间,5 链接,6 好友,7 最近聊天,8 文字频道
|
|
246
|
+
*/
|
|
247
|
+
shareChannel?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
248
|
+
/** IM 群聊 ID,群聊时赋值 */
|
|
249
|
+
imGroupId?: string;
|
|
250
|
+
/** 分享对象用户 ID,私聊最近联系人时赋值 */
|
|
251
|
+
toUserId?: string;
|
|
252
|
+
/** 动态操作 */
|
|
253
|
+
dynamichandle?: DynamicHandle;
|
|
254
|
+
}
|
|
255
|
+
/** onAdFinished 事件 payload */
|
|
256
|
+
export interface AdFinishedResult {
|
|
257
|
+
/** 广告模块 */
|
|
258
|
+
module: number;
|
|
259
|
+
}
|
|
260
|
+
/** openFriendsList 选中的好友 */
|
|
261
|
+
export interface SelectedFriend {
|
|
262
|
+
/** 用户 ID */
|
|
263
|
+
uid: string;
|
|
264
|
+
/** 用户昵称 */
|
|
265
|
+
uname: string;
|
|
266
|
+
/** 用户头像地址 */
|
|
267
|
+
avatar: string;
|
|
268
|
+
}
|
|
269
|
+
/** openFriendsList 的业务数据 */
|
|
270
|
+
export interface OpenFriendsListResult {
|
|
271
|
+
/** 选中的好友列表;用户取消或页面被关闭时为空数组 */
|
|
272
|
+
selectedList: SelectedFriend[];
|
|
273
|
+
}
|
|
274
|
+
/** getSharePictureUrl 处理函数返回值 */
|
|
275
|
+
export interface SharePictureUrlResult {
|
|
276
|
+
/** 分享图片地址;截图或上传失败时不返回 */
|
|
277
|
+
pictureUrl?: string;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 分享完成回调。
|
|
281
|
+
*
|
|
282
|
+
* @param res Native 回传的分享信息,部分场景下 Native 不携带数据,此时为 undefined
|
|
283
|
+
*/
|
|
284
|
+
export type SharedCallback = (res?: SharedResult) => void;
|
|
285
|
+
/**
|
|
286
|
+
* 广告播放完成回调。
|
|
287
|
+
*
|
|
288
|
+
* @param res 播放完成的广告信息
|
|
289
|
+
*/
|
|
290
|
+
export type AdFinishedCallback = (res: AdFinishedResult) => void;
|
|
291
|
+
/** 提供分享图片地址的处理函数,返回 { pictureUrl },可以返回 Promise */
|
|
292
|
+
export type SharePictureUrlHandler = () => SharePictureUrlResult | Promise<SharePictureUrlResult>;
|
|
293
|
+
/** 会员激活通知的处理函数,Native 通知 H5 会员已激活时调用,可以返回 Promise */
|
|
294
|
+
export type MemberActivateHandler = () => void | Promise<void>;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { Callbacks } from './base';
|
|
2
|
+
import { ActivityCenterTab, CircleRelationType, DiscoverSubTab, HomeTab, NavigatePage, ReportObjectType, TabBarType, WebviewExtType, WebviewType } from './enums';
|
|
3
|
+
/**
|
|
4
|
+
* 页面跳转类 API 的公共回调:在 Callbacks 之上增加唤起 App 失败的通知。
|
|
5
|
+
*
|
|
6
|
+
* 这几个 API 在 App 外统一走 launch.ts 唤起,失败检测规则相同,回调只声明一份。
|
|
7
|
+
*/
|
|
8
|
+
export interface LaunchCallbacks extends Callbacks {
|
|
9
|
+
/** 不在 App 内时,唤起失败(超时仍停留在当前页,大概率未安装)的回调,用于业务侧引导下载 */
|
|
10
|
+
onLaunchFail?: () => void;
|
|
11
|
+
}
|
|
12
|
+
/** switchTab 参数 */
|
|
13
|
+
export interface SwitchTabParams extends LaunchCallbacks {
|
|
14
|
+
/** 目标底部 tab */
|
|
15
|
+
tab: TabBarType;
|
|
16
|
+
/** 附加参数 */
|
|
17
|
+
params?: SwitchTabExtraParams;
|
|
18
|
+
}
|
|
19
|
+
/** switchTab 附加参数 */
|
|
20
|
+
export interface SwitchTabExtraParams {
|
|
21
|
+
/** 发现页二级 tab,仅 tab 为 discover 时有效 */
|
|
22
|
+
subTab?: DiscoverSubTab;
|
|
23
|
+
/** 是否来自 MBTI 分享页 */
|
|
24
|
+
fromMbtiShare?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** openWebview 参数 */
|
|
27
|
+
export interface OpenWebviewParams extends LaunchCallbacks {
|
|
28
|
+
/** 目标 URL */
|
|
29
|
+
url: string;
|
|
30
|
+
/**
|
|
31
|
+
* 容器类型,用外部浏览器打开请用 openInExternalBrowser。
|
|
32
|
+
*
|
|
33
|
+
* @default 'normal'
|
|
34
|
+
*/
|
|
35
|
+
type?: WebviewType | WebviewExtType;
|
|
36
|
+
/** 附加参数 */
|
|
37
|
+
params?: OpenWebviewExtraParams;
|
|
38
|
+
}
|
|
39
|
+
/** openWebview 附加参数 */
|
|
40
|
+
export interface OpenWebviewExtraParams {
|
|
41
|
+
/** 是否是升级 App 的链接(iOS 使用) */
|
|
42
|
+
isUpdateApp?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** 无参数页面 */
|
|
45
|
+
export type EmptyPageParams = Record<string, never>;
|
|
46
|
+
/** 动态详情 */
|
|
47
|
+
export interface DynamicDetailPageParams {
|
|
48
|
+
/** 动态 ID */
|
|
49
|
+
dynamicId: string | number;
|
|
50
|
+
/** 定位到的评论 ID */
|
|
51
|
+
commentId?: string | number;
|
|
52
|
+
}
|
|
53
|
+
/** 动态话题 */
|
|
54
|
+
export interface TopicPageParams {
|
|
55
|
+
/** 话题 ID */
|
|
56
|
+
topicId: string | number;
|
|
57
|
+
}
|
|
58
|
+
/** 点赞列表 */
|
|
59
|
+
export interface LikeListPageParams {
|
|
60
|
+
/** 动态 ID */
|
|
61
|
+
dynamicId: string | number;
|
|
62
|
+
/** 发布类型 */
|
|
63
|
+
publishType: string | number;
|
|
64
|
+
}
|
|
65
|
+
/** 圈子主页 */
|
|
66
|
+
export interface CircleHomePageParams {
|
|
67
|
+
/** 圈子(服务器)ID */
|
|
68
|
+
serverId: string | number;
|
|
69
|
+
/** 进入后执行的操作:publish 为发布动态 */
|
|
70
|
+
action?: "publish";
|
|
71
|
+
/** 关系操作 */
|
|
72
|
+
relationType?: CircleRelationType;
|
|
73
|
+
/** 图片链接 */
|
|
74
|
+
imageUrl?: string;
|
|
75
|
+
}
|
|
76
|
+
/** 查询圈子并加入 */
|
|
77
|
+
export interface JoinCirclePageParams {
|
|
78
|
+
/** 圈子(服务器)ID */
|
|
79
|
+
serverId: string | number;
|
|
80
|
+
/** 邀请码 */
|
|
81
|
+
inviteCode: string;
|
|
82
|
+
}
|
|
83
|
+
/** 新版首页 */
|
|
84
|
+
export interface HomePageParams {
|
|
85
|
+
/** 顶部 tab,不传则不指定 */
|
|
86
|
+
tab?: HomeTab;
|
|
87
|
+
/** 圈子(服务器)ID,不传则停留在当前首页圈子,App 4.4.0 起支持 */
|
|
88
|
+
serverId?: string | number;
|
|
89
|
+
/** 圈子频道 ID,App 4.4.0 起支持 */
|
|
90
|
+
channelId?: string | number;
|
|
91
|
+
}
|
|
92
|
+
/** 攻略一级分类 */
|
|
93
|
+
export interface GuideCatalogPageParams {
|
|
94
|
+
/** 圈子(服务器)ID */
|
|
95
|
+
serverId: string | number;
|
|
96
|
+
/** 圈子频道 ID */
|
|
97
|
+
channelId: string | number;
|
|
98
|
+
/** 攻略分类 ID */
|
|
99
|
+
catalogId: string | number;
|
|
100
|
+
}
|
|
101
|
+
/** 游戏离线推送开关 */
|
|
102
|
+
export interface GamePushSettingPageParams {
|
|
103
|
+
/** 圈子(服务器)ID */
|
|
104
|
+
serverId: string | number;
|
|
105
|
+
}
|
|
106
|
+
/** 用户主页 */
|
|
107
|
+
export interface UserHomePageParams {
|
|
108
|
+
/** 用户 ID */
|
|
109
|
+
userId: string | number;
|
|
110
|
+
/** 礼物 ID,传入后会拉起送礼弹窗 */
|
|
111
|
+
giftId?: string | number;
|
|
112
|
+
}
|
|
113
|
+
/** 群聊 */
|
|
114
|
+
export interface GroupChatPageParams {
|
|
115
|
+
/** 圈子(服务器)ID */
|
|
116
|
+
serverId: string | number;
|
|
117
|
+
/** 群 ID,例如 @TGS#_[circle_50311]5 */
|
|
118
|
+
groupId: string;
|
|
119
|
+
/** 群名称 */
|
|
120
|
+
groupName?: string;
|
|
121
|
+
}
|
|
122
|
+
/** 查询小群并加入 */
|
|
123
|
+
export interface JoinGroupPageParams {
|
|
124
|
+
/** 邀请码 */
|
|
125
|
+
inviteCode: string;
|
|
126
|
+
}
|
|
127
|
+
/** 私聊 */
|
|
128
|
+
export interface PrivateChatPageParams {
|
|
129
|
+
/** 对方用户 ID */
|
|
130
|
+
userId: string | number;
|
|
131
|
+
/** 对方昵称 */
|
|
132
|
+
nickName: string;
|
|
133
|
+
}
|
|
134
|
+
/** 活动中心 */
|
|
135
|
+
export interface ActivityCenterPageParams {
|
|
136
|
+
/** 默认选中的 tab */
|
|
137
|
+
tab?: ActivityCenterTab;
|
|
138
|
+
}
|
|
139
|
+
/** 广告 SDK 页面 */
|
|
140
|
+
export interface AdPageParams {
|
|
141
|
+
/** 广告页地址 */
|
|
142
|
+
url: string;
|
|
143
|
+
}
|
|
144
|
+
/** 绑定游戏角色 */
|
|
145
|
+
export interface BindGamePageParams {
|
|
146
|
+
/** 圈子(服务器)ID */
|
|
147
|
+
serverId: string | number;
|
|
148
|
+
/** 游戏名称 */
|
|
149
|
+
gameName: string;
|
|
150
|
+
}
|
|
151
|
+
/** 玩家举报 */
|
|
152
|
+
export interface PlayerReportPageParams {
|
|
153
|
+
/** 被举报对象的 ID,随 objectType 变化:用户 ID、评论 ID、动态 ID 等 */
|
|
154
|
+
objectId: string | number;
|
|
155
|
+
/** 被举报对象的类型 */
|
|
156
|
+
objectType: ReportObjectType;
|
|
157
|
+
/** 会话 ID,举报会话时需要 */
|
|
158
|
+
conversationId?: string | number;
|
|
159
|
+
/** 服务器 ID,举报服务器时需要 */
|
|
160
|
+
serverId?: string | number;
|
|
161
|
+
}
|
|
162
|
+
/** navigateTo 各页面对应的 params,页面名与 enums.ts 的 NavigatePage 一一对应 */
|
|
163
|
+
export interface NavigatePageParamsMap {
|
|
164
|
+
dynamicDetailPage: DynamicDetailPageParams;
|
|
165
|
+
topicPage: TopicPageParams;
|
|
166
|
+
likeListPage: LikeListPageParams;
|
|
167
|
+
circleHomePage: CircleHomePageParams;
|
|
168
|
+
joinCirclePage: JoinCirclePageParams;
|
|
169
|
+
homePage: HomePageParams;
|
|
170
|
+
guideCatalogPage: GuideCatalogPageParams;
|
|
171
|
+
gamePushSettingPage: GamePushSettingPageParams;
|
|
172
|
+
userHomePage: UserHomePageParams;
|
|
173
|
+
groupChatPage: GroupChatPageParams;
|
|
174
|
+
joinGroupPage: JoinGroupPageParams;
|
|
175
|
+
privateChatPage: PrivateChatPageParams;
|
|
176
|
+
myPublishPage: EmptyPageParams;
|
|
177
|
+
myFavoritePage: EmptyPageParams;
|
|
178
|
+
browseHistoryPage: EmptyPageParams;
|
|
179
|
+
profileEditPage: EmptyPageParams;
|
|
180
|
+
coinRechargePage: EmptyPageParams;
|
|
181
|
+
gameSubscribePage: EmptyPageParams;
|
|
182
|
+
douyinMallPage: EmptyPageParams;
|
|
183
|
+
activityCenterPage: ActivityCenterPageParams;
|
|
184
|
+
adPage: AdPageParams;
|
|
185
|
+
coinDetailPage: EmptyPageParams;
|
|
186
|
+
miniGamesPage: EmptyPageParams;
|
|
187
|
+
bindGamePage: BindGamePageParams;
|
|
188
|
+
playerReportPage: PlayerReportPageParams;
|
|
189
|
+
addCustomEmojiPage: EmptyPageParams;
|
|
190
|
+
}
|
|
191
|
+
/** 有必填字段的页面必须传 params,其余页面 params 可省略 */
|
|
192
|
+
type PageParamsField<K extends NavigatePage> = {} extends NavigatePageParamsMap[K] ? {
|
|
193
|
+
params?: NavigatePageParamsMap[K];
|
|
194
|
+
} : {
|
|
195
|
+
params: NavigatePageParamsMap[K];
|
|
196
|
+
};
|
|
197
|
+
/** navigateTo 按页面跳转的参数,type 决定 params 的结构 */
|
|
198
|
+
export type NavigateToPageParams<K extends NavigatePage = NavigatePage> = K extends NavigatePage ? LaunchCallbacks & {
|
|
199
|
+
type: K;
|
|
200
|
+
} & PageParamsField<K> : never;
|
|
201
|
+
/** navigateTo 按 daoke:// 链接跳转的参数,用于服务端下发的存量链接 */
|
|
202
|
+
export interface NavigateToUrlParams extends LaunchCallbacks {
|
|
203
|
+
/** daoke://page?type=... 链接 */
|
|
204
|
+
url: string;
|
|
205
|
+
}
|
|
206
|
+
/** navigateTo 参数 */
|
|
207
|
+
export type NavigateToParams = NavigateToPageParams | NavigateToUrlParams;
|
|
208
|
+
/** openScheme 参数 */
|
|
209
|
+
export interface OpenSchemeParams extends LaunchCallbacks {
|
|
210
|
+
/** daoke://page?type=... 链接,与服务端下发的存量链接格式一致,原样处理 */
|
|
211
|
+
url: string;
|
|
212
|
+
/** 额外的结构化数据,随链接一起交给 Native。App 4.4.0 以下不支持,会被忽略 */
|
|
213
|
+
params?: Record<string, unknown>;
|
|
214
|
+
}
|
|
215
|
+
/** openInExternalBrowser 参数 */
|
|
216
|
+
export interface OpenInExternalBrowserParams extends Callbacks {
|
|
217
|
+
/** 要在外部浏览器打开的地址,http(s) 链接或 weixin:// 等 scheme 均可 */
|
|
218
|
+
url: string;
|
|
219
|
+
}
|
|
220
|
+
/** 一次跳转调用,仅 SDK 内部使用 */
|
|
221
|
+
export type NavigationCall = {
|
|
222
|
+
api: "navigateTo";
|
|
223
|
+
params: NavigateToParams;
|
|
224
|
+
} | {
|
|
225
|
+
api: "switchTab";
|
|
226
|
+
params: SwitchTabParams;
|
|
227
|
+
} | {
|
|
228
|
+
api: "openWebview";
|
|
229
|
+
params: OpenWebviewParams;
|
|
230
|
+
};
|
|
231
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AppBaseInfo, SystemInfoResult } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* 获取 App 基础信息(UA 中的 webBaseInfo),不在 App 内(或解析失败)返回 null。
|
|
4
|
+
* 结果会缓存,页面生命周期内只解析一次。
|
|
5
|
+
*/
|
|
6
|
+
export declare function getAppBaseInfo(): AppBaseInfo | null;
|
|
7
|
+
/** 是否在 App 的 WebView 内。 */
|
|
8
|
+
export declare function isInApp(): boolean;
|
|
9
|
+
/** 当前 App 版本低于 since(compareVersions 返回 -1 表示 since 更大),不判断是否在 App 内 */
|
|
10
|
+
export declare function isAppVersionBelow(since?: string): boolean;
|
|
11
|
+
/** 设备像素比,非浏览器环境(SSR)按 1 处理 */
|
|
12
|
+
export declare function getDevicePixelRatio(): number;
|
|
13
|
+
/**
|
|
14
|
+
* 版本号对比,语义与业务侧 compareVersions 一致。
|
|
15
|
+
* targetVersion 不传时使用当前 App 版本。
|
|
16
|
+
* - sourceVersion > targetVersion 返回 -1
|
|
17
|
+
* - sourceVersion = targetVersion 返回 0
|
|
18
|
+
* - sourceVersion < targetVersion 返回 1
|
|
19
|
+
*/
|
|
20
|
+
export declare function compareVersions(sourceVersion: string, targetVersion?: string): -1 | 0 | 1;
|
|
21
|
+
/** 设备平台,判断规则与业务侧 device.ts 一致(Linux 也算 Android) */
|
|
22
|
+
export declare function getPlatform(): 'ios' | 'android' | 'unknown';
|
|
23
|
+
/** 是否被 web 版社区以 iframe 内嵌,依赖 community 壳在 iframe 上声明的 name */
|
|
24
|
+
export declare function isInWebCommunity(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 4.4.0 以下旧 Native 没有 getSystemInfo,用 UA 里的 webBaseInfo 合成,字段名和取值保持 UA 原样。
|
|
27
|
+
* 屏幕、窗口和像素比 UA 里没有,从 window 补上。
|
|
28
|
+
* 状态栏高度保持 UA 原值,不做单位换算:iOS 上报的是 CSS 逻辑像素,Android 上报的是物理像素。
|
|
29
|
+
*/
|
|
30
|
+
export declare function collectSystemInfo(): SystemInfoResult;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据处理工具:类型判断、容错解析、错误原因提取,以及发往 Native 前的数据规整。
|
|
3
|
+
* 原生已有的(Array.isArray、Number.isFinite、Number.isInteger)不再包装;仅 SDK 内部使用,不从 index.ts 导出。
|
|
4
|
+
*
|
|
5
|
+
* 规整的背景:iOS 的 postMessage 对消息体做结构化克隆,Vue 响应式 Proxy 无法克隆(抛 DataCloneError),
|
|
6
|
+
* 而 Android 先 JSON.stringify,同一份响应式参数就会 iOS 收不到、Android 正常。
|
|
7
|
+
* 因此在 SDK 出口统一做一次 JSON 往返:Android 本就是这个语义,iOS 对齐到同一语义。
|
|
8
|
+
*
|
|
9
|
+
* @module utils/data
|
|
10
|
+
*/
|
|
11
|
+
export declare function isString(value: unknown): value is string;
|
|
12
|
+
/** NaN 也是 number,需要有限数用 Number.isFinite */
|
|
13
|
+
export declare function isNumber(value: unknown): value is number;
|
|
14
|
+
/** 非 null 的对象,数组、Error 实例等都算。类型收窄为 Record 是为了方便读属性 */
|
|
15
|
+
export declare function isObjectLike(value: unknown): value is Record<string, unknown>;
|
|
16
|
+
/** 纯对象:字面量、JSON.parse 的结果、Object.create(null)、Vue 响应式 Proxy;数组、Error、class 实例不算 */
|
|
17
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
18
|
+
/** App 版本号:x.y.z 或 x.y.z.w(Native 真实上报含构建号,如 4.4.0.452) */
|
|
19
|
+
export declare function isVersion(value: unknown): value is string;
|
|
20
|
+
/** 图片的 base64 数据:data URL 或纯 base64;网络地址、本地路径不算 */
|
|
21
|
+
export declare function isBase64Source(value: unknown): value is string;
|
|
22
|
+
/** JSON.parse 遇到非法文本会抛错,这里返回 fallback(默认 null) */
|
|
23
|
+
export declare function safeParse(text: string, fallback?: unknown): unknown;
|
|
24
|
+
/** decodeURIComponent 遇到非法编码会抛错,这里原样返回 */
|
|
25
|
+
export declare function safeDecode(value: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* 从任意错误值里取一句可读的原因:字符串原样,Error 取 message,对象取 errMsg / msg / message。
|
|
28
|
+
*
|
|
29
|
+
* 两个通道的失败都要转成 errMsg,只此一份实现,避免同一类失败在两个通道上说法不同。
|
|
30
|
+
*/
|
|
31
|
+
export declare function getErrorReason(err: unknown): string;
|
|
32
|
+
/** 规整失败时抛出,带上字段名,由调用方转成参数错误 */
|
|
33
|
+
export declare class PlainDataError extends Error {
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 把参数规整成纯 JSON 数据(去掉 Proxy、函数、undefined、symbol)。
|
|
37
|
+
* 循环引用、BigInt、Map、Set、二进制数据会抛 PlainDataError。
|
|
38
|
+
*/
|
|
39
|
+
export declare function toPlainData(data: unknown): unknown;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docoi/mys-sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "基于 JSBridge 封装的H5 SDK,统一 Native 通信与业务 API 封装",
|
|
5
5
|
"author": "tanyangkang",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,18 +28,18 @@
|
|
|
28
28
|
"files": [
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "vite build --watch",
|
|
33
|
+
"build": "vite build",
|
|
34
|
+
"type-check": "tsc --noEmit",
|
|
35
|
+
"prepublishOnly": "pnpm build"
|
|
36
|
+
},
|
|
31
37
|
"dependencies": {
|
|
32
|
-
"@docoi/jsbridge-sdk": "2.0.
|
|
38
|
+
"@docoi/jsbridge-sdk": "2.0.3"
|
|
33
39
|
},
|
|
34
40
|
"devDependencies": {
|
|
35
|
-
"@changesets/cli": "^2.31.1",
|
|
36
41
|
"typescript": "^5.9.3",
|
|
37
42
|
"vite": "^5.4.21",
|
|
38
43
|
"vite-plugin-dts": "^5.0.3"
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"dev": "vite build --watch",
|
|
42
|
-
"build": "vite build",
|
|
43
|
-
"type-check": "tsc --noEmit"
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 docoi
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|