cosey 0.4.12 → 0.4.14

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.
@@ -9,16 +9,17 @@ export interface UseUpsertExpose<Row extends Record<string, any>, Data = any> {
9
9
  setOptions: (options: UseUpsertExposeOptions) => any;
10
10
  }
11
11
  export type UpsertType = 'edit' | 'add';
12
- export interface UseUpsertOptions<Model, Row = Model, Data = Model> {
12
+ export interface UseUpsertOptions<Model, Row = Model> {
13
13
  title?: string;
14
14
  stuffTitle?: string;
15
15
  model: Model;
16
- show?: (type: UpsertType, row?: Row) => void;
17
- details?: (row: Row) => any;
16
+ onAdd?: (...args: any[]) => void;
17
+ onEdit?: (row: Row, ...args: any[]) => void;
18
+ onShow?: () => void;
19
+ detailsFetch?: (row: Row) => any;
18
20
  beforeFill?: (row: Row) => any;
19
- beforeSubmit?: (model: Model) => Data | Promise<Data>;
20
- add?: (data: Data) => any;
21
- edit?: (data: Data) => any;
21
+ addFetch?: () => any;
22
+ editFetch?: () => any;
22
23
  success?: (res: any) => any;
23
24
  addSuccessText?: string;
24
25
  editSuccessText?: string;
@@ -42,13 +43,13 @@ export interface UseUpsertReturn<Model extends Record<string, any>, Row extends
42
43
  isEdit: ComputedRef<boolean>;
43
44
  isAdd: ComputedRef<boolean>;
44
45
  }
45
- export declare function useUpsert<Model extends Record<string, any>, Row extends Record<string, any> = Model, Data = any>(options: MaybeRef<UseUpsertOptions<Model, Row, Data>>): UseUpsertReturn<Model, Row, Data>;
46
+ export declare function useUpsert<Model extends Record<string, any>, Row extends Record<string, any> = Model, Data = any>(options: MaybeRef<UseUpsertOptions<Model, Row>>): UseUpsertReturn<Model, Row, Data>;
46
47
  export interface UseExternalUpsertOptions {
47
48
  success?: () => any;
48
49
  }
49
50
  export interface UseExternalUpsertReturn<Row extends Record<string, any>, Data> {
50
- add: () => void;
51
- edit: (row: Row) => void;
51
+ add: (...args: any[]) => void;
52
+ edit: (...args: any[]) => void;
52
53
  setData: (data: Data) => void;
53
54
  expose: Readonly<ShallowRef<UseUpsertExpose<Row, Data> | null>>;
54
55
  ref: string;
@@ -17,12 +17,13 @@ function useUpsert(options) {
17
17
  title,
18
18
  addSuccessText,
19
19
  editSuccessText,
20
- show,
21
- details,
20
+ onAdd,
21
+ onEdit,
22
+ onShow,
23
+ detailsFetch,
22
24
  beforeFill,
23
- beforeSubmit,
24
- add,
25
- edit,
25
+ addFetch,
26
+ editFetch,
26
27
  success
27
28
  } = toRefs(computed(() => unref(options)));
28
29
  const { t, lang } = useLocale();
@@ -45,13 +46,12 @@ function useUpsert(options) {
45
46
  const formRefKey = uuid();
46
47
  const formRef = useTemplateRef(formRefKey);
47
48
  const onSubmit = async () => {
48
- const data2 = await unref(beforeSubmit)?.(unref(model)) || unref(model);
49
49
  let res;
50
50
  if (type.value === "add") {
51
- res = await unref(add)?.(data2);
51
+ res = await unref(addFetch)?.();
52
52
  ElMessage.success(unref(addSuccessText) || t("co.common.addSuccess"));
53
53
  } else {
54
- res = await unref(edit)?.(data2);
54
+ res = await unref(editFetch)?.();
55
55
  ElMessage.success(unref(editSuccessText) || t("co.common.editSuccess"));
56
56
  }
57
57
  unref(success)?.(res);
@@ -66,26 +66,28 @@ function useUpsert(options) {
66
66
  const row = shallowRef();
67
67
  let exposeOptions;
68
68
  const expose = {
69
- edit: async (_row) => {
69
+ edit: async (...args) => {
70
70
  type.value = "edit";
71
- row.value = _row;
71
+ row.value = args[0];
72
72
  deepAssign(unref(model), initialModel);
73
+ unref(onEdit)?.(...args);
73
74
  visible.value = true;
74
- unref(show)?.(type.value, row.value);
75
- let filledRow = _row;
76
- if (unref(details)) {
77
- filledRow = await unref(details)(_row);
75
+ unref(onShow)?.();
76
+ let filledRow = row.value;
77
+ if (unref(detailsFetch)) {
78
+ filledRow = await unref(detailsFetch)(row.value);
78
79
  }
79
80
  filledRow = { ...filledRow };
80
81
  filledRow = unref(beforeFill)?.(filledRow) || filledRow;
81
82
  Object.assign(unref(model), pick(filledRow, modelKeys));
82
83
  },
83
- add: () => {
84
+ add: (...args) => {
84
85
  type.value = "add";
85
86
  row.value = void 0;
86
87
  deepAssign(unref(model), initialModel);
88
+ unref(onAdd)?.(...args);
87
89
  visible.value = true;
88
- unref(show)?.(type.value);
90
+ unref(onShow)?.();
89
91
  },
90
92
  setData: (_data) => {
91
93
  data.value = _data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosey",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "description": "基于 Vue3 + vite 的后台管理系统框架",
5
5
  "type": "module",
6
6
  "main": "index.js",