cosey 0.7.8 → 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.
@@ -143,7 +143,7 @@ export declare const formEmits: {
143
143
  };
144
144
  export type FormEmits = typeof formEmits;
145
145
  export interface FormExpose {
146
- reset: () => void;
146
+ reset: (callback?: () => void) => void;
147
147
  submit: () => Promise<any>;
148
148
  validate: (callback?: FormValidateCallback) => FormValidationResult;
149
149
  validateField: (props?: Arrayable<FormItemProp>, callback?: FormValidateCallback) => FormValidationResult;
@@ -5,7 +5,7 @@ export interface UseFormTemplateOptions<T> {
5
5
  export declare function useFormTemplate<T extends FormProps, U extends FormExpose = FormExpose>(props: T, options?: UseFormTemplateOptions<T>): {
6
6
  elFormProps: import("@vueuse/core").ReactiveOmitReturn<T, keyof T>;
7
7
  expose: U;
8
- reset: () => void;
8
+ reset: (callback?: () => void) => void;
9
9
  resetFields: () => void;
10
10
  clearValidate: () => void;
11
11
  submit: (throwError?: boolean) => Promise<void>;
@@ -31,8 +31,9 @@ function useFormTemplate(props, options = {}) {
31
31
  reset2();
32
32
  });
33
33
  };
34
- const reset = () => {
34
+ const reset = (callback) => {
35
35
  resetFields();
36
+ callback?.();
36
37
  props.reset?.();
37
38
  };
38
39
  const clearValidate = () => {
@@ -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",
@@ -296,17 +296,17 @@ declare const _Table: {
296
296
  page: number;
297
297
  pageSize: number;
298
298
  };
299
- reset: () => void;
300
299
  submit: () => Promise<any>;
301
300
  validate: (callback?: import("element-plus").FormValidateCallback) => import("element-plus").FormValidationResult;
301
+ clearValidate: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
302
302
  validateField: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>, callback?: import("element-plus").FormValidateCallback) => import("element-plus").FormValidationResult;
303
303
  resetFields: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
304
- clearValidate: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
305
304
  scrollToField: (prop: import("element-plus").FormItemProp) => void;
306
305
  fields: import("element-plus").FormItemContext[];
307
306
  getFieldsValue: () => Record<string, any>;
308
- setFieldsValue: (value: Record<string, any>) => void;
307
+ setFieldsValue: (values: Record<PropertyKey, any>) => void;
309
308
  getFormModel: () => Record<string, any>;
309
+ reset: (values?: Record<PropertyKey, any>) => void;
310
310
  clearSelection: () => void;
311
311
  getSelectionRows: () => any[];
312
312
  toggleRowSelection: (row: any, selected?: boolean, emitChange?: boolean, ignoreSelectable?: boolean) => void;
@@ -648,17 +648,17 @@ declare const _Table: {
648
648
  page: number;
649
649
  pageSize: number;
650
650
  };
651
- reset: () => void;
652
651
  submit: () => Promise<any>;
653
652
  validate: (callback?: import("element-plus").FormValidateCallback) => import("element-plus").FormValidationResult;
653
+ clearValidate: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
654
654
  validateField: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>, callback?: import("element-plus").FormValidateCallback) => import("element-plus").FormValidationResult;
655
655
  resetFields: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
656
- clearValidate: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
657
656
  scrollToField: (prop: import("element-plus").FormItemProp) => void;
658
657
  fields: import("element-plus").FormItemContext[];
659
658
  getFieldsValue: () => Record<string, any>;
660
- setFieldsValue: (value: Record<string, any>) => void;
659
+ setFieldsValue: (values: Record<PropertyKey, any>) => void;
661
660
  getFormModel: () => Record<string, any>;
661
+ reset: (values?: Record<PropertyKey, any>) => void;
662
662
  clearSelection: () => void;
663
663
  getSelectionRows: () => any[];
664
664
  toggleRowSelection: (row: any, selected?: boolean, emitChange?: boolean, ignoreSelectable?: boolean) => void;
@@ -855,17 +855,17 @@ declare const _Table: {
855
855
  page: number;
856
856
  pageSize: number;
857
857
  };
858
- reset: () => void;
859
858
  submit: () => Promise<any>;
860
859
  validate: (callback?: import("element-plus").FormValidateCallback) => import("element-plus").FormValidationResult;
860
+ clearValidate: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
861
861
  validateField: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>, callback?: import("element-plus").FormValidateCallback) => import("element-plus").FormValidationResult;
862
862
  resetFields: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
863
- clearValidate: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
864
863
  scrollToField: (prop: import("element-plus").FormItemProp) => void;
865
864
  fields: import("element-plus").FormItemContext[];
866
865
  getFieldsValue: () => Record<string, any>;
