cosey 0.4.27 → 0.4.29

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.
@@ -16,10 +16,13 @@ export interface UseUpsertOptions<Model, Row = Model> {
16
16
  onAdd?: (...args: any[]) => void;
17
17
  onEdit?: (row: Row, ...args: any[]) => void;
18
18
  onShow?: () => void;
19
+ onShown?: () => void;
20
+ onShownAdd?: (...args: any[]) => void;
21
+ onShownEdit?: (...args: any[]) => void;
19
22
  detailsFetch?: (row: Row) => any;
20
23
  beforeFill?: (row: Row) => any;
21
- addFetch?: () => any;
22
- editFetch?: (row: Row) => any;
24
+ addFetch?: (...args: any[]) => any;
25
+ editFetch?: (row: Row, ...args: any[]) => any;
23
26
  success?: (res: any) => any;
24
27
  addSuccessText?: string;
25
28
  editSuccessText?: string;
@@ -1,6 +1,6 @@
1
1
  import { ElMessage } from 'element-plus';
2
2
  import { cloneDeep, pick } from 'lodash-es';
3
- import { ref, computed, unref, reactive, useTemplateRef, shallowRef, readonly } from 'vue';
3
+ import { ref, computed, unref, reactive, shallowRef, useTemplateRef, readonly, nextTick } from 'vue';
4
4
  import { toRefs } from '@vueuse/core';
5
5
  import { useLocale } from './useLocale.js';
6
6
  import { uuid } from '../utils/string.js';
@@ -20,6 +20,9 @@ function useUpsert(options) {
20
20
  onAdd,
21
21
  onEdit,
22
22
  onShow,
23
+ onShown,
24
+ onShownAdd,
25
+ onShownEdit,
23
26
  detailsFetch,
24
27
  beforeFill,
25
28
  addFetch,
@@ -43,15 +46,19 @@ function useUpsert(options) {
43
46
  },
44
47
  title: mergedTitle
45
48
  });
49
+ const data = shallowRef();
50
+ const row = shallowRef();
51
+ let addParams = [];
52
+ let editParams = [];
46
53
  const formRefKey = uuid();
47
54
  const formRef = useTemplateRef(formRefKey);
48
55
  const onSubmit = async () => {
49
56
  let res;
50
57
  if (type.value === "add") {
51
- res = await unref(addFetch)?.();
58
+ res = await unref(addFetch)?.(...addParams);
52
59
  ElMessage.success(unref(addSuccessText) || t("co.common.operateSuccess"));
53
60
  } else {
54
- res = await unref(editFetch)?.(row.value);
61
+ res = await unref(editFetch)?.(row.value, ...editParams);
55
62
  ElMessage.success(unref(editSuccessText) || t("co.common.operateSuccess"));
56
63
  }
57
64
  unref(success)?.(res);
@@ -62,17 +69,20 @@ function useUpsert(options) {
62
69
  ref: formRefKey,
63
70
  submit: onSubmit
64
71
  });
65
- const data = shallowRef();
66
- const row = shallowRef();
67
72
  let exposeOptions;
68
73
  const expose = {
69
- edit: async (...args) => {
74
+ edit: async (_row, ...args) => {
75
+ editParams = args;
70
76
  type.value = "edit";
71
- row.value = args[0];
77
+ row.value = _row;
72
78
  deepAssign(unref(model), initialModel);
73
- unref(onEdit)?.(...args);
79
+ unref(onEdit)?.(_row, ...editParams);
74
80
  visible.value = true;
75
81
  unref(onShow)?.();
82
+ nextTick(() => {
83
+ unref(onShown)?.();
84
+ unref(onShownEdit)?.(...editParams);
85
+ });
76
86
  let filledRow = row.value;
77
87
  if (unref(detailsFetch)) {
78
88
  filledRow = await unref(detailsFetch)(row.value);
@@ -82,12 +92,17 @@ function useUpsert(options) {
82
92
  Object.assign(unref(model), pick(filledRow, modelKeys));
83
93
  },
84
94
  add: (...args) => {
95
+ addParams = args;
85
96
  type.value = "add";
86
97
  row.value = void 0;
87
98
  deepAssign(unref(model), initialModel);
88
- unref(onAdd)?.(...args);
99
+ unref(onAdd)?.(...addParams);
89
100
  visible.value = true;
90
101
  unref(onShow)?.();
102
+ nextTick(() => {
103
+ unref(onShown)?.();
104
+ unref(onShownAdd)?.(...addParams);
105
+ });
91
106
  },
92
107
  setData: (_data) => {
93
108
  data.value = _data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cosey",
3
- "version": "0.4.27",
3
+ "version": "0.4.29",
4
4
  "description": "基于 Vue3 + vite 的后台管理系统框架",
5
5
  "type": "module",
6
6
  "main": "index.js",