@foundbyte/uni-libs 0.0.15 → 1.0.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 +21 -10
- package/es/index.d.ts +3 -3
- package/es/index.js +3 -3
- package/es/services/goods/service.js +10 -9
- package/es/services/goods/type.d.ts +10 -10
- package/es/utils/common/index.js +2 -2
- package/es/utils/native-app/index.js +2 -2
- package/es/utils/pages/food/index.d.ts +1 -4
- package/es/utils/pages/food/index.js +3 -7
- package/es/utils/uni-env/index.d.ts +12 -7
- package/es/utils/uni-env/index.js +17 -10
- package/es/utils/web-view/index.d.ts +41 -1
- package/es/utils/web-view/index.js +73 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -74,17 +74,28 @@ navigateBack({
|
|
|
74
74
|
})
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
### 4.
|
|
78
|
-
|
|
77
|
+
### 4.setShareParam
|
|
78
|
+
设置页面分享内容
|
|
79
79
|
```typescript
|
|
80
|
-
import {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
import { setShareParam, EBusinessLine } from '@foundbyte/uni-libs'
|
|
81
|
+
|
|
82
|
+
setShareParam({
|
|
83
|
+
/** 标题 */
|
|
84
|
+
title: '',
|
|
85
|
+
/** 缩略图 */
|
|
86
|
+
imageUrl: '',
|
|
87
|
+
/** web完整链接,不需要encodeURIComponent */
|
|
88
|
+
shareUrl: ''
|
|
89
|
+
},
|
|
90
|
+
/** 业务线id, 没有可忽略 */
|
|
91
|
+
businessType: EBusinessLine.Foods
|
|
92
|
+
)
|
|
88
93
|
```
|
|
89
94
|
|
|
95
|
+
### 5.环境判断
|
|
96
|
+
```typescript
|
|
97
|
+
import { isAlipay, isWeixin, isHarmony, isAndroid, isiOS } from '@foundbyte/uni-libs'
|
|
90
98
|
|
|
99
|
+
/** 支付宝小程序、微信、鸿蒙app、安卓app、苹果app */
|
|
100
|
+
console.info(isAlipay, isWeixin, isHarmony, isAndroid, isiOS)
|
|
101
|
+
```
|
package/es/index.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ import { ActivityCalendarDetailPageParams, getActivityCalendarDetailPage } from
|
|
|
13
13
|
import { WebviewPageParams, getWebviewPage } from "./utils/pages/webview/index.js";
|
|
14
14
|
import { getFoodPackagePage, getFoodStorePage } from "./utils/pages/food/index.js";
|
|
15
15
|
import { getMoviePage } from "./utils/pages/movie/index.js";
|
|
16
|
-
import { EMessagesType, navigateBack, navigateTo, postMessage, redirectTo } from "./utils/web-view/index.js";
|
|
17
|
-
import { getSystemInfoSync,
|
|
16
|
+
import { EMessagesType, IShareParam, isAlipay, isAndroid, isHarmony, isIOSOrAndroid, isWeixin, isiOS, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay } from "./utils/web-view/index.js";
|
|
17
|
+
import { getSystemInfoSync, isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isWeixinEnv, isiOSEnv } from "./utils/uni-env/index.js";
|
|
18
18
|
import { checkAndRequestNativeAppPermission } from "./utils/native-app/index.js";
|
|
19
19
|
import { OneTravelSDK } from "./entry.js";
|
|
20
|
-
export { ActivityCalendarDetailPageParams, BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, ESubBizType, EUniPlatform, EVenueSimpleTypes, EVenueTypes, IOneTravelSDKConfig, OneTravelSDK, WebviewPageParams, app_permission, checkAndRequestNativeAppPermission, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getSystemInfoSync, getWebviewPage, isAndroid,
|
|
20
|
+
export { ActivityCalendarDetailPageParams, BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, ESubBizType, EUniPlatform, EVenueSimpleTypes, EVenueTypes, IOneTravelSDKConfig, IShareParam, OneTravelSDK, WebviewPageParams, app_permission, checkAndRequestNativeAppPermission, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getSystemInfoSync, getWebviewPage, isAlipay, isAlipayEnv, isAndroid, isAndroidEnv, isAppEnv, isEmpty, isH5Env, isHarmony, isHarmonyEnv, isIOSOrAndroid, isWeixin, isWeixinEnv, isiOS, isiOSEnv, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes, setShareParam, toPay };
|
package/es/index.js
CHANGED
|
@@ -12,9 +12,9 @@ import { getActivityCalendarDetailPage } from "./utils/pages/activity-calendar/i
|
|
|
12
12
|
import { getWebviewPage } from "./utils/pages/webview/index.js";
|
|
13
13
|
import { getFoodPackagePage, getFoodStorePage } from "./utils/pages/food/index.js";
|
|
14
14
|
import { getMoviePage } from "./utils/pages/movie/index.js";
|
|
15
|
-
import { EMessagesType, navigateBack, navigateTo, postMessage, redirectTo } from "./utils/web-view/index.js";
|
|
16
|
-
import { getSystemInfoSync,
|
|
15
|
+
import { EMessagesType, isAlipay, isAndroid, isHarmony, isIOSOrAndroid, isWeixin, isiOS, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay } from "./utils/web-view/index.js";
|
|
16
|
+
import { getSystemInfoSync, isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isWeixinEnv, isiOSEnv } from "./utils/uni-env/index.js";
|
|
17
17
|
import { checkAndRequestNativeAppPermission } from "./utils/native-app/index.js";
|
|
18
18
|
import { OneTravelSDK } from "./entry.js";
|
|
19
19
|
|
|
20
|
-
export { BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, ESubBizType, EUniPlatform, EVenueSimpleTypes, EVenueTypes, OneTravelSDK, app_permission, checkAndRequestNativeAppPermission, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getSystemInfoSync, getWebviewPage, isAndroid,
|
|
20
|
+
export { BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, ESubBizType, EUniPlatform, EVenueSimpleTypes, EVenueTypes, OneTravelSDK, app_permission, checkAndRequestNativeAppPermission, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getSystemInfoSync, getWebviewPage, isAlipay, isAlipayEnv, isAndroid, isAndroidEnv, isAppEnv, isEmpty, isH5Env, isHarmony, isHarmonyEnv, isIOSOrAndroid, isWeixin, isWeixinEnv, isiOS, isiOSEnv, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes, setShareParam, toPay };
|
|
@@ -28,27 +28,28 @@ var GoodsService = class {
|
|
|
28
28
|
const extInfo = item?.common?.extInfoMap || item?.common?.extInfo;
|
|
29
29
|
switch (businessLine) {
|
|
30
30
|
case EBusinessLine.Scenic:
|
|
31
|
-
const scenicId = item?.scenic?.id || item?.common?.spuId || item?.common?.id;
|
|
32
|
-
const scenicReservationId = item?.scenic?.reservationId || extInfo?.reservationId || item?.common?.reservationId;
|
|
31
|
+
const scenicId = item?.scenic?.id || item?.common?.spuId || item?.common?.id || "";
|
|
32
|
+
const scenicReservationId = item?.scenic?.reservationId || extInfo?.reservationId || item?.common?.reservationId || "";
|
|
33
33
|
const scenicIsOld = item?.scenic?.isOld || extInfo?.isOld;
|
|
34
34
|
page = `${routePrefix.ticket}/detail/index?scenicId=${scenicId}&reservationId=${scenicReservationId}&isOld=${scenicIsOld}`;
|
|
35
35
|
break;
|
|
36
36
|
case EBusinessLine.Hotel:
|
|
37
|
-
const hotelId = item?.hotel?.id || extInfo?.storeId || item?.common?.storeId;
|
|
37
|
+
const hotelId = item?.hotel?.id || extInfo?.storeId || item?.common?.storeId || "";
|
|
38
38
|
page = `${routePrefix.hotel}/home/details/index?id=${hotelId}`;
|
|
39
39
|
break;
|
|
40
40
|
case EBusinessLine.Homestay:
|
|
41
|
-
const homestayType = item?.homestay?.type || extInfo?.type || item?.common?.type;
|
|
41
|
+
const homestayType = item?.homestay?.type || extInfo?.type || item?.common?.type || "";
|
|
42
42
|
if (homestayType === EHotelType.hotel) {
|
|
43
|
-
/** 酒店 (天下房仓酒店详情页)*/
|
|
44
|
-
const id = item?.homestay?.id || extInfo?.storeId || item?.common?.storeId;
|
|
43
|
+
/** 酒店 (天下房仓酒店详情页) */
|
|
44
|
+
const id = item?.homestay?.id || extInfo?.storeId || item?.common?.storeId || "";
|
|
45
45
|
page = `${routePrefix.hotel}/home/details/index?id=${id}`;
|
|
46
46
|
} else {
|
|
47
47
|
const subBizType = item?.homestay?.subBizType || extInfo?.subBizType;
|
|
48
|
-
const id = item?.homestay?.id || item?.common?.spuId || item?.common?.id;
|
|
48
|
+
const id = item?.homestay?.id || item?.common?.spuId || item?.common?.id || "";
|
|
49
49
|
/** 民宿 */
|
|
50
50
|
if (`${subBizType}` === `${ESubBizType.HomestayHotel}`) page = `${routePrefix.hotel}/home/details/index?id=${id}`;
|
|
51
|
-
else page = `${routePrefix.hotel}/home/hot-sale-details/index?id=${id}`;
|
|
51
|
+
else if (`${subBizType}` === `${ESubBizType.HomestayHot}`) page = `${routePrefix.hotel}/home/hot-sale-details/index?id=${id}`;
|
|
52
|
+
else page = `${routePrefix.hotel}/home/pms-details/index?id=${id}`;
|
|
52
53
|
}
|
|
53
54
|
break;
|
|
54
55
|
case EBusinessLine.Route:
|
|
@@ -93,7 +94,7 @@ var GoodsService = class {
|
|
|
93
94
|
let movieId = item?.movie?.id || "";
|
|
94
95
|
try {
|
|
95
96
|
movieId = JSON.parse(extInfo?.extInfo || "{}")?.thirdMovieId || "";
|
|
96
|
-
} catch
|
|
97
|
+
} catch {}
|
|
97
98
|
page = getMoviePage(appConfig.domain.movie, movieId);
|
|
98
99
|
break;
|
|
99
100
|
case EBusinessLine.Strategy:
|
|
@@ -7,17 +7,17 @@ type IJumpProductDetailItemCommonExtInfo = {
|
|
|
7
7
|
type?: 'hotel' | '1' | '3';
|
|
8
8
|
storeId?: string;
|
|
9
9
|
subBizType?: ESubBizType;
|
|
10
|
-
|
|
10
|
+
/** ********** 景区相关字段 ************/
|
|
11
11
|
isOld?: number;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
/** ********** 景区相关字段 ************/
|
|
13
|
+
/** ********** 美食相关字段 ************/
|
|
14
14
|
storePrecedentType?: EFoodPackageType;
|
|
15
15
|
moduleType?: EFoodsModuleType;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/** ********** 美食相关字段 ************/
|
|
17
|
+
/** ********** 种草相关字段 ************/
|
|
18
18
|
moreParameter?: string;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/** ********** 种草相关字段 ************/
|
|
20
|
+
/** ********** 电影相关字段 ************/
|
|
21
21
|
extInfo: string;
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
@@ -36,12 +36,12 @@ type IJumpProductDetailItem = {
|
|
|
36
36
|
skuId: string;
|
|
37
37
|
/** spuId */
|
|
38
38
|
spuId: string;
|
|
39
|
-
|
|
39
|
+
/** ****** 收藏、搜索等(优先取扩展字段里面的) ********/
|
|
40
40
|
id?: string;
|
|
41
41
|
storeId?: string;
|
|
42
42
|
type?: 'hotel' | '1' | '3';
|
|
43
43
|
reservationId?: string;
|
|
44
|
-
|
|
44
|
+
/** ****** 收藏、搜索等 ********/
|
|
45
45
|
/** 扩展字段 */
|
|
46
46
|
extInfo?: IJumpProductDetailItemCommonExtInfo;
|
|
47
47
|
/** 扩展字段 */
|
|
@@ -75,7 +75,7 @@ type IJumpProductDetailItem = {
|
|
|
75
75
|
buy?: {
|
|
76
76
|
spuId: string;
|
|
77
77
|
};
|
|
78
|
-
/**
|
|
78
|
+
/** 购物(新) */
|
|
79
79
|
onebuygz?: {
|
|
80
80
|
spuId: string;
|
|
81
81
|
skuId: string;
|
package/es/utils/common/index.js
CHANGED
|
@@ -13,7 +13,7 @@ function isEmpty(value) {
|
|
|
13
13
|
*/
|
|
14
14
|
function query2url(query, options) {
|
|
15
15
|
const { encode = true } = options || {};
|
|
16
|
-
const url = Object.entries(query || {}).filter(([
|
|
16
|
+
const url = Object.entries(query || {}).filter(([_, val]) => val !== void 0 && val !== null).map(([key, val]) => {
|
|
17
17
|
return encode ? `${encodeURIComponent(key)}=${encodeURIComponent(val)}` : `${key}=${val}`;
|
|
18
18
|
}).join("&");
|
|
19
19
|
return url ? `?${url}` : "";
|
|
@@ -33,7 +33,7 @@ function getQueryParameters(url) {
|
|
|
33
33
|
let value = decodeURIComponent(pair[1] || "");
|
|
34
34
|
try {
|
|
35
35
|
value = JSON.parse(value);
|
|
36
|
-
} catch
|
|
36
|
+
} catch {}
|
|
37
37
|
params[key] = value;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { app_permission } from "../../constants/permission/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isH5Env, isHarmonyEnv, isWeixinEnv, isiOSEnv } from "../uni-env/index.js";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/native-app/index.ts
|
|
5
5
|
let plusNativeObjView;
|
|
@@ -61,7 +61,7 @@ const showAndroidTip = (options) => {
|
|
|
61
61
|
*/
|
|
62
62
|
const checkAndRequestNativeAppPermission = (options) => {
|
|
63
63
|
const { type, success, fail } = options || {};
|
|
64
|
-
if (
|
|
64
|
+
if (isWeixinEnv() || isH5Env() || isHarmonyEnv() || isiOSEnv()) {
|
|
65
65
|
success?.();
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { EFoodPackageType } from "../../../enums/sub/foods/index.js";
|
|
2
|
-
|
|
3
1
|
//#region src/utils/pages/food/index.d.ts
|
|
4
|
-
|
|
5
2
|
/**
|
|
6
3
|
* 店铺
|
|
7
4
|
* @param domain 域名
|
|
@@ -18,6 +15,6 @@ declare const getFoodStorePage: (domain: string, storeId: string, isDiamondLevel
|
|
|
18
15
|
* @param storePrecedentType 套餐类型 (1、特色美食,2、休闲娱乐套餐)
|
|
19
16
|
* @returns
|
|
20
17
|
*/
|
|
21
|
-
declare const getFoodPackagePage: (domain: string, storeId: string, packageId: string, storePrecedentType?:
|
|
18
|
+
declare const getFoodPackagePage: (domain: string, storeId: string, packageId: string, storePrecedentType?: number) => string;
|
|
22
19
|
//#endregion
|
|
23
20
|
export { getFoodPackagePage, getFoodStorePage };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EFoodPackageType } from "../../../enums/sub/foods/index.js";
|
|
2
1
|
import { query2url } from "../../common/index.js";
|
|
3
2
|
|
|
4
3
|
//#region src/utils/pages/food/index.ts
|
|
@@ -24,13 +23,10 @@ const getFoodStorePage = (domain, storeId, isDiamondLevel) => {
|
|
|
24
23
|
* @returns
|
|
25
24
|
*/
|
|
26
25
|
const getFoodPackagePage = (domain, storeId, packageId, storePrecedentType) => {
|
|
27
|
-
|
|
26
|
+
return `${domain}store/arrive/package-detail-middle/index${query2url({
|
|
28
27
|
storeId,
|
|
29
|
-
packageId
|
|
30
|
-
|
|
31
|
-
return `${domain}store/arrive/package-detail/index${query2url({
|
|
32
|
-
storeId,
|
|
33
|
-
packageId
|
|
28
|
+
packageId,
|
|
29
|
+
storePrecedentType
|
|
34
30
|
}, { encode: false })}`;
|
|
35
31
|
};
|
|
36
32
|
|
|
@@ -1,34 +1,39 @@
|
|
|
1
1
|
//#region src/utils/uni-env/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 是否是支付宝小程序
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
declare const isAlipayEnv: () => boolean;
|
|
2
7
|
/**
|
|
3
8
|
* 是否是web环境
|
|
4
9
|
* @returns
|
|
5
10
|
*/
|
|
6
|
-
declare const
|
|
11
|
+
declare const isH5Env: () => boolean;
|
|
7
12
|
/**
|
|
8
13
|
* 是否是微信小程序
|
|
9
14
|
* @returns
|
|
10
15
|
*/
|
|
11
|
-
declare const
|
|
16
|
+
declare const isWeixinEnv: () => boolean;
|
|
12
17
|
/**
|
|
13
18
|
* 是否是鸿蒙
|
|
14
19
|
* @returns
|
|
15
20
|
*/
|
|
16
|
-
declare const
|
|
21
|
+
declare const isHarmonyEnv: () => boolean;
|
|
17
22
|
/**
|
|
18
23
|
* 是否是app
|
|
19
24
|
* @returns
|
|
20
25
|
*/
|
|
21
|
-
declare const
|
|
26
|
+
declare const isAppEnv: () => boolean;
|
|
22
27
|
/**
|
|
23
28
|
* 是否是安卓
|
|
24
29
|
* @returns
|
|
25
30
|
*/
|
|
26
|
-
declare const
|
|
31
|
+
declare const isAndroidEnv: () => boolean;
|
|
27
32
|
/**
|
|
28
33
|
* 是否是iOS
|
|
29
34
|
* @returns
|
|
30
35
|
*/
|
|
31
|
-
declare const
|
|
36
|
+
declare const isiOSEnv: () => boolean;
|
|
32
37
|
declare function getSystemInfoSync(): UniApp.GetSystemInfoResult | {
|
|
33
38
|
pixelRatio: number;
|
|
34
39
|
screenWidth: number;
|
|
@@ -53,4 +58,4 @@ declare function getSystemInfoSync(): UniApp.GetSystemInfoResult | {
|
|
|
53
58
|
platform: string;
|
|
54
59
|
};
|
|
55
60
|
//#endregion
|
|
56
|
-
export { getSystemInfoSync,
|
|
61
|
+
export { getSystemInfoSync, isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isWeixinEnv, isiOSEnv };
|
|
@@ -2,48 +2,55 @@ import { EUniPlatform } from "../../enums/platform/index.js";
|
|
|
2
2
|
|
|
3
3
|
//#region src/utils/uni-env/index.ts
|
|
4
4
|
/**
|
|
5
|
+
* 是否是支付宝小程序
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
const isAlipayEnv = () => {
|
|
9
|
+
return true;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
5
12
|
* 是否是web环境
|
|
6
13
|
* @returns
|
|
7
14
|
*/
|
|
8
|
-
const
|
|
15
|
+
const isH5Env = () => {
|
|
9
16
|
return true;
|
|
10
17
|
};
|
|
11
18
|
/**
|
|
12
19
|
* 是否是微信小程序
|
|
13
20
|
* @returns
|
|
14
21
|
*/
|
|
15
|
-
const
|
|
22
|
+
const isWeixinEnv = () => {
|
|
16
23
|
return true;
|
|
17
24
|
};
|
|
18
25
|
/**
|
|
19
26
|
* 是否是鸿蒙
|
|
20
27
|
* @returns
|
|
21
28
|
*/
|
|
22
|
-
const
|
|
29
|
+
const isHarmonyEnv = () => {
|
|
23
30
|
return true;
|
|
24
31
|
};
|
|
25
32
|
/**
|
|
26
33
|
* 是否是app
|
|
27
34
|
* @returns
|
|
28
35
|
*/
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
36
|
+
const isAppEnv = () => {
|
|
37
|
+
if (isHarmonyEnv()) return true;
|
|
31
38
|
return true;
|
|
32
39
|
};
|
|
33
40
|
/**
|
|
34
41
|
* 是否是安卓
|
|
35
42
|
* @returns
|
|
36
43
|
*/
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
44
|
+
const isAndroidEnv = () => {
|
|
45
|
+
if (isAppEnv() && getSystemInfoSync().platform === EUniPlatform.android) return true;
|
|
39
46
|
return false;
|
|
40
47
|
};
|
|
41
48
|
/**
|
|
42
49
|
* 是否是iOS
|
|
43
50
|
* @returns
|
|
44
51
|
*/
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
52
|
+
const isiOSEnv = () => {
|
|
53
|
+
if (isAppEnv() && getSystemInfoSync().platform === EUniPlatform.ios) return true;
|
|
47
54
|
return false;
|
|
48
55
|
};
|
|
49
56
|
function getSystemInfoSync() {
|
|
@@ -54,4 +61,4 @@ function getSystemInfoSync() {
|
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
//#endregion
|
|
57
|
-
export { getSystemInfoSync,
|
|
64
|
+
export { getSystemInfoSync, isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isWeixinEnv, isiOSEnv };
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
+
import { EBusinessLine } from "../../enums/business-line/index.js";
|
|
2
|
+
|
|
1
3
|
//#region src/utils/web-view/index.d.ts
|
|
4
|
+
/** 判断是否是iOS还是安卓 */
|
|
5
|
+
declare const isIOSOrAndroid: boolean;
|
|
6
|
+
/** 判断是否支付宝小程序 */
|
|
7
|
+
declare const isAlipay: boolean;
|
|
8
|
+
/** 判断是否微信小程序 */
|
|
9
|
+
declare const isWeixin: boolean;
|
|
10
|
+
/** 判断是否鸿蒙APP */
|
|
11
|
+
declare const isHarmony: boolean;
|
|
12
|
+
/** 判断是否安卓APP */
|
|
13
|
+
declare const isAndroid: boolean;
|
|
14
|
+
/** 判断是否苹果APP */
|
|
15
|
+
declare const isiOS: boolean;
|
|
2
16
|
declare enum EMessagesType {
|
|
17
|
+
/** app直接调用分享 */
|
|
18
|
+
share = "share",
|
|
19
|
+
/** 设置分享参数 */
|
|
20
|
+
shareParam = "shareParam",
|
|
21
|
+
/** 去支付 */
|
|
3
22
|
pay = "pay",
|
|
4
23
|
}
|
|
5
24
|
/**
|
|
@@ -37,5 +56,26 @@ declare const postMessage: (data: {
|
|
|
37
56
|
type?: EMessagesType;
|
|
38
57
|
params: Record<string, any>;
|
|
39
58
|
}) => void;
|
|
59
|
+
interface IShareParam {
|
|
60
|
+
/** 分享标题 */
|
|
61
|
+
title?: string;
|
|
62
|
+
/** 分享图片url */
|
|
63
|
+
imageUrl?: string;
|
|
64
|
+
/** 分享链接 */
|
|
65
|
+
shareUrl?: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 设置页面分享信息
|
|
69
|
+
* @param data
|
|
70
|
+
*/
|
|
71
|
+
declare const setShareParam: (data: IShareParam, businessType?: number | EBusinessLine) => void;
|
|
72
|
+
/**
|
|
73
|
+
* 去支付
|
|
74
|
+
* @param data
|
|
75
|
+
*/
|
|
76
|
+
declare const toPay: (data: {
|
|
77
|
+
cashStageUrl: string;
|
|
78
|
+
orderNo: string;
|
|
79
|
+
}) => void;
|
|
40
80
|
//#endregion
|
|
41
|
-
export { EMessagesType, navigateBack, navigateTo, postMessage, redirectTo };
|
|
81
|
+
export { EMessagesType, IShareParam, isAlipay, isAndroid, isHarmony, isIOSOrAndroid, isWeixin, isiOS, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay };
|
|
@@ -2,16 +2,43 @@ import wx from "weixin-js-sdk";
|
|
|
2
2
|
|
|
3
3
|
//#region src/utils/web-view/index.ts
|
|
4
4
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
5
|
+
/** 判断是否是iOS还是安卓 */
|
|
5
6
|
const isIOSOrAndroid = !userAgent.includes("miniprogram") && (userAgent.includes("android") || userAgent.includes("iphone") || userAgent.includes("ipad"));
|
|
7
|
+
/** 判断是否支付宝小程序 */
|
|
8
|
+
const isAlipay = userAgent.includes("miniprogram") && userAgent.includes("aliapp");
|
|
9
|
+
/** 判断是否微信小程序 */
|
|
10
|
+
const isWeixin = window.__wxjs_environment === "miniprogram";
|
|
11
|
+
/** 判断是否鸿蒙APP */
|
|
12
|
+
const isHarmony = !userAgent.includes("miniprogram") && !userAgent.includes("android") && userAgent.includes("openharmony");
|
|
13
|
+
/** 判断是否安卓APP */
|
|
14
|
+
const isAndroid = !userAgent.includes("miniprogram") && userAgent.includes("android");
|
|
15
|
+
/** 判断是否苹果APP */
|
|
16
|
+
const isiOS = !userAgent.includes("miniprogram") && (userAgent.includes("iphone") || userAgent.includes("ipad"));
|
|
17
|
+
let uni = {};
|
|
6
18
|
async function loadWebview() {
|
|
7
|
-
if (isIOSOrAndroid)
|
|
8
|
-
|
|
19
|
+
if (isIOSOrAndroid) {
|
|
20
|
+
const res = await import("../../assets/js/webview/uni.webview.1.5.6.js");
|
|
21
|
+
uni = res.default;
|
|
22
|
+
} else {
|
|
23
|
+
const res = await import("../../assets/js/webview/uni.webview.1.5.5.js");
|
|
24
|
+
uni = res.default;
|
|
25
|
+
}
|
|
26
|
+
if (isAlipay) {
|
|
27
|
+
const scriptTag = document.createElement("script");
|
|
28
|
+
scriptTag.src = "https://appx/web-view.min.js";
|
|
29
|
+
document.head.appendChild(scriptTag);
|
|
30
|
+
}
|
|
9
31
|
}
|
|
10
32
|
loadWebview();
|
|
11
33
|
document.addEventListener("UniAppJSBridgeReady", function() {
|
|
12
|
-
uni.webView.getEnv(function(
|
|
34
|
+
uni.webView.getEnv(function(_) {});
|
|
13
35
|
});
|
|
14
36
|
let EMessagesType = /* @__PURE__ */ function(EMessagesType$1) {
|
|
37
|
+
/** app直接调用分享 */
|
|
38
|
+
EMessagesType$1["share"] = "share";
|
|
39
|
+
/** 设置分享参数 */
|
|
40
|
+
EMessagesType$1["shareParam"] = "shareParam";
|
|
41
|
+
/** 去支付 */
|
|
15
42
|
EMessagesType$1["pay"] = "pay";
|
|
16
43
|
return EMessagesType$1;
|
|
17
44
|
}({});
|
|
@@ -26,6 +53,7 @@ const navigateTo = (parameters) => {
|
|
|
26
53
|
uni?.webView?.navigateTo?.({ url });
|
|
27
54
|
/** 不兼容上面的方法会自动往下执行 */
|
|
28
55
|
wx.miniProgram.navigateTo({ url });
|
|
56
|
+
my.navigateTo({ url });
|
|
29
57
|
} catch (error) {
|
|
30
58
|
console.error(error);
|
|
31
59
|
}
|
|
@@ -41,6 +69,7 @@ const redirectTo = (parameters) => {
|
|
|
41
69
|
uni?.webView?.redirectTo?.({ url });
|
|
42
70
|
/** 不兼容上面的方法会自动往下执行 */
|
|
43
71
|
wx.miniProgram.redirectTo({ url });
|
|
72
|
+
my.redirectTo({ url });
|
|
44
73
|
} catch (error) {
|
|
45
74
|
console.error(error);
|
|
46
75
|
}
|
|
@@ -54,6 +83,7 @@ const navigateBack = (parameters) => {
|
|
|
54
83
|
uni?.webView?.navigateBack?.(parameters);
|
|
55
84
|
/** 不兼容上面的方法会自动往下执行 */
|
|
56
85
|
wx.miniProgram.navigateBack(parameters);
|
|
86
|
+
my.navigateBack(parameters);
|
|
57
87
|
} catch (error) {
|
|
58
88
|
console.error(error);
|
|
59
89
|
}
|
|
@@ -63,14 +93,47 @@ const navigateBack = (parameters) => {
|
|
|
63
93
|
* @param data
|
|
64
94
|
*/
|
|
65
95
|
const postMessage = (data) => {
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
96
|
+
if (data.type === EMessagesType.pay) {
|
|
97
|
+
if (isWeixin || isAlipay) {
|
|
98
|
+
redirectTo({
|
|
99
|
+
src: "/pages/web-view/index",
|
|
100
|
+
params: data.params
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
72
104
|
}
|
|
73
105
|
uni?.webView?.postMessage({ data });
|
|
106
|
+
wx.miniProgram.postMessage({ data });
|
|
107
|
+
my.postMessage({ data });
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* 设置页面分享信息
|
|
111
|
+
* @param data
|
|
112
|
+
*/
|
|
113
|
+
const setShareParam = (data, businessType) => {
|
|
114
|
+
const { shareUrl,...res } = data;
|
|
115
|
+
const params = { data: {
|
|
116
|
+
...res,
|
|
117
|
+
businessType,
|
|
118
|
+
shareUrl: encodeURIComponent(shareUrl || "")
|
|
119
|
+
} };
|
|
120
|
+
postMessage({
|
|
121
|
+
type: EMessagesType.shareParam,
|
|
122
|
+
params
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* 去支付
|
|
127
|
+
* @param data
|
|
128
|
+
*/
|
|
129
|
+
const toPay = (data) => {
|
|
130
|
+
postMessage({
|
|
131
|
+
type: EMessagesType.pay,
|
|
132
|
+
params: {
|
|
133
|
+
url: encodeURIComponent(data.cashStageUrl),
|
|
134
|
+
orderId: data.orderNo
|
|
135
|
+
}
|
|
136
|
+
});
|
|
74
137
|
};
|
|
75
138
|
function objectToQueryString(obj) {
|
|
76
139
|
const params = Object.entries(obj).map(([key, value]) => {
|
|
@@ -81,4 +144,4 @@ function objectToQueryString(obj) {
|
|
|
81
144
|
}
|
|
82
145
|
|
|
83
146
|
//#endregion
|
|
84
|
-
export { EMessagesType, navigateBack, navigateTo, postMessage, redirectTo };
|
|
147
|
+
export { EMessagesType, isAlipay, isAndroid, isHarmony, isIOSOrAndroid, isWeixin, isiOS, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay };
|