@fmdevui/fm-dev 1.0.44 → 1.0.45

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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! fm-dev v1.0.44 */
1
+ /*! fm-dev v1.0.45 */
2
2
  import { defineComponent, reactive, computed, watch, resolveComponent, createBlock, openBlock, withCtx, createVNode, createElementVNode, createTextVNode, toDisplayString as toDisplayString$1, withDirectives, createElementBlock, Fragment, renderList, vShow, ref, onMounted, nextTick, normalizeStyle, createCommentVNode, normalizeClass, withModifiers, resolveDynamicComponent, effectScope, getCurrentInstance, shallowRef, isRef as isRef$1, inject, onUnmounted, h, Text, markRaw, toRaw as toRaw$1, hasInjectionContext, unref, isReactive as isReactive$1, toRef, getCurrentScope, onScopeDispose, toRefs, resolveDirective } from 'vue';
3
3
  import crypto from 'crypto';
4
4
  import require$$0 from 'url';
@@ -8,7 +8,7 @@ import util from 'util';
8
8
  import stream, { Readable } from 'stream';
9
9
  import require$$4 from 'assert';
10
10
  import zlib from 'zlib';
11
- import { ElMessage, dayjs } from 'element-plus';
11
+ import { ElMessage, ElLoading, dayjs } from 'element-plus';
12
12
 
13
13
  const _hoisted_1$3 = { class: "fm-transfer-panel" };
14
14
  const _hoisted_2$2 = { class: "fm-transfer-panel__header" };
@@ -29524,8 +29524,34 @@ const clearAccessTokens = () => {
29524
29524
  window.location.reload();
29525
29525
  };
29526
29526
  const axiosInstance = axios;
29527
+ let loadingCount = 0;
29528
+ let loadingInstance = null;
29529
+ function startLoading() {
29530
+ if (loadingCount === 0) {
29531
+ loadingInstance = ElLoading.service({
29532
+ lock: true,
29533
+ text: "\u52A0\u8F7D\u4E2D...",
29534
+ background: "rgba(0, 0, 0, 0.7)"
29535
+ });
29536
+ }
29537
+ loadingCount++;
29538
+ }
29539
+ function endLoading() {
29540
+ if (loadingCount <= 0) return;
29541
+ loadingCount--;
29542
+ if (loadingCount === 0 && loadingInstance) {
29543
+ setTimeout(() => {
29544
+ loadingInstance?.close();
29545
+ loadingInstance = null;
29546
+ }, 200);
29547
+ }
29548
+ }
29527
29549
  service.interceptors.request.use(
29528
29550
  (config) => {
29551
+ const customConfig = config;
29552
+ if (customConfig.loading) {
29553
+ startLoading();
29554
+ }
29529
29555
  const controller = new AbortController();
29530
29556
  config.signal = controller.signal;
29531
29557
  const url = config.url || "";
@@ -29551,11 +29577,19 @@ service.interceptors.request.use(
29551
29577
  return config;
29552
29578
  },
29553
29579
  (error) => {
29580
+ const customConfig = error.config;
29581
+ if (customConfig?.loading === true) {
29582
+ endLoading();
29583
+ }
29554
29584
  return Promise.reject(error);
29555
29585
  }
29556
29586
  );
29557
29587
  service.interceptors.response.use(
29558
29588
  (res) => {
29589
+ const customConfig = res.config;
29590
+ if (customConfig.loading === true) {
29591
+ endLoading();
29592
+ }
29559
29593
  const url = res.config.url || "";
29560
29594
  abortControllerMap.delete(url);
29561
29595
  var status = res.status;
@@ -29594,6 +29628,10 @@ service.interceptors.response.use(
29594
29628
  return res;
29595
29629
  },
29596
29630
  (error) => {
29631
+ const customConfig = error.config;
29632
+ if (customConfig?.loading === true) {
29633
+ endLoading();
29634
+ }
29597
29635
  if (error.response) {
29598
29636
  if (error.response.status === 401) {
29599
29637
  clearAccessTokens();
@@ -1,4 +1,7 @@
1
1
  import { AxiosInstance, AxiosRequestConfig } from 'axios';
2
+ export interface CustomAxiosRequestConfig extends AxiosRequestConfig {
3
+ loading?: boolean;
4
+ }
2
5
  export declare const service: AxiosInstance;
3
6
  export declare const accessTokenKey: string;
4
7
  export declare const refreshAccessTokenKey: string;
@@ -32,5 +35,5 @@ export declare function getJWTDate(timestamp: number): Date;
32
35
  * @config AxiosRequestConfig 请求参数
33
36
  * @returns 返回对象
34
37
  */
35
- export declare function request2(config: AxiosRequestConfig<any>): any;
38
+ export declare function request2(config: CustomAxiosRequestConfig): any;
36
39
  export default service;
@@ -29,8 +29,34 @@ const clearAccessTokens = () => {
29
29
  window.location.reload();
30
30
  };
31
31
  const axiosInstance = axios;
32
+ let loadingCount = 0;
33
+ let loadingInstance = null;
34
+ function startLoading() {
35
+ if (loadingCount === 0) {
36
+ loadingInstance = elementPlus.ElLoading.service({
37
+ lock: true,
38
+ text: "\u52A0\u8F7D\u4E2D...",
39
+ background: "rgba(0, 0, 0, 0.7)"
40
+ });
41
+ }
42
+ loadingCount++;
43
+ }
44
+ function endLoading() {
45
+ if (loadingCount <= 0) return;
46
+ loadingCount--;
47
+ if (loadingCount === 0 && loadingInstance) {
48
+ setTimeout(() => {
49
+ loadingInstance?.close();
50
+ loadingInstance = null;
51
+ }, 200);
52
+ }
53
+ }
32
54
  service.interceptors.request.use(
33
55
  (config) => {
56
+ const customConfig = config;
57
+ if (customConfig.loading) {
58
+ startLoading();
59
+ }
34
60
  const controller = new AbortController();
35
61
  config.signal = controller.signal;
36
62
  const url = config.url || "";
@@ -56,11 +82,19 @@ service.interceptors.request.use(
56
82
  return config;
57
83
  },
58
84
  (error) => {
85
+ const customConfig = error.config;
86
+ if (customConfig?.loading === true) {
87
+ endLoading();
88
+ }
59
89
  return Promise.reject(error);
60
90
  }
61
91
  );
62
92
  service.interceptors.response.use(
63
93
  (res) => {
94
+ const customConfig = res.config;
95
+ if (customConfig.loading === true) {
96
+ endLoading();
97
+ }
64
98
  const url = res.config.url || "";
65
99
  abortControllerMap.delete(url);
66
100
  var status = res.status;
@@ -99,6 +133,10 @@ service.interceptors.response.use(
99
133
  return res;
100
134
  },
101
135
  (error) => {
136
+ const customConfig = error.config;
137
+ if (customConfig?.loading === true) {
138
+ endLoading();
139
+ }
102
140
  if (error.response) {
103
141
  if (error.response.status === 401) {
104
142
  clearAccessTokens();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fmdevui/fm-dev",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "Page level components developed based on Element Plus.",
5
5
  "author": "fmdevui",
6
6
  "keywords": [
File without changes