@hairy/vue-lib 1.47.0 → 1.49.0
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.md +21 -21
- package/README.md +36 -36
- package/dist/index.cjs +388 -383
- package/dist/index.d.cts +184 -0
- package/dist/index.d.mts +184 -0
- package/dist/index.mjs +387 -0
- package/package.json +17 -18
- package/dist/index.d.ts +0 -175
- package/dist/index.global.js +0 -1258
- package/dist/index.js +0 -376
package/dist/index.cjs
CHANGED
|
@@ -1,422 +1,427 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
14
|
+
__defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
useSelectedSingle: () => useSelectedSingle,
|
|
42
|
-
useServerPagination: () => useServerPagination
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
//#endregion
|
|
29
|
+
let vue_demi = require("vue-demi");
|
|
30
|
+
let css_render = require("css-render");
|
|
31
|
+
css_render = __toESM(css_render);
|
|
32
|
+
let _vueuse_core = require("@vueuse/core");
|
|
33
|
+
let lodash_debounce = require("lodash/debounce");
|
|
34
|
+
lodash_debounce = __toESM(lodash_debounce);
|
|
35
|
+
let lodash_throttle = require("lodash/throttle");
|
|
36
|
+
lodash_throttle = __toESM(lodash_throttle);
|
|
37
|
+
let vue = require("vue");
|
|
38
|
+
let _hairy_utils = require("@hairy/utils");
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
40
|
+
//#region src/components/c-field.ts
|
|
41
|
+
const Field = (0, vue_demi.defineComponent)({
|
|
42
|
+
name: "Field",
|
|
43
|
+
props: { is: {
|
|
44
|
+
type: [
|
|
45
|
+
String,
|
|
46
|
+
Number,
|
|
47
|
+
Object
|
|
48
|
+
],
|
|
49
|
+
default: ""
|
|
50
|
+
} },
|
|
51
|
+
setup(props) {
|
|
52
|
+
return () => {
|
|
53
|
+
if (typeof props.is === "string" || typeof props.is === "number") return props.is;
|
|
54
|
+
return props.is ? (0, vue_demi.h)(props.is) : null;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
63
57
|
});
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
style.mount();
|
|
128
|
-
return () => (0, import_vue_demi2.h)(import_vue_demi2.Transition, on, slots);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
var style = c(".collapse-transition", {
|
|
132
|
-
transition: "0.2s height ease-in-out, 0.2s padding-top ease-in-out,0.2s padding-bottom ease-in-out"
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/components/collapse-transition.ts
|
|
61
|
+
const { c } = (0, css_render.default)();
|
|
62
|
+
const CollapseTransition = (0, vue_demi.defineComponent)({
|
|
63
|
+
name: "CollapseTransition",
|
|
64
|
+
setup(_, { slots }) {
|
|
65
|
+
const on = {
|
|
66
|
+
onBeforeEnter(el) {
|
|
67
|
+
el.classList.add("collapse-transition");
|
|
68
|
+
if (!el.dataset) el.dataset = {};
|
|
69
|
+
el.dataset.oldPaddingTop = el.style.paddingTop;
|
|
70
|
+
el.dataset.oldPaddingBottom = el.style.paddingBottom;
|
|
71
|
+
el.style.height = "0";
|
|
72
|
+
el.style.paddingTop = "0";
|
|
73
|
+
el.style.paddingBottom = "0";
|
|
74
|
+
},
|
|
75
|
+
onEnter(el) {
|
|
76
|
+
el.dataset.oldOverflow = el.style.overflow;
|
|
77
|
+
if (el.scrollHeight !== 0) {
|
|
78
|
+
el.style.height = `${el.scrollHeight}px`;
|
|
79
|
+
el.style.paddingTop = el.dataset.oldPaddingTop || "0";
|
|
80
|
+
el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
|
|
81
|
+
} else {
|
|
82
|
+
el.style.height = "";
|
|
83
|
+
el.style.paddingTop = el.dataset.oldPaddingTop || "0";
|
|
84
|
+
el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
|
|
85
|
+
}
|
|
86
|
+
el.style.overflow = "hidden";
|
|
87
|
+
},
|
|
88
|
+
onAfterEnter(el) {
|
|
89
|
+
el.classList.remove("collapse-transition");
|
|
90
|
+
el.style.height = "";
|
|
91
|
+
el.style.overflow = el.dataset.oldOverflow || "0";
|
|
92
|
+
},
|
|
93
|
+
onBeforeLeave(el) {
|
|
94
|
+
if (!el.dataset) el.dataset = {};
|
|
95
|
+
el.dataset.oldPaddingTop = el.style.paddingTop;
|
|
96
|
+
el.dataset.oldPaddingBottom = el.style.paddingBottom;
|
|
97
|
+
el.dataset.oldOverflow = el.style.overflow;
|
|
98
|
+
el.style.height = `${el.scrollHeight}px`;
|
|
99
|
+
el.style.overflow = "hidden";
|
|
100
|
+
},
|
|
101
|
+
onLeave(el) {
|
|
102
|
+
if (el.scrollHeight !== 0) {
|
|
103
|
+
el.classList.add("collapse-transition");
|
|
104
|
+
el.style.transitionProperty = "height";
|
|
105
|
+
el.style.height = "0";
|
|
106
|
+
el.style.paddingTop = "0";
|
|
107
|
+
el.style.paddingBottom = "0";
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
onAfterLeave(el) {
|
|
111
|
+
el.classList.remove("collapse-transition");
|
|
112
|
+
el.style.height = "";
|
|
113
|
+
el.style.overflow = el.dataset.oldOverflow || "0";
|
|
114
|
+
el.style.paddingTop = el.dataset.oldPaddingTop || "0";
|
|
115
|
+
el.style.paddingBottom = el.dataset.oldPaddingBottom || "0";
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
style.mount();
|
|
119
|
+
return () => (0, vue_demi.h)(vue_demi.Transition, on, slots);
|
|
120
|
+
}
|
|
133
121
|
});
|
|
122
|
+
const style = c(".collapse-transition", { transition: "0.2s height ease-in-out, 0.2s padding-top ease-in-out,0.2s padding-bottom ease-in-out" });
|
|
134
123
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/hooks/syncElementScroll/index.ts
|
|
126
|
+
/**
|
|
127
|
+
* Synchronize scrolling between two DOM with the same scrollbar
|
|
128
|
+
* @param fromTarget DOM-A
|
|
129
|
+
* @param toTarget DOM-B
|
|
130
|
+
* @param options
|
|
131
|
+
* @todo optimizes the reuse of useEventListener
|
|
132
|
+
* @todo may have bugs when using wait
|
|
133
|
+
*/
|
|
140
134
|
function syncElementSyncScroll(fromTarget, toTarget, options = {}) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
135
|
+
const { left = true, top = true, wait, immediate = true } = options;
|
|
136
|
+
const debounceScrollLocks = (0, vue.reactive)({
|
|
137
|
+
from: false,
|
|
138
|
+
to: false
|
|
139
|
+
});
|
|
140
|
+
const onChangeLockScrollListener = (0, lodash_debounce.default)((type) => {
|
|
141
|
+
debounceScrollLocks[type] = true;
|
|
142
|
+
}, 20, {
|
|
143
|
+
leading: true,
|
|
144
|
+
trailing: false
|
|
145
|
+
});
|
|
146
|
+
const offChangeLockScrollListener = (0, lodash_debounce.default)((type) => {
|
|
147
|
+
debounceScrollLocks[type] = false;
|
|
148
|
+
}, 20, {
|
|
149
|
+
leading: false,
|
|
150
|
+
trailing: true
|
|
151
|
+
});
|
|
152
|
+
const syncScroll = (type) => {
|
|
153
|
+
const positive = type;
|
|
154
|
+
const opposite = type === "from" ? "to" : "from";
|
|
155
|
+
const elements = (0, vue.reactive)({
|
|
156
|
+
from: fromTarget,
|
|
157
|
+
to: toTarget
|
|
158
|
+
});
|
|
159
|
+
if (debounceScrollLocks[type]) return;
|
|
160
|
+
onChangeLockScrollListener(opposite);
|
|
161
|
+
const aElement = elements[positive];
|
|
162
|
+
const bElement = elements[opposite];
|
|
163
|
+
const options = {};
|
|
164
|
+
if (left) options.left = aElement.scrollLeft;
|
|
165
|
+
if (top) options.top = aElement.scrollTop;
|
|
166
|
+
if (!aElement || !bElement) return;
|
|
167
|
+
bElement?.scroll(options);
|
|
168
|
+
offChangeLockScrollListener(opposite);
|
|
169
|
+
};
|
|
170
|
+
const syncFromTo = () => syncScroll("from");
|
|
171
|
+
const syncToFrom = () => syncScroll("to");
|
|
172
|
+
let toStopHandle;
|
|
173
|
+
let formStopHandle;
|
|
174
|
+
const stop = () => {
|
|
175
|
+
toStopHandle?.();
|
|
176
|
+
formStopHandle?.();
|
|
177
|
+
};
|
|
178
|
+
const start = () => {
|
|
179
|
+
toStopHandle = (0, _vueuse_core.useEventListener)(fromTarget, "scroll", (0, lodash_throttle.default)(syncFromTo, wait));
|
|
180
|
+
formStopHandle = (0, _vueuse_core.useEventListener)(toTarget, "scroll", (0, lodash_throttle.default)(syncToFrom, wait));
|
|
181
|
+
};
|
|
182
|
+
if (immediate) start();
|
|
183
|
+
return {
|
|
184
|
+
stop,
|
|
185
|
+
start,
|
|
186
|
+
syncFromTo,
|
|
187
|
+
syncToFrom
|
|
188
|
+
};
|
|
194
189
|
}
|
|
195
190
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/hooks/syncElementSize/index.ts
|
|
193
|
+
/**
|
|
194
|
+
* Synchronize the width or height of from DOM to the specified to DOM
|
|
195
|
+
* @param fromTarget width and height source element
|
|
196
|
+
* @param toTarget width and height setting elements
|
|
197
|
+
* @param options
|
|
198
|
+
*/
|
|
200
199
|
function syncElementSize(fromTarget, toTarget, options = {}) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
200
|
+
const { width: isOnWidth = true, height: isOnHeight = false } = options;
|
|
201
|
+
const defaultSize = {
|
|
202
|
+
width: "",
|
|
203
|
+
height: ""
|
|
204
|
+
};
|
|
205
|
+
const fromSize = (0, _vueuse_core.useElementSize)(fromTarget);
|
|
206
|
+
let widthStopHandle;
|
|
207
|
+
let heightStopHandle;
|
|
208
|
+
const sync = (type) => {
|
|
209
|
+
const sources = [fromSize[type], toTarget];
|
|
210
|
+
const callback = () => {
|
|
211
|
+
const element = (0, _vueuse_core.unrefElement)(toTarget);
|
|
212
|
+
if (!element) return void 0;
|
|
213
|
+
element.style[type] = (0, _hairy_utils.unit)(fromSize[type].value);
|
|
214
|
+
};
|
|
215
|
+
return (0, vue.watch)(sources, callback, {
|
|
216
|
+
immediate: true,
|
|
217
|
+
...options
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
const stop = () => {
|
|
221
|
+
widthStopHandle?.();
|
|
222
|
+
heightStopHandle?.();
|
|
223
|
+
const element = (0, _vueuse_core.unrefElement)(toTarget);
|
|
224
|
+
element.style.width = defaultSize.width;
|
|
225
|
+
element.style.height = defaultSize.height;
|
|
226
|
+
};
|
|
227
|
+
const start = () => {
|
|
228
|
+
if (isOnWidth) widthStopHandle = sync("width");
|
|
229
|
+
if (isOnHeight) heightStopHandle = sync("height");
|
|
230
|
+
};
|
|
231
|
+
(0, vue.watch)(() => (0, vue.unref)(toTarget), () => {
|
|
232
|
+
const element = (0, _vueuse_core.unrefElement)(toTarget);
|
|
233
|
+
defaultSize.width = element.style.width;
|
|
234
|
+
defaultSize.height = element.style.height;
|
|
235
|
+
});
|
|
236
|
+
start();
|
|
237
|
+
return {
|
|
238
|
+
start,
|
|
239
|
+
stop
|
|
240
|
+
};
|
|
239
241
|
}
|
|
240
242
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/hooks/useChecked/index.ts
|
|
245
|
+
/**
|
|
246
|
+
* Get the status of checked and customize the value of checked | unchecked
|
|
247
|
+
* @param target
|
|
248
|
+
* @param checked
|
|
249
|
+
* @param unchecked
|
|
250
|
+
*/
|
|
243
251
|
function useChecked(target, checked = true, unchecked = false) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
252
|
+
return (0, vue.computed)({
|
|
253
|
+
get: () => target.value === (0, vue.unref)(checked),
|
|
254
|
+
set: (_value) => {
|
|
255
|
+
target.value = _value ? (0, vue.unref)(checked) : (0, vue.unref)(unchecked);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
250
258
|
}
|
|
251
259
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
var import_debounce2 = __toESM(require("lodash/debounce"), 1);
|
|
255
|
-
var import_vue4 = require("vue");
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/hooks/usePaginationServer/index.ts
|
|
256
262
|
function useServerPagination(options) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
263
|
+
const total = (0, vue.ref)(Infinity);
|
|
264
|
+
const pagination = (0, _vueuse_core.useOffsetPagination)({
|
|
265
|
+
total,
|
|
266
|
+
...options
|
|
267
|
+
});
|
|
268
|
+
const resolveOptions = (0, vue.reactive)({
|
|
269
|
+
currentPage: pagination.currentPage,
|
|
270
|
+
currentPageSize: pagination.currentPageSize,
|
|
271
|
+
total
|
|
272
|
+
});
|
|
273
|
+
const paginationRef = (0, vue.reactive)({
|
|
274
|
+
currentPage: pagination.currentPage,
|
|
275
|
+
currentPageSize: pagination.currentPageSize,
|
|
276
|
+
pageCount: pagination.pageCount,
|
|
277
|
+
isFirstPage: pagination.isFirstPage,
|
|
278
|
+
isLastPage: pagination.isLastPage,
|
|
279
|
+
total
|
|
280
|
+
});
|
|
281
|
+
const state = (0, vue.ref)([]);
|
|
282
|
+
const { execute: _execute, isLoading: loading, error } = (0, _vueuse_core.useAsyncState)(async () => {
|
|
283
|
+
return await options.resolve(resolveOptions);
|
|
284
|
+
}, []);
|
|
285
|
+
const execute = (0, lodash_debounce.default)(async () => {
|
|
286
|
+
state.value = await _execute();
|
|
287
|
+
}, 100);
|
|
288
|
+
(0, vue.nextTick)(() => {
|
|
289
|
+
(0, vue.watch)([pagination.currentPageSize, ...options.sources || []], execute, {
|
|
290
|
+
immediate: true,
|
|
291
|
+
...options
|
|
292
|
+
});
|
|
293
|
+
(0, vue.watch)(pagination.currentPage, (newValue, oldValue) => newValue !== oldValue && execute());
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
state,
|
|
297
|
+
loading,
|
|
298
|
+
error,
|
|
299
|
+
execute,
|
|
300
|
+
pagination: paginationRef,
|
|
301
|
+
next: pagination.next,
|
|
302
|
+
prev: pagination.prev
|
|
303
|
+
};
|
|
297
304
|
}
|
|
298
305
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
// src/hooks/utils/extendSelected.ts
|
|
303
|
-
var import_core4 = require("@vueuse/core");
|
|
304
|
-
var import_vue5 = require("vue");
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/hooks/utils/extendSelected.ts
|
|
305
308
|
function extendSelected(array, fieldName) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
},
|
|
314
|
-
{ immediate: true, flush: "sync" }
|
|
315
|
-
);
|
|
309
|
+
(0, vue.watch)(array, (items) => {
|
|
310
|
+
for (const item of items) if (typeof item[fieldName] === "undefined") (0, _vueuse_core.extendRef)(item, { [fieldName]: (0, vue.ref)(false) });
|
|
311
|
+
}, {
|
|
312
|
+
immediate: true,
|
|
313
|
+
flush: "sync"
|
|
314
|
+
});
|
|
316
315
|
}
|
|
317
316
|
|
|
318
|
-
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/hooks/useSelectedMultiple/index.ts
|
|
319
319
|
function useSelectedMultiple(array, options = {}) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
320
|
+
const { fieldName = "select", disabled } = options;
|
|
321
|
+
extendSelected(array, fieldName);
|
|
322
|
+
/** 当前选中的项列表 */
|
|
323
|
+
const selected = (0, vue.computed)(() => (0, vue.unref)(array).filter((item) => item[fieldName]));
|
|
324
|
+
return {
|
|
325
|
+
selected,
|
|
326
|
+
isSelectedAll: (0, vue.computed)({
|
|
327
|
+
get: () => !selected.value?.length && !(0, vue.unref)(array).some((item) => !item[fieldName]),
|
|
328
|
+
set: (value) => (0, vue.unref)(array).forEach((item, index) => {
|
|
329
|
+
if (!disabled?.(item, index)) item[fieldName] = value;
|
|
330
|
+
})
|
|
331
|
+
}),
|
|
332
|
+
isSelected: (0, vue.computed)(() => !!(0, vue.unref)(array).some((item) => item[fieldName])),
|
|
333
|
+
isIndeterminate: (0, vue.computed)(() => {
|
|
334
|
+
const selectCount = selected.value.length;
|
|
335
|
+
return selectCount > 0 && selectCount < (0, vue.unref)(array).length;
|
|
336
|
+
})
|
|
337
|
+
};
|
|
336
338
|
}
|
|
337
339
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
+
//#endregion
|
|
341
|
+
//#region src/hooks/useSelectedSingle/index.ts
|
|
340
342
|
function useSelectedSingle(array, options = {}) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
(0, import_vue7.unref)(array).forEach(targetEffect);
|
|
386
|
-
},
|
|
387
|
-
{ immediate: true, flush: "sync" }
|
|
388
|
-
);
|
|
389
|
-
const selected = (0, import_vue7.computed)(() => (0, import_vue7.unref)(array).find((v) => v[fieldName]));
|
|
390
|
-
return { selected, isSelected };
|
|
343
|
+
const fieldName = options.fieldName ?? "select";
|
|
344
|
+
const required = options.required ?? false;
|
|
345
|
+
extendSelected(array, fieldName);
|
|
346
|
+
const SELECTED_SINGLE_KEY = "selected_single_key";
|
|
347
|
+
const isLocked = (0, vue.ref)(false);
|
|
348
|
+
/** 当前是否已经选择 */
|
|
349
|
+
const isSelected = (0, vue.computed)(() => !!(0, vue.unref)(array).some((item) => item.select));
|
|
350
|
+
if (required) {
|
|
351
|
+
const recover = (bool) => {
|
|
352
|
+
const index = required === true ? 0 : required;
|
|
353
|
+
if (!bool && (0, vue.unref)(array).length > 0) (0, vue.unref)(array)[index][fieldName] = true;
|
|
354
|
+
};
|
|
355
|
+
(0, vue.watch)(isSelected, recover, {
|
|
356
|
+
flush: "sync",
|
|
357
|
+
immediate: true
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
const itemChange = (neglect) => {
|
|
361
|
+
if (isLocked.value) return;
|
|
362
|
+
isLocked.value = true;
|
|
363
|
+
const _array = (0, vue.unref)(array);
|
|
364
|
+
const _value = !_array[neglect][fieldName];
|
|
365
|
+
if (required && !_value) _array[neglect][fieldName] = true;
|
|
366
|
+
_array.forEach((target, index) => {
|
|
367
|
+
if (neglect === index) return void 0;
|
|
368
|
+
if (!target[fieldName]) return void 0;
|
|
369
|
+
target[fieldName] = false;
|
|
370
|
+
});
|
|
371
|
+
isLocked.value = false;
|
|
372
|
+
};
|
|
373
|
+
const targetEffect = (target, index) => {
|
|
374
|
+
if (!target[SELECTED_SINGLE_KEY]) return (0, vue.watch)(() => target[fieldName], () => itemChange(index), { flush: "sync" });
|
|
375
|
+
Object.defineProperty(target, SELECTED_SINGLE_KEY, { value: true });
|
|
376
|
+
};
|
|
377
|
+
(0, vue.watch)(array, () => {
|
|
378
|
+
(0, vue.unref)(array).forEach(targetEffect);
|
|
379
|
+
}, {
|
|
380
|
+
immediate: true,
|
|
381
|
+
flush: "sync"
|
|
382
|
+
});
|
|
383
|
+
return {
|
|
384
|
+
selected: (0, vue.computed)(() => (0, vue.unref)(array).find((v) => v[fieldName])),
|
|
385
|
+
isSelected
|
|
386
|
+
};
|
|
391
387
|
}
|
|
392
388
|
|
|
393
|
-
|
|
394
|
-
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/utils/index.ts
|
|
391
|
+
/**
|
|
392
|
+
* Directly render the incoming function components
|
|
393
|
+
* @param component
|
|
394
|
+
* @param tag Rendering container (default div)
|
|
395
|
+
*/
|
|
395
396
|
function ehr(component, tag) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
const container = document.createElement(tag || "dev");
|
|
398
|
+
(0, vue_demi.render)((0, vue_demi.h)(component), container);
|
|
399
|
+
return container;
|
|
399
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Convert the properties of an object to ref
|
|
403
|
+
* @param data
|
|
404
|
+
* @param prop
|
|
405
|
+
*/
|
|
400
406
|
function propertyToRef(data, prop) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
return (0, vue_demi.computed)({
|
|
408
|
+
get() {
|
|
409
|
+
return data[prop];
|
|
410
|
+
},
|
|
411
|
+
set(v) {
|
|
412
|
+
data[prop] = v;
|
|
413
|
+
}
|
|
414
|
+
});
|
|
409
415
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
});
|
|
416
|
+
|
|
417
|
+
//#endregion
|
|
418
|
+
exports.CollapseTransition = CollapseTransition;
|
|
419
|
+
exports.Field = Field;
|
|
420
|
+
exports.ehr = ehr;
|
|
421
|
+
exports.propertyToRef = propertyToRef;
|
|
422
|
+
exports.syncElementSize = syncElementSize;
|
|
423
|
+
exports.syncElementSyncScroll = syncElementSyncScroll;
|
|
424
|
+
exports.useChecked = useChecked;
|
|
425
|
+
exports.useSelectedMultiple = useSelectedMultiple;
|
|
426
|
+
exports.useSelectedSingle = useSelectedSingle;
|
|
427
|
+
exports.useServerPagination = useServerPagination;
|