@astrolimit/vue3-web-hooks 25.11.1 → 26.1.3
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.d.ts +24 -8
- package/dist/index.js +101 -20
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as vue0 from "vue";
|
|
2
|
-
import { DefineComponent, FunctionalComponent, Ref, VNode } from "vue";
|
|
2
|
+
import { ComputedRef, DefineComponent, FunctionalComponent, Ref, VNode } from "vue";
|
|
3
3
|
import * as _vueuse_core0 from "@vueuse/core";
|
|
4
4
|
import mitt from "mitt";
|
|
5
|
-
import * as _vue_reactivity0 from "@vue/reactivity";
|
|
6
5
|
|
|
7
6
|
//#region src/hooks/useDivSize.d.ts
|
|
8
7
|
|
|
@@ -33,7 +32,7 @@ declare const useDivSize: (target?: Ref<HTMLDivElement | undefined> | HTMLDivEle
|
|
|
33
32
|
* @returns
|
|
34
33
|
*/
|
|
35
34
|
declare const useDrawerWidth: (percentage?: number, minWidth?: number) => {
|
|
36
|
-
drawerWidth: vue0.ComputedRef<number
|
|
35
|
+
drawerWidth: vue0.ComputedRef<number>;
|
|
37
36
|
};
|
|
38
37
|
//#endregion
|
|
39
38
|
//#region src/hooks/useMitt.d.ts
|
|
@@ -41,8 +40,8 @@ type AnyRecord$1 = Record<string, any>;
|
|
|
41
40
|
type R<T extends AnyRecord$1> = ReturnType<typeof mitt<T>> & {
|
|
42
41
|
stop(key: keyof T): void;
|
|
43
42
|
pause(key: keyof T): void;
|
|
44
|
-
subscribe<P
|
|
45
|
-
once<P
|
|
43
|
+
subscribe<P extends keyof T>(key: P, cb: (data: T[P]) => void): void;
|
|
44
|
+
once<P extends keyof T>(key: P, cb: (data: T[P]) => void): void;
|
|
46
45
|
};
|
|
47
46
|
/**
|
|
48
47
|
* 在父祖组件中使用
|
|
@@ -78,6 +77,23 @@ declare const useNow: (immediate?: boolean) => {
|
|
|
78
77
|
meridiem: vue0.Ref<string, string>;
|
|
79
78
|
};
|
|
80
79
|
//#endregion
|
|
80
|
+
//#region src/hooks/usePageSize.d.ts
|
|
81
|
+
/**
|
|
82
|
+
* @example
|
|
83
|
+
* const pagita = usePageSize()
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
declare const usePageSize: () => {
|
|
87
|
+
total: vue0.WritableComputedRef<number, number>;
|
|
88
|
+
page: vue0.WritableComputedRef<number, number>;
|
|
89
|
+
pageNo: vue0.WritableComputedRef<number, number>;
|
|
90
|
+
limit: vue0.WritableComputedRef<number, number>;
|
|
91
|
+
pageSize: vue0.WritableComputedRef<number, number>;
|
|
92
|
+
pending: vue0.WritableComputedRef<boolean, boolean>;
|
|
93
|
+
loading: vue0.WritableComputedRef<boolean, boolean>;
|
|
94
|
+
resetPageAndFetch(fn: () => Promise<void>): Promise<void>;
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
81
97
|
//#region src/hooks/useStyleSheetLink.d.ts
|
|
82
98
|
/**
|
|
83
99
|
* 基于vue3组合式api的样式注入(动态创建link标签)
|
|
@@ -113,12 +129,12 @@ declare const useSortable: <T extends AnyRecord>(params: {
|
|
|
113
129
|
/**
|
|
114
130
|
* 原始数据列表
|
|
115
131
|
*/
|
|
116
|
-
rawDataList: Ref<Array<T>>;
|
|
132
|
+
rawDataList: Ref<Array<T>> | ComputedRef<Array<T>>;
|
|
117
133
|
}) => {
|
|
118
134
|
initSort: _vueuse_core0.PromisifyFn<() => void>;
|
|
119
135
|
handleSortCancel: () => void;
|
|
120
136
|
handleSortToggle: () => void;
|
|
121
|
-
|
|
137
|
+
sortedResult: ComputedRef<any>;
|
|
122
138
|
isSorting: Ref<boolean, boolean>;
|
|
123
139
|
};
|
|
124
140
|
//#endregion
|
|
@@ -187,4 +203,4 @@ type ExtractComponentProps<C> = C extends (new (...args: any[]) => {
|
|
|
187
203
|
*/
|
|
188
204
|
type IVueProps<T> = Partial<ExtractComponentProps<T>>;
|
|
189
205
|
//#endregion
|
|
190
|
-
export { type ExtractFirstParam, type IVueComponent, type IVueProps, useDivSize, useDrawerWidth, useInjectMitt, useNetwork, useNewMitt, useNow, useSortable, useStyleSheetLink, useViewRefresh, useVueInterval, useWatermark };
|
|
206
|
+
export { type ExtractFirstParam, type IVueComponent, type IVueProps, useDivSize, useDrawerWidth, useInjectMitt, useNetwork, useNewMitt, useNow, usePageSize, useSortable, useStyleSheetLink, useViewRefresh, useVueInterval, useWatermark };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import _, {
|
|
1
|
+
import _, { isNil } from "lodash";
|
|
2
2
|
import { computed, createElementVNode, defineComponent, inject, isRef, nextTick, onBeforeUnmount, onMounted, onUnmounted, provide, reactive, ref, toRefs, unref, watch } from "vue";
|
|
3
3
|
import { tryOnMounted, tryOnUnmounted, useDebounceFn, useWindowSize } from "@vueuse/core";
|
|
4
4
|
import mitt from "mitt";
|
|
5
|
-
import { get, isInteger, isNil } from "lodash-es";
|
|
5
|
+
import { get, isInteger, isNil as isNil$1, toSafeInteger } from "lodash-es";
|
|
6
6
|
import dayjs from "dayjs";
|
|
7
7
|
import Sortable from "sortablejs";
|
|
8
8
|
|
|
@@ -227,6 +227,69 @@ const useNow = (immediate = true) => {
|
|
|
227
227
|
};
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region src/hooks/usePageSize.ts
|
|
232
|
+
/**
|
|
233
|
+
* @example
|
|
234
|
+
* const pagita = usePageSize()
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
const usePageSize = () => {
|
|
238
|
+
const _data = reactive({
|
|
239
|
+
pending: false,
|
|
240
|
+
total: 0,
|
|
241
|
+
page: 1,
|
|
242
|
+
limit: 10
|
|
243
|
+
});
|
|
244
|
+
const total = computed({
|
|
245
|
+
get() {
|
|
246
|
+
return _data.total;
|
|
247
|
+
},
|
|
248
|
+
set(val) {
|
|
249
|
+
_data.total = toSafeInteger(val);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
const page = computed({
|
|
253
|
+
get() {
|
|
254
|
+
return _data.page;
|
|
255
|
+
},
|
|
256
|
+
set(val) {
|
|
257
|
+
_data.page = toSafeInteger(val);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
const limit = computed({
|
|
261
|
+
get() {
|
|
262
|
+
return _data.limit;
|
|
263
|
+
},
|
|
264
|
+
set(val) {
|
|
265
|
+
_data.limit = toSafeInteger(val);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
const pending = computed({
|
|
269
|
+
get() {
|
|
270
|
+
return _data.pending;
|
|
271
|
+
},
|
|
272
|
+
set(val) {
|
|
273
|
+
_data.pending = val ? true : false;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
total,
|
|
278
|
+
page,
|
|
279
|
+
pageNo: page,
|
|
280
|
+
limit,
|
|
281
|
+
pageSize: limit,
|
|
282
|
+
pending,
|
|
283
|
+
loading: pending,
|
|
284
|
+
async resetPageAndFetch(fn) {
|
|
285
|
+
_data.pending = true;
|
|
286
|
+
_data.page = 1;
|
|
287
|
+
await fn();
|
|
288
|
+
_data.pending = false;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
230
293
|
//#endregion
|
|
231
294
|
//#region src/hooks/useStyleSheetLink.ts
|
|
232
295
|
/**
|
|
@@ -240,7 +303,7 @@ const useStyleSheetLink = (option) => {
|
|
|
240
303
|
const rLinkUrl = ref();
|
|
241
304
|
const createLink = () => {
|
|
242
305
|
const eid = `${id}`;
|
|
243
|
-
if (!isNil(document.getElementById(eid))) return;
|
|
306
|
+
if (!isNil$1(document.getElementById(eid))) return;
|
|
244
307
|
const blob = new Blob([`${cssContent}`], { type: "text/css" });
|
|
245
308
|
const url = URL.createObjectURL(blob);
|
|
246
309
|
const link = document.createElement("link");
|
|
@@ -252,11 +315,11 @@ const useStyleSheetLink = (option) => {
|
|
|
252
315
|
rLinkUrl.value = url;
|
|
253
316
|
};
|
|
254
317
|
const destroy = () => {
|
|
255
|
-
if (!isNil(rLinkDom.value)) {
|
|
318
|
+
if (!isNil$1(rLinkDom.value)) {
|
|
256
319
|
document.head.removeChild(rLinkDom.value);
|
|
257
320
|
rLinkDom.value = null;
|
|
258
321
|
}
|
|
259
|
-
if (!isNil(rLinkUrl.value)) {
|
|
322
|
+
if (!isNil$1(rLinkUrl.value)) {
|
|
260
323
|
URL.revokeObjectURL(rLinkUrl.value);
|
|
261
324
|
rLinkUrl.value = null;
|
|
262
325
|
}
|
|
@@ -286,45 +349,63 @@ const useStyleSheetLink = (option) => {
|
|
|
286
349
|
const useSortable = (params) => {
|
|
287
350
|
const { tableCls, handleCls, rawDataList } = params;
|
|
288
351
|
/**
|
|
289
|
-
*
|
|
352
|
+
* 排序内部数组
|
|
290
353
|
*/
|
|
291
354
|
const tableDataList = ref([]);
|
|
292
355
|
/**
|
|
356
|
+
* 排序结果
|
|
357
|
+
*/
|
|
358
|
+
const sortedResult = computed(() => {
|
|
359
|
+
return JSON.parse(JSON.stringify(tableDataList.value));
|
|
360
|
+
});
|
|
361
|
+
/**
|
|
293
362
|
* 是否正处于排序状态
|
|
294
363
|
*/
|
|
295
364
|
const isSorting = ref(false);
|
|
296
365
|
const initSort = useDebounceFn(() => {
|
|
297
366
|
const table = document.querySelector(`.${tableCls} .el-table__body-wrapper tbody`);
|
|
298
367
|
if (!table) return;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
368
|
+
nextTick(() => {
|
|
369
|
+
Sortable.create(table, {
|
|
370
|
+
group: "shared",
|
|
371
|
+
animation: 150,
|
|
372
|
+
draggable: ".el-table__row",
|
|
373
|
+
handle: `.${handleCls || "drag-icon"}`,
|
|
374
|
+
onEnd: ({ newDraggableIndex, oldDraggableIndex }) => {
|
|
375
|
+
if (oldDraggableIndex !== newDraggableIndex) tableDataList.value.splice(newDraggableIndex, 0, tableDataList.value.splice(oldDraggableIndex, 1)[0]);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
307
378
|
});
|
|
308
379
|
}, 200);
|
|
380
|
+
/**
|
|
381
|
+
* 开始排序,完成排序
|
|
382
|
+
*/
|
|
309
383
|
const handleSortToggle = () => {
|
|
310
|
-
if (isSorting.value)
|
|
384
|
+
if (isSorting.value) isSorting.value = false;
|
|
311
385
|
else {
|
|
312
386
|
isSorting.value = true;
|
|
313
387
|
initSort();
|
|
314
388
|
}
|
|
315
389
|
};
|
|
390
|
+
/**
|
|
391
|
+
* 取消排序(重置内部数组)
|
|
392
|
+
*/
|
|
316
393
|
const handleSortCancel = () => {
|
|
317
|
-
tableDataList.value =
|
|
394
|
+
tableDataList.value = JSON.parse(JSON.stringify(rawDataList.value));
|
|
318
395
|
isSorting.value = false;
|
|
319
396
|
};
|
|
320
|
-
watch(() => rawDataList.value, () => {
|
|
321
|
-
tableDataList.value =
|
|
397
|
+
watch(() => rawDataList.value, (newVal) => {
|
|
398
|
+
if (!isNil(newVal) && JSON.stringify(newVal) != JSON.stringify(tableDataList.value)) tableDataList.value = JSON.parse(JSON.stringify(newVal));
|
|
399
|
+
}, {
|
|
400
|
+
deep: true,
|
|
401
|
+
immediate: true,
|
|
402
|
+
flush: "post"
|
|
322
403
|
});
|
|
323
404
|
return {
|
|
324
405
|
initSort,
|
|
325
406
|
handleSortCancel,
|
|
326
407
|
handleSortToggle,
|
|
327
|
-
|
|
408
|
+
sortedResult,
|
|
328
409
|
isSorting
|
|
329
410
|
};
|
|
330
411
|
};
|
|
@@ -468,4 +549,4 @@ function useWatermark(opts) {
|
|
|
468
549
|
}
|
|
469
550
|
|
|
470
551
|
//#endregion
|
|
471
|
-
export { useDivSize, useDrawerWidth, useInjectMitt, useNetwork, useNewMitt, useNow, useSortable, useStyleSheetLink, useViewRefresh, useVueInterval, useWatermark };
|
|
552
|
+
export { useDivSize, useDrawerWidth, useInjectMitt, useNetwork, useNewMitt, useNow, usePageSize, useSortable, useStyleSheetLink, useViewRefresh, useVueInterval, useWatermark };
|