@foundbyte/uni-libs 1.0.6 → 1.0.8

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.
Files changed (39) hide show
  1. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  2. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  3. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  4. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js +13 -0
  5. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutPropertiesLoose.js +12 -0
  6. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  7. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  8. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
  9. package/es/configs/app/app.hwtest.js +2 -4
  10. package/es/configs/app/app.prod.js +1 -3
  11. package/es/configs/app/index.js +13 -17
  12. package/es/constants/permission/index.js +1 -2
  13. package/es/constants/routes/index.d.ts +0 -2
  14. package/es/constants/routes/index.js +1 -3
  15. package/es/entry.js +8 -9
  16. package/es/enums/business-line/index.d.ts +64 -2
  17. package/es/enums/business-line/index.js +75 -44
  18. package/es/enums/environment/index.js +5 -6
  19. package/es/enums/platform/index.js +6 -7
  20. package/es/enums/sdk/index.js +5 -6
  21. package/es/enums/sub/enjoy/index.js +13 -14
  22. package/es/enums/sub/foods/index.js +8 -9
  23. package/es/enums/sub/hotel/index.js +4 -5
  24. package/es/index.d.ts +3 -2
  25. package/es/index.js +3 -3
  26. package/es/services/goods/service.js +123 -107
  27. package/es/services/goods/type.d.ts +70 -70
  28. package/es/utils/common/index.js +3 -4
  29. package/es/utils/native-app/index.js +8 -10
  30. package/es/utils/obs/image.d.ts +45 -0
  31. package/es/utils/obs/image.js +85 -0
  32. package/es/utils/pages/activity-calendar/index.js +1 -3
  33. package/es/utils/pages/food/index.js +1 -3
  34. package/es/utils/pages/movie/index.js +1 -3
  35. package/es/utils/pages/webview/index.js +1 -3
  36. package/es/utils/uni-env/index.d.ts +3 -53
  37. package/es/utils/uni-env/index.js +10 -62
  38. package/es/utils/web-view/index.js +45 -33
  39. package/package.json +2 -2
