qsh-webview-sdk 2.4.4 → 2.4.6

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
@@ -197,8 +197,8 @@ console.log('是否在 App 基座中:', env.isUniApp);
197
197
  |------|------|------|
198
198
  | `getLocation` | 获取当前位置 | `{ type?: string; altitude?: boolean; success?: Function; fail?: Function }` |
199
199
  | `getLocationAsync` | 获取位置(Promise 版) | `{ type?: string; altitude?: boolean }` |
200
- | `openLocation` | 查看位置(打开地图) | `{ latitude: number; longitude: number; name?: string; address?: string; scale?: number; success?: Function; fail?: Function }` |
201
- | `openLocationAsync` | 查看位置(Promise 版) | `{ latitude: number; longitude: number; name?: string; address?: string; scale?: number }` |
200
+ | `openLocation` | 查看位置(打开地图) | `{ latitude: number; longitude: number; type?: 'wgs84' \| 'gcj02'; name?: string; address?: string; scale?: number; success?: Function; fail?: Function }` |
201
+ | `openLocationAsync` | 查看位置(Promise 版) | `{ latitude: number; longitude: number; type?: 'wgs84' \| 'gcj02'; name?: string; address?: string; scale?: number }` |
202
202
  | `startLocationUpdate` | 开启前台持续定位(仅 APP) | `{ type?: string; needFullAccuracy?: boolean; success?: Function; fail?: Function }` |
203
203
  | `stopLocationUpdate` | 停止前台持续定位(仅 APP) | `{ success?: Function; fail?: Function }` |
204
204
  | `onLocationChange` | 监听实时位置变化(仅 APP) | `callback: Function` |