867
- setFieldsValue: (value: Record<string, any>) => void;
866
+ setFieldsValue: (values: Record<PropertyKey, any>) => void;
868
867
  getFormModel: () => Record<string, any>;
868
+ reset: (values?: Record<PropertyKey, any>) => void;
869
869
  clearSelection: () => void;
870
870
  getSelectionRows: () => any[];
871
871
  toggleRowSelection: (row: any, selected?: boolean, emitChange?: boolean, ignoreSelectable?: boolean) => void;
@@ -163,10 +163,11 @@ export declare const tableQueryEmits: {
163
163
  export type TableQueryEmits = typeof tableQueryEmits;
164
164
  export interface TableQueryCustomExpose {
165
165
  getFieldsValue: () => Record<string, any>;
166
- setFieldsValue: (value: Record<string, any>) => void;
166
+ setFieldsValue: (values: Record<PropertyKey, any>) => void;
167
167
  getFormModel: () => Record<string, any>;
168
+ reset: (values?: Record<PropertyKey, any>) => void;
168
169
  }
169
- export interface TableQueryExpose extends FormQueryExpose, TableQueryCustomExpose {
170
+ export interface TableQueryExpose extends Omit<FormQueryExpose, 'reset'>, TableQueryCustomExpose {
170
171
  }
171
172
  export declare const tableQueryExposeKeys: string[];
172
173
  export declare function createScheme<T extends FieldType>(props: FormItemProps<T>): FormItemProps<T>;
@@ -22,7 +22,8 @@ const tableQueryExposeKeys = [
22
22
  ...formExposeKeys,
23
23
  "getFieldsValue",
24
24
  "setFieldsValue",
25
- "getFormModel"
25
+ "getFormModel",
26
+ "reset"
26
27
  ];
27
28
  function createScheme(props) {
28
29
  return props;
@@ -30,16 +30,25 @@ var stdin_default = defineComponent({
30
30
  const onEnter = () => {
31
31
  formQueryRef.value?.submit();
32
32
  };
33
+ const setFieldsValue = values => {
34
+ Object.assign(unref(formModel), values);
35
+ };
36
+ const reset = values => {
37
+ formQueryRef.value?.reset(() => {
38
+ if (values) {
39
+ setFieldsValue(values);
40
+ }
41
+ });
42
+ };
33
43
  const customExpose = {
34
44
  getFieldsValue() {
35
45
  return cloneDeep(unref(formModel));
36
46
  },
37
- setFieldsValue(value) {
38
- Object.assign(unref(formModel), value);
39
- },
47
+ setFieldsValue,
40
48
  getFormModel() {
41
49
  return unref(formModel);
42
- }
50
+ },
51
+ reset
43
52
  };
44
53
  expose(createMergedExpose(tableQueryExposeKeys, () => formQueryRef.value, customExpose));
45
54
  return () => {
@@ -152,17 +152,17 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
152
152
  page: number;
153
153
  pageSize: number;
154
154
  };
155
- reset: () => void;
156
155
  submit: () => Promise<any>;
157
156
  validate: (callback?: import("element-plus").FormValidateCallback) => import("element-plus").FormValidationResult;
157
+ clearValidate: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
158
158
  validateField: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>, callback?: import("element-plus").FormValidateCallback) => import("element-plus").FormValidationResult;
159
159
  resetFields: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
160
- clearValidate: (props?: import("@vueuse/core").Arrayable<import("element-plus").FormItemProp>) => void;
161
160
  scrollToField: (prop: import("element-plus").FormItemProp) => void;
162
161
  fields: import("element-plus").FormItemContext[];
163
162
  getFieldsValue: () => Record<string, any>;
164
- setFieldsValue: (value: Record<string, any>) => void;
163
+ setFieldsValue: (values: Record<PropertyKey, any>) => void;
165
164
  getFormModel: () => Record<string, any>;
165
+ reset: (values?: Record<PropertyKey, any>) => void;
166
166
  clearSelection: () => void;
167
167
  getSelectionRows: () => any[];
168
168
  toggleRowSelection: (row: any, selected?: boolean, emitChange?: boolean, ignoreSelectable?: boolean) => void;
@@ -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
- const reset = async () => {
354
- if (props.formProps) {
355
- return tableQueryRef.value?.reset();
356
- } else {
357
- return onReset();
358
- }
349
+ const reset = async values => {
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.8",
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
+
package/utils/vue.js CHANGED
@@ -19,7 +19,8 @@ function createMergedExpose(keys, ...exposeList) {
19
19
  const result = {};
20
20
  for (const key of keys) {
21
21
  result[key] = (...args) => {
22
- for (const expose of exposeList) {
22
+ for (let i = exposeList.length - 1; i >= 0; i--) {
23
+ const expose = exposeList[i];
23
24
  const obj = typeof expose === "function" ? expose() : expose;
24
25
  if (obj && key in obj) {
25
26
  const value = obj[key];