@@ -0,0 +1,45 @@
1
+ //#region src/utils/obs/image.d.ts
2
+ declare enum EObsSource {
3
+ /** 华为 */
4
+ Huawei = 1,
5
+ /** 腾讯 */
6
+ Tencent = 2,
7
+ /** ali */
8
+ Ali = 2,
9
+ }
10
+ /**
11
+ * 参考 https://support.huaweicloud.com/intl/zh-cn/fg-obs/obs_01_0430.html
12
+ */
13
+ type CompressOptions = {
14
+ w?: number;
15
+ h?: number;
16
+ /**
17
+ * 缩率类型,默认 'lfit'
18
+ * - `lfit`: 等比缩放,限制在容器内
19
+ * - `mfit`: 等比缩放,覆盖容器
20
+ * - `fill`: 等比缩放,裁剪填充容器
21
+ */
22
+ m?: 'lfit' | 'mfit' | 'fill';
23
+ p?: number;
24
+ l?: number;
25
+ s?: number;
26
+ color?: string;
27
+ /** 默认为 1,限制图片放大 */
28
+ limit?: 0 | 1;
29
+ q?: number;
30
+ Q?: number;
31
+ /** 是否开启图片瘦身 */
32
+ imageslim?: boolean;
33
+ /** obs 源 (huawei-华为; tencent-腾讯) */
34
+ source?: EObsSource;
35
+ };
36
+ /**
37
+ * 华为 obs 压缩
38
+ * @param url
39
+ * @param opts
40
+ * @returns
41
+ */
42
+ declare function compressHuaweiObsImg(url: string, opts: CompressOptions): string;
43
+ declare function compressObsImg(url: string, opts: CompressOptions): string;
44
+ //#endregion
45
+ export { CompressOptions, EObsSource, compressHuaweiObsImg, compressObsImg };
@@ -0,0 +1,85 @@
1
+ import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
+ //#region src/utils/obs/image.ts
3
+ let EObsSource = /* @__PURE__ */ function(EObsSource) {
4
+ /** 华为 */
5
+ EObsSource[EObsSource["Huawei"] = 1] = "Huawei";
6
+ /** 腾讯 */
7
+ EObsSource[EObsSource["Tencent"] = 2] = "Tencent";
8
+ /** ali */
9
+ EObsSource[EObsSource["Ali"] = 2] = "Ali";
10
+ return EObsSource;
11
+ }({});
12
+ function filterEmptyValue(obj) {
13
+ return (key) => {
14
+ return ![
15
+ void 0,
16
+ null,
17
+ "",
18
+ NaN
19
+ ].includes(obj[key]);
20
+ };
21
+ }
22
+ function getValues(keys, obj) {
23
+ return keys.filter(filterEmptyValue(obj)).map((key) => `${key}_${obj[key]}`);
24
+ }
25
+ /**
26
+ * 华为 obs 压缩
27
+ * @param url
28
+ * @param opts
29
+ * @returns
30
+ */
31
+ function compressHuaweiObsImg(url, opts) {
32
+ if (opts === null || opts === void 0 ? void 0 : opts.w) opts = _objectSpread2(_objectSpread2({}, opts), {}, { w: Math.floor(opts.w) });
33
+ if (opts === null || opts === void 0 ? void 0 : opts.h) opts = _objectSpread2(_objectSpread2({}, opts), {}, { h: Math.floor(opts.h) });
34
+ const { imageslim = true } = opts;
35
+ if (url && [
36
+ ".jpg",
37
+ ".jpeg",
38
+ ".png",
39
+ ".bmp"
40
+ ].some((suffix) => url.toLowerCase().endsWith(suffix))) {
41
+ const actions = ["x-image-process=image"];
42
+ const resize = getValues([
43
+ "w",
44
+ "h",
45
+ "m",
46
+ "p",
47
+ "l",
48
+ "s",
49
+ "color",
50
+ "limit"
51
+ ], opts);
52
+ if (resize.length) {
53
+ resize.splice(0, 0, "resize");
54
+ actions.push(resize.join(","));
55
+ }
56
+ const quality = getValues(["q", "Q"], opts);
57
+ if (quality.length) {
58
+ quality.splice(0, 0, "quality");
59
+ actions.push(quality.join(","));
60
+ }
61
+ if (imageslim) actions.push("imageslim");
62
+ return `${url}?${actions.join("/")}`;
63
+ }
64
+ return url;
65
+ }
66
+ /**
67
+ * 腾讯 obs 压缩
68
+ * https://cloud.tencent.com/document/product/436/113295
69
+ * @param url
70
+ * @param opts
71
+ * @returns
72
+ */
73
+ function compressTencentObsImg(url, opts) {
74
+ if (opts.w || opts.h) return `${url}?imageMogr2/thumbnail/!${opts.w || ""}x${opts.h || ""}r`;
75
+ return url;
76
+ }
77
+ function compressObsImg(url, opts) {
78
+ switch (opts.source) {
79
+ case EObsSource.Huawei: return compressHuaweiObsImg(url, opts);
80
+ case EObsSource.Ali: return compressHuaweiObsImg(url, opts);
81
+ default: return compressTencentObsImg(url, opts);
82
+ }
83
+ }
84
+ //#endregion
85
+ export { EObsSource, compressHuaweiObsImg, compressObsImg };
@@ -1,11 +1,9 @@
1
1
  import { routePrefix } from "../../../constants/routes/index.js";
2
2
  import { query2url } from "../../common/index.js";
3
-
4
3
  //#region src/utils/pages/activity-calendar/index.ts
5
4
  const rootPage = routePrefix.activityCalendar;
6
5
  function getActivityCalendarDetailPage(params) {
7
6
  return `${rootPage}/detail/index${query2url(params, { encode: false })}`;
8
7
  }
