cosey 0.7.9 → 0.7.10

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.
@@ -2,9 +2,9 @@ import { defineComponent, ref, watch, createVNode, createTextVNode } from 'vue';
2
2
  import { inputNumberRangeEmits, inputNumberRangeProps } from './input-number-range.api.js';
3
3
  import stdin_default$1 from './input-number-range.style.js';
4
4
  import { useFormItem, CHANGE_EVENT, ElInputNumber } from 'element-plus';
5
- import { isNullish } from '../../utils/is.js';
6
5
  import { debugWarn } from 'element-plus/es/utils/error.mjs';
7
6
  import { useComponentConfig } from '../config-provider/config-provider.api.js';
7
+ import { isNullish } from '../../utils/is.js';
8
8
 
9
9
  var stdin_default = defineComponent({
10
10
  name: "CoInputNumberRange",
@@ -344,18 +344,10 @@ var stdin_default = /* @__PURE__ */defineComponent({
344
344
  }
345
345
  };
346
346
  const submit = async () => {
347
- if (props.formProps) {
348
- return tableQueryRef.value?.submit();
349
- } else {
350
- return onSubmit();
351
- }
347
+ return props.formProps && tableQueryRef.value ? tableQueryRef.value.submit() : onSubmit();
352
348
  };
353
349
  const reset = async values => {
354
- if (props.formProps) {
355
- return tableQueryRef.value?.reset(values);
356
- } else {
357
- return onReset();
358
- }
350
+ return props.formProps && tableQueryRef.value ? tableQueryRef.value.reset(values) : onReset();
359
351
  };
360
352
  const statsColumns = computed(() => unref(props.statsColumns));
361
353
  const statsData = computed(() => unref(props.statsData));
@@ -1,13 +1,19 @@
1
+ import { type ShallowRef } from 'vue';
1
2
  export interface UseFetchOptions<T> {
2
3
  onSuccess?: (data: T) => void;
3
4
  onError?: (err: any) => void;
4
5
  onFinally?: () => void;
5
6
  immediate?: boolean;
6
7
  initialData?: T;
8
+ stale?: any;
7
9
  }
8
- export declare function useFetch<T = any, U = any>(fetcher: (params: U) => Promise<any> | any, options?: UseFetchOptions<T>): {
9
- isFetching: import("vue").ShallowRef<boolean, boolean>;
10
- data: import("vue").Ref<any, any> extends T | undefined ? import("vue").ShallowRef<undefined, undefined> | (T extends T & import("vue").Ref<any, any> ? import("@vue/shared").IfAny<T, import("vue").ShallowRef<T, T>, T> : import("vue").ShallowRef<T, T>) : import("vue").ShallowRef<T | undefined, T | undefined>;
11
- error: import("vue").ShallowRef<any, any>;
12
- execute: (params?: U) => Promise<void>;
13
- };
10
+ interface UseFetchStale<T> {
11
+ isFetching: ShallowRef<boolean>;
12
+ data: ShallowRef<T | undefined>;
13
+ error: ShallowRef<any>;
14
+ }
15
+ interface UseFetchResult<T, U> extends UseFetchStale<T> {
16
+ execute: (params?: U | undefined) => Promise<void>;
17
+ }
18
+ export declare function useFetch<T = any, U = any>(fetcher: (params: U) => Promise<any> | any, options?: UseFetchOptions<T>): UseFetchResult<T, U>;
19
+ export {};
package/hooks/useFetch.js CHANGED
@@ -1,11 +1,22 @@
1
1
  import { shallowRef } from 'vue';
2
+ import { isNullish } from '../utils/is.js';
2
3
 
4
+ const staleMap = /* @__PURE__ */ new Map();
3
5
  function useFetch(fetcher, options = {}) {
4
- const { immediate = true, initialData, onSuccess, onError, onFinally } = options;
5
- const isFetching = shallowRef(false);
6
- const data = shallowRef(initialData);
7
- const error = shallowRef();
8
- const execute = async (params) => {
6
+ const { immediate = true, initialData, stale, onSuccess, onError, onFinally } = options;
7
+ const { isFetching, error, data } = !isNullish(stale) && staleMap.get(stale) || {
8
+ isFetching: shallowRef(false),
9
+ data: shallowRef(initialData),
10
+ error: shallowRef()
11
+ };
12
+ if (!isNullish(stale) && !staleMap.get(stale)) {
13
+ staleMap.set(stale, {
14
+ isFetching,
15
+ error,
16
+ data
17
+ });
18
+ }
19
+ async function execute(params) {
9
20
  if (isFetching.value) {
10
21
  return;
11
22
  }
@@ -22,7 +33,7 @@ function useFetch(fetcher, options = {}) {
22
33
  isFetching.value = false;
23
34
  onFinally?.();
24
35
  }
25
- };
36
+ }
26
37
  if (immediate) {
27
38
  Promise.resolve().then(() => {
28
39
  execute();
@@ -30,8 +41,8 @@ function useFetch(fetcher, options = {}) {
30
41
  }
31
42
  return {
32
43
  isFetching,
33
- data,
34
44
  error,
45
+ data,
35
46
  execute
36
47
  };
37
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosey",
3
- "version": "0.7.9",
3
+ "version": "0.7.10",
4
4
  "description": "基于 Vue3 + vite 的后台管理系统框架",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/utils/index.js CHANGED
@@ -6,7 +6,7 @@ export { addPxUnit, cssObjectToString, getContextBoxWidth, getDir, getStyle, set
6
6
  export { DATE_FORMAT, DATE_TIME_FORMAT, MONTH_FORMAT, TIME_FORMAT, YEAR_FORMAT, formatAsBasicDateTime, formatToDate, formatToDateTime, getDayjs } from './date.js';
7
7
  export { exportExcel, flatColumns } from './excel/index.js';
8
8
  export { chooseFiles, downloadAttachment, getFileType, readAsArrayBuffer, readAsDataURL } from './file.js';
9
- export { isBoolean, isEmpty, isFunction, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isUndefined } from './is.js';
9
+ export { isBoolean, isEmpty, isFunction, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isThenable, isUndefined } from './is.js';
10
10
  export { minmax } from './number.js';
11
11
  export { deepAssign, initObject, omitObject, omitUndefined, uniformAssign } from './object.js';
12
12
  export { getBasename, getExtname } from './path.js';
package/utils/is.d.ts CHANGED
@@ -38,3 +38,7 @@ export declare function isPrimitive(target: any): target is string | number | bo
38
38
  * 判断是否为空,包括空数组和空字符串
39
39
  */
40
40
  export declare function isEmpty(target: any): boolean;
41
+ /**
42
+ * 判断是否为类Promise对象
43
+ */
44
+ export declare function isThenable(target: any): target is PromiseLike<any>;
package/utils/is.js CHANGED
@@ -28,5 +28,8 @@ function isPrimitive(target) {
28
28
  function isEmpty(target) {
29
29
  return isNullish(target) || target === "" || Array.isArray(target) && target.length === 0;
30
30
  }
31
+ function isThenable(target) {
32
+ return (isFunction(target) || isObject(target)) && isFunction(target.then);
33
+ }
31
34
 
32
- export { isBoolean, isEmpty, isFunction, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isUndefined };
35
+ export { isBoolean, isEmpty, isFunction, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isString, isThenable, isUndefined };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+