@tonar/vue-kit 0.3.3 → 0.3.6
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/components.es.js +1 -1
- package/dist/composables.es.js +34 -2
- package/dist/index.es.js +3 -3
- package/dist/js/{components.29YtMKby.js → components.BVZ4uiu-.js} +1 -1
- package/dist/types/composables/async-guard/index.d.ts +10 -0
- package/dist/types/composables/index.d.ts +2 -1
- package/dist/types/index.d.ts +2 -1
- package/package.json +2 -2
package/dist/components.es.js
CHANGED
package/dist/composables.es.js
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
import { computed, ref } from "vue";
|
|
1
|
+
import { computed, ref, shallowRef } from "vue";
|
|
2
|
+
|
|
3
|
+
// src/composables/async-guard/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* @author sonion
|
|
6
|
+
* @description 异步操作锁,防止重复调用。通过返回的 Promise 确定是否执行中,执行中不可重复触发。
|
|
7
|
+
* @param {(...args: T)=>Promise<R>} asyncAction - 异步方法,需返回Promise
|
|
8
|
+
* @param {(isPending: boolean, ...args: T) => void} [onPendingChange] - 状态变化回调
|
|
9
|
+
* @param {string} [msg] - 警告信息
|
|
10
|
+
* @returns {[boolean, (...args: T) => Promise<R | void>]} - 返回是否执行中,执行方法
|
|
11
|
+
*/
|
|
12
|
+
const useAsyncActionLock = (asyncAction, onPendingChange, msg) => {
|
|
13
|
+
const isPending = shallowRef(false);
|
|
14
|
+
const handler = (...args) => {
|
|
15
|
+
if (isPending.value) {
|
|
16
|
+
console.log(msg || "正在提交中,请稍后再试");
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
}
|
|
19
|
+
isPending.value = true;
|
|
20
|
+
onPendingChange?.(true, ...args);
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
try {
|
|
23
|
+
resolve(asyncAction?.(...args));
|
|
24
|
+
} catch (err) {
|
|
25
|
+
reject(err);
|
|
26
|
+
}
|
|
27
|
+
}).finally(() => {
|
|
28
|
+
isPending.value = false;
|
|
29
|
+
onPendingChange?.(false, ...args);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
return [isPending, handler];
|
|
33
|
+
};
|
|
2
34
|
|
|
3
35
|
// src/composables/storage/index.ts
|
|
4
36
|
const useStorage = ({ key, defaultValue, hasDiff, onChange, storage = localStorage, checkType = () => true, beforeunload }) => {
|
|
@@ -56,4 +88,4 @@ const useStorage = ({ key, defaultValue, hasDiff, onChange, storage = localStora
|
|
|
56
88
|
];
|
|
57
89
|
};
|
|
58
90
|
|
|
59
|
-
export { useStorage };
|
|
91
|
+
export { useAsyncActionLock, useStorage };
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as so_authority_default, t as _sfc_main } from "./js/components.
|
|
2
|
-
import { useStorage } from "./composables.es.js";
|
|
1
|
+
import { n as so_authority_default, t as _sfc_main } from "./js/components.BVZ4uiu-.js";
|
|
2
|
+
import { useAsyncActionLock, useStorage } from "./composables.es.js";
|
|
3
3
|
|
|
4
|
-
export { so_authority_default as SoAuthority, _sfc_main as SoTest, useStorage };
|
|
4
|
+
export { so_authority_default as SoAuthority, _sfc_main as SoTest, useAsyncActionLock, useStorage };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed, createElementBlock, createElementVNode, defineComponent, openBlock, ref, toDisplayString } from "vue";
|
|
2
|
-
import { isNil } from "@tonar/utils";
|
|
2
|
+
import { isNil } from "@tonar/utils/common";
|
|
3
3
|
|
|
4
4
|
// src/components/so-authority/composables/index.ts
|
|
5
5
|
/**
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author sonion
|
|
3
|
+
* @description 异步操作锁,防止重复调用。通过返回的 Promise 确定是否执行中,执行中不可重复触发。
|
|
4
|
+
* @param {(...args: T)=>Promise<R>} asyncAction - 异步方法,需返回Promise
|
|
5
|
+
* @param {(isPending: boolean, ...args: T) => void} [onPendingChange] - 状态变化回调
|
|
6
|
+
* @param {string} [msg] - 警告信息
|
|
7
|
+
* @returns {[boolean, (...args: T) => Promise<R | void>]} - 返回是否执行中,执行方法
|
|
8
|
+
*/
|
|
9
|
+
declare const useAsyncActionLock: <T extends unknown[], R>(asyncAction: (...args: T) => Promise<R>, onPendingChange?: (isPending: boolean, ...args: T) => void, msg?: string) => readonly [import("vue").ShallowRef<boolean, boolean>, (...args: T) => Promise<R> | Promise<void>];
|
|
10
|
+
export { useAsyncActionLock };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _default from "./components/so-authority/index.js";
|
|
2
2
|
import _default$1 from "./components/so-test/so-test.vue.js";
|
|
3
3
|
import "./components/index.js";
|
|
4
|
+
import { useAsyncActionLock } from "./composables/async-guard/index.js";
|
|
4
5
|
import { useStorage } from "./composables/storage/index.js";
|
|
5
|
-
export { _default as SoAuthority, _default$1 as SoTest, useStorage };
|
|
6
|
+
export { _default as SoAuthority, _default$1 as SoTest, useAsyncActionLock, useStorage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tonar/vue-kit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "@tonar/vue-kit: Vue 3 ESM toolkit with permission-based rendering components such as SoAuthority.",
|
|
6
6
|
"keywords": [
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@tonar/utils": "0.3.
|
|
46
|
+
"@tonar/utils": "0.3.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@vue/test-utils": "^2.5.1",
|