@@ -466,7 +466,7 @@ qsh.scanCode({
466
466
  ```javascript
467
467
  // 回调方式
468
468
  qsh.getLocation({
469
- type: 'wgs84', // 坐标类型:wgs84(GPS) 目前仅支持wgs84
469
+ type: 'wgs84', // 坐标类型:wgs84(GPS)
470
470
  altitude: false, // 是否返回高度信息
471
471
  success: (res) => {
472
472
  console.log('纬度:', res.latitude);
@@ -497,9 +497,11 @@ try {
497
497
 
498
498
  ```javascript
499
499
  // 打开地图查看指定位置
500
+ // type 默认 wgs84;小程序会转成 gcj02 后调用 wx.openLocation,App 会直接使用 wgs84 坐标
500
501
  qsh.openLocation({
501
- latitude: 39.908823, // 需传入wgs84坐标
502
- longitude: 116.397470, // 需传入wgs84坐标
502
+ latitude: 39.908823,
503
+ longitude: 116.397470,
504
+ type: 'wgs84',
503
505
  name: '天安门',
504
506
  address: '北京市东城区东长安街',
505
507
  scale: 15, // 缩放级别 1-28
@@ -510,14 +512,15 @@ qsh.openLocation({
510
512
 
511
513
  // Promise 版本
512
514
  await qsh.openLocationAsync({
513
- latitude: 39.908823, // 需传入wgs84坐标
514
- longitude: 116.397470, // 需传入wgs84坐标
515
+ latitude: 39.908823,
516
+ longitude: 116.397470,
517
+ type: 'wgs84',
515
518
  name: '天安门'
516
519
  });
517
520
  ```
518
521
 
519
522
  #### 坐标类型
520
- 目前定位相关接口仅支持wgs84
523
+ 目前定位相关接口 App 端建议统一使用 wgs84 坐标。`openLocation` 支持 `wgs84` / `gcj02`,SDK 会按环境自动转换坐标。
521
524
  | 类型 | 说明 | 常量 |
522
525
  |------|------|------|
523
526
  | `wgs84` | GPS 坐标 | `qsh.CoordinateTypes.WGS84` |
@@ -631,6 +634,26 @@ qsh.printPdf({
631
634
  });
632
635
  ```
633
636
 
637
+ ### 文件预览
638
+
639
+ ```javascript
640
+ qsh.filePreview({
641
+ url: 'https://example.com/files/demo.pdf', // 文件地址
642
+ showMenu: true, // 是否显示右上角菜单,默认 false
643
+ success: (res) => console.log('文件预览请求成功', res),
644
+ fail: (err) => console.error('文件预览失败:', err)
645
+ });
646
+
647
+ // Promise 用法
648
+ await qsh.filePreviewAsync({
649
+ url: 'https://example.com/files/demo.pdf',
650
+ showMenu: false
651
+ });
652
+ ```
653
+
654
+ > 仅支持以下文件格式:`doc`、`xls`、`ppt`、`pdf`、`docx`、`xlsx`、`pptx`。
655
+ > 微信小程序 `web-view` 下,SDK 会通过 `wx.miniProgram.postMessage` 把预览请求投递给宿主,再调用 `wx.miniProgram.navigateBack` 返回基座;APP 端通过 `callApiInWebView` 调用基座能力。
656
+
634
657
  ### 跳转其他微信小程序
635
658
 
636
659
  ```javascript
package/dist/index.d.ts CHANGED
@@ -48,6 +48,25 @@ declare namespace UniWebView {
48
48
  complete?: () => void;
49
49
  }
50
50
 
51
+ interface FilePreviewResult {
52
+ /** errMsg */
53
+ errMsg?: string;
54
+ [key: string]: any;
55
+ }
56
+
57
+ interface FilePreviewOptions {
58
+ /** file url */
59
+ url: string;
60
+ /** whether to show the top-right menu */
61
+ showMenu?: boolean;
62
+ /** success callback */
63
+ success?: (res: FilePreviewResult) => void;
64
+ /** fail callback */
65
+ fail?: (error: any) => void;
66
+ /** complete callback */
67
+ complete?: () => void;
68
+ }
69
+
51
70
  /**
52
71
  * 环境信息
53
72
  */
@@ -206,6 +225,83 @@ declare namespace UniWebView {
206
225
  };
207
226
  }
208
227
 
228
+ type OpenLocationCoordinateType = "wgs84" | "gcj02";
229
+ type LocationCoordinateType = OpenLocationCoordinateType | "bd09";
230
+
231
+ interface LocationResult {
232
+ /** 纬度 */
233
+ latitude: number;
234
+ /** 经度 */
235
+ longitude: number;
236
+ /** 位置精度 */
237
+ accuracy?: number;
238
+ /** 高度 */
239
+ altitude?: number;
240
+ /** 错误信息 */
241
+ errMsg?: string;
242
+ [key: string]: any;
243
+ }
244
+
245
+ interface GetLocationOptions {
246
+ /** 坐标类型,默认 wgs84 */
247
+ type?: LocationCoordinateType;
248
+ /** 是否返回高度信息 */
249
+ altitude?: boolean;
250
+ /** 成功回调 */
251
+ success?: (res: LocationResult) => void;
252
+ /** 失败回调 */
253
+ fail?: (error: any) => void;
254
+ /** 完成回调(无论成功失败) */
255
+ complete?: () => void;
256
+ }
257
+
258
+ interface OpenLocationOptions {
259
+ /** 纬度(必填) */
260
+ latitude: number;
261
+ /** 经度(必填) */
262
+ longitude: number;
263
+ /** 坐标类型,默认 wgs84 */
264
+ type?: OpenLocationCoordinateType;
265
+ /** 位置名称 */
266
+ name?: string;
267
+ /** 详细地址 */
268
+ address?: string;
269
+ /** 缩放级别 */
270
+ scale?: number;
271
+ /** 底部链接 */
272
+ infoUrl?: string;
273
+ /** 成功回调 */
274
+ success?: (res: any) => void;
275
+ /** 失败回调 */
276
+ fail?: (error: any) => void;
277
+ /** 完成回调(无论成功失败) */
278
+ complete?: () => void;
279
+ }
280
+
281
+ interface CoordinateTypesEnum {
282
+ readonly WGS84: "wgs84";
283
+ readonly GCJ02: "gcj02";
284
+ readonly BD09: "bd09";
285
+ }
286
+
287
+ interface LocationCapabilities {
288
+ /** 是否支持定位功能 */
289
+ supported: boolean;
290
+ /** 当前环境类型 */
291
+ environment: string;
292
+ /** 底层实现类型 */
293
+ implementation: string;
294
+ /** 功能特性 */
295
+ features: {
296
+ getLocation: boolean;
297
+ openLocation: boolean;
298
+ coordinateTypes: boolean;
299
+ altitudeSupport: boolean;
300
+ asyncSupport: boolean;
301
+ onLocationChange: boolean;
302
+ };
303
+ }
304
+
209
305
  /**
210
306
  * 环境对象
211
307
  */
@@ -411,6 +507,8 @@ declare namespace UniWebView {
411
507
  interface QshConfigOptions {
412
508
  clientId: string;
413
509
  isProd?: boolean;
510
+ debug?: boolean;
511
+ url?: string;
414
512
  }
415
513
 
416
514
  /**
@@ -462,6 +560,7 @@ declare namespace UniWebView {
462
560
  reLaunch(options: NavigateOptions): void;
463
561
  redirectTo(options: NavigateOptions): void;
464
562
  navigateToMiniProgram(options: MiniProgramNavigateOptions): void;
563
+ filePreview(options: FilePreviewOptions): void;
465
564
  postMessage(options?: PostMessageOptions): void;
466
565
  getEnv(callback: (info: EnvironmentInfo) => void): void;
467
566
  chooseImage(options?: ChooseImageOptions): void;
@@ -482,6 +581,8 @@ declare namespace UniWebView {
482
581
 
483
582
  navigateToMiniProgram(options: MiniProgramNavigateOptions): Promise<MiniProgramNavigateResult> | void;
484
583
  navigateToMiniProgramAsync(options: Omit<MiniProgramNavigateOptions, "success" | "fail" | "complete">): Promise<MiniProgramNavigateResult>;
584
+ filePreview(options: FilePreviewOptions): Promise<FilePreviewResult> | void;
585
+ filePreviewAsync(options: Omit<FilePreviewOptions, "success" | "fail" | "complete">): Promise<FilePreviewResult>;
485
586
 
486
587
  weixin: WeixinNamespace;
487
588
 
@@ -495,6 +596,19 @@ declare namespace UniWebView {
495
596
  /** 获取位置选择功能能力信息 */
496
597
  getChooseLocationCapabilities(): ChooseLocationCapabilities;
497
598
 
599
+ /** 获取当前位置 */
600
+ getLocation(options?: GetLocationOptions): void;
601
+ /** 获取位置(Promise版本) */
602
+ getLocationAsync(options?: Omit<GetLocationOptions, "success" | "fail" | "complete">): Promise<LocationResult>;
603
+ /** 查看位置 */
604
+ openLocation(options: OpenLocationOptions): void;
605
+ /** 查看位置(Promise版本) */
606
+ openLocationAsync(options: Omit<OpenLocationOptions, "success" | "fail" | "complete">): Promise<any>;
607
+ /** 位置相关常量 */
608
+ CoordinateTypes: CoordinateTypesEnum;
609
+ /** 获取位置功能能力信息 */
610
+ getLocationCapabilities(): LocationCapabilities;
611
+
498
612
  /** 图片来源类型枚举 */
499
613
  ImageSourceTypes: ImageSourceTypesEnum;
500
614
  /** 图片大小类型枚举 */