v3-utils-lib 1.0.0 → 1.0.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/dist/Page.js CHANGED
@@ -1,21 +1 @@
1
- import { reactive as e } from "vue";
2
- //#region src/Page.js
3
- function t(t) {
4
- let n = e({
5
- pageNum: 1,
6
- pageSize: 10,
7
- total: 0
8
- });
9
- return {
10
- pageInfo: n,
11
- PageIndexChange: (e) => {
12
- if (e !== n.pageNum) return n.pageNum = e, t();
13
- },
14
- SizeChange: (e) => {
15
- if (e !== n.pageSize) return n.pageSize = e, t();
16
- },
17
- ResetPage: () => (n.pageNum = 1, t())
18
- };
19
- }
20
- //#endregion
21
- export { t as page };
1
+ import"vue";
@@ -1,38 +1 @@
1
- import { hideLoadMask as e, showLoadMask as t } from "./loadMask.js";
2
- import n from "./request.js";
3
- //#region src/SuccessAjax.js
4
- async function r(r, i = {}, a = {}) {
5
- let o = {
6
- method: "GET",
7
- fullscreen: !0,
8
- needToken: !0,
9
- loadingText: "加载中...",
10
- pageInfo: null,
11
- isFormData: !1,
12
- headers: {},
13
- ...a
14
- }, s = o.method.toUpperCase();
15
- o.fullscreen && t(o.loadingText);
16
- let c = {
17
- ...o.headers,
18
- needToken: String(o.needToken)
19
- }, l = i;
20
- o.pageInfo && (o.isFormData ? (l.append("pageNum", o.pageInfo.pageNum), l.append("pageSize", o.pageInfo.pageSize)) : l = {
21
- ...i,
22
- ...o.pageInfo
23
- }), o.isFormData && delete c["Content-Type"];
24
- let u = {
25
- url: r,
26
- method: s,
27
- headers: c,
28
- ...o
29
- };
30
- return s === "GET" || s === "DELETE" ? u.params = l : u.data = l, n(u).then((e) => {
31
- let t = e.data ?? e;
32
- return o.pageInfo && t.total && (o.pageInfo.total = t.total), t;
33
- }).catch((e) => Promise.reject(e)).finally(() => {
34
- o.fullscreen && e();
35
- });
36
- }
37
- //#endregion
38
- export { r as default };
1
+ import"./request.js";
@@ -1,2 +1 @@
1
- import { n as e, r as t, t as n } from "./src-DLRBzo3h.js";
2
- export { n as generateRoutes, e as routeStore, t as routerUtils };
1
+ import"./v3-utils-lib.js";
package/dist/loadMask.js CHANGED
@@ -1,31 +0,0 @@
1
- //#region src/loadMask.js
2
- var e = null, t = 0;
3
- function n(n = "加载中...") {
4
- if (t++, e) {
5
- e.style.display = "flex", e.querySelector(".load-text").innerText = n;
6
- return;
7
- }
8
- let r = document.createElement("div");
9
- r.id = "global-loading-mask", r.innerHTML = `
10
- <div class="load-box">
11
- <div class="load-spinner"></div>
12
- <div class="load-text">${n}</div>
13
- </div>
14
- `, r.style.cssText = "\n position: fixed; top: 0; left: 0; right: 0; bottom: 0;\n background: rgba(0, 0, 0, 0.5);\n display: flex; align-items: center; justify-content: center;\n z-index: 99999; color: #fff;\n user-select: none;\n ";
15
- let i = r.querySelector(".load-box");
16
- i.style.cssText = "\n display: flex; flex-direction: column; align-items: center; gap: 12px;\n ";
17
- let a = r.querySelector(".load-spinner");
18
- a.style.cssText = "\n width: 36px; height: 36px;\n border: 3px solid rgba(255,255,255,.3);\n border-top: 3px solid #fff;\n border-radius: 50%;\n animation: spin 0.8s linear infinite;\n ";
19
- let o = r.querySelector(".load-text");
20
- o.style.cssText = "\n font-size: 14px; text-shadow: 0 1px 2px rgba(0,0,0,.2);\n ";
21
- let s = document.createElement("style");
22
- s.innerHTML = "@keyframes spin { to { transform: rotate(360deg); } }", document.head.appendChild(s), document.body.appendChild(r), e = r;
23
- }
24
- function r() {
25
- t--, t <= 0 && (t = 0, e && (e.style.display = "none"));
26
- }
27
- function i() {
28
- t = 0, e && (e.style.display = "none");
29
- }
30
- //#endregion
31
- export { i as forceHideLoadMask, r as hideLoadMask, n as showLoadMask };
package/dist/request.js CHANGED
@@ -1,51 +1 @@
1
- import e from "axios";
2
- //#region src/request.js
3
- var t = null, n = "/api", r = 1e4, i = null;
4
- function a(e = {}) {
5
- e.refreshTokenApi && (t = e.refreshTokenApi), e.baseURL && (n = e.baseURL), e.timeout && (r = e.timeout), e.errorHandler && (i = e.errorHandler);
6
- }
7
- var o = e.create({
8
- baseURL: n,
9
- timeout: r
10
- }), s = !1, c = [];
11
- o.interceptors.request.use((e) => {
12
- let { needToken: t } = e;
13
- if (t) {
14
- let t = sessionStorage.getItem("loginInfo");
15
- if (!t) return Promise.reject({ response: {
16
- status: 401,
17
- data: { message: "未登录,请先登录" }
18
- } });
19
- let n = JSON.parse(t).accessToken;
20
- n && (e.headers.Authorization = n);
21
- }
22
- return e;
23
- }, (e) => Promise.reject(e)), o.interceptors.response.use((e) => {
24
- let { code: t, msg: n } = e.data;
25
- return t != 200 && (i || console.error)(n || "请求失败"), e.data;
26
- }, async (e) => {
27
- let n = e.config;
28
- if (e.response?.status === 401 && !n._retry) {
29
- if (s) return new Promise((e) => {
30
- c.push((t) => {
31
- n.headers.Authorization = t, e(o(n));
32
- });
33
- });
34
- n._retry = !0, s = !0;
35
- try {
36
- let e = JSON.parse(sessionStorage.getItem("loginInfo")), r = e?.refreshToken;
37
- if (!r) throw Error("refreshToken 不存在");
38
- if (!t) throw Error("未配置 refreshTokenApi");
39
- let i = (await t({ refreshToken: r })).data.accessToken;
40
- return e.accessToken = i, sessionStorage.setItem("loginInfo", JSON.stringify(e)), c.forEach((e) => e(i)), c = [], n.headers.Authorization = i, o(n);
41
- } catch (e) {
42
- return sessionStorage.clear(), window.location.href = "/login", Promise.reject(e);
43
- } finally {
44
- s = !1;
45
- }
46
- }
47
- let r = e?.response?.data?.msg || "请求失败";
48
- return i && i(r), Promise.reject(e);
49
- });
50
- //#endregion
51
- export { a as configRequest, o as default };
1
+ import e from"axios";var t=null,n=`/api`,r=1e4,i=null,a=e.create({baseURL:n,timeout:r}),o=!1,s=[];a.interceptors.request.use(e=>{let{needToken:t}=e;if(t){let t=sessionStorage.getItem(`loginInfo`);if(!t)return Promise.reject({response:{status:401,data:{message:`未登录,请先登录`}}});let n=JSON.parse(t).accessToken;n&&(e.headers.Authorization=n)}return e},e=>Promise.reject(e)),a.interceptors.response.use(e=>{let{code:t,msg:n}=e.data;return t!=200&&(i||console.error)(n||`请求失败`),e.data},async e=>{let n=e.config;if(e.response?.status===401&&!n._retry){if(o)return new Promise(e=>{s.push(t=>{n.headers.Authorization=t,e(a(n))})});n._retry=!0,o=!0;try{let e=JSON.parse(sessionStorage.getItem(`loginInfo`)),r=e?.refreshToken;if(!r)throw Error(`refreshToken 不存在`);if(!t)throw Error(`未配置 refreshTokenApi`);let i=(await t({refreshToken:r})).data.accessToken;return e.accessToken=i,sessionStorage.setItem(`loginInfo`,JSON.stringify(e)),s.forEach(e=>e(i)),s=[],n.headers.Authorization=i,a(n)}catch(e){return sessionStorage.clear(),window.location.href=`/login`,Promise.reject(e)}finally{o=!1}}let r=e?.response?.data?.msg||`请求失败`;return i&&i(r),Promise.reject(e)});export{a as default};
@@ -0,0 +1 @@
1
+ import"./Page.js";import"./generateRoutes.js";import"./request.js";import"./SuccessAjax.js";
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "v3-utils-lib",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "前端工具函数库:路由生成、请求封装、分页、加载遮罩",
5
5
  "type": "module",
