@silver-formily/element-plus 1.0.1 → 2.0.1
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/LICENSE +21 -21
- package/README.md +35 -35
- package/esm/__builtins__/configs/index.mjs.map +1 -1
- package/esm/__builtins__/shared/hooks.mjs.map +1 -1
- package/esm/__builtins__/shared/loading.mjs.map +1 -1
- package/esm/__builtins__/shared/simple-version-compare.mjs.map +1 -1
- package/esm/__builtins__/shared/transform-component.d.ts +1 -2
- package/esm/__builtins__/shared/transform-component.mjs +1 -1
- package/esm/__builtins__/shared/transform-component.mjs.map +1 -1
- package/esm/__builtins__/shared/utils.mjs +1 -1
- package/esm/__builtins__/shared/utils.mjs.map +1 -1
- package/esm/array-base/index.mjs +39 -42
- package/esm/array-base/index.mjs.map +1 -1
- package/esm/array-base/symbols.mjs.map +1 -1
- package/esm/array-base/utils.mjs +29 -33
- package/esm/array-base/utils.mjs.map +1 -1
- package/esm/array-cards/array-cards.d.ts +1 -1
- package/esm/array-cards/index.d.ts +3 -3
- package/esm/array-cards/index.mjs +23 -25
- package/esm/array-cards/index.mjs.map +1 -1
- package/esm/array-collapse/array-collapse.d.ts +2 -2
- package/esm/array-collapse/index.d.ts +3 -3
- package/esm/array-collapse/index.mjs +87 -88
- package/esm/array-collapse/index.mjs.map +1 -1
- package/esm/array-collapse/utils.mjs +2 -8
- package/esm/array-collapse/utils.mjs.map +1 -1
- package/esm/array-items/index.mjs +29 -32
- package/esm/array-items/index.mjs.map +1 -1
- package/esm/array-list-tabs/array-list-tabs.d.ts +3 -3
- package/esm/array-list-tabs/index.d.ts +6 -6
- package/esm/array-list-tabs/index.mjs +88 -86
- package/esm/array-list-tabs/index.mjs.map +1 -1
- package/esm/array-list-tabs/utils.mjs +5 -11
- package/esm/array-list-tabs/utils.mjs.map +1 -1
- package/esm/array-table/array-table.d.ts +1 -1
- package/esm/array-table/index.d.ts +3 -3
- package/esm/array-table/index.mjs +48 -50
- package/esm/array-table/index.mjs.map +1 -1
- package/esm/array-table/types.d.ts +1 -1
- package/esm/array-table/utils.mjs +12 -18
- package/esm/array-table/utils.mjs.map +1 -1
- package/esm/array-tabs/index.mjs +26 -28
- package/esm/array-tabs/index.mjs.map +1 -1
- package/esm/cascader/cascader.d.ts +1 -6
- package/esm/cascader/index.d.ts +3 -16
- package/esm/cascader/index.mjs +26 -32
- package/esm/cascader/index.mjs.map +1 -1
- package/esm/checkbox/checkbox-group.d.ts +2 -15
- package/esm/checkbox/index.d.ts +3 -28
- package/esm/checkbox/index.mjs +33 -45
- package/esm/checkbox/index.mjs.map +1 -1
- package/esm/date-picker/index.d.ts +442 -1
- package/esm/date-picker/index.mjs +9 -18
- package/esm/date-picker/index.mjs.map +1 -1
- package/esm/editable/index.mjs +34 -36
- package/esm/editable/index.mjs.map +1 -1
- package/esm/form/form.mjs +7 -7
- package/esm/form/form.mjs.map +1 -1
- package/esm/form-button-group/index.mjs +20 -23
- package/esm/form-button-group/index.mjs.map +1 -1
- package/esm/form-button-group/utils.mjs +2 -8
- package/esm/form-button-group/utils.mjs.map +1 -1
- package/esm/form-collapse/index.mjs +31 -32
- package/esm/form-collapse/index.mjs.map +1 -1
- package/esm/form-collapse/utils.mjs.map +1 -1
- package/esm/form-dialog/index.mjs +18 -18
- package/esm/form-dialog/index.mjs.map +1 -1
- package/esm/form-drawer/index.mjs +17 -17
- package/esm/form-drawer/index.mjs.map +1 -1
- package/esm/form-grid/hooks.mjs.map +1 -1
- package/esm/form-grid/index.mjs +20 -23
- package/esm/form-grid/index.mjs.map +1 -1
- package/esm/form-item/index.mjs +30 -32
- package/esm/form-item/index.mjs.map +1 -1
- package/esm/form-item/utils.mjs.map +1 -1
- package/esm/form-layout/form-layout.mjs +11 -14
- package/esm/form-layout/form-layout.mjs.map +1 -1
- package/esm/form-layout/utils.mjs +19 -24
- package/esm/form-layout/utils.mjs.map +1 -1
- package/esm/form-step/index.mjs +22 -24
- package/esm/form-step/index.mjs.map +1 -1
- package/esm/form-step/utils.mjs.map +1 -1
- package/esm/form-tab/form-tab.d.ts +2 -2
- package/esm/form-tab/hooks.mjs +1 -1
- package/esm/form-tab/hooks.mjs.map +1 -1
- package/esm/form-tab/index.d.ts +5 -5
- package/esm/form-tab/index.mjs +28 -29
- package/esm/form-tab/index.mjs.map +1 -1
- package/esm/form-tab/types.d.ts +1 -1
- package/esm/form-tab/utils.mjs.map +1 -1
- package/esm/index.mjs +58 -58
- package/esm/input/index.d.ts +6 -38
- package/esm/input/index.mjs +36 -48
- package/esm/input/index.mjs.map +1 -1
- package/esm/input/input.d.ts +1 -8
- package/esm/input-number/index.d.ts +215 -1
- package/esm/input-number/index.mjs +8 -17
- package/esm/input-number/index.mjs.map +1 -1
- package/esm/pagination/components/jumper.mjs.map +1 -1
- package/esm/pagination/components/next.mjs.map +1 -1
- package/esm/pagination/components/pager.mjs.map +1 -1
- package/esm/pagination/components/prev.mjs.map +1 -1
- package/esm/pagination/components/total.mjs.map +1 -1
- package/esm/pagination/pagination.mjs +1 -1
- package/esm/pagination/pagination.mjs.map +1 -1
- package/esm/password/index.d.ts +6 -38
- package/esm/password/index.mjs +1 -1
- package/esm/password/index.mjs.map +1 -1
- package/esm/preview-text/cascader.d.ts +1 -1
- package/esm/preview-text/date-picker.d.ts +1 -1
- package/esm/preview-text/index.d.ts +13 -13
- package/esm/preview-text/index.mjs +115 -118
- package/esm/preview-text/index.mjs.map +1 -1
- package/esm/preview-text/input.d.ts +1 -1
- package/esm/preview-text/select.d.ts +1 -1
- package/esm/preview-text/time-picker.d.ts +1 -1
- package/esm/preview-text/tree.d.ts +1 -1
- package/esm/preview-text/utils.mjs.map +1 -1
- package/esm/radio/index.d.ts +3 -25
- package/esm/radio/index.mjs +34 -44
- package/esm/radio/index.mjs.map +1 -1
- package/esm/radio/radio-group.d.ts +2 -13
- package/esm/reset/index.mjs +1 -1
- package/esm/reset/index.mjs.map +1 -1
- package/esm/select/index.d.ts +3 -16
- package/esm/select/index.mjs +62 -70
- package/esm/select/index.mjs.map +1 -1
- package/esm/select/select.d.ts +1 -6
- package/esm/select-table/index.d.ts +5 -5
- package/esm/select-table/index.mjs +78 -81
- package/esm/select-table/index.mjs.map +1 -1
- package/esm/select-table/select-table.d.ts +2 -2
- package/esm/select-table/types.d.ts +1 -1
- package/esm/submit/index.mjs +1 -1
- package/esm/submit/index.mjs.map +1 -1
- package/esm/switch/index.d.ts +260 -1
- package/esm/switch/index.mjs +5 -11
- package/esm/switch/index.mjs.map +1 -1
- package/esm/time-picker/index.d.ts +442 -1
- package/esm/time-picker/index.mjs +8 -15
- package/esm/time-picker/index.mjs.map +1 -1
- package/esm/time-select/index.d.ts +124 -1
- package/esm/time-select/index.mjs +10 -17
- package/esm/time-select/index.mjs.map +1 -1
- package/esm/transfer/index.mjs +5 -5
- package/esm/transfer/index.mjs.map +1 -1
- package/esm/tree/index.d.ts +5 -5
- package/esm/tree/index.mjs +42 -45
- package/esm/tree/index.mjs.map +1 -1
- package/esm/tree/tree.d.ts +2 -2
- package/esm/tree/types.d.ts +1 -1
- package/esm/tree/utils.mjs.map +1 -1
- package/esm/tree-select/index.d.ts +3 -19
- package/esm/tree-select/index.mjs +22 -32
- package/esm/tree-select/index.mjs.map +1 -1
- package/esm/tree-select/tree-select.d.ts +1 -8
- package/esm/upload/index.d.ts +5 -5
- package/esm/upload/index.mjs +14 -16
- package/esm/upload/index.mjs.map +1 -1
- package/esm/upload/upload.d.ts +2 -2
- package/esm/vendor/sizes.mjs.map +1 -1
- package/package.json +114 -116
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { useField as W, connect as z, mapProps as G } from "@formily/vue";
|
|
2
|
-
import { defineComponent as U, ref as
|
|
3
|
-
import { isValid as
|
|
4
|
-
import { useAttrs as ne, ElLink as re, version as E, ElTable as
|
|
5
|
-
import {
|
|
6
|
-
import "
|
|
7
|
-
import { lt as
|
|
8
|
-
import
|
|
9
|
-
import "@formily/reactive-vue";
|
|
10
|
-
import { u as L, x as de, d as fe, a as me, r as pe } from "../vendor/lodash.mjs";
|
|
11
|
-
import '../styles/select-table/index.css';const ge = /* @__PURE__ */ U({
|
|
1
|
+
import { useField as W, connect as z, mapProps as G } from "@silver-formily/vue";
|
|
2
|
+
import { defineComponent as U, ref as g, computed as j, watch as R, nextTick as v, createElementBlock as S, openBlock as s, normalizeClass as A, unref as r, createCommentVNode as J, withDirectives as Q, createElementVNode as X, createVNode as V, toDisplayString as Y, withCtx as f, createTextVNode as C, createBlock as y, mergeProps as w, renderSlot as Z, Fragment as ee, renderList as le } from "vue";
|
|
3
|
+
import { isValid as te, isEqual as oe, isFn as ae } from "@formily/shared";
|
|
4
|
+
import { useAttrs as ne, ElLink as re, version as E, ElTable as ue, ElTableColumn as b, ElRadioGroup as ie, ElRadio as se, vLoading as ce } from "element-plus";
|
|
5
|
+
import { u as x, x as de, d as me, a as fe, r as pe } from "../vendor/lodash.mjs";
|
|
6
|
+
import { stylePrefix as K } from "../__builtins__/configs/index.mjs";
|
|
7
|
+
import { lt as L } from "../__builtins__/shared/simple-version-compare.mjs";
|
|
8
|
+
import '../styles/select-table/index.css';const ye = /* @__PURE__ */ U({
|
|
12
9
|
name: "FSelectTable",
|
|
13
10
|
inheritAttrs: !1,
|
|
14
11
|
__name: "select-table",
|
|
@@ -22,55 +19,55 @@ import '../styles/select-table/index.css';const ge = /* @__PURE__ */ U({
|
|
|
22
19
|
rowKey: null,
|
|
23
20
|
clickRowToSelect: { type: Boolean, default: !0 },
|
|
24
21
|
showAlertToolbar: { type: Boolean, default: !0 },
|
|
25
|
-
|
|
22
|
+
modelValue: null,
|
|
26
23
|
data: null,
|
|
27
24
|
selectable: { type: Function },
|
|
28
25
|
ignoreSelectable: { type: Boolean, default: !0 }
|
|
29
26
|
},
|
|
30
|
-
emits: ["
|
|
27
|
+
emits: ["update:modelValue"],
|
|
31
28
|
setup(B, { emit: D }) {
|
|
32
29
|
const e = B, c = D, _ = ne(), q = W();
|
|
33
|
-
function F(
|
|
34
|
-
return
|
|
30
|
+
function F(l) {
|
|
31
|
+
return L(E, "2.6.0") ? { label: l } : { value: l };
|
|
35
32
|
}
|
|
36
|
-
const d =
|
|
33
|
+
const d = g(), t = e.rowKey;
|
|
37
34
|
function M() {
|
|
38
|
-
return e.mode === "multiple" ? e.
|
|
39
|
-
[
|
|
40
|
-
}) ?? [] : e.optionAsValue ? [e.
|
|
35
|
+
return e.mode === "multiple" ? e.modelValue?.map((l) => e.optionAsValue ? l : {
|
|
36
|
+
[t]: l
|
|
37
|
+
}) ?? [] : e.optionAsValue ? [e.modelValue] : [{ [t]: e.modelValue }];
|
|
41
38
|
}
|
|
42
|
-
const N = M(),
|
|
39
|
+
const N = M(), u = g(N);
|
|
43
40
|
let p = [];
|
|
44
|
-
const
|
|
41
|
+
const m = g(), k = j(() => e.mode === "multiple" ? Array.isArray(e.modelValue) ? e.modelValue.length : 0 : te(m.value) ? 1 : 0);
|
|
45
42
|
R(
|
|
46
43
|
() => e.dataSource,
|
|
47
44
|
async () => {
|
|
48
|
-
const
|
|
49
|
-
|
|
45
|
+
const l = x(
|
|
46
|
+
u.value.map((a) => a[t])
|
|
50
47
|
);
|
|
51
48
|
await v();
|
|
52
49
|
for (const a of e.dataSource)
|
|
53
|
-
|
|
50
|
+
l.includes(a[t]) && (e.mode === "multiple" ? d.value.toggleRowSelection(a, !0, e.ignoreSelectable) : (d.value.setCurrentRow(a), T(a))), await v(), p = d.value?.getSelectionRows();
|
|
54
51
|
},
|
|
55
52
|
{ immediate: !0 }
|
|
56
53
|
), R(
|
|
57
|
-
() => [e.
|
|
58
|
-
async ([
|
|
54
|
+
() => [e.modelValue, e.loading],
|
|
55
|
+
async ([l, a]) => {
|
|
59
56
|
if (!a)
|
|
60
57
|
if (e.mode === "single")
|
|
61
|
-
|
|
58
|
+
m.value = e.optionAsValue ? l[t] : l;
|
|
62
59
|
else {
|
|
63
60
|
await v();
|
|
64
|
-
const n = d.value?.getSelectionRows().map((
|
|
65
|
-
if (
|
|
66
|
-
(
|
|
61
|
+
const n = d.value?.getSelectionRows().map((i) => i[t]), o = e.optionAsValue ? l?.map((i) => i[t]) : l ?? [];
|
|
62
|
+
if (u.value = u.value.filter(
|
|
63
|
+
(i) => o.includes(i[t])
|
|
67
64
|
), oe(o, n))
|
|
68
65
|
return;
|
|
69
66
|
const I = de(o, n);
|
|
70
|
-
for (const
|
|
71
|
-
if (I.includes(
|
|
72
|
-
const O = o.includes(
|
|
73
|
-
d.value.toggleRowSelection(
|
|
67
|
+
for (const i of e.dataSource)
|
|
68
|
+
if (I.includes(i[t])) {
|
|
69
|
+
const O = o.includes(i[t]);
|
|
70
|
+
d.value.toggleRowSelection(i, O, e.ignoreSelectable);
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
73
|
},
|
|
@@ -78,35 +75,35 @@ import '../styles/select-table/index.css';const ge = /* @__PURE__ */ U({
|
|
|
78
75
|
immediate: !0
|
|
79
76
|
}
|
|
80
77
|
);
|
|
81
|
-
function
|
|
78
|
+
function h(l) {
|
|
82
79
|
/* istanbul ignore if -- @preserve */
|
|
83
|
-
if (!
|
|
80
|
+
if (!t)
|
|
84
81
|
throw new Error("rowKey is required");
|
|
85
|
-
const a = p.length >
|
|
82
|
+
const a = p.length > l.length ? me(
|
|
86
83
|
p,
|
|
87
|
-
|
|
88
|
-
(n, o) => n[
|
|
84
|
+
l,
|
|
85
|
+
(n, o) => n[t] === o[t]
|
|
89
86
|
) : [];
|
|
90
|
-
if (p = [...
|
|
91
|
-
[...
|
|
92
|
-
(n, o) => n[
|
|
87
|
+
if (p = [...l], u.value = fe(
|
|
88
|
+
[...u.value, ...l],
|
|
89
|
+
(n, o) => n[t] === o[t]
|
|
93
90
|
), a.length > 0) {
|
|
94
|
-
const n =
|
|
95
|
-
pe(
|
|
91
|
+
const n = x(a.map((o) => o[t]));
|
|
92
|
+
pe(u.value, (o) => n.includes(o[t]));
|
|
96
93
|
}
|
|
97
94
|
if (e.optionAsValue)
|
|
98
|
-
c("
|
|
95
|
+
c("update:modelValue", u.value);
|
|
99
96
|
else {
|
|
100
|
-
const n =
|
|
101
|
-
(o) => o[
|
|
97
|
+
const n = u.value.map(
|
|
98
|
+
(o) => o[t]
|
|
102
99
|
);
|
|
103
|
-
c("
|
|
100
|
+
c("update:modelValue", n);
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
|
-
function
|
|
107
|
-
|
|
103
|
+
function T(l) {
|
|
104
|
+
m.value = l[t], e.optionAsValue ? c("update:modelValue", l) : c("update:modelValue", l[t]);
|
|
108
105
|
}
|
|
109
|
-
function P(
|
|
106
|
+
function P(l, a, n) {
|
|
110
107
|
if (e.clickRowToSelect)
|
|
111
108
|
if (e.mode === "multiple") {
|
|
112
109
|
const o = n.target.closest("tr").querySelector('input[type="checkbox"]');
|
|
@@ -117,63 +114,63 @@ import '../styles/select-table/index.css';const ge = /* @__PURE__ */ U({
|
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
function $() {
|
|
120
|
-
e.mode === "multiple" ? (c("
|
|
117
|
+
e.mode === "multiple" ? (c("update:modelValue", []), u.value = []) : (m.value = null, c("update:modelValue", null));
|
|
121
118
|
}
|
|
122
|
-
function H(
|
|
123
|
-
return e.selectable && ae(e.selectable) ? e.selectable(
|
|
119
|
+
function H(l, a) {
|
|
120
|
+
return e.selectable && ae(e.selectable) ? e.selectable(l, a, q.value) : !0;
|
|
124
121
|
}
|
|
125
|
-
return (
|
|
126
|
-
class: A(`${r(
|
|
122
|
+
return (l, a) => (s(), S("div", {
|
|
123
|
+
class: A(`${r(K)}-select-table`)
|
|
127
124
|
}, [
|
|
128
|
-
k.value > 0 && e.showAlertToolbar ? (s(),
|
|
125
|
+
k.value > 0 && e.showAlertToolbar ? (s(), S("div", {
|
|
129
126
|
key: 0,
|
|
130
|
-
class: A(`${r(
|
|
127
|
+
class: A(`${r(K)}-select-table-alert-container`)
|
|
131
128
|
}, [
|
|
132
129
|
X("span", null, "已选择 " + Y(k.value) + " 项", 1),
|
|
133
|
-
|
|
130
|
+
V(r(re), {
|
|
134
131
|
type: "primary",
|
|
135
|
-
underline: r(
|
|
132
|
+
underline: r(L)(r(E), "2.9.9") ? !1 : "never",
|
|
136
133
|
style: { "margin-left": "8px" },
|
|
137
134
|
onClick: $
|
|
138
135
|
}, {
|
|
139
|
-
default:
|
|
136
|
+
default: f(() => [...a[1] || (a[1] = [
|
|
140
137
|
C(" 取消选择 ", -1)
|
|
141
138
|
])]),
|
|
142
139
|
_: 1
|
|
143
140
|
}, 8, ["underline"])
|
|
144
141
|
], 2)) : J("", !0),
|
|
145
|
-
Q((s(),
|
|
142
|
+
Q((s(), y(r(ue), w({
|
|
146
143
|
ref_key: "elTableRef",
|
|
147
144
|
ref: d
|
|
148
145
|
}, r(_), {
|
|
149
|
-
"row-key": r(
|
|
146
|
+
"row-key": r(t),
|
|
150
147
|
"row-class-name": e.clickRowToSelect ? "--click-row-select" : "",
|
|
151
148
|
data: e.dataSource,
|
|
152
149
|
"highlight-current-row": e.mode === "single",
|
|
153
|
-
onSelect:
|
|
154
|
-
onSelectAll:
|
|
150
|
+
onSelect: h,
|
|
151
|
+
onSelectAll: h,
|
|
155
152
|
onRowClick: P
|
|
156
153
|
}), {
|
|
157
|
-
default:
|
|
158
|
-
e.mode === "multiple" ? (s(),
|
|
154
|
+
default: f(() => [
|
|
155
|
+
e.mode === "multiple" ? (s(), y(r(b), {
|
|
159
156
|
key: 0,
|
|
160
157
|
type: "selection",
|
|
161
158
|
selectable: H
|
|
162
|
-
})) : (s(),
|
|
159
|
+
})) : (s(), y(r(b), {
|
|
163
160
|
key: 1,
|
|
164
161
|
width: "46"
|
|
165
162
|
}, {
|
|
166
|
-
default:
|
|
167
|
-
|
|
168
|
-
modelValue:
|
|
169
|
-
"onUpdate:modelValue": a[0] || (a[0] = (o) =>
|
|
163
|
+
default: f(({ row: n }) => [
|
|
164
|
+
V(r(ie), {
|
|
165
|
+
modelValue: m.value,
|
|
166
|
+
"onUpdate:modelValue": a[0] || (a[0] = (o) => m.value = o),
|
|
170
167
|
style: { width: "100%" }
|
|
171
168
|
}, {
|
|
172
|
-
default:
|
|
173
|
-
|
|
174
|
-
onChange: () =>
|
|
169
|
+
default: f(() => [
|
|
170
|
+
V(r(se), w(F(n[r(t)]), {
|
|
171
|
+
onChange: () => T(n)
|
|
175
172
|
}), {
|
|
176
|
-
default:
|
|
173
|
+
default: f(() => [...a[2] || (a[2] = [
|
|
177
174
|
C(" ", -1)
|
|
178
175
|
])]),
|
|
179
176
|
_: 1
|
|
@@ -184,7 +181,7 @@ import '../styles/select-table/index.css';const ge = /* @__PURE__ */ U({
|
|
|
184
181
|
]),
|
|
185
182
|
_: 1
|
|
186
183
|
})),
|
|
187
|
-
e.columns.length === 0 ? Z(
|
|
184
|
+
e.columns.length === 0 ? Z(l.$slots, "default", { key: 2 }) : (s(!0), S(ee, { key: 3 }, le(e.columns, (n) => (s(), y(r(b), w({ ref_for: !0 }, n, {
|
|
188
185
|
key: n.prop || n.type
|
|
189
186
|
}), null, 16))), 128))
|
|
190
187
|
]),
|
|
@@ -194,12 +191,12 @@ import '../styles/select-table/index.css';const ge = /* @__PURE__ */ U({
|
|
|
194
191
|
])
|
|
195
192
|
], 2));
|
|
196
193
|
}
|
|
197
|
-
}),
|
|
198
|
-
|
|
194
|
+
}), he = z(
|
|
195
|
+
ye,
|
|
199
196
|
G({ dataSource: "dataSource", loading: "loading" })
|
|
200
197
|
);
|
|
201
198
|
export {
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
he as SelectTable,
|
|
200
|
+
he as default
|
|
204
201
|
};
|
|
205
202
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/select-table/select-table.vue","../../src/select-table/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport type { TableInstance } from 'element-plus'\nimport type { ISelectTableProps } from './types'\nimport { isEqual, isFn, isValid } from '@formily/shared'\nimport { useField } from '@formily/vue'\nimport {\n ElLink,\n ElRadio,\n ElRadioGroup,\n ElTable,\n ElTableColumn,\n useAttrs,\n version,\n vLoading,\n} from 'element-plus'\nimport { differenceWith, remove, uniq, uniqWith, xor } from 'lodash-es'\nimport { computed, nextTick, ref, watch } from 'vue'\nimport { lt, stylePrefix } from '../__builtins__'\n\ndefineOptions({\n name: 'FSelectTable',\n inheritAttrs: false,\n})\n\nconst props = defineProps({\n columns: { default: () => [] },\n mode: { default: 'multiple' },\n dataSource: { default: () => [] },\n optionAsValue: { type: Boolean, default: false },\n valueType: { default: 'all' },\n loading: { type: Boolean, default: false },\n rowKey: null,\n clickRowToSelect: { type: Boolean, default: true },\n showAlertToolbar: { type: Boolean, default: true },\n value: null,\n data: null,\n selectable: { type: Function },\n ignoreSelectable: { type: Boolean, default: true }\n})\n\nconst emit = defineEmits(['change'])\n\nconst elTableProps = useAttrs()\nconst field = useField()\n\nfunction compatibleRadioValue(key: string) {\n return lt(version, '2.6.0') ? { label: key } : { value: key }\n}\n\nconst elTableRef = ref<TableInstance>()\nconst rowKey = props.rowKey\nfunction getInitialSelectedList() {\n if (props.mode === 'multiple') {\n return props.value?.map((item) => {\n if (!props.optionAsValue) {\n return {\n [rowKey]: item,\n }\n }\n return item\n }) ?? []\n }\n else {\n return props.optionAsValue ? [props.value] : [{ [rowKey]: props.value }]\n }\n}\nconst initialSelectedList = getInitialSelectedList()\nconst selectedFlatDataSource = ref(initialSelectedList)\n// 为了获取移除的项而缓存的当前页面的前一次选择。由于element-plus没有获取移除项的方法,需要通过这种方式移除field中移除的项\nlet prevSelection = []\n\nconst radioSelectedKey = ref()\n\nconst currentSelectLength = computed(() => {\n if (props.mode === 'multiple') {\n return Array.isArray(props.value) ? props.value.length : 0\n }\n else {\n return isValid(radioSelectedKey.value) ? 1 : 0\n }\n})\n\nwatch(\n () => props.dataSource,\n async () => {\n const selectedKeys = uniq(\n selectedFlatDataSource.value.map(item => item[rowKey]),\n )\n await nextTick()\n for (const item of props.dataSource) {\n if (selectedKeys.includes(item[rowKey])) {\n if (props.mode === 'multiple') {\n elTableRef.value.toggleRowSelection(item, true, props.ignoreSelectable)\n }\n else {\n elTableRef.value.setCurrentRow(item)\n onRadioClick(item)\n }\n }\n await nextTick()\n prevSelection = elTableRef.value?.getSelectionRows()\n }\n },\n { immediate: true },\n)\n\nwatch(\n () => [props.value, props.loading],\n async ([value, loading]) => {\n if (loading) {\n return\n }\n if (props.mode === 'single') {\n radioSelectedKey.value = props.optionAsValue ? value[rowKey] : value\n }\n else {\n await nextTick()\n const currentDisplayDataKeys = elTableRef.value\n ?.getSelectionRows()\n .map(item => item[rowKey])\n const valueKeys = props.optionAsValue\n ? value?.map(item => item[rowKey])\n : value ?? []\n selectedFlatDataSource.value = selectedFlatDataSource.value.filter(\n item => valueKeys.includes(item[rowKey]),\n )\n if (isEqual(valueKeys, currentDisplayDataKeys)) {\n return\n }\n const diffItems = xor(valueKeys, currentDisplayDataKeys)\n for (const tableItem of props.dataSource) {\n if (diffItems.includes(tableItem[rowKey])) {\n const shouldSelect = valueKeys.includes(tableItem[rowKey])\n elTableRef.value.toggleRowSelection(tableItem, shouldSelect, props.ignoreSelectable)\n }\n }\n }\n },\n {\n immediate: true,\n },\n)\n\nfunction onSelect(newSelection: Record<string, any>[]) {\n /* istanbul ignore if -- @preserve */\n if (!rowKey) {\n throw new Error('rowKey is required')\n }\n\n const removedItemList\n = prevSelection.length > newSelection.length\n ? differenceWith(\n prevSelection,\n newSelection,\n (itemPrev, itemNext) => {\n return itemPrev[rowKey] === itemNext[rowKey]\n },\n )\n : []\n prevSelection = [...newSelection]\n selectedFlatDataSource.value = uniqWith(\n [...selectedFlatDataSource.value, ...newSelection],\n (itemPrev, itemNext) => {\n return itemPrev[rowKey] === itemNext[rowKey]\n },\n )\n if (removedItemList.length > 0) {\n const removedKeys = uniq(removedItemList.map(item => item[rowKey]))\n remove(selectedFlatDataSource.value, item =>\n removedKeys.includes(item[rowKey]))\n }\n\n if (props.optionAsValue) {\n emit('change', selectedFlatDataSource.value)\n }\n else {\n const selectedKeys = selectedFlatDataSource.value.map(\n item => item[rowKey],\n )\n emit('change', selectedKeys)\n }\n}\n\nfunction onRadioClick(item) {\n radioSelectedKey.value = item[rowKey]\n if (props.optionAsValue) {\n emit('change', item)\n }\n else {\n emit('change', item[rowKey])\n }\n}\n\nfunction onRowClick(row: Record<string, any>, _, event: Event) {\n if (!props.clickRowToSelect)\n return\n\n if (props.mode === 'multiple') {\n const checkboxDOM = (event.target as Element)\n .closest('tr')\n .querySelector('input[type=\"checkbox\"]')\n if (checkboxDOM instanceof HTMLElement) {\n checkboxDOM.click()\n }\n }\n else {\n const radioDOM = (event.target as Element)\n .closest('tr')\n .querySelector('input[type=\"radio\"]')\n if (radioDOM instanceof HTMLElement) {\n radioDOM.click()\n }\n }\n}\n\nfunction onClearSelectionClick() {\n if (props.mode === 'multiple') {\n emit('change', [])\n selectedFlatDataSource.value = []\n }\n else {\n radioSelectedKey.value = null\n emit('change', null)\n }\n}\n\nfunction selectable(row: Record<string, any>, index: number) {\n if (props.selectable && isFn(props.selectable)) {\n return props.selectable(row, index, field.value)\n }\n return true\n}\n</script>\n\n<template>\n <div :class=\"`${stylePrefix}-select-table`\">\n <div\n v-if=\"currentSelectLength > 0 && props.showAlertToolbar\"\n :class=\"`${stylePrefix}-select-table-alert-container`\"\n >\n <span>已选择 {{ currentSelectLength }} 项</span>\n <ElLink\n type=\"primary\"\n :underline=\"lt(version, '2.9.9') ? false : 'never'\"\n style=\"margin-left: 8px;\"\n @click=\"onClearSelectionClick\"\n >\n 取消选择\n </ElLink>\n </div>\n <ElTable\n ref=\"elTableRef\"\n v-loading=\"props.loading\"\n v-bind=\"elTableProps\"\n :row-key=\"rowKey\"\n :row-class-name=\"props.clickRowToSelect ? `--click-row-select` : ''\"\n :data=\"props.dataSource\"\n :highlight-current-row=\"props.mode === 'single'\"\n @select=\"onSelect\"\n @select-all=\"onSelect\"\n @row-click=\"onRowClick\"\n >\n <ElTableColumn\n v-if=\"props.mode === 'multiple'\"\n type=\"selection\"\n :selectable=\"selectable\"\n />\n <ElTableColumn\n v-else\n width=\"46\"\n >\n <template #default=\"{ row }\">\n <ElRadioGroup v-model=\"radioSelectedKey\" style=\"width: 100%;\">\n <ElRadio\n v-bind=\"compatibleRadioValue(row[rowKey])\"\n @change=\"() => onRadioClick(row)\"\n >\n \n </ElRadio>\n </ElRadioGroup>\n </template>\n </ElTableColumn>\n <template v-if=\"props.columns.length === 0\">\n <slot />\n </template>\n <template v-else>\n <ElTableColumn\n v-for=\"colItem of props.columns\"\n v-bind=\"colItem\"\n :key=\"colItem.prop || colItem.type\"\n />\n </template>\n </ElTable>\n </div>\n</template>\n","import { connect, mapProps } from '@formily/vue'\r\nimport InnerSelectTable from './select-table.vue'\r\nimport './style.scss'\r\n\r\nconst SelectTable = connect(\r\n InnerSelectTable,\r\n mapProps({ dataSource: 'dataSource', loading: 'loading' }),\r\n)\r\n\r\nexport { SelectTable }\r\n\r\nexport default SelectTable\r\n"],"names":["props","__props","emit","__emit","elTableProps","useAttrs","field","useField","compatibleRadioValue","key","lt","version","elTableRef","ref","rowKey","getInitialSelectedList","item","initialSelectedList","selectedFlatDataSource","prevSelection","radioSelectedKey","currentSelectLength","computed","isValid","watch","selectedKeys","uniq","nextTick","onRadioClick","value","loading","currentDisplayDataKeys","valueKeys","isEqual","diffItems","xor","tableItem","shouldSelect","onSelect","newSelection","removedItemList","differenceWith","itemPrev","itemNext","uniqWith","removedKeys","remove","onRowClick","row","_","event","checkboxDOM","radioDOM","onClearSelectionClick","selectable","index","isFn","_createElementBlock","_unref","stylePrefix","_createElementVNode","_toDisplayString","_createVNode","ElLink","_cache","_withDirectives","_openBlock","_createBlock","_mergeProps","ElTableColumn","_withCtx","ElRadioGroup","$event","_renderSlot","_ctx","_Fragment","_renderList","colItem","vLoading","SelectTable","connect","InnerSelectTable","mapProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,UAAMA,IAAQC,GAgBR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gBT,EAAAW,CAAA,GAAA;AAAA;YAZd,OAAM;AAAA,UAAA;YAEK,SAAOC,EAChB,CAOe,EARK,KAAAtB,QAAG;AAAA,cACvBc,EAOeJ,EAAAa,EAAA,GAAA;AAAA,4BAPQnD,EAAA;AAAA,8DAAAA,EAAgB,QAAAoD;AAAA,gBAAE,OAAA,EAAA,OAAA,OAAA;AAAA,cAAA;2BACvC,MAKU;AAAA,kBALVV,EAKUJ,OALVU,EAKU5D,EAJqBwC,EAAIU,EAAA5C,CAAA,CAAM,CAAA,GAAA;AAAA,oBACtC,UAAM,MAAQc,EAAaoB,CAAG;AAAA,kBAAA;+BAChC,MAED,CAAA,GAAAgB,EAAA,CAAA,MAAAA,EAAA,CAAA,IAAA;AAAA,wBAFC,OAED,EAAA;AAAA,oBAAA;;;;;;;;;UAIUhE,EAAM,QAAQ,WAAM,IAClCyE,EAAQC,EAAA,QAAA,WAAA,EAAA,KAAA,EAAA,CAAA,KAGRR,EAAA,EAAA,GAAAT,EAIEkB,IAAA,EAAA,KAAA,EAAA,GAAAC,GAHkB5E,EAAM,UAAjB6E,YADTV,EAIET,EAAAW,CAAA,GAJFD,EAIE,EAAA,SAAA,GAAA,GAFQS,GAAO;AAAA,YACd,KAAKA,EAAQ,QAAQA,EAAQ;AAAA,UAAA;;;;QArCvB,CAAAnB,EAAAoB,EAAA,GAAA9E,EAAM,OAAO;AAAA,MAAA;;;ICxPxB+E,KAAcC;AAAA,EAClBC;AAAAA,EACAC,EAAS,EAAE,YAAY,cAAc,SAAS,WAAW;AAC3D;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/select-table/select-table.vue","../../src/select-table/index.ts"],"sourcesContent":["<script setup lang=\"ts\">\r\nimport type { TableInstance } from 'element-plus'\r\nimport type { ISelectTableProps } from './types'\r\nimport { isEqual, isFn, isValid } from '@formily/shared'\r\nimport { useField } from '@silver-formily/vue'\r\nimport {\r\n ElLink,\r\n ElRadio,\r\n ElRadioGroup,\r\n ElTable,\r\n ElTableColumn,\r\n useAttrs,\r\n version,\r\n vLoading,\r\n} from 'element-plus'\r\nimport { differenceWith, remove, uniq, uniqWith, xor } from 'lodash-es'\r\nimport { computed, nextTick, ref, watch } from 'vue'\r\nimport { lt, stylePrefix } from '../__builtins__'\r\n\r\ndefineOptions({\r\n name: 'FSelectTable',\r\n inheritAttrs: false,\r\n})\r\n\r\nconst props = defineProps({\n columns: { default: () => [] },\n mode: { default: 'multiple' },\n dataSource: { default: () => [] },\n optionAsValue: { type: Boolean, default: false },\n valueType: { default: 'all' },\n loading: { type: Boolean, default: false },\n rowKey: null,\n clickRowToSelect: { type: Boolean, default: true },\n showAlertToolbar: { type: Boolean, default: true },\n modelValue: null,\n data: null,\n selectable: { type: Function },\n ignoreSelectable: { type: Boolean, default: true }\n})\r\n\r\nconst emit = defineEmits(['update:modelValue'])\r\n\r\nconst elTableProps = useAttrs()\r\nconst field = useField()\r\n\r\nfunction compatibleRadioValue(key: string) {\r\n return lt(version, '2.6.0') ? { label: key } : { value: key }\r\n}\r\n\r\nconst elTableRef = ref<TableInstance>()\r\nconst rowKey = props.rowKey\r\nfunction getInitialSelectedList() {\r\n if (props.mode === 'multiple') {\r\n return props.modelValue?.map((item) => {\r\n if (!props.optionAsValue) {\r\n return {\r\n [rowKey]: item,\r\n }\r\n }\r\n return item\r\n }) ?? []\r\n }\r\n else {\r\n return props.optionAsValue ? [props.modelValue] : [{ [rowKey]: props.modelValue }]\r\n }\r\n}\r\nconst initialSelectedList = getInitialSelectedList()\r\nconst selectedFlatDataSource = ref(initialSelectedList)\r\n// 为了获取移除的项而缓存的当前页面的前一次选择。由于element-plus没有获取移除项的方法,需要通过这种方式移除field中移除的项\r\nlet prevSelection = []\r\n\r\nconst radioSelectedKey = ref()\r\n\r\nconst currentSelectLength = computed(() => {\r\n if (props.mode === 'multiple') {\r\n return Array.isArray(props.modelValue) ? props.modelValue.length : 0\r\n }\r\n else {\r\n return isValid(radioSelectedKey.value) ? 1 : 0\r\n }\r\n})\r\n\r\nwatch(\r\n () => props.dataSource,\r\n async () => {\r\n const selectedKeys = uniq(\r\n selectedFlatDataSource.value.map(item => item[rowKey]),\r\n )\r\n await nextTick()\r\n for (const item of props.dataSource) {\r\n if (selectedKeys.includes(item[rowKey])) {\r\n if (props.mode === 'multiple') {\r\n elTableRef.value.toggleRowSelection(item, true, props.ignoreSelectable)\r\n }\r\n else {\r\n elTableRef.value.setCurrentRow(item)\r\n onRadioClick(item)\r\n }\r\n }\r\n await nextTick()\r\n prevSelection = elTableRef.value?.getSelectionRows()\r\n }\r\n },\r\n { immediate: true },\r\n)\r\n\r\nwatch(\r\n () => [props.modelValue, props.loading],\r\n async ([value, loading]) => {\r\n if (loading) {\r\n return\r\n }\r\n if (props.mode === 'single') {\r\n radioSelectedKey.value = props.optionAsValue ? value[rowKey] : value\r\n }\r\n else {\r\n await nextTick()\r\n const currentDisplayDataKeys = elTableRef.value\r\n ?.getSelectionRows()\r\n .map(item => item[rowKey])\r\n const valueKeys = props.optionAsValue\r\n ? value?.map(item => item[rowKey])\r\n : value ?? []\r\n selectedFlatDataSource.value = selectedFlatDataSource.value.filter(\r\n item => valueKeys.includes(item[rowKey]),\r\n )\r\n if (isEqual(valueKeys, currentDisplayDataKeys)) {\r\n return\r\n }\r\n const diffItems = xor(valueKeys, currentDisplayDataKeys)\r\n for (const tableItem of props.dataSource) {\r\n if (diffItems.includes(tableItem[rowKey])) {\r\n const shouldSelect = valueKeys.includes(tableItem[rowKey])\r\n elTableRef.value.toggleRowSelection(tableItem, shouldSelect, props.ignoreSelectable)\r\n }\r\n }\r\n }\r\n },\r\n {\r\n immediate: true,\r\n },\r\n)\r\n\r\nfunction onSelect(newSelection: Record<string, any>[]) {\r\n /* istanbul ignore if -- @preserve */\r\n if (!rowKey) {\r\n throw new Error('rowKey is required')\r\n }\r\n\r\n const removedItemList\r\n = prevSelection.length > newSelection.length\r\n ? differenceWith(\r\n prevSelection,\r\n newSelection,\r\n (itemPrev, itemNext) => {\r\n return itemPrev[rowKey] === itemNext[rowKey]\r\n },\r\n )\r\n : []\r\n prevSelection = [...newSelection]\r\n selectedFlatDataSource.value = uniqWith(\r\n [...selectedFlatDataSource.value, ...newSelection],\r\n (itemPrev, itemNext) => {\r\n return itemPrev[rowKey] === itemNext[rowKey]\r\n },\r\n )\r\n if (removedItemList.length > 0) {\r\n const removedKeys = uniq(removedItemList.map(item => item[rowKey]))\r\n remove(selectedFlatDataSource.value, item =>\r\n removedKeys.includes(item[rowKey]))\r\n }\r\n\r\n if (props.optionAsValue) {\r\n emit('update:modelValue', selectedFlatDataSource.value)\r\n }\r\n else {\r\n const selectedKeys = selectedFlatDataSource.value.map(\r\n item => item[rowKey],\r\n )\r\n emit('update:modelValue', selectedKeys)\r\n }\r\n}\r\n\r\nfunction onRadioClick(item) {\r\n radioSelectedKey.value = item[rowKey]\r\n if (props.optionAsValue) {\r\n emit('update:modelValue', item)\r\n }\r\n else {\r\n emit('update:modelValue', item[rowKey])\r\n }\r\n}\r\n\r\nfunction onRowClick(row: Record<string, any>, _, event: Event) {\r\n if (!props.clickRowToSelect)\r\n return\r\n\r\n if (props.mode === 'multiple') {\r\n const checkboxDOM = (event.target as Element)\r\n .closest('tr')\r\n .querySelector('input[type=\"checkbox\"]')\r\n if (checkboxDOM instanceof HTMLElement) {\r\n checkboxDOM.click()\r\n }\r\n }\r\n else {\r\n const radioDOM = (event.target as Element)\r\n .closest('tr')\r\n .querySelector('input[type=\"radio\"]')\r\n if (radioDOM instanceof HTMLElement) {\r\n radioDOM.click()\r\n }\r\n }\r\n}\r\n\r\nfunction onClearSelectionClick() {\r\n if (props.mode === 'multiple') {\r\n emit('update:modelValue', [])\r\n selectedFlatDataSource.value = []\r\n }\r\n else {\r\n radioSelectedKey.value = null\r\n emit('update:modelValue', null)\r\n }\r\n}\r\n\r\nfunction selectable(row: Record<string, any>, index: number) {\r\n if (props.selectable && isFn(props.selectable)) {\r\n return props.selectable(row, index, field.value)\r\n }\r\n return true\r\n}\r\n</script>\r\n\r\n<template>\r\n <div :class=\"`${stylePrefix}-select-table`\">\r\n <div\r\n v-if=\"currentSelectLength > 0 && props.showAlertToolbar\"\r\n :class=\"`${stylePrefix}-select-table-alert-container`\"\r\n >\r\n <span>已选择 {{ currentSelectLength }} 项</span>\r\n <ElLink\r\n type=\"primary\"\r\n :underline=\"lt(version, '2.9.9') ? false : 'never'\"\r\n style=\"margin-left: 8px;\"\r\n @click=\"onClearSelectionClick\"\r\n >\r\n 取消选择\r\n </ElLink>\r\n </div>\r\n <ElTable\r\n ref=\"elTableRef\"\r\n v-loading=\"props.loading\"\r\n v-bind=\"elTableProps\"\r\n :row-key=\"rowKey\"\r\n :row-class-name=\"props.clickRowToSelect ? `--click-row-select` : ''\"\r\n :data=\"props.dataSource\"\r\n :highlight-current-row=\"props.mode === 'single'\"\r\n @select=\"onSelect\"\r\n @select-all=\"onSelect\"\r\n @row-click=\"onRowClick\"\r\n >\r\n <ElTableColumn\r\n v-if=\"props.mode === 'multiple'\"\r\n type=\"selection\"\r\n :selectable=\"selectable\"\r\n />\r\n <ElTableColumn\r\n v-else\r\n width=\"46\"\r\n >\r\n <template #default=\"{ row }\">\r\n <ElRadioGroup v-model=\"radioSelectedKey\" style=\"width: 100%;\">\r\n <ElRadio\r\n v-bind=\"compatibleRadioValue(row[rowKey])\"\r\n @change=\"() => onRadioClick(row)\"\r\n >\r\n \r\n </ElRadio>\r\n </ElRadioGroup>\r\n </template>\r\n </ElTableColumn>\r\n <template v-if=\"props.columns.length === 0\">\r\n <slot />\r\n </template>\r\n <template v-else>\r\n <ElTableColumn\r\n v-for=\"colItem of props.columns\"\r\n v-bind=\"colItem\"\r\n :key=\"colItem.prop || colItem.type\"\r\n />\r\n </template>\r\n </ElTable>\r\n </div>\r\n</template>\r\n","import { connect, mapProps } from '@silver-formily/vue'\r\nimport InnerSelectTable from './select-table.vue'\r\nimport './style.scss'\r\n\r\nconst SelectTable = connect(\r\n InnerSelectTable,\r\n mapProps({ dataSource: 'dataSource', loading: 'loading' }),\r\n)\r\n\r\nexport { SelectTable }\r\n\r\nexport default SelectTable\r\n"],"names":["props","__props","emit","__emit","elTableProps","useAttrs","field","useField","compatibleRadioValue","key","lt","version","elTableRef","ref","rowKey","getInitialSelectedList","item","initialSelectedList","selectedFlatDataSource","prevSelection","radioSelectedKey","currentSelectLength","computed","isValid","watch","selectedKeys","uniq","nextTick","onRadioClick","value","loading","currentDisplayDataKeys","valueKeys","isEqual","diffItems","xor","tableItem","shouldSelect","onSelect","newSelection","removedItemList","differenceWith","itemPrev","itemNext","uniqWith","removedKeys","remove","onRowClick","row","_","event","checkboxDOM","radioDOM","onClearSelectionClick","selectable","index","isFn","_createElementBlock","_unref","stylePrefix","_createElementVNode","_toDisplayString","_createVNode","ElLink","_cache","_withDirectives","_openBlock","_createBlock","_mergeProps","ElTableColumn","_withCtx","ElRadioGroup","$event","_renderSlot","_ctx","_Fragment","_renderList","colItem","vLoading","SelectTable","connect","InnerSelectTable","mapProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,UAAMA,IAAQC,GAgBRC,IAAOC,GAEPC,IAAeC,GAAA,GACfC,IAAQC,EAAA;AAEd,aAASC,EAAqBC,GAAa;AACzC,aAAOC,EAAGC,GAAS,OAAO,IAAI,EAAE,OAAOF,EAAA,IAAQ,EAAE,OAAOA,EAAA;AAAA,IAC1D;AAEA,UAAMG,IAAaC,EAAA,GACbC,IAASd,EAAM;AACrB,aAASe,IAAyB;AAChC,aAAIf,EAAM,SAAS,aACVA,EAAM,YAAY,IAAI,CAACgB,MACvBhB,EAAM,gBAKJgB,IAJE;AAAA,QACL,CAACF,CAAM,GAAGE;AAAA,MAAA,CAIf,KAAK,CAAA,IAGChB,EAAM,gBAAgB,CAACA,EAAM,UAAU,IAAI,CAAC,EAAE,CAACc,CAAM,GAAGd,EAAM,YAAY;AAAA,IAErF;AACA,UAAMiB,IAAsBF,EAAA,GACtBG,IAAyBL,EAAII,CAAmB;AAEtD,QA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yE,EAAQC,EAAA,QAAA,WAAA,EAAA,KAAA,EAAA,CAAA,KAGRR,EAAA,EAAA,GAAAT,EAIEkB,IAAA,EAAA,KAAA,EAAA,GAAAC,GAHkB5E,EAAM,UAAjB6E,YADTV,EAIET,EAAAW,CAAA,GAJFD,EAIE,EAAA,SAAA,GAAA,GAFQS,GAAO;AAAA,YACd,KAAKA,EAAQ,QAAQA,EAAQ;AAAA,UAAA;;;;QArCvB,CAAAnB,EAAAoB,EAAA,GAAA9E,EAAM,OAAO;AAAA,MAAA;;;ICxPxB+E,KAAcC;AAAA,EAClBC;AAAAA,EACAC,EAAS,EAAE,YAAY,cAAc,SAAS,WAAW;AAC3D;"}
|
|
@@ -1480,9 +1480,9 @@ declare function __VLS_template(): {
|
|
|
1480
1480
|
};
|
|
1481
1481
|
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
1482
1482
|
declare const __VLS_component: import('vue').DefineComponent<ISelectTableProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
1483
|
-
|
|
1483
|
+
"update:modelValue": (...args: any[]) => void;
|
|
1484
1484
|
}, string, import('vue').PublicProps, Readonly<ISelectTableProps> & Readonly<{
|
|
1485
|
-
|
|
1485
|
+
"onUpdate:modelValue"?: (...args: any[]) => any;
|
|
1486
1486
|
}>, {
|
|
1487
1487
|
mode: "multiple" | "single";
|
|
1488
1488
|
loading: boolean;
|
|
@@ -10,7 +10,7 @@ export interface ISelectTableProps {
|
|
|
10
10
|
rowKey?: string;
|
|
11
11
|
clickRowToSelect?: boolean;
|
|
12
12
|
showAlertToolbar?: boolean;
|
|
13
|
-
|
|
13
|
+
modelValue?: any;
|
|
14
14
|
data?: Record<string, any>[];
|
|
15
15
|
selectable?: (row: Record<string, any>, index: number, field: GeneralField) => boolean;
|
|
16
16
|
ignoreSelectable?: boolean;
|
package/esm/submit/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { observer as m } from "@formily/reactive-vue";
|
|
2
2
|
import { defineComponent as s, createBlock as a, openBlock as c, unref as e, mergeProps as l, withCtx as f, renderSlot as b } from "vue";
|
|
3
|
-
import { useParentForm as p } from "@formily/vue";
|
|
3
|
+
import { useParentForm as p } from "@silver-formily/vue";
|
|
4
4
|
import { ElButton as d } from "element-plus";
|
|
5
5
|
const S = /* @__PURE__ */ s({
|
|
6
6
|
name: "FSubmit",
|
package/esm/submit/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/submit/submit.vue","../../src/submit/index.ts"],"sourcesContent":["<script lang=\"ts\" setup>\nimport type { IFormFeedback } from '@formily/core'\nimport type { PropType } from 'vue'\nimport { useParentForm } from '@formily/vue'\nimport { ElButton } from 'element-plus'\n\ndefineOptions({\n name: 'FSubmit',\n inheritAttrs: false,\n})\n\nconst props = defineProps({\n onClick: Function as PropType<(e: MouseEvent) => any>,\n onSubmit: Function as PropType<(values: any) => Promise<any>>,\n onSubmitSuccess: Function as PropType<(payload: any) => void>,\n onSubmitFailed: Function as PropType<(feedbacks: IFormFeedback[]) => void>,\n submit: Boolean,\n loading: Boolean,\n})\n\nconst formRef = useParentForm()\n\nfunction handleClick(e: MouseEvent) {\n if (props.onClick?.(e) === false)\n return\n if (props.onSubmit) {\n const form = formRef?.value\n form?.submit(props.onSubmit)\n .then(props.onSubmitSuccess)\n .catch(props.onSubmitFailed ?? console.log)\n }\n}\n</script>\n\n<template>\n <ElButton\n :native-type=\"props.submit ? 'button' : 'submit'\"\n type=\"primary\"\n v-bind=\"$attrs\"\n :loading=\"formRef?.submitting ?? props.loading\"\n @click=\"handleClick\"\n >\n <template #default>\n <slot />\n </template>\n </ElButton>\n</template>\n","import { observer } from '@formily/reactive-vue'\nimport FSubmit from './submit.vue'\n\nexport const Submit = observer(FSubmit)\n\nexport default Submit\n"],"names":["props","__props","formRef","useParentForm","handleClick","e","_openBlock","_createBlock","_unref","_mergeProps","$attrs","_renderSlot","_ctx","Submit","observer","FSubmit"],"mappings":";;;;;;;;;;;;;;;;;AAWA,UAAMA,IAAQC,GASRC,IAAUC,EAAA;AAEhB,aAASC,EAAYC,GAAe;AAClC,MAAIL,EAAM,UAAUK,CAAC,MAAM,MAEvBL,EAAM,YACKE,GAAS,OAChB,OAAOF,EAAM,QAAQ,EACxB,KAAKA,EAAM,eAAe,EAC1B,MAAMA,EAAM,kBAAkB,QAAQ,GAAG;AAAA,IAEhD;sBAIEM,KAAAC,EAUWC,MAVXC,EAUW;AAAA,MATR,eAAaT,EAAM,SAAM,WAAA;AAAA,MAC1B,MAAK;AAAA,IAAA,GACGU,EAAAA,QAAM;AAAA,MACb,SAASF,EAAAN,CAAA,GAAS,cAAcF,EAAM;AAAA,MACtC,SAAOI;AAAA,IAAA;MAEG,WACT,MAAQ;AAAA,QAARO,EAAQC,EAAA,QAAA,SAAA;AAAA,MAAA;;;;ICxCDC,IAASC,EAASC,CAAO;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/submit/submit.vue","../../src/submit/index.ts"],"sourcesContent":["<script lang=\"ts\" setup>\r\nimport type { IFormFeedback } from '@formily/core'\r\nimport type { PropType } from 'vue'\r\nimport { useParentForm } from '@silver-formily/vue'\r\nimport { ElButton } from 'element-plus'\r\n\r\ndefineOptions({\r\n name: 'FSubmit',\r\n inheritAttrs: false,\r\n})\r\n\r\nconst props = defineProps({\r\n onClick: Function as PropType<(e: MouseEvent) => any>,\r\n onSubmit: Function as PropType<(values: any) => Promise<any>>,\r\n onSubmitSuccess: Function as PropType<(payload: any) => void>,\r\n onSubmitFailed: Function as PropType<(feedbacks: IFormFeedback[]) => void>,\r\n submit: Boolean,\r\n loading: Boolean,\r\n})\r\n\r\nconst formRef = useParentForm()\r\n\r\nfunction handleClick(e: MouseEvent) {\r\n if (props.onClick?.(e) === false)\r\n return\r\n if (props.onSubmit) {\r\n const form = formRef?.value\r\n form?.submit(props.onSubmit)\r\n .then(props.onSubmitSuccess)\r\n .catch(props.onSubmitFailed ?? console.log)\r\n }\r\n}\r\n</script>\r\n\r\n<template>\r\n <ElButton\r\n :native-type=\"props.submit ? 'button' : 'submit'\"\r\n type=\"primary\"\r\n v-bind=\"$attrs\"\r\n :loading=\"formRef?.submitting ?? props.loading\"\r\n @click=\"handleClick\"\r\n >\r\n <template #default>\r\n <slot />\r\n </template>\r\n </ElButton>\r\n</template>\r\n","import { observer } from '@formily/reactive-vue'\r\nimport FSubmit from './submit.vue'\r\n\r\nexport const Submit = observer(FSubmit)\r\n\r\nexport default Submit\r\n"],"names":["props","__props","formRef","useParentForm","handleClick","e","_openBlock","_createBlock","_unref","_mergeProps","$attrs","_renderSlot","_ctx","Submit","observer","FSubmit"],"mappings":";;;;;;;;;;;;;;;;;AAWA,UAAMA,IAAQC,GASRC,IAAUC,EAAA;AAEhB,aAASC,EAAYC,GAAe;AAClC,MAAIL,EAAM,UAAUK,CAAC,MAAM,MAEvBL,EAAM,YACKE,GAAS,OAChB,OAAOF,EAAM,QAAQ,EACxB,KAAKA,EAAM,eAAe,EAC1B,MAAMA,EAAM,kBAAkB,QAAQ,GAAG;AAAA,IAEhD;sBAIEM,KAAAC,EAUWC,MAVXC,EAUW;AAAA,MATR,eAAaT,EAAM,SAAM,WAAA;AAAA,MAC1B,MAAK;AAAA,IAAA,GACGU,EAAAA,QAAM;AAAA,MACb,SAASF,EAAAN,CAAA,GAAS,cAAcF,EAAM;AAAA,MACtC,SAAOI;AAAA,IAAA;MAEG,WACT,MAAQ;AAAA,QAARO,EAAQC,EAAA,QAAA,SAAA;AAAA,MAAA;;;;ICxCDC,IAASC,EAASC,CAAO;"}
|