@foundbyte/uni-libs 0.0.14 → 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 CHANGED
@@ -74,17 +74,28 @@ navigateBack({
74
74
  })
75
75
  ```
76
76
 
77
- ### 4.postMessage
78
- 网页向应用发送消息
77
+ ### 4.setShareParam
78
+ 设置页面分享内容
79
79
  ```typescript
80
- import { postMessage } from '@foundbyte/uni-libs'
81
-
82
- postMessage({
83
- type: EMessagesType.pay,
84
- params: {
85
- url: encodeURIComponent('预下单返回的收银台地址')
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
+ ```
@@ -0,0 +1,8 @@
1
+ //#region src/enums/platform/index.d.ts
2
+ declare enum EUniPlatform {
3
+ android = "android",
4
+ ios = "ios",
5
+ harmony = "harmony",
6
+ }
7
+ //#endregion
8
+ export { EUniPlatform };
@@ -0,0 +1,10 @@
1
+ //#region src/enums/platform/index.ts
2
+ let EUniPlatform = /* @__PURE__ */ function(EUniPlatform$1) {
3
+ EUniPlatform$1["android"] = "android";
4
+ EUniPlatform$1["ios"] = "ios";
5
+ EUniPlatform$1["harmony"] = "harmony";
6
+ return EUniPlatform$1;
7
+ }({});
8
+
9
+ //#endregion
10
+ export { EUniPlatform };
package/es/index.d.ts CHANGED
@@ -6,14 +6,15 @@ import { ECaller } from "./enums/sdk/index.js";
6
6
  import { EVenueSimpleTypes, EVenueTypes } from "./enums/sub/enjoy/index.js";
7
7
  import { EFoodPackageType, EFoodsModuleType } from "./enums/sub/foods/index.js";
8
8
  import { EHotelType } from "./enums/sub/hotel/index.js";
9
+ import { EUniPlatform } from "./enums/platform/index.js";
9
10
  import { IOneTravelSDKConfig } from "./types/one-travel-service/index.js";
10
11
  import { getQueryParameters, isEmpty, query2url } from "./utils/common/index.js";
11
12
  import { ActivityCalendarDetailPageParams, getActivityCalendarDetailPage } from "./utils/pages/activity-calendar/index.js";
12
13
  import { WebviewPageParams, getWebviewPage } from "./utils/pages/webview/index.js";
13
14
  import { getFoodPackagePage, getFoodStorePage } from "./utils/pages/food/index.js";
14
15
  import { getMoviePage } from "./utils/pages/movie/index.js";
15
- import { EMessagesType, navigateBack, navigateTo, postMessage, redirectTo } from "./utils/web-view/index.js";
16
- import { isAndroid, isApp, isH5, isHarmony, isWeixin, isiOS } from "./utils/uni-env/index.js";
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";
17
18
  import { checkAndRequestNativeAppPermission } from "./utils/native-app/index.js";
18
19
  import { OneTravelSDK } from "./entry.js";
19
- export { ActivityCalendarDetailPageParams, BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, ESubBizType, EVenueSimpleTypes, EVenueTypes, IOneTravelSDKConfig, OneTravelSDK, WebviewPageParams, app_permission, checkAndRequestNativeAppPermission, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getWebviewPage, isAndroid, isApp, isEmpty, isH5, isHarmony, isWeixin, isiOS, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes };
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
@@ -6,14 +6,15 @@ import { ECaller } from "./enums/sdk/index.js";
6
6
  import { EVenueSimpleTypes, EVenueTypes } from "./enums/sub/enjoy/index.js";
7
7
  import { EFoodPackageType, EFoodsModuleType } from "./enums/sub/foods/index.js";
8
8
  import { EHotelType } from "./enums/sub/hotel/index.js";
9
+ import { EUniPlatform } from "./enums/platform/index.js";
9
10
  import { getQueryParameters, isEmpty, query2url } from "./utils/common/index.js";
10
11
  import { getActivityCalendarDetailPage } from "./utils/pages/activity-calendar/index.js";
11
12
  import { getWebviewPage } from "./utils/pages/webview/index.js";
12
13
  import { getFoodPackagePage, getFoodStorePage } from "./utils/pages/food/index.js";
13
14
  import { getMoviePage } from "./utils/pages/movie/index.js";
14
- import { EMessagesType, navigateBack, navigateTo, postMessage, redirectTo } from "./utils/web-view/index.js";
15
- import { isAndroid, isApp, isH5, isHarmony, isWeixin, isiOS } from "./utils/uni-env/index.js";
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";
16
17
  import { checkAndRequestNativeAppPermission } from "./utils/native-app/index.js";
17
18
  import { OneTravelSDK } from "./entry.js";
18
19
 
19
- export { BusinessLineDict, EAppEnv, EBusinessLine, ECaller, EFoodPackageType, EFoodsModuleType, EHotelType, EMessagesType, ESubBizType, EVenueSimpleTypes, EVenueTypes, OneTravelSDK, app_permission, checkAndRequestNativeAppPermission, getActivityCalendarDetailPage, getFoodPackagePage, getFoodStorePage, getMoviePage, getQueryParameters, getWebviewPage, isAndroid, isApp, isEmpty, isH5, isHarmony, isWeixin, isiOS, navigateBack, navigateTo, postMessage, query2url, redirectTo, routePrefix, routes };
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?: EFoodPackageType) => string;
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
- if (storePrecedentType === EFoodPackageType.Enjoy) return `${domain}store/arrive/package-detail-enjoy/index${query2url({
26
+ return `${domain}store/arrive/package-detail-middle/index${query2url({
28
27
  storeId,
29
- packageId
30
- }, { encode: false })}`;
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
- declare const isWeixin: () => boolean;
12
- /**
13
- * 是否是鸿蒙
14
- * @returns
15
- */
16
- declare const isHarmony: () => boolean;
11
+
17
12
  /**
18
13
  * 是否是app
19
14
  * @returns
@@ -23,11 +18,29 @@ declare const isApp: () => boolean;
23
18
  * 是否是安卓
24
19
  * @returns
25
20
  */
26
- declare const isAndroid: () => boolean;
27
- /**
28
- * 是否是iOS
29
- * @returns
30
- */
31
- declare const isiOS: () => boolean;
21
+
22
+ declare function getSystemInfoSync(): UniApp.GetSystemInfoResult | {
23
+ pixelRatio: number;
24
+ screenWidth: number;
25
+ screenHeight: number;
26
+ windowWidth: number;
27
+ windowHeight: number;
28
+ statusBarHeight: number;
29
+ windowTop: number;
30
+ windowBottom: number;
31
+ safeArea: UniApp.SafeArea;
32
+ safeAreaInsets: UniApp.SafeAreaInsets;
33
+ screenTop: number;
34
+ deviceBrand?: string;
35
+ deviceModel: string;
36
+ deviceId: string;
37
+ deviceType: string;
38
+ devicePixelRatio: number;
39
+ deviceOrientation: "portrait" | "landscape";
40
+ brand?: string;
41
+ model: string;
42
+ system: string;
43
+ platform: string;
44
+ };
32
45
  //#endregion
33
- export { isAndroid, isApp, isH5, isHarmony, isWeixin, isiOS };
46
+ export { getSystemInfoSync, isApp, isH5 };
@@ -1,3 +1,5 @@
1
+ import { EUniPlatform } from "../../enums/platform/index.js";
2
+
1
3
  //#region src/utils/uni-env/index.ts
2
4
  /**
3
5
  * 是否是web环境
@@ -29,19 +31,19 @@ const isApp = () => {
29
31
  return true;
30
32
  };
31
33
  /**
32
- * 是否是安卓
33
- * @returns
34
- */
35
- const isAndroid = () => {
36
- return true;
37
- };
38
- /**
39
34
  * 是否是iOS
40
35
  * @returns
41
36
  */
42
37
  const isiOS = () => {
43
- return true;
38
+ if (isApp() && getSystemInfoSync().platform === EUniPlatform.ios) return true;
39
+ return false;
44
40
  };
41
+ function getSystemInfoSync() {
42
+ return {
43
+ ...uni.getDeviceInfo(),
44
+ ...uni.getWindowInfo()
45
+ };
46
+ }
45
47
 
46
48
  //#endregion
47
- export { isAndroid, isApp, isH5, isHarmony, isWeixin, isiOS };
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(res) {});
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 (window.__wxjs_environment === "miniprogram" && data.type === EMessagesType.pay) {
67
- redirectTo({
68
- src: "/pages/web-view/index",
69
- params: data.params
70
- });
71
- return;
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 };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@foundbyte/uni-libs",
3
3
  "description": "FoundByte Uni Libs",
4
4
  "author": "yangshuai <704807396@qq.com>",
5
- "version": "0.0.14",
5
+ "version": "0.1.0",
6
6
  "private": false,
7
7
  "type": "module",
8
8
  "main": "es/index.js",