9
-
10
8
  //#endregion
11
- export { getActivityCalendarDetailPage };
9
+ export { getActivityCalendarDetailPage };
@@ -1,5 +1,4 @@
1
1
  import { query2url } from "../../common/index.js";
2
-
3
2
  //#region src/utils/pages/food/index.ts
4
3
  /**
5
4
  * 店铺
@@ -29,6 +28,5 @@ const getFoodPackagePage = (domain, storeId, packageId, storePrecedentType) => {
29
28
  storePrecedentType
30
29
  }, { encode: false })}`;
31
30
  };
32
-
33
31
  //#endregion
34
- export { getFoodPackagePage, getFoodStorePage };
32
+ export { getFoodPackagePage, getFoodStorePage };
@@ -1,5 +1,4 @@
1
1
  import { query2url } from "../../common/index.js";
2
-
3
2
  //#region src/utils/pages/movie/index.ts
4
3
  /**
5
4
  * 电影票地址
@@ -10,6 +9,5 @@ const getMoviePage = (domain, movie_id) => {
10
9
  movie_id
11
10
  }, { encode: false })}`;
12
11
  };
13
-
14
12
  //#endregion
15
- export { getMoviePage };
13
+ export { getMoviePage };
@@ -1,10 +1,8 @@
1
1
  import { routes } from "../../../constants/routes/index.js";
2
2
  import { query2url } from "../../common/index.js";
3
-
4
3
  //#region src/utils/pages/webview/index.ts
5
4
  function getWebviewPage(params) {
6
5
  return `${routes.webView}${query2url(params)}`;
7
6
  }
8
-
9
7
  //#endregion
10
- export { getWebviewPage };
8
+ export { getWebviewPage };
@@ -1,61 +1,11 @@
1
1
  //#region src/utils/uni-env/index.d.ts
2
- /**
3
- * 是否是支付宝小程序
4
- * @returns
5
- */
6
2
  declare const isAlipayEnv: () => boolean;
7
- /**
8
- * 是否是web环境
9
- * @returns
10
- */
11
3
  declare const isH5Env: () => boolean;
12
- /**
13
- * 是否是微信小程序
14
- * @returns
15
- */
16
4
  declare const isWeixinEnv: () => boolean;
17
- /**
18
- * 是否是鸿蒙
19
- * @returns
20
- */
21
- declare const isHarmonyEnv: () => boolean;
22
- /**
23
- * 是否是app
24
- * @returns
25
- */
5
+ declare const isToutiaoEnv: () => boolean;
26
6
  declare const isAppEnv: () => boolean;
27
- /**
28
- * 是否是安卓
29
- * @returns
30
- */
7
+ declare const isHarmonyEnv: () => boolean;
31
8
  declare const isAndroidEnv: () => boolean;
32
- /**
33
- * 是否是iOS
34
- * @returns
35
- */
36
9
  declare const isiOSEnv: () => boolean;
37
- declare function getSystemInfoSync(): UniApp.GetSystemInfoResult | {
38
- pixelRatio: number;
39
- screenWidth: number;
40
- screenHeight: number;
41
- windowWidth: number;
42
- windowHeight: number;
43
- statusBarHeight: number;
44
- windowTop: number;
45
- windowBottom: number;
46
- safeArea: UniApp.SafeArea;
47
- safeAreaInsets: UniApp.SafeAreaInsets;
48
- screenTop: number;
49
- deviceBrand?: string;
50
- deviceModel: string;
51
- deviceId: string;
52
- deviceType: string;
53
- devicePixelRatio: number;
54
- deviceOrientation: "portrait" | "landscape";
55
- brand?: string;
56
- model: string;
57
- system: string;
58
- platform: string;
59
- };
60
10
  //#endregion
