@astrolimit/vue3-web-hooks 25.12.14 → 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 +3 -4
- package/dist/index.js +37 -19
- 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
|
|
|
@@ -130,12 +129,12 @@ declare const useSortable: <T extends AnyRecord>(params: {
|
|
|
130
129
|
/**
|
|
131
130
|
* 原始数据列表
|
|
132
131
|
*/
|
|
133
|
-
rawDataList: Ref<Array<T>>;
|
|
132
|
+
rawDataList: Ref<Array<T>> | ComputedRef<Array<T>>;
|
|
134
133
|
}) => {
|
|
135
134
|
initSort: _vueuse_core0.PromisifyFn<() => void>;
|
|
136
135
|
handleSortCancel: () => void;
|
|
137
136
|
handleSortToggle: () => void;
|
|
138
|
-
|
|
137
|
+
sortedResult: ComputedRef<any>;
|
|
139
138
|
isSorting: Ref<boolean, boolean>;
|
|
140
139
|
};
|
|
141
140
|
//#endregion
|
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, toSafeInteger } 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
|
|
|
@@ -303,7 +303,7 @@ const useStyleSheetLink = (option) => {
|
|
|
303
303
|
const rLinkUrl = ref();
|
|
304
304
|
const createLink = () => {
|
|
305
305
|
const eid = `${id}`;
|
|
306
|
-
if (!isNil(document.getElementById(eid))) return;
|
|
306
|
+
if (!isNil$1(document.getElementById(eid))) return;
|
|
307
307
|
const blob = new Blob([`${cssContent}`], { type: "text/css" });
|
|
308
308
|
const url = URL.createObjectURL(blob);
|
|
309
309
|
const link = document.createElement("link");
|
|
@@ -315,11 +315,11 @@ const useStyleSheetLink = (option) => {
|
|
|
315
315
|
rLinkUrl.value = url;
|
|
316
316
|
};
|
|
317
317
|
const destroy = () => {
|
|
318
|
-
if (!isNil(rLinkDom.value)) {
|
|
318
|
+
if (!isNil$1(rLinkDom.value)) {
|
|
319
319
|
document.head.removeChild(rLinkDom.value);
|
|
320
320
|
rLinkDom.value = null;
|
|
321
321
|
}
|
|
322
|
-
if (!isNil(rLinkUrl.value)) {
|
|
322
|
+
if (!isNil$1(rLinkUrl.value)) {
|
|
323
323
|
URL.revokeObjectURL(rLinkUrl.value);
|
|
324
324
|
rLinkUrl.value = null;
|
|
325
325
|
}
|
|
@@ -349,45 +349,63 @@ const useStyleSheetLink = (option) => {
|
|
|
349
349
|
const useSortable = (params) => {
|
|
350
350
|
const { tableCls, handleCls, rawDataList } = params;
|
|
351
351
|
/**
|
|
352
|
-
*
|
|
352
|
+
* 排序内部数组
|
|
353
353
|
*/
|
|
354
354
|
const tableDataList = ref([]);
|
|
355
355
|
/**
|
|
356
|
+
* 排序结果
|
|
357
|
+
*/
|
|
358
|
+
const sortedResult = computed(() => {
|
|
359
|
+
return JSON.parse(JSON.stringify(tableDataList.value));
|
|
360
|
+
});
|
|
361
|
+
/**
|
|
356
362
|
* 是否正处于排序状态
|
|
357
363
|
*/
|
|
358
364
|
const isSorting = ref(false);
|
|
359
365
|
const initSort = useDebounceFn(() => {
|
|
360
366
|
const table = document.querySelector(`.${tableCls} .el-table__body-wrapper tbody`);
|
|
361
367
|
if (!table) return;
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
+
});
|
|
370
378
|
});
|
|
371
379
|
}, 200);
|
|
380
|
+
/**
|
|
381
|
+
* 开始排序,完成排序
|
|
382
|
+
*/
|
|
372
383
|
const handleSortToggle = () => {
|
|
373
|
-
if (isSorting.value)
|
|
384
|
+
if (isSorting.value) isSorting.value = false;
|
|
374
385
|
else {
|
|
375
386
|
isSorting.value = true;
|
|
376
387
|
initSort();
|
|
377
388
|
}
|
|
378
389
|
};
|
|
390
|
+
/**
|
|
391
|
+
* 取消排序(重置内部数组)
|
|
392
|
+
*/
|
|
379
393
|
const handleSortCancel = () => {
|
|
380
|
-
tableDataList.value =
|
|
394
|
+
tableDataList.value = JSON.parse(JSON.stringify(rawDataList.value));
|
|
381
395
|
isSorting.value = false;
|
|
382
396
|
};
|
|
383
|
-
watch(() => rawDataList.value, () => {
|
|
384
|
-
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"
|
|
385
403
|
});
|
|
386
404
|
return {
|
|
387
405
|
initSort,
|
|
388
406
|
handleSortCancel,
|
|
389
407
|
handleSortToggle,
|
|
390
|
-
|
|
408
|
+
sortedResult,
|
|
391
409
|
isSorting
|
|
392
410
|
};
|
|
393
411
|
};
|