@chewel611/naive-ui-plus 0.0.4 → 0.0.6
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.
- package/dist/index.js +713 -716
- package/dist/index.umd.cjs +1 -1
- package/es/modal/PModal.d.ts +1 -1
- package/es/modal/PModal.vue.js +57 -68
- package/es/modal/index.d.ts +1 -1
- package/es/table/PTable.d.ts +1 -0
- package/es/table/PTable.vue.js +117 -113
- package/es/table/index.d.ts +3 -0
- package/es/table/typing.d.ts +2 -2
- package/es/utils/helper.d.ts +1 -0
- package/es/utils/helper.js +9 -0
- package/lib/modal/PModal.d.ts +1 -1
- package/lib/modal/PModal.vue.cjs +1 -1
- package/lib/modal/index.d.ts +1 -1
- package/lib/table/PTable.d.ts +1 -0
- package/lib/table/PTable.vue.cjs +1 -1
- package/lib/table/index.d.ts +3 -0
- package/lib/table/typing.d.ts +2 -2
- package/lib/utils/helper.cjs +1 -0
- package/lib/utils/helper.d.ts +1 -0
- package/package.json +2 -2
package/es/table/PTable.vue.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { useDialog as he, useMessage as
|
|
2
|
-
import { defineComponent as
|
|
3
|
-
import { PlusSquareOutlined as
|
|
4
|
-
|
|
1
|
+
import { useDialog as he, useMessage as ve, NCard as ye, NDataTable as we, NModal as ke, NSpace as be, NButton as w, NTooltip as _e, NIcon as O, NDropdown as Ce } from "naive-ui";
|
|
2
|
+
import { defineComponent as Se, ref as u, computed as G, unref as r, onMounted as Me, createBlock as H, openBlock as m, withCtx as n, createElementVNode as E, createElementBlock as x, createCommentVNode as k, createVNode as s, renderSlot as P, normalizeStyle as K, createTextVNode as B, h as T, toRaw as $ } from "vue";
|
|
3
|
+
import { PlusSquareOutlined as De, DeleteOutlined as Oe, ReloadOutlined as Ee, MoreOutlined as Be } from "@vicons/antd";
|
|
4
|
+
import { resetObject as Te } from "../utils/helper.js";
|
|
5
|
+
const $e = { id: "data-content" }, Ne = {
|
|
5
6
|
key: 0,
|
|
6
7
|
class: "rounded-lg bg-gray-50 flex flex-row gap-2 items-center justify-end p-5 mb-5"
|
|
7
|
-
},
|
|
8
|
+
}, Re = { key: 1 }, ze = { key: 2 }, We = /* @__PURE__ */ Se({
|
|
8
9
|
__name: "PTable",
|
|
9
10
|
props: {
|
|
10
11
|
idField: { default: "id" },
|
|
11
|
-
item: {},
|
|
12
|
+
item: { default: {} },
|
|
12
13
|
columns: {},
|
|
13
14
|
modalWidth: { default: 800 },
|
|
14
15
|
hiddenAdd: { type: Boolean, default: !1 },
|
|
@@ -21,8 +22,8 @@ const Be = { id: "data-content" }, Te = {
|
|
|
21
22
|
onSave: {},
|
|
22
23
|
onDelete: {}
|
|
23
24
|
},
|
|
24
|
-
setup(
|
|
25
|
-
const W =
|
|
25
|
+
setup(X, { expose: Y }) {
|
|
26
|
+
const W = u(null), J = he(), h = ve(), b = u(!1), _ = u([]), C = u([]), S = u(null), p = u(!1), v = u(!1), M = u(!1), f = u({
|
|
26
27
|
page: 1,
|
|
27
28
|
itemCount: 0,
|
|
28
29
|
pageSize: 10,
|
|
@@ -34,14 +35,14 @@ const Be = { id: "data-content" }, Te = {
|
|
|
34
35
|
onUpdatePageSize: async (e) => {
|
|
35
36
|
f.value.pageSize = e, await g();
|
|
36
37
|
}
|
|
37
|
-
}),
|
|
38
|
-
const t = (
|
|
38
|
+
}), l = X, Q = (e) => {
|
|
39
|
+
const t = (o) => {
|
|
39
40
|
const a = [];
|
|
40
41
|
return e && e.forEach((i) => {
|
|
41
42
|
i.key !== "edit" && i.key !== "delete" && a.push({
|
|
42
43
|
label: i.name,
|
|
43
44
|
key: i.key,
|
|
44
|
-
props: { onClick: () => i.action(
|
|
45
|
+
props: { onClick: () => i.action(o) }
|
|
45
46
|
});
|
|
46
47
|
}), a;
|
|
47
48
|
};
|
|
@@ -50,173 +51,176 @@ const Be = { id: "data-content" }, Te = {
|
|
|
50
51
|
key: "actions",
|
|
51
52
|
width: 100,
|
|
52
53
|
fixed: "right",
|
|
53
|
-
render: (
|
|
54
|
+
render: (o) => {
|
|
54
55
|
let a = [];
|
|
55
|
-
if (
|
|
56
|
+
if (l.hiddenEdit || a.push({
|
|
56
57
|
label: "编辑",
|
|
57
58
|
key: "edit",
|
|
58
|
-
props: { onClick: () =>
|
|
59
|
-
}),
|
|
59
|
+
props: { onClick: () => le(o) }
|
|
60
|
+
}), l.hiddenDelete || a.push({
|
|
60
61
|
label: "删除",
|
|
61
62
|
key: "delete",
|
|
62
|
-
props: { onClick: () =>
|
|
63
|
-
}), a = [...a, ...t(
|
|
63
|
+
props: { onClick: () => ee(o) }
|
|
64
|
+
}), a = [...a, ...t(o)], !(a.length <= 0))
|
|
64
65
|
return T(
|
|
65
|
-
|
|
66
|
+
Ce,
|
|
66
67
|
{
|
|
67
68
|
options: a,
|
|
68
69
|
placement: "bottom-start"
|
|
69
70
|
},
|
|
70
71
|
{
|
|
71
72
|
default: () => T(
|
|
72
|
-
|
|
73
|
+
w,
|
|
73
74
|
{ size: "small", type: "primary" },
|
|
74
|
-
{ default: () => ["操作", T(
|
|
75
|
+
{ default: () => ["操作", T(O, () => T(Be))] }
|
|
75
76
|
)
|
|
76
77
|
}
|
|
77
78
|
);
|
|
78
79
|
}
|
|
79
80
|
};
|
|
80
|
-
},
|
|
81
|
-
const e =
|
|
82
|
-
title:
|
|
83
|
-
key:
|
|
84
|
-
width:
|
|
85
|
-
fixed:
|
|
86
|
-
render:
|
|
87
|
-
ellipsis:
|
|
88
|
-
})), t =
|
|
89
|
-
(
|
|
81
|
+
}, Z = G(() => {
|
|
82
|
+
const e = l.columns.filter((o) => o.key != "action").map((o) => ({
|
|
83
|
+
title: o.title,
|
|
84
|
+
key: o.key,
|
|
85
|
+
width: o.width,
|
|
86
|
+
fixed: o.fixed ?? !1,
|
|
87
|
+
render: o.render,
|
|
88
|
+
ellipsis: o.ellipsis ? { tooltip: !0 } : !1
|
|
89
|
+
})), t = l.columns.reduce(
|
|
90
|
+
(o, a) => a.key === "action" ? a : o,
|
|
90
91
|
void 0
|
|
91
92
|
)?.action;
|
|
92
|
-
return t && t?.length > 0 || !
|
|
93
|
+
return t && t?.length > 0 || !l.hiddenDelete || !l.hiddenEdit ? [
|
|
93
94
|
{ type: "selection", fixed: "left" },
|
|
94
95
|
...e,
|
|
95
|
-
|
|
96
|
+
Q(t)
|
|
96
97
|
] : [{ type: "selection", fixed: "left" }, ...e];
|
|
97
98
|
}), A = async () => {
|
|
98
99
|
await g();
|
|
99
|
-
},
|
|
100
|
+
}, ee = (e) => {
|
|
100
101
|
I([e]);
|
|
101
|
-
},
|
|
102
|
+
}, te = () => {
|
|
102
103
|
const e = N();
|
|
103
104
|
I(e);
|
|
104
105
|
}, I = (e) => {
|
|
105
|
-
e && e.length > 0 &&
|
|
106
|
+
e && e.length > 0 && J.warning({
|
|
106
107
|
title: "警告",
|
|
107
108
|
content: "删除数据不可恢复, 确认删除吗?",
|
|
108
109
|
positiveText: "确定",
|
|
109
110
|
negativeText: "取消",
|
|
110
111
|
onPositiveClick: async () => {
|
|
111
|
-
if (
|
|
112
|
+
if (l.onDelete)
|
|
112
113
|
try {
|
|
113
|
-
await
|
|
114
|
+
await l.onDelete(e) ? (g(), h.success("删除成功")) : h.error("删除失败");
|
|
114
115
|
} catch (t) {
|
|
115
|
-
|
|
116
|
+
h.error(t.message);
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
});
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}, oe = async (e) => {
|
|
126
|
-
if (o.onOpenModal) {
|
|
127
|
-
o.onOpenModal(e);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
o.onGet && (e = await o.onGet(e[o.idField])), $.value = e, Object.assign(o.item, e), p.value = !1, v.value = !0;
|
|
120
|
+
}, oe = () => {
|
|
121
|
+
S.value = null, F();
|
|
122
|
+
}, le = async (e) => {
|
|
123
|
+
S.value = e, F(e, async () => {
|
|
124
|
+
l.onGet && (e = await l.onGet(e[l.idField])), Object.assign(l.item, e);
|
|
125
|
+
});
|
|
131
126
|
}, V = async () => {
|
|
132
|
-
if (
|
|
127
|
+
if (l.onSave)
|
|
133
128
|
try {
|
|
134
|
-
|
|
129
|
+
M.value = !0, (p.value ? await l.onSave(void 0, $(l.item)) : await l.onSave(S.value[l.idField], $(l.item))) && (D(), await g());
|
|
135
130
|
} catch (e) {
|
|
136
|
-
|
|
131
|
+
h.error(e.message);
|
|
137
132
|
} finally {
|
|
138
|
-
|
|
133
|
+
M.value = !1;
|
|
139
134
|
}
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
}, F = async (e, t) => {
|
|
136
|
+
if (Te(l.item), l.onOpenModal) {
|
|
137
|
+
l.onOpenModal(e);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
await t?.(), e ? (p.value = !1, v.value = !0) : (v.value = !1, p.value = !0);
|
|
141
|
+
}, D = () => {
|
|
142
|
+
if (S.value = null, l.onCloseModal) {
|
|
143
|
+
l.onCloseModal();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
p.value = !1, v.value = !1;
|
|
147
|
+
}, N = () => _.value ? C.value.filter((t) => _.value.includes(t.id)).map((t) => $(t)) : [], ne = () => N()[0], ae = () => $(C.value), g = async () => {
|
|
143
148
|
if (!b.value) {
|
|
144
149
|
b.value = !0;
|
|
145
150
|
try {
|
|
146
|
-
if (
|
|
147
|
-
var { data: e, total: t } = await
|
|
151
|
+
if (l.onLoad) {
|
|
152
|
+
var { data: e, total: t } = await l.onLoad(
|
|
148
153
|
f.value.page,
|
|
149
154
|
f.value.pageSize
|
|
150
155
|
);
|
|
151
156
|
C.value = e, f.value.itemCount = t;
|
|
152
157
|
}
|
|
153
|
-
} catch (
|
|
154
|
-
|
|
158
|
+
} catch (o) {
|
|
159
|
+
h.error(o.message);
|
|
155
160
|
} finally {
|
|
156
161
|
b.value = !1;
|
|
157
162
|
}
|
|
158
163
|
}
|
|
159
|
-
},
|
|
164
|
+
}, se = G(() => {
|
|
160
165
|
const e = r(W);
|
|
161
166
|
if (!e) return;
|
|
162
|
-
const t = e?.$el,
|
|
163
|
-
let
|
|
167
|
+
const t = e?.$el, o = t.querySelector(".n-data-table-thead "), { bottomIncludeBody: a } = de(o), i = 64;
|
|
168
|
+
let c = 2, d = 24;
|
|
164
169
|
const y = t.querySelector(
|
|
165
170
|
".n-data-table__pagination"
|
|
166
171
|
);
|
|
167
172
|
if (y) {
|
|
168
173
|
const R = y.offsetHeight;
|
|
169
|
-
|
|
174
|
+
c += R || 0;
|
|
170
175
|
} else
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const t = document.documentElement, l = t.scrollLeft, a = t.scrollTop, i = t.clientLeft, u = t.clientTop, d = window.pageXOffset, y = window.pageYOffset, O = se(e), {
|
|
176
|
+
c += 28;
|
|
177
|
+
return a - (i + c + d);
|
|
178
|
+
}), ie = (e) => !e || !e.getBoundingClientRect ? 0 : e.getBoundingClientRect(), de = (e) => {
|
|
179
|
+
const t = document.documentElement, o = t.scrollLeft, a = t.scrollTop, i = t.clientLeft, c = t.clientTop, d = window.pageXOffset, y = window.pageYOffset, U = ie(e), {
|
|
176
180
|
left: R,
|
|
177
|
-
top:
|
|
178
|
-
width:
|
|
181
|
+
top: re,
|
|
182
|
+
width: ue,
|
|
179
183
|
height: ce
|
|
180
|
-
} =
|
|
184
|
+
} = U, fe = (d || o) - (i || 0), pe = (y || a) - (c || 0), ge = R + d, me = re + y, z = ge - fe, L = me - pe, j = window.document.documentElement.clientWidth, q = window.document.documentElement.clientHeight;
|
|
181
185
|
return {
|
|
182
186
|
left: z,
|
|
183
187
|
top: L,
|
|
184
|
-
right:
|
|
185
|
-
bottom:
|
|
186
|
-
rightIncludeBody:
|
|
187
|
-
bottomIncludeBody:
|
|
188
|
+
right: j - ue - z,
|
|
189
|
+
bottom: q - ce - L,
|
|
190
|
+
rightIncludeBody: j - z,
|
|
191
|
+
bottomIncludeBody: q - L
|
|
188
192
|
};
|
|
189
193
|
};
|
|
190
|
-
return
|
|
191
|
-
getData:
|
|
192
|
-
getSelectedRow:
|
|
194
|
+
return Me(async () => await A()), Y({
|
|
195
|
+
getData: ae,
|
|
196
|
+
getSelectedRow: ne,
|
|
193
197
|
getSelectedRows: N,
|
|
194
|
-
closeModal:
|
|
198
|
+
closeModal: D,
|
|
195
199
|
refreshData: g,
|
|
196
200
|
resetPage: () => {
|
|
197
201
|
f.value.page = 1;
|
|
198
202
|
}
|
|
199
203
|
}), (e, t) => {
|
|
200
|
-
const
|
|
201
|
-
return
|
|
204
|
+
const o = _e, a = we, i = be, c = ke;
|
|
205
|
+
return m(), H(r(ye), {
|
|
202
206
|
title: " ",
|
|
203
207
|
"header-class": "p-4",
|
|
204
208
|
"content-class": "pl-4 pr-4",
|
|
205
209
|
bordered: !1
|
|
206
210
|
}, {
|
|
207
211
|
"header-extra": n(() => [
|
|
208
|
-
e.hiddenAdd ?
|
|
212
|
+
e.hiddenAdd ? k("", !0) : (m(), H(o, {
|
|
209
213
|
key: 0,
|
|
210
214
|
trigger: "hover"
|
|
211
215
|
}, {
|
|
212
216
|
trigger: n(() => [
|
|
213
|
-
s(r(
|
|
217
|
+
s(r(O), {
|
|
214
218
|
size: "18",
|
|
215
219
|
class: "mr-1 cursor-pointer hover:text-blue-600",
|
|
216
|
-
onClick:
|
|
220
|
+
onClick: oe
|
|
217
221
|
}, {
|
|
218
222
|
default: n(() => [
|
|
219
|
-
s(r(
|
|
223
|
+
s(r(De))
|
|
220
224
|
]),
|
|
221
225
|
_: 1
|
|
222
226
|
})
|
|
@@ -227,15 +231,15 @@ const Be = { id: "data-content" }, Te = {
|
|
|
227
231
|
_: 1,
|
|
228
232
|
__: [3]
|
|
229
233
|
})),
|
|
230
|
-
e.hiddenDelete ?
|
|
234
|
+
e.hiddenDelete ? k("", !0) : (m(), H(o, {
|
|
231
235
|
key: 1,
|
|
232
236
|
trigger: "hover"
|
|
233
237
|
}, {
|
|
234
238
|
trigger: n(() => [
|
|
235
|
-
s(r(
|
|
239
|
+
s(r(O), {
|
|
236
240
|
size: "18",
|
|
237
241
|
class: "mr-1 cursor-pointer hover:text-blue-600",
|
|
238
|
-
onClick:
|
|
242
|
+
onClick: te
|
|
239
243
|
}, {
|
|
240
244
|
default: n(() => [
|
|
241
245
|
s(r(Oe))
|
|
@@ -249,15 +253,15 @@ const Be = { id: "data-content" }, Te = {
|
|
|
249
253
|
_: 1,
|
|
250
254
|
__: [4]
|
|
251
255
|
})),
|
|
252
|
-
s(
|
|
256
|
+
s(o, { trigger: "hover" }, {
|
|
253
257
|
trigger: n(() => [
|
|
254
|
-
s(r(
|
|
258
|
+
s(r(O), {
|
|
255
259
|
size: "18",
|
|
256
260
|
class: "cursor-pointer hover:text-blue-600",
|
|
257
261
|
onClick: A
|
|
258
262
|
}, {
|
|
259
263
|
default: n(() => [
|
|
260
|
-
s(r(
|
|
264
|
+
s(r(Ee))
|
|
261
265
|
]),
|
|
262
266
|
_: 1
|
|
263
267
|
})
|
|
@@ -270,27 +274,27 @@ const Be = { id: "data-content" }, Te = {
|
|
|
270
274
|
})
|
|
271
275
|
]),
|
|
272
276
|
default: n(() => [
|
|
273
|
-
E("div",
|
|
274
|
-
e.$slots.toolbar ? (
|
|
277
|
+
E("div", $e, [
|
|
278
|
+
e.$slots.toolbar ? (m(), x("div", Ne, [
|
|
275
279
|
P(e.$slots, "toolbar")
|
|
276
|
-
])) :
|
|
280
|
+
])) : k("", !0),
|
|
277
281
|
s(a, {
|
|
278
282
|
remote: "",
|
|
279
283
|
ref_key: "$table",
|
|
280
284
|
ref: W,
|
|
281
285
|
"checked-row-keys": _.value,
|
|
282
286
|
"onUpdate:checkedRowKeys": t[0] || (t[0] = (d) => _.value = d),
|
|
283
|
-
"max-height":
|
|
287
|
+
"max-height": se.value,
|
|
284
288
|
loading: b.value,
|
|
285
289
|
bordered: !1,
|
|
286
290
|
"single-line": !1,
|
|
287
|
-
columns:
|
|
291
|
+
columns: Z.value,
|
|
288
292
|
data: C.value,
|
|
289
293
|
pagination: f.value,
|
|
290
294
|
"row-key": (d) => d[e.idField]
|
|
291
295
|
}, null, 8, ["checked-row-keys", "max-height", "loading", "columns", "data", "pagination", "row-key"]),
|
|
292
|
-
e.$slots.addModal ? (
|
|
293
|
-
s(
|
|
296
|
+
e.$slots.addModal ? (m(), x("div", Re, [
|
|
297
|
+
s(c, {
|
|
294
298
|
title: "新增",
|
|
295
299
|
preset: "dialog",
|
|
296
300
|
show: p.value,
|
|
@@ -298,14 +302,14 @@ const Be = { id: "data-content" }, Te = {
|
|
|
298
302
|
closable: !1,
|
|
299
303
|
"close-on-esc": !1,
|
|
300
304
|
"mask-closable": !1,
|
|
301
|
-
style:
|
|
305
|
+
style: K({ width: `${e.modalWidth}px` })
|
|
302
306
|
}, {
|
|
303
307
|
action: n(() => [
|
|
304
308
|
s(i, null, {
|
|
305
309
|
default: n(() => [
|
|
306
|
-
s(r(
|
|
310
|
+
s(r(w), {
|
|
307
311
|
type: "primary",
|
|
308
|
-
loading:
|
|
312
|
+
loading: M.value,
|
|
309
313
|
onClick: V
|
|
310
314
|
}, {
|
|
311
315
|
default: n(() => t[6] || (t[6] = [
|
|
@@ -314,7 +318,7 @@ const Be = { id: "data-content" }, Te = {
|
|
|
314
318
|
_: 1,
|
|
315
319
|
__: [6]
|
|
316
320
|
}, 8, ["loading"]),
|
|
317
|
-
s(r(
|
|
321
|
+
s(r(w), { onClick: D }, {
|
|
318
322
|
default: n(() => t[7] || (t[7] = [
|
|
319
323
|
B("取消", -1)
|
|
320
324
|
])),
|
|
@@ -330,9 +334,9 @@ const Be = { id: "data-content" }, Te = {
|
|
|
330
334
|
]),
|
|
331
335
|
_: 3
|
|
332
336
|
}, 8, ["show", "style"])
|
|
333
|
-
])) :
|
|
334
|
-
e.$slots.editModal ? (
|
|
335
|
-
s(
|
|
337
|
+
])) : k("", !0),
|
|
338
|
+
e.$slots.editModal ? (m(), x("div", ze, [
|
|
339
|
+
s(c, {
|
|
336
340
|
title: "编辑",
|
|
337
341
|
show: v.value,
|
|
338
342
|
"onUpdate:show": t[2] || (t[2] = (d) => v.value = d),
|
|
@@ -340,14 +344,14 @@ const Be = { id: "data-content" }, Te = {
|
|
|
340
344
|
closable: !1,
|
|
341
345
|
"close-on-esc": !1,
|
|
342
346
|
"mask-closable": !1,
|
|
343
|
-
style:
|
|
347
|
+
style: K({ width: `${e.modalWidth}px` })
|
|
344
348
|
}, {
|
|
345
349
|
action: n(() => [
|
|
346
350
|
s(i, null, {
|
|
347
351
|
default: n(() => [
|
|
348
|
-
s(r(
|
|
352
|
+
s(r(w), {
|
|
349
353
|
type: "primary",
|
|
350
|
-
loading:
|
|
354
|
+
loading: M.value,
|
|
351
355
|
onClick: V
|
|
352
356
|
}, {
|
|
353
357
|
default: n(() => t[8] || (t[8] = [
|
|
@@ -356,7 +360,7 @@ const Be = { id: "data-content" }, Te = {
|
|
|
356
360
|
_: 1,
|
|
357
361
|
__: [8]
|
|
358
362
|
}, 8, ["loading"]),
|
|
359
|
-
s(r(
|
|
363
|
+
s(r(w), { onClick: D }, {
|
|
360
364
|
default: n(() => t[9] || (t[9] = [
|
|
361
365
|
B("取消", -1)
|
|
362
366
|
])),
|
|
@@ -372,7 +376,7 @@ const Be = { id: "data-content" }, Te = {
|
|
|
372
376
|
]),
|
|
373
377
|
_: 3
|
|
374
378
|
}, 8, ["show", "style"])
|
|
375
|
-
])) :
|
|
379
|
+
])) : k("", !0)
|
|
376
380
|
])
|
|
377
381
|
]),
|
|
378
382
|
_: 3
|
|
@@ -381,5 +385,5 @@ const Be = { id: "data-content" }, Te = {
|
|
|
381
385
|
}
|
|
382
386
|
});
|
|
383
387
|
export {
|
|
384
|
-
|
|
388
|
+
We as default
|
|
385
389
|
};
|
package/es/table/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare const _default: {
|
|
|
8
8
|
getSelectedRow: <T>() => T;
|
|
9
9
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, import('vue').PublicProps, {
|
|
10
10
|
idField: string;
|
|
11
|
+
item: any;
|
|
11
12
|
modalWidth: number;
|
|
12
13
|
hiddenAdd: boolean;
|
|
13
14
|
hiddenEdit: boolean;
|
|
@@ -30,6 +31,7 @@ declare const _default: {
|
|
|
30
31
|
getSelectedRow: <T>() => T;
|
|
31
32
|
}, {}, {}, {}, {
|
|
32
33
|
idField: string;
|
|
34
|
+
item: any;
|
|
33
35
|
modalWidth: number;
|
|
34
36
|
hiddenAdd: boolean;
|
|
35
37
|
hiddenEdit: boolean;
|
|
@@ -47,6 +49,7 @@ declare const _default: {
|
|
|
47
49
|
getSelectedRow: <T>() => T;
|
|
48
50
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, {
|
|
49
51
|
idField: string;
|
|
52
|
+
item: any;
|
|
50
53
|
modalWidth: number;
|
|
51
54
|
hiddenAdd: boolean;
|
|
52
55
|
hiddenEdit: boolean;
|
package/es/table/typing.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface DataTableColumnDefine {
|
|
|
16
16
|
}
|
|
17
17
|
export interface DataTableProps {
|
|
18
18
|
idField?: string;
|
|
19
|
-
item
|
|
19
|
+
item?: any;
|
|
20
20
|
columns: DataTableColumnDefine[];
|
|
21
21
|
modalWidth?: number;
|
|
22
22
|
hiddenAdd?: boolean;
|
|
@@ -29,7 +29,7 @@ export interface DataTableProps {
|
|
|
29
29
|
onGet?: (id: string | number) => Promise<any>;
|
|
30
30
|
onOpenModal?: (item?: any) => void;
|
|
31
31
|
onCloseModal?: (item?: any) => void;
|
|
32
|
-
onSave?: (id?: string | number) => Promise<boolean> | boolean;
|
|
32
|
+
onSave?: (id?: string | number, row?: any) => Promise<boolean> | boolean;
|
|
33
33
|
onDelete?: (rows: any[]) => Promise<boolean> | boolean;
|
|
34
34
|
}
|
|
35
35
|
export interface DataTableMethods {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resetObject: (obj: Record<string, any>) => void;
|
package/lib/modal/PModal.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ declare function __VLS_template(): {
|
|
|
3
3
|
attrs: Partial<{}>;
|
|
4
4
|
slots: {
|
|
5
5
|
default?(_: {}): any;
|
|
6
|
-
action?(_: {}): any;
|
|
6
|
+
'action-extra'?(_: {}): any;
|
|
7
7
|
};
|
|
8
8
|
refs: {
|
|
9
9
|
$modal: import('vue').CreateComponentPublicInstanceWithMixins<Readonly<import('vue').ExtractPropTypes<{
|
package/lib/modal/PModal.vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("naive-ui"),e=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("naive-ui"),e=require("vue"),m={class:"w-full cursor-move",id:"basic-modal-bar"},w=e.defineComponent({__name:"PModal",props:{saveBtnText:{default:"保 存"},closable:{type:Boolean,default:!1},preset:{default:"dialog"},title:{default:"操作"},width:{default:800},onSave:{},onClose:{}},setup(d,{expose:u}){const i=r.useMessage(),a=d,o=e.ref(!1),s=e.ref(!1),f=async()=>{o.value=!0;try{a.onSave&&await a.onSave()&&l()}catch(t){i.error(t.message)}finally{o.value=!1}},l=()=>{s.value=!1,o.value=!1},p=async()=>{try{a.onClose?await a.onClose()&&l():l()}catch(t){i.error(t.message)}};return u({open:()=>{o.value=!1,s.value=!0},close:()=>{s.value=!1,o.value=!1}}),(t,n)=>{const c=r.NButton,v=r.NSpace;return e.openBlock(),e.createBlock(e.unref(r.NModal),e.mergeProps({ref:"$modal",preset:"dialog",show:s.value,"onUpdate:show":n[0]||(n[0]=g=>s.value=g)},t.$attrs,{draggable:!0,closable:!1,"close-on-esc":!1,"mask-closable":!1,style:{width:`${a.width}px`},onClose:l}),{header:e.withCtx(()=>[e.createElementVNode("div",m,e.toDisplayString(t.title),1)]),default:e.withCtx(()=>[e.renderSlot(t.$slots,"default")]),action:e.withCtx(()=>[e.createVNode(v,null,{default:e.withCtx(()=>[e.createVNode(c,{type:"primary",loading:o.value,onClick:f},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(t.saveBtnText),1)]),_:1},8,["loading"]),e.renderSlot(t.$slots,"action-extra"),e.createVNode(c,{onClick:p},{default:e.withCtx(()=>n[1]||(n[1]=[e.createTextVNode("取 消",-1)])),_:1,__:[1]})]),_:3})]),_:3},16,["show","style"])}}});exports.default=w;
|
package/lib/modal/index.d.ts
CHANGED
|
@@ -2113,7 +2113,7 @@ declare const _default: {
|
|
|
2113
2113
|
}, {}, string, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, import('vue').ComponentProvideOptions> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
|
|
2114
2114
|
$slots: {
|
|
2115
2115
|
default?(_: {}): any;
|
|
2116
|
-
action?(_: {}): any;
|
|
2116
|
+
'action-extra'?(_: {}): any;
|
|
2117
2117
|
};
|
|
2118
2118
|
}) & import('vue').Plugin;
|
|
2119
2119
|
export default _default;
|
package/lib/table/PTable.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ declare const __VLS_component: import('vue').DefineComponent<DataTableProps, {
|
|
|
21
21
|
getSelectedRow: <T>() => T;
|
|
22
22
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<DataTableProps> & Readonly<{}>, {
|
|
23
23
|
idField: string;
|
|
24
|
+
item: any;
|
|
24
25
|
modalWidth: number;
|
|
25
26
|
hiddenAdd: boolean;
|
|
26
27
|
hiddenEdit: boolean;
|
package/lib/table/PTable.vue.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const s=require("naive-ui"),e=require("vue"),N=require("@vicons/antd"),oe=require("../utils/helper.cjs"),le={id:"data-content"},ne={key:0,class:"rounded-lg bg-gray-50 flex flex-row gap-2 items-center justify-end p-5 mb-5"},ae={key:1},se={key:2},ie=e.defineComponent({__name:"PTable",props:{idField:{default:"id"},item:{default:{}},columns:{},modalWidth:{default:800},hiddenAdd:{type:Boolean,default:!1},hiddenEdit:{type:Boolean,default:!1},hiddenDelete:{type:Boolean,default:!1},onLoad:{},onGet:{},onOpenModal:{},onCloseModal:{},onSave:{},onDelete:{}},setup($,{expose:z}){const B=e.ref(null),L=s.useDialog(),p=s.useMessage(),m=e.ref(!1),v=e.ref([]),w=e.ref([]),y=e.ref(null),u=e.ref(!1),h=e.ref(!1),C=e.ref(!1),c=e.ref({page:1,itemCount:0,pageSize:10,pageSizes:[10,20,30,50],showSizePicker:!0,onChange:async t=>{c.value.page=t,await f()},onUpdatePageSize:async t=>{c.value.pageSize=t,await f()}}),n=$,H=t=>{const o=l=>{const a=[];return t&&t.forEach(i=>{i.key!=="edit"&&i.key!=="delete"&&a.push({label:i.name,key:i.key,props:{onClick:()=>i.action(l)}})}),a};return{title:"操作",key:"actions",width:100,fixed:"right",render:l=>{let a=[];if(n.hiddenEdit||a.push({label:"编辑",key:"edit",props:{onClick:()=>A(l)}}),n.hiddenDelete||a.push({label:"删除",key:"delete",props:{onClick:()=>q(l)}}),a=[...a,...o(l)],!(a.length<=0))return e.h(s.NDropdown,{options:a,placement:"bottom-start"},{default:()=>e.h(s.NButton,{size:"small",type:"primary"},{default:()=>["操作",e.h(s.NIcon,()=>e.h(N.MoreOutlined))]})})}}},I=e.computed(()=>{const t=n.columns.filter(l=>l.key!="action").map(l=>({title:l.title,key:l.key,width:l.width,fixed:l.fixed??!1,render:l.render,ellipsis:l.ellipsis?{tooltip:!0}:!1})),o=n.columns.reduce((l,a)=>a.key==="action"?a:l,void 0)?.action;return o&&o?.length>0||!n.hiddenDelete||!n.hiddenEdit?[{type:"selection",fixed:"left"},...t,H(o)]:[{type:"selection",fixed:"left"},...t]}),S=async()=>{await f()},q=t=>{M([t])},P=()=>{const t=b();M(t)},M=t=>{t&&t.length>0&&L.warning({title:"警告",content:"删除数据不可恢复, 确认删除吗?",positiveText:"确定",negativeText:"取消",onPositiveClick:async()=>{if(n.onDelete)try{await n.onDelete(t)?(f(),p.success("删除成功")):p.error("删除失败")}catch(o){p.error(o.message)}}})},W=()=>{y.value=null,T()},A=async t=>{y.value=t,T(t,async()=>{n.onGet&&(t=await n.onGet(t[n.idField])),Object.assign(n.item,t)})},E=async()=>{if(n.onSave)try{C.value=!0,(u.value?await n.onSave(void 0,e.toRaw(n.item)):await n.onSave(y.value[n.idField],e.toRaw(n.item)))&&(k(),await f())}catch(t){p.error(t.message)}finally{C.value=!1}},T=async(t,o)=>{if(oe.resetObject(n.item),n.onOpenModal){n.onOpenModal(t);return}await o?.(),t?(u.value=!1,h.value=!0):(h.value=!1,u.value=!0)},k=()=>{if(y.value=null,n.onCloseModal){n.onCloseModal();return}u.value=!1,h.value=!1},b=()=>v.value?w.value.filter(o=>v.value.includes(o.id)).map(o=>e.toRaw(o)):[],U=()=>b()[0],j=()=>e.toRaw(w.value),f=async()=>{if(!m.value){m.value=!0;try{if(n.onLoad){var{data:t,total:o}=await n.onLoad(c.value.page,c.value.pageSize);w.value=t,c.value.itemCount=o}}catch(l){p.error(l.message)}finally{m.value=!1}}},F=e.computed(()=>{const t=e.unref(B);if(!t)return;const o=t?.$el,l=o.querySelector(".n-data-table-thead "),{bottomIncludeBody:a}=K(l),i=64;let d=2,r=24;const g=o.querySelector(".n-data-table__pagination");if(g){const x=g.offsetHeight;d+=x||0}else d+=28;return a-(i+d+r)}),G=t=>!t||!t.getBoundingClientRect?0:t.getBoundingClientRect(),K=t=>{const o=document.documentElement,l=o.scrollLeft,a=o.scrollTop,i=o.clientLeft,d=o.clientTop,r=window.pageXOffset,g=window.pageYOffset,D=G(t),{left:x,top:X,width:Y,height:J}=D,Q=(r||l)-(i||0),Z=(g||a)-(d||0),ee=x+r,te=X+g,V=ee-Q,_=te-Z,O=window.document.documentElement.clientWidth,R=window.document.documentElement.clientHeight;return{left:V,top:_,right:O-Y-V,bottom:R-J-_,rightIncludeBody:O-V,bottomIncludeBody:R-_}};return e.onMounted(async()=>await S()),z({getData:j,getSelectedRow:U,getSelectedRows:b,closeModal:k,refreshData:f,resetPage:()=>{c.value.page=1}}),(t,o)=>{const l=s.NTooltip,a=s.NDataTable,i=s.NSpace,d=s.NModal;return e.openBlock(),e.createBlock(e.unref(s.NCard),{title:" ","header-class":"p-4","content-class":"pl-4 pr-4",bordered:!1},{"header-extra":e.withCtx(()=>[t.hiddenAdd?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(l,{key:0,trigger:"hover"},{trigger:e.withCtx(()=>[e.createVNode(e.unref(s.NIcon),{size:"18",class:"mr-1 cursor-pointer hover:text-blue-600",onClick:W},{default:e.withCtx(()=>[e.createVNode(e.unref(N.PlusSquareOutlined))]),_:1})]),default:e.withCtx(()=>[o[3]||(o[3]=e.createElementVNode("span",null,"新增",-1))]),_:1,__:[3]})),t.hiddenDelete?e.createCommentVNode("",!0):(e.openBlock(),e.createBlock(l,{key:1,trigger:"hover"},{trigger:e.withCtx(()=>[e.createVNode(e.unref(s.NIcon),{size:"18",class:"mr-1 cursor-pointer hover:text-blue-600",onClick:P},{default:e.withCtx(()=>[e.createVNode(e.unref(N.DeleteOutlined))]),_:1})]),default:e.withCtx(()=>[o[4]||(o[4]=e.createElementVNode("span",null,"删除",-1))]),_:1,__:[4]})),e.createVNode(l,{trigger:"hover"},{trigger:e.withCtx(()=>[e.createVNode(e.unref(s.NIcon),{size:"18",class:"cursor-pointer hover:text-blue-600",onClick:S},{default:e.withCtx(()=>[e.createVNode(e.unref(N.ReloadOutlined))]),_:1})]),default:e.withCtx(()=>[o[5]||(o[5]=e.createElementVNode("span",null,"刷新",-1))]),_:1,__:[5]})]),default:e.withCtx(()=>[e.createElementVNode("div",le,[t.$slots.toolbar?(e.openBlock(),e.createElementBlock("div",ne,[e.renderSlot(t.$slots,"toolbar")])):e.createCommentVNode("",!0),e.createVNode(a,{remote:"",ref_key:"$table",ref:B,"checked-row-keys":v.value,"onUpdate:checkedRowKeys":o[0]||(o[0]=r=>v.value=r),"max-height":F.value,loading:m.value,bordered:!1,"single-line":!1,columns:I.value,data:w.value,pagination:c.value,"row-key":r=>r[t.idField]},null,8,["checked-row-keys","max-height","loading","columns","data","pagination","row-key"]),t.$slots.addModal?(e.openBlock(),e.createElementBlock("div",ae,[e.createVNode(d,{title:"新增",preset:"dialog",show:u.value,"onUpdate:show":o[1]||(o[1]=r=>u.value=r),closable:!1,"close-on-esc":!1,"mask-closable":!1,style:e.normalizeStyle({width:`${t.modalWidth}px`})},{action:e.withCtx(()=>[e.createVNode(i,null,{default:e.withCtx(()=>[e.createVNode(e.unref(s.NButton),{type:"primary",loading:C.value,onClick:E},{default:e.withCtx(()=>o[6]||(o[6]=[e.createTextVNode("保存",-1)])),_:1,__:[6]},8,["loading"]),e.createVNode(e.unref(s.NButton),{onClick:k},{default:e.withCtx(()=>o[7]||(o[7]=[e.createTextVNode("取消",-1)])),_:1,__:[7]})]),_:1})]),default:e.withCtx(()=>[e.renderSlot(t.$slots,"addModal")]),_:3},8,["show","style"])])):e.createCommentVNode("",!0),t.$slots.editModal?(e.openBlock(),e.createElementBlock("div",se,[e.createVNode(d,{title:"编辑",show:h.value,"onUpdate:show":o[2]||(o[2]=r=>h.value=r),preset:"dialog",closable:!1,"close-on-esc":!1,"mask-closable":!1,style:e.normalizeStyle({width:`${t.modalWidth}px`})},{action:e.withCtx(()=>[e.createVNode(i,null,{default:e.withCtx(()=>[e.createVNode(e.unref(s.NButton),{type:"primary",loading:C.value,onClick:E},{default:e.withCtx(()=>o[8]||(o[8]=[e.createTextVNode("保存",-1)])),_:1,__:[8]},8,["loading"]),e.createVNode(e.unref(s.NButton),{onClick:k},{default:e.withCtx(()=>o[9]||(o[9]=[e.createTextVNode("取消",-1)])),_:1,__:[9]})]),_:1})]),default:e.withCtx(()=>[e.renderSlot(t.$slots,"editModal")]),_:3},8,["show","style"])])):e.createCommentVNode("",!0)])]),_:3})}}});exports.default=ie;
|
package/lib/table/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ declare const _default: {
|
|
|
8
8
|
getSelectedRow: <T>() => T;
|
|
9
9
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, import('vue').PublicProps, {
|
|
10
10
|
idField: string;
|
|
11
|
+
item: any;
|
|
11
12
|
modalWidth: number;
|
|
12
13
|
hiddenAdd: boolean;
|
|
13
14
|
hiddenEdit: boolean;
|
|
@@ -30,6 +31,7 @@ declare const _default: {
|
|
|
30
31
|
getSelectedRow: <T>() => T;
|
|
31
32
|
}, {}, {}, {}, {
|
|
32
33
|
idField: string;
|
|
34
|
+
item: any;
|
|
33
35
|
modalWidth: number;
|
|
34
36
|
hiddenAdd: boolean;
|
|
35
37
|
hiddenEdit: boolean;
|
|
@@ -47,6 +49,7 @@ declare const _default: {
|
|
|
47
49
|
getSelectedRow: <T>() => T;
|
|
48
50
|
}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, {
|
|
49
51
|
idField: string;
|
|
52
|
+
item: any;
|
|
50
53
|
modalWidth: number;
|
|
51
54
|
hiddenAdd: boolean;
|
|
52
55
|
hiddenEdit: boolean;
|
package/lib/table/typing.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface DataTableColumnDefine {
|
|
|
16
16
|
}
|
|
17
17
|
export interface DataTableProps {
|
|
18
18
|
idField?: string;
|
|
19
|
-
item
|
|
19
|
+
item?: any;
|
|
20
20
|
columns: DataTableColumnDefine[];
|
|
21
21
|
modalWidth?: number;
|
|
22
22
|
hiddenAdd?: boolean;
|
|
@@ -29,7 +29,7 @@ export interface DataTableProps {
|
|
|
29
29
|
onGet?: (id: string | number) => Promise<any>;
|
|
30
30
|
onOpenModal?: (item?: any) => void;
|
|
31
31
|
onCloseModal?: (item?: any) => void;
|
|
32
|
-
onSave?: (id?: string | number) => Promise<boolean> | boolean;
|
|
32
|
+
onSave?: (id?: string | number, row?: any) => Promise<boolean> | boolean;
|
|
33
33
|
onDelete?: (rows: any[]) => Promise<boolean> | boolean;
|
|
34
34
|
}
|
|
35
35
|
export interface DataTableMethods {
|