61
- export { getSystemInfoSync, isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isWeixinEnv, isiOSEnv };
11
+ export { isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isToutiaoEnv, isWeixinEnv, isiOSEnv };
@@ -1,64 +1,12 @@
1
- import { EUniPlatform } from "../../enums/platform/index.js";
2
-
1
+ import { isAlipay, isAndroid, isApp, isH5, isHarmony, isToutiao, isWeixin, isiOS } from "@foundbyte/uni-hooks";
3
2
  //#region src/utils/uni-env/index.ts
4
- /**
5
- * 是否是支付宝小程序
6
- * @returns
7
- */
8
- const isAlipayEnv = () => {
9
- return true;
10
- };
11
- /**
12
- * 是否是web环境
13
- * @returns
14
- */
15
- const isH5Env = () => {
16
- return true;
17
- };
18
- /**
19
- * 是否是微信小程序
20
- * @returns
21
- */
22
- const isWeixinEnv = () => {
23
- return true;
24
- };
25
- /**
26
- * 是否是鸿蒙
27
- * @returns
28
- */
29
- const isHarmonyEnv = () => {
30
- return true;
31
- };
32
- /**
33
- * 是否是app
34
- * @returns
35
- */
36
- const isAppEnv = () => {
37
- if (isHarmonyEnv()) return true;
38
- return true;
39
- };
40
- /**
41
- * 是否是安卓
42
- * @returns
43
- */
44
- const isAndroidEnv = () => {
45
- if (isAppEnv() && getSystemInfoSync().platform === EUniPlatform.android) return true;
46
- return false;
47
- };
48
- /**
49
- * 是否是iOS
50
- * @returns
51
- */
52
- const isiOSEnv = () => {
53
- if (isAppEnv() && getSystemInfoSync().platform === EUniPlatform.ios) return true;
54
- return false;
55
- };
56
- function getSystemInfoSync() {
57
- return {
58
- ...uni.getDeviceInfo(),
59
- ...uni.getWindowInfo()
60
- };
61
- }
62
-
3
+ const isAlipayEnv = isAlipay;
4
+ const isH5Env = isH5;
5
+ const isWeixinEnv = isWeixin;
6
+ const isToutiaoEnv = isToutiao;
7
+ const isAppEnv = isApp;
8
+ const isHarmonyEnv = isHarmony;
9
+ const isAndroidEnv = isAndroid;
10
+ const isiOSEnv = isiOS;
63
11
  //#endregion
64
- export { getSystemInfoSync, isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isWeixinEnv, isiOSEnv };
12
+ export { isAlipayEnv, isAndroidEnv, isAppEnv, isH5Env, isHarmonyEnv, isToutiaoEnv, isWeixinEnv, isiOSEnv };
@@ -1,6 +1,9 @@
1
+ import { _asyncToGenerator } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
2
+ import { _objectWithoutProperties } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
3
+ import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
1
4
  import wx from "weixin-js-sdk";
2
-
3
5
  //#region src/utils/web-view/index.ts
6
+ const _excluded = ["shareUrl"];
4
7
  const userAgent = navigator.userAgent.toLowerCase();
5
8
  /** 判断是否是iOS还是安卓 */
6
9
  const isIOSOrAndroid = !userAgent.includes("miniprogram") && (userAgent.includes("android") || userAgent.includes("iphone") || userAgent.includes("ipad"));