6
- "main": "./dist/utils-lib.cjs",
7
- "module": "./dist/utils-lib.js",
6
+ "main": "./dist/v3-utils-lib.cjs",
7
+ "module": "./dist/v3-utils-lib.js",
8
8
  "exports": {
9
- ".": "./dist/utils-lib.js",
9
+ ".": "./dist/v3-utils-lib.js",
10
10
  "./loadMask": "./dist/loadMask.js",
11
11
  "./Page": "./dist/Page.js",
12
12
  "./generateRoutes": "./dist/generateRoutes.js",
@@ -1,76 +0,0 @@
1
- import { forceHideLoadMask as e, hideLoadMask as t, showLoadMask as n } from "./loadMask.js";
2
- import { page as r } from "./Page.js";
3
- import i from "./request.js";
4
- import a from "./SuccessAjax.js";
5
- //#region \0rolldown/runtime.js
6
- var o = Object.defineProperty, s = (e, t) => {
7
- let n = {};
8
- for (var r in e) o(n, r, {
9
- get: e[r],
10
- enumerable: !0
11
- });
12
- return t || o(n, Symbol.toStringTag, { value: "Module" }), n;
13
- }, c = {};
14
- function l(e, t) {
15
- try {
16
- let n = (/* @__PURE__ */ Error()).stack.split("\n"), r = (n[3] || n[2]).match(/(\/src\/.*?\.js)/), i = r ? r[1] : "unknown";
17
- setTimeout(() => {
18
- c[i] = {
19
- options: e,
20
- meta: t
21
- };
22
- }, 0);
23
- } catch {}
24
- }
25
- function u(e) {
26
- let t = /* @__PURE__ */ Object.assign({ "/src/index.js": d }), n = [];
27
- for (let r in t) {
28
- if (!r.startsWith(e)) continue;
29
- let i = t[r].component, a = c[r] || {};
30
- if (!i) continue;
31
- let o = r.replace(e, "").replace("/index.js", "").replace(/\[(\w+)\]/g, ":$1");
32
- o === "" && (o = "/");
33
- let s = o.split("/").filter(Boolean).map((e) => e[0].toUpperCase() + e.slice(1)).join("");
34
- n.push({
35
- filePath: r,
36
- path: o,
37
- name: s,
38
- component: i,
39
- ...a.options,
40
- meta: a.meta || {},
41
- children: []
42
- });
43
- }
44
- function r(t, n = "") {
45
- return t.filter((t) => {
46
- if (!t.filePath) return !1;
47
- let r = t.filePath.replace("/index.js", ""), i = `${e}${n}`;
48
- return RegExp(`^${i}\\/[^\\/]+$`).test(r);
49
- }).map((e) => {
50
- let i = { ...e };
51
- if (n !== "") {
52
- let e = i.path.split("/");
53
- i.path = e[e.length - 1];
54
- } else i.path.startsWith("/") || (i.path = "/" + i.path);
55
- i.children = r(t, i.path), i.children?.length || delete i.children;
56
- let { filePath: a, ...o } = i;
57
- return o;
58
- });
59
- }
60
- return r(n);
61
- }
62
- //#endregion
63
- //#region src/index.js
64
- var d = /* @__PURE__ */ s({
65
- SuccessAjax: () => a,
66
- forceHideLoadMask: () => e,
67
- generateRoutes: () => u,
68
- hideLoadMask: () => t,
69
- page: () => r,
70
- routeStore: () => c,
71
- routerUtils: () => l,
72
- service: () => i,
73
- showLoadMask: () => n
74
- });
75
- //#endregion
76
- export { c as n, l as r, u as t };
package/dist/utils-lib.js DELETED
@@ -1,6 +0,0 @@
1
- import { n as e, r as t, t as n } from "./src-DLRBzo3h.js";
2
- import { forceHideLoadMask as r, hideLoadMask as i, showLoadMask as a } from "./loadMask.js";
3
- import { page as o } from "./Page.js";
4
- import s from "./request.js";
5
- import c from "./SuccessAjax.js";
6
- export { c as SuccessAjax, r as forceHideLoadMask, n as generateRoutes, i as hideLoadMask, o as page, e as routeStore, t as routerUtils, s as service, a as showLoadMask };