@chewel611/naive-ui-plus 0.0.5 → 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 +681 -688
- 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 +83 -80
- package/es/table/index.d.ts +3 -0
- package/es/table/typing.d.ts +2 -2
- package/es/utils/helper.d.ts +1 -1
- package/es/utils/helper.js +5 -4
- 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 -1
- package/lib/utils/helper.d.ts +1 -1
- package/package.json +2 -2
package/es/table/PTable.vue.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { useDialog as
|
|
2
|
-
import { defineComponent as
|
|
3
|
-
import { PlusSquareOutlined as
|
|
4
|
-
import { resetObject as
|
|
5
|
-
const
|
|
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 = {
|
|
6
6
|
key: 0,
|
|
7
7
|
class: "rounded-lg bg-gray-50 flex flex-row gap-2 items-center justify-end p-5 mb-5"
|
|
8
|
-
},
|
|
8
|
+
}, Re = { key: 1 }, ze = { key: 2 }, We = /* @__PURE__ */ Se({
|
|
9
9
|
__name: "PTable",
|
|
10
10
|
props: {
|
|
11
11
|
idField: { default: "id" },
|
|
12
|
-
item: {},
|
|
12
|
+
item: { default: {} },
|
|
13
13
|
columns: {},
|
|
14
14
|
modalWidth: { default: 800 },
|
|
15
15
|
hiddenAdd: { type: Boolean, default: !1 },
|
|
@@ -22,8 +22,8 @@ const Te = { id: "data-content" }, $e = {
|
|
|
22
22
|
onSave: {},
|
|
23
23
|
onDelete: {}
|
|
24
24
|
},
|
|
25
|
-
setup(
|
|
26
|
-
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({
|
|
27
27
|
page: 1,
|
|
28
28
|
itemCount: 0,
|
|
29
29
|
pageSize: 10,
|
|
@@ -35,7 +35,7 @@ const Te = { id: "data-content" }, $e = {
|
|
|
35
35
|
onUpdatePageSize: async (e) => {
|
|
36
36
|
f.value.pageSize = e, await g();
|
|
37
37
|
}
|
|
38
|
-
}), l =
|
|
38
|
+
}), l = X, Q = (e) => {
|
|
39
39
|
const t = (o) => {
|
|
40
40
|
const a = [];
|
|
41
41
|
return e && e.forEach((i) => {
|
|
@@ -56,14 +56,14 @@ const Te = { id: "data-content" }, $e = {
|
|
|
56
56
|
if (l.hiddenEdit || a.push({
|
|
57
57
|
label: "编辑",
|
|
58
58
|
key: "edit",
|
|
59
|
-
props: { onClick: () =>
|
|
59
|
+
props: { onClick: () => le(o) }
|
|
60
60
|
}), l.hiddenDelete || a.push({
|
|
61
61
|
label: "删除",
|
|
62
62
|
key: "delete",
|
|
63
|
-
props: { onClick: () =>
|
|
63
|
+
props: { onClick: () => ee(o) }
|
|
64
64
|
}), a = [...a, ...t(o)], !(a.length <= 0))
|
|
65
65
|
return T(
|
|
66
|
-
|
|
66
|
+
Ce,
|
|
67
67
|
{
|
|
68
68
|
options: a,
|
|
69
69
|
placement: "bottom-start"
|
|
@@ -72,13 +72,13 @@ const Te = { id: "data-content" }, $e = {
|
|
|
72
72
|
default: () => T(
|
|
73
73
|
w,
|
|
74
74
|
{ size: "small", type: "primary" },
|
|
75
|
-
{ default: () => ["操作", T(
|
|
75
|
+
{ default: () => ["操作", T(O, () => T(Be))] }
|
|
76
76
|
)
|
|
77
77
|
}
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
},
|
|
81
|
+
}, Z = G(() => {
|
|
82
82
|
const e = l.columns.filter((o) => o.key != "action").map((o) => ({
|
|
83
83
|
title: o.title,
|
|
84
84
|
key: o.key,
|
|
@@ -93,17 +93,17 @@ const Te = { id: "data-content" }, $e = {
|
|
|
93
93
|
return t && t?.length > 0 || !l.hiddenDelete || !l.hiddenEdit ? [
|
|
94
94
|
{ type: "selection", fixed: "left" },
|
|
95
95
|
...e,
|
|
96
|
-
|
|
96
|
+
Q(t)
|
|
97
97
|
] : [{ type: "selection", fixed: "left" }, ...e];
|
|
98
98
|
}), A = async () => {
|
|
99
99
|
await g();
|
|
100
|
-
},
|
|
100
|
+
}, ee = (e) => {
|
|
101
101
|
I([e]);
|
|
102
|
-
},
|
|
102
|
+
}, te = () => {
|
|
103
103
|
const e = N();
|
|
104
104
|
I(e);
|
|
105
105
|
}, I = (e) => {
|
|
106
|
-
e && e.length > 0 &&
|
|
106
|
+
e && e.length > 0 && J.warning({
|
|
107
107
|
title: "警告",
|
|
108
108
|
content: "删除数据不可恢复, 确认删除吗?",
|
|
109
109
|
positiveText: "确定",
|
|
@@ -117,30 +117,34 @@ const Te = { id: "data-content" }, $e = {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}, oe = async (e) => {
|
|
127
|
-
if (l.onOpenModal) {
|
|
128
|
-
l.onOpenModal(e);
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
l.onGet && (e = await l.onGet(e[l.idField])), $.value = e, Object.assign(l.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
|
+
});
|
|
132
126
|
}, V = async () => {
|
|
133
127
|
if (l.onSave)
|
|
134
128
|
try {
|
|
135
|
-
|
|
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());
|
|
136
130
|
} catch (e) {
|
|
137
131
|
h.error(e.message);
|
|
138
132
|
} finally {
|
|
139
|
-
|
|
133
|
+
M.value = !1;
|
|
140
134
|
}
|
|
141
|
-
},
|
|
142
|
-
|
|
143
|
-
|
|
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 () => {
|
|
144
148
|
if (!b.value) {
|
|
145
149
|
b.value = !0;
|
|
146
150
|
try {
|
|
@@ -157,49 +161,48 @@ const Te = { id: "data-content" }, $e = {
|
|
|
157
161
|
b.value = !1;
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
|
-
},
|
|
164
|
+
}, se = G(() => {
|
|
161
165
|
const e = r(W);
|
|
162
166
|
if (!e) return;
|
|
163
|
-
const t = e?.$el, o = t.querySelector(".n-data-table-thead "), { bottomIncludeBody: a } =
|
|
164
|
-
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;
|
|
165
169
|
const y = t.querySelector(
|
|
166
170
|
".n-data-table__pagination"
|
|
167
171
|
);
|
|
168
172
|
if (y) {
|
|
169
173
|
const R = y.offsetHeight;
|
|
170
|
-
|
|
174
|
+
c += R || 0;
|
|
171
175
|
} else
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const t = document.documentElement, o = 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), {
|
|
177
180
|
left: R,
|
|
178
|
-
top:
|
|
179
|
-
width:
|
|
181
|
+
top: re,
|
|
182
|
+
width: ue,
|
|
180
183
|
height: ce
|
|
181
|
-
} =
|
|
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;
|
|
182
185
|
return {
|
|
183
186
|
left: z,
|
|
184
187
|
top: L,
|
|
185
|
-
right:
|
|
186
|
-
bottom:
|
|
187
|
-
rightIncludeBody:
|
|
188
|
-
bottomIncludeBody:
|
|
188
|
+
right: j - ue - z,
|
|
189
|
+
bottom: q - ce - L,
|
|
190
|
+
rightIncludeBody: j - z,
|
|
191
|
+
bottomIncludeBody: q - L
|
|
189
192
|
};
|
|
190
193
|
};
|
|
191
|
-
return
|
|
192
|
-
getData:
|
|
193
|
-
getSelectedRow:
|
|
194
|
+
return Me(async () => await A()), Y({
|
|
195
|
+
getData: ae,
|
|
196
|
+
getSelectedRow: ne,
|
|
194
197
|
getSelectedRows: N,
|
|
195
|
-
closeModal:
|
|
198
|
+
closeModal: D,
|
|
196
199
|
refreshData: g,
|
|
197
200
|
resetPage: () => {
|
|
198
201
|
f.value.page = 1;
|
|
199
202
|
}
|
|
200
203
|
}), (e, t) => {
|
|
201
|
-
const o =
|
|
202
|
-
return m(), H(r(
|
|
204
|
+
const o = _e, a = we, i = be, c = ke;
|
|
205
|
+
return m(), H(r(ye), {
|
|
203
206
|
title: " ",
|
|
204
207
|
"header-class": "p-4",
|
|
205
208
|
"content-class": "pl-4 pr-4",
|
|
@@ -211,13 +214,13 @@ const Te = { id: "data-content" }, $e = {
|
|
|
211
214
|
trigger: "hover"
|
|
212
215
|
}, {
|
|
213
216
|
trigger: n(() => [
|
|
214
|
-
s(r(
|
|
217
|
+
s(r(O), {
|
|
215
218
|
size: "18",
|
|
216
219
|
class: "mr-1 cursor-pointer hover:text-blue-600",
|
|
217
|
-
onClick:
|
|
220
|
+
onClick: oe
|
|
218
221
|
}, {
|
|
219
222
|
default: n(() => [
|
|
220
|
-
s(r(
|
|
223
|
+
s(r(De))
|
|
221
224
|
]),
|
|
222
225
|
_: 1
|
|
223
226
|
})
|
|
@@ -233,10 +236,10 @@ const Te = { id: "data-content" }, $e = {
|
|
|
233
236
|
trigger: "hover"
|
|
234
237
|
}, {
|
|
235
238
|
trigger: n(() => [
|
|
236
|
-
s(r(
|
|
239
|
+
s(r(O), {
|
|
237
240
|
size: "18",
|
|
238
241
|
class: "mr-1 cursor-pointer hover:text-blue-600",
|
|
239
|
-
onClick:
|
|
242
|
+
onClick: te
|
|
240
243
|
}, {
|
|
241
244
|
default: n(() => [
|
|
242
245
|
s(r(Oe))
|
|
@@ -252,13 +255,13 @@ const Te = { id: "data-content" }, $e = {
|
|
|
252
255
|
})),
|
|
253
256
|
s(o, { trigger: "hover" }, {
|
|
254
257
|
trigger: n(() => [
|
|
255
|
-
s(r(
|
|
258
|
+
s(r(O), {
|
|
256
259
|
size: "18",
|
|
257
260
|
class: "cursor-pointer hover:text-blue-600",
|
|
258
261
|
onClick: A
|
|
259
262
|
}, {
|
|
260
263
|
default: n(() => [
|
|
261
|
-
s(r(
|
|
264
|
+
s(r(Ee))
|
|
262
265
|
]),
|
|
263
266
|
_: 1
|
|
264
267
|
})
|
|
@@ -271,8 +274,8 @@ const Te = { id: "data-content" }, $e = {
|
|
|
271
274
|
})
|
|
272
275
|
]),
|
|
273
276
|
default: n(() => [
|
|
274
|
-
E("div",
|
|
275
|
-
e.$slots.toolbar ? (m(), x("div",
|
|
277
|
+
E("div", $e, [
|
|
278
|
+
e.$slots.toolbar ? (m(), x("div", Ne, [
|
|
276
279
|
P(e.$slots, "toolbar")
|
|
277
280
|
])) : k("", !0),
|
|
278
281
|
s(a, {
|
|
@@ -281,17 +284,17 @@ const Te = { id: "data-content" }, $e = {
|
|
|
281
284
|
ref: W,
|
|
282
285
|
"checked-row-keys": _.value,
|
|
283
286
|
"onUpdate:checkedRowKeys": t[0] || (t[0] = (d) => _.value = d),
|
|
284
|
-
"max-height":
|
|
287
|
+
"max-height": se.value,
|
|
285
288
|
loading: b.value,
|
|
286
289
|
bordered: !1,
|
|
287
290
|
"single-line": !1,
|
|
288
|
-
columns:
|
|
291
|
+
columns: Z.value,
|
|
289
292
|
data: C.value,
|
|
290
293
|
pagination: f.value,
|
|
291
294
|
"row-key": (d) => d[e.idField]
|
|
292
295
|
}, null, 8, ["checked-row-keys", "max-height", "loading", "columns", "data", "pagination", "row-key"]),
|
|
293
|
-
e.$slots.addModal ? (m(), x("div",
|
|
294
|
-
s(
|
|
296
|
+
e.$slots.addModal ? (m(), x("div", Re, [
|
|
297
|
+
s(c, {
|
|
295
298
|
title: "新增",
|
|
296
299
|
preset: "dialog",
|
|
297
300
|
show: p.value,
|
|
@@ -299,14 +302,14 @@ const Te = { id: "data-content" }, $e = {
|
|
|
299
302
|
closable: !1,
|
|
300
303
|
"close-on-esc": !1,
|
|
301
304
|
"mask-closable": !1,
|
|
302
|
-
style:
|
|
305
|
+
style: K({ width: `${e.modalWidth}px` })
|
|
303
306
|
}, {
|
|
304
307
|
action: n(() => [
|
|
305
308
|
s(i, null, {
|
|
306
309
|
default: n(() => [
|
|
307
310
|
s(r(w), {
|
|
308
311
|
type: "primary",
|
|
309
|
-
loading:
|
|
312
|
+
loading: M.value,
|
|
310
313
|
onClick: V
|
|
311
314
|
}, {
|
|
312
315
|
default: n(() => t[6] || (t[6] = [
|
|
@@ -315,7 +318,7 @@ const Te = { id: "data-content" }, $e = {
|
|
|
315
318
|
_: 1,
|
|
316
319
|
__: [6]
|
|
317
320
|
}, 8, ["loading"]),
|
|
318
|
-
s(r(w), { onClick:
|
|
321
|
+
s(r(w), { onClick: D }, {
|
|
319
322
|
default: n(() => t[7] || (t[7] = [
|
|
320
323
|
B("取消", -1)
|
|
321
324
|
])),
|
|
@@ -332,8 +335,8 @@ const Te = { id: "data-content" }, $e = {
|
|
|
332
335
|
_: 3
|
|
333
336
|
}, 8, ["show", "style"])
|
|
334
337
|
])) : k("", !0),
|
|
335
|
-
e.$slots.editModal ? (m(), x("div",
|
|
336
|
-
s(
|
|
338
|
+
e.$slots.editModal ? (m(), x("div", ze, [
|
|
339
|
+
s(c, {
|
|
337
340
|
title: "编辑",
|
|
338
341
|
show: v.value,
|
|
339
342
|
"onUpdate:show": t[2] || (t[2] = (d) => v.value = d),
|
|
@@ -341,14 +344,14 @@ const Te = { id: "data-content" }, $e = {
|
|
|
341
344
|
closable: !1,
|
|
342
345
|
"close-on-esc": !1,
|
|
343
346
|
"mask-closable": !1,
|
|
344
|
-
style:
|
|
347
|
+
style: K({ width: `${e.modalWidth}px` })
|
|
345
348
|
}, {
|
|
346
349
|
action: n(() => [
|
|
347
350
|
s(i, null, {
|
|
348
351
|
default: n(() => [
|
|
349
352
|
s(r(w), {
|
|
350
353
|
type: "primary",
|
|
351
|
-
loading:
|
|
354
|
+
loading: M.value,
|
|
352
355
|
onClick: V
|
|
353
356
|
}, {
|
|
354
357
|
default: n(() => t[8] || (t[8] = [
|
|
@@ -357,7 +360,7 @@ const Te = { id: "data-content" }, $e = {
|
|
|
357
360
|
_: 1,
|
|
358
361
|
__: [8]
|
|
359
362
|
}, 8, ["loading"]),
|
|
360
|
-
s(r(w), { onClick:
|
|
363
|
+
s(r(w), { onClick: D }, {
|
|
361
364
|
default: n(() => t[9] || (t[9] = [
|
|
362
365
|
B("取消", -1)
|
|
363
366
|
])),
|
|
@@ -382,5 +385,5 @@ const Te = { id: "data-content" }, $e = {
|
|
|
382
385
|
}
|
|
383
386
|
});
|
|
384
387
|
export {
|
|
385
|
-
|
|
388
|
+
We as default
|
|
386
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 {
|
package/es/utils/helper.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const resetObject: (obj:
|
|
1
|
+
export declare const resetObject: (obj: Record<string, any>) => void;
|
package/es/utils/helper.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
Object.keys(
|
|
3
|
-
|
|
1
|
+
const s = (e) => {
|
|
2
|
+
Object.keys(e).forEach((r) => {
|
|
3
|
+
const t = e[r];
|
|
4
|
+
Array.isArray(t) ? e[r] = [] : t !== null && typeof t == "object" ? s(t) : e[r] = void 0;
|
|
4
5
|
});
|
|
5
6
|
};
|
|
6
7
|
export {
|
|
7
|
-
|
|
8
|
+
s as resetObject
|
|
8
9
|
};
|
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 s=require("naive-ui"),e=require("vue"),N=require("@vicons/antd"),
|
|
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 {
|
package/lib/utils/helper.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=e=>{Object.keys(e).forEach(r=>{const t=e[r];Array.isArray(t)?e[r]=[]:t!==null&&typeof t=="object"?s(t):e[r]=void 0})};exports.resetObject=s;
|
package/lib/utils/helper.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const resetObject: (obj:
|
|
1
|
+
export declare const resetObject: (obj: Record<string, any>) => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chewel611/naive-ui-plus",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"vue-router": "^4.5.1"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@chewel611/naive-ui-plus": "^0.0.
|
|
42
|
+
"@chewel611/naive-ui-plus": "^0.0.5",
|
|
43
43
|
"@vicons/antd": "^0.13.0",
|
|
44
44
|
"element-resize-detector": "^1.2.4",
|
|
45
45
|
"i18n-jsautotranslate": "^3.18.98",
|