@foundbyte/uni-libs 0.0.1-alpha.1
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/es/index.d.ts +1 -0
- package/es/index.js +10 -0
- package/es/web-view/index.d.ts +38 -0
- package/es/web-view/index.js +51 -0
- package/package.json +34 -0
package/es/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './web-view';
|
package/es/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { EMessagesType as a, EWebViewMessages as g, getWebViewEnv as t, navigateBack as i, navigateTo as o, postMessage as r, redirectTo as n } from "./web-view/index.js";
|
|
2
|
+
export {
|
|
3
|
+
a as EMessagesType,
|
|
4
|
+
g as EWebViewMessages,
|
|
5
|
+
t as getWebViewEnv,
|
|
6
|
+
i as navigateBack,
|
|
7
|
+
o as navigateTo,
|
|
8
|
+
r as postMessage,
|
|
9
|
+
n as redirectTo
|
|
10
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare enum EWebViewMessages {
|
|
2
|
+
navigateTo = "navigateTo"
|
|
3
|
+
}
|
|
4
|
+
export declare enum EMessagesType {
|
|
5
|
+
pay = "pay"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 当前环境
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare const getWebViewEnv: () => {};
|
|
12
|
+
/**
|
|
13
|
+
* 原生路由跳转
|
|
14
|
+
* @param src
|
|
15
|
+
* @param params
|
|
16
|
+
*/
|
|
17
|
+
export declare const navigateTo: <T = any>(src: string, params?: T) => void;
|
|
18
|
+
/**
|
|
19
|
+
* 原生路由重定向
|
|
20
|
+
* @param src
|
|
21
|
+
* @param params
|
|
22
|
+
*/
|
|
23
|
+
export declare const redirectTo: <T = any>(src: string, params?: T) => void;
|
|
24
|
+
/**
|
|
25
|
+
* 原生路由返回
|
|
26
|
+
* @param param
|
|
27
|
+
*/
|
|
28
|
+
export declare const navigateBack: (param: {
|
|
29
|
+
delta: 1;
|
|
30
|
+
}) => void;
|
|
31
|
+
/**
|
|
32
|
+
* 发送消息
|
|
33
|
+
* @param data
|
|
34
|
+
*/
|
|
35
|
+
export declare const postMessage: (data: {
|
|
36
|
+
type?: EMessagesType;
|
|
37
|
+
params: any;
|
|
38
|
+
}) => void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import a from "weixin-js-sdk";
|
|
2
|
+
let c = {};
|
|
3
|
+
document.addEventListener("UniAppJSBridgeReady", function() {
|
|
4
|
+
uni.webView.getEnv(function(e) {
|
|
5
|
+
c = e;
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
var g = /* @__PURE__ */ ((e) => (e.navigateTo = "navigateTo", e))(g || {}), u = /* @__PURE__ */ ((e) => (e.pay = "pay", e))(u || {});
|
|
9
|
+
const p = () => c, v = (e, n) => {
|
|
10
|
+
var r, t;
|
|
11
|
+
const o = `${e}${n ? `?${s(n)}` : ""}`;
|
|
12
|
+
try {
|
|
13
|
+
(t = (r = uni == null ? void 0 : uni.webView) == null ? void 0 : r.navigateTo) == null || t.call(r, { url: o }), a.miniProgram.navigateTo({ url: o });
|
|
14
|
+
} catch (i) {
|
|
15
|
+
console.error(i);
|
|
16
|
+
}
|
|
17
|
+
}, w = (e, n) => {
|
|
18
|
+
var r, t;
|
|
19
|
+
const o = `${e}${n ? `?${s(n)}` : ""}`;
|
|
20
|
+
try {
|
|
21
|
+
(t = (r = uni == null ? void 0 : uni.webView) == null ? void 0 : r.redirectTo) == null || t.call(r, { url: o }), a.miniProgram.redirectTo({ url: o });
|
|
22
|
+
} catch (i) {
|
|
23
|
+
console.error(i);
|
|
24
|
+
}
|
|
25
|
+
}, d = (e) => {
|
|
26
|
+
var n, o;
|
|
27
|
+
try {
|
|
28
|
+
(o = (n = uni == null ? void 0 : uni.webView) == null ? void 0 : n.navigateBack) == null || o.call(n, e), a.miniProgram.navigateBack(e);
|
|
29
|
+
} catch (r) {
|
|
30
|
+
console.error(r);
|
|
31
|
+
}
|
|
32
|
+
}, y = (e) => {
|
|
33
|
+
var n;
|
|
34
|
+
if (window.__wxjs_environment === "miniprogram" && e.type === "pay") {
|
|
35
|
+
w("/pages/web-view/index", e.params);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
(n = uni == null ? void 0 : uni.webView) == null || n.postMessage({ data: e });
|
|
39
|
+
};
|
|
40
|
+
function s(e) {
|
|
41
|
+
return Object.entries(e).map(([o, r]) => Array.isArray(r) ? r.map((t) => `${encodeURI(o)}[]=${encodeURI(t)}`).join("&") : `${encodeURI(o)}=${encodeURI(r)}`).join("&");
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
u as EMessagesType,
|
|
45
|
+
g as EWebViewMessages,
|
|
46
|
+
p as getWebViewEnv,
|
|
47
|
+
d as navigateBack,
|
|
48
|
+
v as navigateTo,
|
|
49
|
+
y as postMessage,
|
|
50
|
+
w as redirectTo
|
|
51
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@foundbyte/uni-libs",
|
|
3
|
+
"description": "FoundByte Uni Libs",
|
|
4
|
+
"author": "yangshuai <704807396@qq.com>",
|
|
5
|
+
"version": "0.0.1-alpha.01",
|
|
6
|
+
"private": false,
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "es/index.js",
|
|
9
|
+
"module": "es/index.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"es",
|
|
12
|
+
"package.json",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"registry": "https://registry.npmjs.org/",
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"weixin-js-sdk": "^1.6.5"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "~5.7.2",
|
|
25
|
+
"@types/node": "^22.10.2",
|
|
26
|
+
"vite": "^6.2.1",
|
|
27
|
+
"vite-plugin-dts": "^4.5.3"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "vite build",
|
|
31
|
+
"publish:npm": "pnpm publish"
|
|
32
|
+
},
|
|
33
|
+
"typings": "es/index.d.ts"
|
|
34
|
+
}
|