@foundbyte/uni-libs 0.0.15 → 0.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 +21 -10
- package/es/index.d.ts +3 -3
- package/es/index.js +3 -3
- package/es/services/goods/type.d.ts +9 -9
- 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 +3 -13
- package/es/utils/uni-env/index.js +1 -9
- package/es/utils/web-view/index.d.ts +35 -1
- package/es/utils/web-view/index.js +65 -8
- 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, isIOSOrAndroid, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay } from "./utils/web-view/index.js";
|
|
17
|
+
import { getSystemInfoSync, isApp, isH5 } 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,
|
|
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, isApp, isEmpty, isH5, isIOSOrAndroid, 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, isIOSOrAndroid, isWeixin, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay } from "./utils/web-view/index.js";
|
|
16
|
+
import { getSystemInfoSync, isApp, isH5 } 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,
|
|
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, isApp, isEmpty, isH5, isIOSOrAndroid, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes, setShareParam, toPay };
|
|
@@ -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
|
/** 扩展字段 */
|
|
@@ -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
|
|
|
@@ -8,12 +8,7 @@ declare const isH5: () => boolean;
|
|
|
8
8
|
* 是否是微信小程序
|
|
9
9
|
* @returns
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 是否是鸿蒙
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
declare const isHarmony: () => boolean;
|
|
11
|
+
|
|
17
12
|
/**
|
|
18
13
|
* 是否是app
|
|
19
14
|
* @returns
|
|
@@ -23,12 +18,7 @@ declare const isApp: () => boolean;
|
|
|
23
18
|
* 是否是安卓
|
|
24
19
|
* @returns
|
|
25
20
|
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 是否是iOS
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
declare const isiOS: () => boolean;
|
|
21
|
+
|
|
32
22
|
declare function getSystemInfoSync(): UniApp.GetSystemInfoResult | {
|
|
33
23
|
pixelRatio: number;
|
|
34
24
|
screenWidth: number;
|
|
@@ -53,4 +43,4 @@ declare function getSystemInfoSync(): UniApp.GetSystemInfoResult | {
|
|
|
53
43
|
platform: string;
|
|
54
44
|
};
|
|
55
45
|
//#endregion
|
|
56
|
-
export { getSystemInfoSync,
|
|
46
|
+
export { getSystemInfoSync, isApp, isH5 };
|
|
@@ -31,14 +31,6 @@ const isApp = () => {
|
|
|
31
31
|
return true;
|
|
32
32
|
};
|
|
33
33
|
/**
|
|
34
|
-
* 是否是安卓
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
|
-
const isAndroid = () => {
|
|
38
|
-
if (isApp() && getSystemInfoSync().platform === EUniPlatform.android) return true;
|
|
39
|
-
return false;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
34
|
* 是否是iOS
|
|
43
35
|
* @returns
|
|
44
36
|
*/
|
|
@@ -54,4 +46,4 @@ function getSystemInfoSync() {
|
|
|
54
46
|
}
|
|
55
47
|
|
|
56
48
|
//#endregion
|
|
57
|
-
export { getSystemInfoSync,
|
|
49
|
+
export { getSystemInfoSync, isApp, isH5, isHarmony, isWeixin, isiOS };
|
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
2
10
|
declare enum EMessagesType {
|
|
11
|
+
/** app直接调用分享 */
|
|
12
|
+
share = "share",
|
|
13
|
+
/** 设置分享参数 */
|
|
14
|
+
shareParam = "shareParam",
|
|
15
|
+
/** 去支付 */
|
|
3
16
|
pay = "pay",
|
|
4
17
|
}
|
|
5
18
|
/**
|
|
@@ -37,5 +50,26 @@ declare const postMessage: (data: {
|
|
|
37
50
|
type?: EMessagesType;
|
|
38
51
|
params: Record<string, any>;
|
|
39
52
|
}) => void;
|
|
53
|
+
interface IShareParam {
|
|
54
|
+
/** 分享标题 */
|
|
55
|
+
title?: string;
|
|
56
|
+
/** 分享图片url */
|
|
57
|
+
imageUrl?: string;
|
|
58
|
+
/** 分享链接 */
|
|
59
|
+
shareUrl?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 设置页面分享信息
|
|
63
|
+
* @param data
|
|
64
|
+
*/
|
|
65
|
+
declare const setShareParam: (data: IShareParam, businessType?: number | EBusinessLine) => void;
|
|
66
|
+
/**
|
|
67
|
+
* 去支付
|
|
68
|
+
* @param data
|
|
69
|
+
*/
|
|
70
|
+
declare const toPay: (data: {
|
|
71
|
+
cashStageUrl: string;
|
|
72
|
+
orderNo: string;
|
|
73
|
+
}) => void;
|
|
40
74
|
//#endregion
|
|
41
|
-
export { EMessagesType, navigateBack, navigateTo, postMessage, redirectTo };
|
|
75
|
+
export { EMessagesType, IShareParam, isAlipay, isIOSOrAndroid, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay };
|
|
@@ -2,16 +2,37 @@ 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"));
|
|
6
17
|
async function loadWebview() {
|
|
7
18
|
if (isIOSOrAndroid) await import("../../assets/js/webview/uni.webview.1.5.6.js");
|
|
8
19
|
else await import("../../assets/js/webview/uni.webview.1.5.5.js");
|
|
20
|
+
if (isAlipay) {
|
|
21
|
+
const scriptTag = document.createElement("script");
|
|
22
|
+
scriptTag.src = "https://appx/web-view.min.js";
|
|
23
|
+
document.head.appendChild(scriptTag);
|
|
24
|
+
}
|
|
9
25
|
}
|
|
10
26
|
loadWebview();
|
|
11
27
|
document.addEventListener("UniAppJSBridgeReady", function() {
|
|
12
|
-
uni.webView.getEnv(function(
|
|
28
|
+
uni.webView.getEnv(function(_) {});
|
|
13
29
|
});
|
|
14
30
|
let EMessagesType = /* @__PURE__ */ function(EMessagesType$1) {
|
|
31
|
+
/** app直接调用分享 */
|
|
32
|
+
EMessagesType$1["share"] = "share";
|
|
33
|
+
/** 设置分享参数 */
|
|
34
|
+
EMessagesType$1["shareParam"] = "shareParam";
|
|
35
|
+
/** 去支付 */
|
|
15
36
|
EMessagesType$1["pay"] = "pay";
|
|
16
37
|
return EMessagesType$1;
|
|
17
38
|
}({});
|
|
@@ -26,6 +47,7 @@ const navigateTo = (parameters) => {
|
|
|
26
47
|
uni?.webView?.navigateTo?.({ url });
|
|
27
48
|
/** 不兼容上面的方法会自动往下执行 */
|
|
28
49
|
wx.miniProgram.navigateTo({ url });
|
|
50
|
+
my.navigateTo({ url });
|
|
29
51
|
} catch (error) {
|
|
30
52
|
console.error(error);
|
|
31
53
|
}
|
|
@@ -41,6 +63,7 @@ const redirectTo = (parameters) => {
|
|
|
41
63
|
uni?.webView?.redirectTo?.({ url });
|
|
42
64
|
/** 不兼容上面的方法会自动往下执行 */
|
|
43
65
|
wx.miniProgram.redirectTo({ url });
|
|
66
|
+
my.redirectTo({ url });
|
|
44
67
|
} catch (error) {
|
|
45
68
|
console.error(error);
|
|
46
69
|
}
|
|
@@ -54,6 +77,7 @@ const navigateBack = (parameters) => {
|
|
|
54
77
|
uni?.webView?.navigateBack?.(parameters);
|
|
55
78
|
/** 不兼容上面的方法会自动往下执行 */
|
|
56
79
|
wx.miniProgram.navigateBack(parameters);
|
|
80
|
+
my.navigateBack(parameters);
|
|
57
81
|
} catch (error) {
|
|
58
82
|
console.error(error);
|
|
59
83
|
}
|
|
@@ -63,14 +87,47 @@ const navigateBack = (parameters) => {
|
|
|
63
87
|
* @param data
|
|
64
88
|
*/
|
|
65
89
|
const postMessage = (data) => {
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
90
|
+
if (data.type === EMessagesType.pay) {
|
|
91
|
+
if (isWeixin || isAlipay) {
|
|
92
|
+
redirectTo({
|
|
93
|
+
src: "/pages/web-view/index",
|
|
94
|
+
params: data.params
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
72
98
|
}
|
|
73
99
|
uni?.webView?.postMessage({ data });
|
|
100
|
+
wx.miniProgram.postMessage({ data });
|
|
101
|
+
my.postMessage({ data });
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* 设置页面分享信息
|
|
105
|
+
* @param data
|
|
106
|
+
*/
|
|
107
|
+
const setShareParam = (data, businessType) => {
|
|
108
|
+
const { shareUrl,...res } = data;
|
|
109
|
+
const params = { data: {
|
|
110
|
+
...res,
|
|
111
|
+
businessType,
|
|
112
|
+
shareUrl: encodeURIComponent(shareUrl || "")
|
|
113
|
+
} };
|
|
114
|
+
postMessage({
|
|
115
|
+
type: EMessagesType.shareParam,
|
|
116
|
+
params
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* 去支付
|
|
121
|
+
* @param data
|
|
122
|
+
*/
|
|
123
|
+
const toPay = (data) => {
|
|
124
|
+
postMessage({
|
|
125
|
+
type: EMessagesType.pay,
|
|
126
|
+
params: {
|
|
127
|
+
url: encodeURIComponent(data.cashStageUrl),
|
|
128
|
+
orderId: data.orderNo
|
|
129
|
+
}
|
|
130
|
+
});
|
|
74
131
|
};
|
|
75
132
|
function objectToQueryString(obj) {
|
|
76
133
|
const params = Object.entries(obj).map(([key, value]) => {
|
|
@@ -81,4 +138,4 @@ function objectToQueryString(obj) {
|
|
|
81
138
|
}
|
|
82
139
|
|
|
83
140
|
//#endregion
|
|
84
|
-
export { EMessagesType, navigateBack, navigateTo, postMessage, redirectTo };
|
|
141
|
+
export { EMessagesType, isAlipay, isIOSOrAndroid, isWeixin, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay };
|