@astrolimit/vue3-web-hooks 25.10.10 → 25.12.14
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 +39 -10
- package/dist/index.js +66 -47
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vue0 from "vue";
|
|
2
|
-
import { Ref, VNode } from "vue";
|
|
2
|
+
import { DefineComponent, FunctionalComponent, Ref, VNode } from "vue";
|
|
3
3
|
import * as _vueuse_core0 from "@vueuse/core";
|
|
4
4
|
import mitt from "mitt";
|
|
5
5
|
import * as _vue_reactivity0 from "@vue/reactivity";
|
|
@@ -33,7 +33,7 @@ declare const useDivSize: (target?: Ref<HTMLDivElement | undefined> | HTMLDivEle
|
|
|
33
33
|
* @returns
|
|
34
34
|
*/
|
|
35
35
|
declare const useDrawerWidth: (percentage?: number, minWidth?: number) => {
|
|
36
|
-
drawerWidth: vue0.ComputedRef<number
|
|
36
|
+
drawerWidth: vue0.ComputedRef<number>;
|
|
37
37
|
};
|
|
38
38
|
//#endregion
|
|
39
39
|
//#region src/hooks/useMitt.d.ts
|
|
@@ -78,6 +78,23 @@ declare const useNow: (immediate?: boolean) => {
|
|
|
78
78
|
meridiem: vue0.Ref<string, string>;
|
|
79
79
|
};
|
|
80
80
|
//#endregion
|
|
81
|
+
//#region src/hooks/usePageSize.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* @example
|
|
84
|
+
* const pagita = usePageSize()
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
declare const usePageSize: () => {
|
|
88
|
+
total: vue0.WritableComputedRef<number, number>;
|
|
89
|
+
page: vue0.WritableComputedRef<number, number>;
|
|
90
|
+
pageNo: vue0.WritableComputedRef<number, number>;
|
|
91
|
+
limit: vue0.WritableComputedRef<number, number>;
|
|
92
|
+
pageSize: vue0.WritableComputedRef<number, number>;
|
|
93
|
+
pending: vue0.WritableComputedRef<boolean, boolean>;
|
|
94
|
+
loading: vue0.WritableComputedRef<boolean, boolean>;
|
|
95
|
+
resetPageAndFetch(fn: () => Promise<void>): Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
//#endregion
|
|
81
98
|
//#region src/hooks/useStyleSheetLink.d.ts
|
|
82
99
|
/**
|
|
83
100
|
* 基于vue3组合式api的样式注入(动态创建link标签)
|
|
@@ -122,13 +139,6 @@ declare const useSortable: <T extends AnyRecord>(params: {
|
|
|
122
139
|
isSorting: Ref<boolean, boolean>;
|
|
123
140
|
};
|
|
124
141
|
//#endregion
|
|
125
|
-
//#region src/hooks/useTitle.d.ts
|
|
126
|
-
declare const setGlobalAppTitle: (title: string) => void;
|
|
127
|
-
declare const setI18nTransFunc: (t: (val: string) => string) => void;
|
|
128
|
-
declare const getGlobalAppTitle: () => string | undefined;
|
|
129
|
-
declare const getI18nTransFunc: () => ((...args: any[]) => any) | undefined;
|
|
130
|
-
declare const useTitle: (newTitle?: string | Ref<string>) => Ref<string, string>;
|
|
131
|
-
//#endregion
|
|
132
142
|
//#region src/hooks/useViewRefresh.d.ts
|
|
133
143
|
type PlaceholderProps = {
|
|
134
144
|
children?: VNode | VNode[] | null | (() => VNode | VNode[] | null);
|
|
@@ -175,4 +185,23 @@ declare function useWatermark(opts?: {
|
|
|
175
185
|
clear: () => void;
|
|
176
186
|
};
|
|
177
187
|
//#endregion
|
|
178
|
-
|
|
188
|
+
//#region src/ivue/index.d.ts
|
|
189
|
+
/**
|
|
190
|
+
* 提取函数第一个参数的类型
|
|
191
|
+
*/
|
|
192
|
+
type ExtractFirstParam<T> = T extends ((first: infer U, ...args: any[]) => any) ? U : never;
|
|
193
|
+
/**
|
|
194
|
+
* Vue 组件类型
|
|
195
|
+
*/
|
|
196
|
+
type IVueComponent = DefineComponent<any, any, any, any> | (new (...args: any[]) => any) | FunctionalComponent<any>;
|
|
197
|
+
type ExtractComponentProps<C> = C extends (new (...args: any[]) => {
|
|
198
|
+
$props: infer P;
|
|
199
|
+
}) ? P : C extends {
|
|
200
|
+
new (...args: any[]): any;
|
|
201
|
+
} ? InstanceType<C>['$props'] : C extends DefineComponent<any, any, any, any> ? InstanceType<C>['$props'] : C extends FunctionalComponent<infer P> ? P : never;
|
|
202
|
+
/**
|
|
203
|
+
* 提取 Vue 组件的 props 类型
|
|
204
|
+
*/
|
|
205
|
+
type IVueProps<T> = Partial<ExtractComponentProps<T>>;
|
|
206
|
+
//#endregion
|
|
207
|
+
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
1
|
import _, { cloneDeep } from "lodash";
|
|
2
|
-
import { computed, createElementVNode, defineComponent,
|
|
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,
|
|
5
|
+
import { get, isInteger, isNil, 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
|
/**
|
|
@@ -329,50 +392,6 @@ const useSortable = (params) => {
|
|
|
329
392
|
};
|
|
330
393
|
};
|
|
331
394
|
|
|
332
|
-
//#endregion
|
|
333
|
-
//#region src/hooks/useTitle.ts
|
|
334
|
-
const setGlobalAppTitle = (title) => {
|
|
335
|
-
const app = getCurrentInstance();
|
|
336
|
-
if (_.isNil(app)) return;
|
|
337
|
-
app.appContext.app.config.globalProperties.$appTitle = `${title}`;
|
|
338
|
-
};
|
|
339
|
-
const setI18nTransFunc = (t) => {
|
|
340
|
-
const app = getCurrentInstance();
|
|
341
|
-
if (_.isNil(app)) return;
|
|
342
|
-
if (!_.isFunction(t)) return;
|
|
343
|
-
app.appContext.app.config.globalProperties.$t = t;
|
|
344
|
-
};
|
|
345
|
-
const getGlobalAppTitle = () => {
|
|
346
|
-
const app = getCurrentInstance();
|
|
347
|
-
if (_.isNil(app)) return;
|
|
348
|
-
if (!_.isString(app.appContext.app.config.globalProperties.$appTitle)) return;
|
|
349
|
-
return app.appContext.app.config.globalProperties.$appTitle;
|
|
350
|
-
};
|
|
351
|
-
const getI18nTransFunc = () => {
|
|
352
|
-
const app = getCurrentInstance();
|
|
353
|
-
if (_.isNil(app)) return;
|
|
354
|
-
if (!_.isFunction(app.appContext.app.config.globalProperties.$t)) return;
|
|
355
|
-
return app.appContext.app.config.globalProperties.$t;
|
|
356
|
-
};
|
|
357
|
-
const useTitle = (newTitle) => {
|
|
358
|
-
const _props = {
|
|
359
|
-
get t() {
|
|
360
|
-
return getI18nTransFunc() || ((val) => val);
|
|
361
|
-
},
|
|
362
|
-
get appTitle() {
|
|
363
|
-
return getGlobalAppTitle() || "";
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
const title = ref("");
|
|
367
|
-
watch(() => `${_props.appTitle}-${unref(newTitle)}`, (n, o) => {
|
|
368
|
-
if (isString(n) && n !== o && document) {
|
|
369
|
-
title.value = newTitle ? `${_props.appTitle} - ${_props.t(newTitle)}` : _props.appTitle;
|
|
370
|
-
document.title = title.value;
|
|
371
|
-
}
|
|
372
|
-
}, { immediate: true });
|
|
373
|
-
return title;
|
|
374
|
-
};
|
|
375
|
-
|
|
376
395
|
//#endregion
|
|
377
396
|
//#region src/hooks/useViewRefresh.ts
|
|
378
397
|
/**
|
|
@@ -512,4 +531,4 @@ function useWatermark(opts) {
|
|
|
512
531
|
}
|
|
513
532
|
|
|
514
533
|
//#endregion
|
|
515
|
-
export {
|
|
534
|
+
export { useDivSize, useDrawerWidth, useInjectMitt, useNetwork, useNewMitt, useNow, usePageSize, useSortable, useStyleSheetLink, useViewRefresh, useVueInterval, useWatermark };
|