@dazhicheng/ui 1.6.43 → 1.6.45
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineComponent as H, useSlots as J, ref as
|
|
1
|
+
import { defineComponent as H, useSlots as J, ref as F, computed as K, toValue as Q, nextTick as y, watch as W, createBlock as C, openBlock as B, unref as d, createSlots as P, withCtx as A, renderSlot as g, createVNode as X, renderList as S, normalizeProps as b, guardReactiveProps as V, createCommentVNode as Y } from "vue";
|
|
2
2
|
import "axios";
|
|
3
3
|
import { ElCheckbox as Z, ElMessage as O } from "element-plus";
|
|
4
|
-
import { isFunction as
|
|
4
|
+
import { isFunction as n } from "../../packages/utils/src/is.js";
|
|
5
5
|
import "dayjs";
|
|
6
6
|
import "numeral";
|
|
7
7
|
import "xe-utils";
|
|
@@ -31,7 +31,7 @@ import "../tt-form/src/shared/zod-defaults.js";
|
|
|
31
31
|
import { useGroupForm as te } from "../tt-form/src/group-form/useGroupForm.js";
|
|
32
32
|
import "../tt-modal/index.js";
|
|
33
33
|
import { useModalFormSlot as ie } from "./hooks/useModalFormSlot.js";
|
|
34
|
-
import { useModalRender as
|
|
34
|
+
import { useModalRender as se } from "../tt-modal/src/hooks/useModalRender.js";
|
|
35
35
|
const xe = /* @__PURE__ */ H({
|
|
36
36
|
name: "TtModalForm",
|
|
37
37
|
__name: "index",
|
|
@@ -40,6 +40,7 @@ const xe = /* @__PURE__ */ H({
|
|
|
40
40
|
model: {},
|
|
41
41
|
addApi: {},
|
|
42
42
|
editApi: {},
|
|
43
|
+
successMessage: {},
|
|
43
44
|
infoApi: {},
|
|
44
45
|
infoApiBefore: {},
|
|
45
46
|
infoApiAfter: {},
|
|
@@ -58,21 +59,21 @@ const xe = /* @__PURE__ */ H({
|
|
|
58
59
|
},
|
|
59
60
|
emits: ["submit", "fetch", "getinfo"],
|
|
60
61
|
setup(I, { emit: D }) {
|
|
61
|
-
var
|
|
62
|
-
const o = I,
|
|
62
|
+
var M, w;
|
|
63
|
+
const o = I, m = D, L = J(), c = F(), r = F(!1), { getFormSlotKeys: T, getModalSlotKeys: E, replaceFormSlotKey: R, replaceModalSlotKey: _ } = ie(L), x = K(() => E.value.filter(Boolean)), $ = K(() => T.value.filter(Boolean)), h = {
|
|
63
64
|
showDefaultActions: !1,
|
|
64
65
|
...Q(o.formProps)
|
|
65
|
-
}, [z,
|
|
66
|
+
}, [z, l] = o.renderType === "groupForm" ? te(h) : oe(h), [N, a] = se({
|
|
66
67
|
...o.modalProps,
|
|
67
68
|
onReceiveSharedData: async (e) => {
|
|
68
69
|
if (!e) {
|
|
69
|
-
|
|
70
|
+
c.value = void 0;
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
|
-
if (e.schemas &&
|
|
73
|
+
if (e.schemas && l.setState({ schema: e.schemas }), e != null && e.title && a.setModalProps({ title: e.title }), c.value = e[o.infoApiIdKey], e != null && e[o.infoApiIdKey]) {
|
|
73
74
|
const i = o.infoApi;
|
|
74
|
-
if (!
|
|
75
|
-
|
|
75
|
+
if (!n(i)) {
|
|
76
|
+
v(e);
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
78
79
|
a.changeLoading(!0);
|
|
@@ -80,83 +81,92 @@ const xe = /* @__PURE__ */ H({
|
|
|
80
81
|
const t = {
|
|
81
82
|
...o.infoApiParams,
|
|
82
83
|
[o.infoApiIdKey]: e[o.infoApiIdKey]
|
|
83
|
-
},
|
|
84
|
-
k(
|
|
84
|
+
}, s = n(o.infoApiBefore) ? await o.infoApiBefore(t) : t, u = await i(s), p = o.dataField ? ee(u, o.dataField) : u, f = n(o.infoApiAfter) ? await o.infoApiAfter(p) : p;
|
|
85
|
+
k(f), m("getinfo", f), await y(), await l.resetForm({ values: f });
|
|
85
86
|
} finally {
|
|
86
87
|
a.changeLoading(!1);
|
|
87
88
|
}
|
|
88
89
|
} else
|
|
89
|
-
|
|
90
|
+
v(e);
|
|
90
91
|
},
|
|
91
92
|
async onOk() {
|
|
92
93
|
await q();
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
|
-
function
|
|
96
|
+
function v(e) {
|
|
96
97
|
const i = e[o.infoDataKey || ""] || {};
|
|
97
98
|
k(i), y(() => {
|
|
98
|
-
|
|
99
|
+
l.resetForm({ values: i });
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
function k(e) {
|
|
102
103
|
const i = Object.keys(o.checkedOptions || {});
|
|
103
104
|
i.length && i.forEach((t) => {
|
|
104
|
-
var
|
|
105
|
-
const
|
|
106
|
-
if (!Array.isArray(
|
|
105
|
+
var f;
|
|
106
|
+
const s = (f = o.checkedOptions) == null ? void 0 : f[t];
|
|
107
|
+
if (!Array.isArray(s) || s.length === 0)
|
|
107
108
|
return;
|
|
108
|
-
const [
|
|
109
|
-
!
|
|
110
|
-
label: e[
|
|
111
|
-
value: e[
|
|
109
|
+
const [u, p] = s.length === 1 ? [s[0], s[0]] : s;
|
|
110
|
+
!u || !p || (e[t] = {
|
|
111
|
+
label: e[u],
|
|
112
|
+
value: e[p]
|
|
112
113
|
});
|
|
113
114
|
});
|
|
114
115
|
}
|
|
115
116
|
async function j() {
|
|
116
|
-
const e = await
|
|
117
|
+
const e = await l.getValues(), { apiParams: i } = o;
|
|
117
118
|
let t = {
|
|
118
119
|
...e,
|
|
119
120
|
...i
|
|
120
121
|
};
|
|
121
|
-
return t =
|
|
122
|
+
return t = n(o.saveApiBefore) ? await o.saveApiBefore(t) : t, { reqParams: t, formValue: e };
|
|
122
123
|
}
|
|
123
124
|
async function G(e, i) {
|
|
124
125
|
const { editApi: t } = o;
|
|
125
|
-
!t || !
|
|
126
|
+
if (!t || !n(t)) return;
|
|
127
|
+
e[o.infoApiIdKey] = c.value;
|
|
128
|
+
const s = await t(e, i.files);
|
|
129
|
+
O.success(
|
|
130
|
+
n(o.successMessage) ? o.successMessage(s, "edit") : o.successMessage ?? "修改成功"
|
|
131
|
+
), m("submit", {
|
|
126
132
|
...e,
|
|
127
133
|
continuousChecked: r.value
|
|
128
|
-
}), a.closeModal()
|
|
134
|
+
}), a.closeModal();
|
|
129
135
|
}
|
|
130
136
|
async function U(e, i) {
|
|
131
137
|
const { addApi: t } = o;
|
|
132
|
-
!t || !
|
|
138
|
+
if (!t || !n(t)) return;
|
|
139
|
+
const s = await t(e, i.files);
|
|
140
|
+
O.success(
|
|
141
|
+
n(o.successMessage) ? o.successMessage(s, "add") : o.successMessage ?? "新增成功"
|
|
142
|
+
), m("submit", {
|
|
133
143
|
...e,
|
|
134
144
|
continuousChecked: r.value
|
|
135
|
-
}), (!r.value || !o.isContinuousChecked) && a.closeModal()
|
|
145
|
+
}), (!r.value || !o.isContinuousChecked) && a.closeModal();
|
|
136
146
|
}
|
|
137
147
|
async function q() {
|
|
138
148
|
a.changeOkLoading(!0);
|
|
139
149
|
try {
|
|
140
|
-
const { valid: e } = await
|
|
150
|
+
const { valid: e } = await l.validate();
|
|
141
151
|
if (!e) return;
|
|
142
152
|
const { reqParams: i, formValue: t } = await j();
|
|
143
153
|
if (!i)
|
|
144
154
|
return;
|
|
145
|
-
const { addApi:
|
|
146
|
-
if (!
|
|
147
|
-
|
|
155
|
+
const { addApi: s, editApi: u } = o;
|
|
156
|
+
if (!s && !u) {
|
|
157
|
+
m("submit", {
|
|
148
158
|
...i,
|
|
149
|
-
[o.infoApiIdKey]:
|
|
159
|
+
[o.infoApiIdKey]: c.value,
|
|
150
160
|
continuousChecked: r.value
|
|
151
161
|
});
|
|
152
162
|
return;
|
|
153
163
|
}
|
|
154
|
-
|
|
164
|
+
c.value ? await G(i, t) : await U(i, t);
|
|
155
165
|
} finally {
|
|
156
166
|
a.changeOkLoading(!1);
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
|
-
return (
|
|
169
|
+
return (M = o.getFormApi) == null || M.call(o, l), (w = o.getModalApi) == null || w.call(o, a), W(
|
|
160
170
|
() => {
|
|
161
171
|
var e;
|
|
162
172
|
return (e = a.getVisible) == null ? void 0 : e.value;
|
|
@@ -164,14 +174,14 @@ const xe = /* @__PURE__ */ H({
|
|
|
164
174
|
async (e) => {
|
|
165
175
|
if (e) {
|
|
166
176
|
await y();
|
|
167
|
-
const i = await
|
|
168
|
-
|
|
177
|
+
const i = await l.getValues();
|
|
178
|
+
m("fetch", i);
|
|
169
179
|
} else
|
|
170
180
|
r.value = !1;
|
|
171
181
|
}
|
|
172
|
-
), (e, i) => (B(),
|
|
182
|
+
), (e, i) => (B(), C(d(N), null, P({
|
|
173
183
|
insertFooter: A(() => [
|
|
174
|
-
o.isContinuousChecked && !
|
|
184
|
+
o.isContinuousChecked && !c.value ? (B(), C(d(Z), {
|
|
175
185
|
key: 0,
|
|
176
186
|
modelValue: r.value,
|
|
177
187
|
"onUpdate:modelValue": i[0] || (i[0] = (t) => r.value = t),
|
|
@@ -180,12 +190,12 @@ const xe = /* @__PURE__ */ H({
|
|
|
180
190
|
}, null, 8, ["modelValue"])) : Y("", !0)
|
|
181
191
|
]),
|
|
182
192
|
default: A(() => [
|
|
183
|
-
|
|
193
|
+
g(e.$slots, "BasicMsgTop"),
|
|
184
194
|
X(d(z), null, P({ _: 2 }, [
|
|
185
195
|
S($.value, (t) => ({
|
|
186
196
|
name: d(R)(t),
|
|
187
|
-
fn: A((
|
|
188
|
-
|
|
197
|
+
fn: A((s) => [
|
|
198
|
+
g(e.$slots, t, b(V(s)))
|
|
189
199
|
])
|
|
190
200
|
}))
|
|
191
201
|
]), 1024)
|
|
@@ -194,8 +204,8 @@ const xe = /* @__PURE__ */ H({
|
|
|
194
204
|
}, [
|
|
195
205
|
S(x.value, (t) => ({
|
|
196
206
|
name: d(_)(t),
|
|
197
|
-
fn: A((
|
|
198
|
-
|
|
207
|
+
fn: A((s) => [
|
|
208
|
+
g(e.$slots, t, b(V(s)))
|
|
199
209
|
])
|
|
200
210
|
}))
|
|
201
211
|
]), 1024));
|
|
@@ -20,6 +20,8 @@ export type TtModalFormProps<TType extends ModalFormType = "form", TValues exten
|
|
|
20
20
|
addApi?: (...arg: any[]) => Promise<any>;
|
|
21
21
|
/** 编辑保存接口 */
|
|
22
22
|
editApi?: (...arg: any[]) => Promise<any>;
|
|
23
|
+
/** 保存成功提示;函数接收保存接口返回值及操作类型,不传时使用新增/修改默认文案。 */
|
|
24
|
+
successMessage?: string | ((result: unknown, type: "add" | "edit") => string);
|
|
23
25
|
/** 详情接口 */
|
|
24
26
|
infoApi?: (...arg: any[]) => Promise<any>;
|
|
25
27
|
/** 详情接口前置钩子 */
|