@@ -15,27 +18,33 @@ const isAndroid = !userAgent.includes("miniprogram") && userAgent.includes("andr
15
18
  /** 判断是否苹果APP */
16
19
  const isiOS = !userAgent.includes("miniprogram") && (userAgent.includes("iphone") || userAgent.includes("ipad"));
17
20
  let uni = {};
18
- async function loadWebview() {
19
- if (isIOSOrAndroid) uni = (await import("../../assets/js/webview/uni.webview.1.5.6.js")).default;
20
- else uni = (await import("../../assets/js/webview/uni.webview.1.5.5.js")).default;
21
- if (isAlipay) {
22
- const scriptTag = document.createElement("script");
23
- scriptTag.src = "https://appx/web-view.min.js";
24
- document.head.appendChild(scriptTag);
25
- }
21
+ function loadWebview() {
22
+ return _loadWebview.apply(this, arguments);
23
+ }
24
+ function _loadWebview() {
25
+ _loadWebview = _asyncToGenerator(function* () {
26
+ if (isIOSOrAndroid) uni = (yield import("../../assets/js/webview/uni.webview.1.5.6.js")).default;
27
+ else uni = (yield import("../../assets/js/webview/uni.webview.1.5.5.js")).default;
28
+ if (isAlipay) {
29
+ const scriptTag = document.createElement("script");
30
+ scriptTag.src = "https://appx/web-view.min.js";
31
+ document.head.appendChild(scriptTag);
32
+ }
33
+ });
34
+ return _loadWebview.apply(this, arguments);
26
35
  }
27
36
  loadWebview();
28
37
  document.addEventListener("UniAppJSBridgeReady", function() {
29
38
  uni.webView.getEnv(function(_) {});
30
39
  });
31
- let EMessagesType = /* @__PURE__ */ function(EMessagesType$1) {
40
+ let EMessagesType = /* @__PURE__ */ function(EMessagesType) {
32
41
  /** app直接调用分享 */
33
- EMessagesType$1["share"] = "share";
42
+ EMessagesType["share"] = "share";
34
43
  /** 设置分享参数 */
35
- EMessagesType$1["shareParam"] = "shareParam";
44
+ EMessagesType["shareParam"] = "shareParam";
36
45
  /** 去支付 */
37
- EMessagesType$1["pay"] = "pay";
38
- return EMessagesType$1;
46
+ EMessagesType["pay"] = "pay";
47
+ return EMessagesType;
39
48
  }({});
40
49
  /**
41
50
  * 原生路由跳转
@@ -45,10 +54,11 @@ const navigateTo = (parameters) => {
45
54
  const { src, params } = parameters;
46
55
  const url = `${src}${params ? `?${objectToQueryString(params)}` : ""}`;
47
56
  try {
48
- uni?.webView?.navigateTo?.({ url });
57
+ var _uni$webView, _uni$webView$navigate, _my;
58
+ uni === null || uni === void 0 || (_uni$webView = uni.webView) === null || _uni$webView === void 0 || (_uni$webView$navigate = _uni$webView.navigateTo) === null || _uni$webView$navigate === void 0 || _uni$webView$navigate.call(_uni$webView, { url });
49
59
  /** 不兼容上面的方法会自动往下执行 */
50
- wx.miniProgram.navigateTo({ url });
51
- my?.navigateTo({ url });
60
+ wx === null || wx === void 0 || wx.miniProgram.navigateTo({ url });
61
+ (_my = my) === null || _my === void 0 || _my.navigateTo({ url });
52
62
  } catch (error) {
53
63
  console.error(error);
54
64
  }
@@ -61,10 +71,11 @@ const redirectTo = (parameters) => {
61
71
  const { src, params } = parameters;
62
72
  const url = `${src}${params ? `?${objectToQueryString(params)}` : ""}`;
63
73
  try {
64
- uni?.webView?.redirectTo?.({ url });
74
+ var _uni$webView2, _uni$webView2$redirec, _my2;
75
+ uni === null || uni === void 0 || (_uni$webView2 = uni.webView) === null || _uni$webView2 === void 0 || (_uni$webView2$redirec = _uni$webView2.redirectTo) === null || _uni$webView2$redirec === void 0 || _uni$webView2$redirec.call(_uni$webView2, { url });
65
76
  /** 不兼容上面的方法会自动往下执行 */
66
- wx.miniProgram.redirectTo({ url });
67
- my?.redirectTo({ url });
77
+ wx === null || wx === void 0 || wx.miniProgram.redirectTo({ url });
78
+ (_my2 = my) === null || _my2 === void 0 || _my2.redirectTo({ url });
68
79
  } catch (error) {
69
80
  console.error(error);
70
81
  }
@@ -75,10 +86,11 @@ const redirectTo = (parameters) => {
75
86
  */
76
87
  const navigateBack = (parameters) => {
77
88
  try {
78
- uni?.webView?.navigateBack?.(parameters);
89
+ var _uni$webView3, _uni$webView3$navigat, _my3;
90
+ uni === null || uni === void 0 || (_uni$webView3 = uni.webView) === null || _uni$webView3 === void 0 || (_uni$webView3$navigat = _uni$webView3.navigateBack) === null || _uni$webView3$navigat === void 0 || _uni$webView3$navigat.call(_uni$webView3, parameters);
79
91
  /** 不兼容上面的方法会自动往下执行 */
80
- wx.miniProgram.navigateBack(parameters);
81
- my?.navigateBack(parameters);
92
+ wx === null || wx === void 0 || wx.miniProgram.navigateBack(parameters);
93
+ (_my3 = my) === null || _my3 === void 0 || _my3.navigateBack(parameters);
82
94
  } catch (error) {
83
95
  console.error(error);
84
96
  }
@@ -98,11 +110,13 @@ const postMessage = (data) => {
98
110
  }
99
111
  }
100
112
  try {
101
- uni?.webView?.postMessage({ data });
102
- wx.miniProgram.postMessage({ data });
103
- my?.postMessage({ data });
113
+ var _uni$webView4, _my4;
114
+ uni === null || uni === void 0 || (_uni$webView4 = uni.webView) === null || _uni$webView4 === void 0 || _uni$webView4.postMessage({ data });
115
+ wx === null || wx === void 0 || wx.miniProgram.postMessage({ data });
116
+ (_my4 = my) === null || _my4 === void 0 || _my4.postMessage({ data });
104
117
  } catch (error) {
105
- if (error?.message?.includes("my is not defined")) return;
118
+ var _message;
119
+ if (error === null || error === void 0 || (_message = error.message) === null || _message === void 0 ? void 0 : _message.includes("my is not defined")) return;
106
120
  console.error(error);
107
121
  }
108
122
  };
@@ -111,12 +125,11 @@ const postMessage = (data) => {
111
125
  * @param data
112
126
  */
113
127
  const setShareParam = (data, businessType) => {
114
- const { shareUrl, ...res } = data;
115
- const params = { data: {
116
- ...res,
128
+ const { shareUrl } = data;
129
+ const params = { data: _objectSpread2(_objectSpread2({}, _objectWithoutProperties(data, _excluded)), {}, {
117
130
  businessType,
118
131
  shareUrl: encodeURIComponent(shareUrl || "")
119
- } };
132
+ }) };
120
133
  postMessage({
121
134
  type: EMessagesType.shareParam,
122
135
  params
@@ -141,6 +154,5 @@ function objectToQueryString(obj) {
141
154
  return `${encodeURI(key)}=${encodeURI(value)}`;
142
155
  }).join("&");
143
156
  }
144
-
145
157
  //#endregion
146
- export { EMessagesType, isAlipay, isAndroid, isHarmony, isIOSOrAndroid, isWeixin, isiOS, navigateBack, navigateTo, postMessage, redirectTo, setShareParam, toPay };
158
+ export { EMessagesType, isAlipay, isAndroid, isHarmony, isIOSOrAndroid, isWeixin, isiOS, 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": "1.0.6",
5
+ "version": "1.0.8",
6
6
  "private": false,
7
7
  "type": "module",
8
8
  "main": "es/index.js",
@@ -19,7 +19,7 @@
19
19
  "sideEffects": false,
20
20
  "dependencies": {
21
21
  "weixin-js-sdk": "^1.6.5",
22
- "@foundbyte/uni-hooks": "^1.0.4"
22
+ "@foundbyte/uni-hooks": "^1.0.6"
23
23
  },
24
24
  "devDependencies": {
25
25
  "typescript": "~5.7.2",