qidian-shared 0.0.1-beta.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 ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present QiDian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # qidian-shared
2
+
3
+ QiDian 共享工具函数和钩子。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install qidian-shared
9
+ ```
10
+
11
+ ## 使用
12
+
13
+ ```typescript
14
+ // 导入 utils、hooks
15
+ import { toMoney, isEmpty, useCsl } from 'qidian-shared'
16
+ ```
17
+
18
+ ## LICENSE
19
+
20
+ [MIT](LICENSE)
@@ -0,0 +1 @@
1
+ export * from './resize';
@@ -0,0 +1,17 @@
1
+ import type { App, DirectiveBinding } from 'vue';
2
+ interface ResizeElement extends HTMLElement {
3
+ _resizeObserver?: ResizeObserver;
4
+ _resizeHandler?: () => void;
5
+ }
6
+ export interface ResizeDirectiveBinding extends DirectiveBinding {
7
+ value: (entries: ResizeObserverEntry[]) => void;
8
+ }
9
+ export declare const resizeDirective: {
10
+ mounted(el: ResizeElement, binding: ResizeDirectiveBinding): void;
11
+ updated(el: ResizeElement, binding: ResizeDirectiveBinding): void;
12
+ unmounted(el: ResizeElement): void;
13
+ };
14
+ export declare const resize: {
15
+ install(app: App): void;
16
+ };
17
+ export default resize;
@@ -0,0 +1,5 @@
1
+ export * from './useActivated';
2
+ export * from './useLog';
3
+ export * from './useProxy';
4
+ export * from './useTimer';
5
+ export * from './useService';
@@ -0,0 +1,3 @@
1
+ export declare function useActivated(): {
2
+ activated: import("vue").Ref<boolean, boolean>;
3
+ };
@@ -0,0 +1,12 @@
1
+ type CslType = 'log' | 'warn' | 'error';
2
+ type Csl = {
3
+ [key in CslType]: {
4
+ (childModule: ChildModule, ...rest: unknown[]): void;
5
+ dev(childModule: ChildModule, ...rest: unknown[]): void;
6
+ };
7
+ } & {
8
+ useNext(childModule: ChildModule): Csl;
9
+ };
10
+ type ChildModule = string | number | Array<string | number>;
11
+ export declare function useCsl(module: string | Array<string>): Csl;
12
+ export {};
@@ -0,0 +1 @@
1
+ export declare function useProxy(): import("vue").ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, import("vue").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}, {}, string, {}, {}, {}, string, import("vue").ComponentProvideOptions>, {}, {}, "", {}, any>;
@@ -0,0 +1,3 @@
1
+ export * from './loadMore';
2
+ export * from './pagination';
3
+ export type { ServicePageParams, ServicePagination, ServicePageRes, ServicePageDataType, ServicePageBaseOptions, ServicePageLoadMoreOptions, ServicePaginationOptions } from './types';
@@ -0,0 +1,10 @@
1
+ import type { Ref } from 'vue';
2
+ import type { ServicePageDataType, ServicePageLoadMoreOptions, ServicePageParams, ServicePagination } from './types';
3
+ import { useLoadMore } from 'vue-request';
4
+ export declare function useServiceLoadMore<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = Ref<{
5
+ pageSize?: number;
6
+ }>>({ service, manual, transformParams, transformRes, pagination, onBefore, onAfter, onSuccess, onError }: ServicePageLoadMoreOptions<D, R, P, TP, Pag>): Omit<ReturnType<typeof useLoadMore<ServicePageDataType<D>>>, "dataList"> & {
7
+ firstLoad: Ref<boolean>;
8
+ manualTriggerLoad: Ref<boolean>;
9
+ dataList: Ref<D[]>;
10
+ };
@@ -0,0 +1,10 @@
1
+ import type { Ref } from 'vue';
2
+ import type { ServicePaginationOptions, ServicePageParams, ServicePagination, ServicePageDataType } from './types';
3
+ import { usePagination } from 'vue-request';
4
+ export declare function useServicePagination<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = Ref<{
5
+ pageSize?: number;
6
+ }>>({ service, manual, cacheKey, cacheTime, pollingInterval, transformParams, transformRes, pagination, onBefore, onAfter, onSuccess, onError }: ServicePaginationOptions<D, R, P, TP, Pag> & {}): ReturnType<typeof usePagination<ServicePageDataType<D>>> & {
7
+ firstLoad: Ref<boolean>;
8
+ manualTriggerLoad: Ref<boolean>;
9
+ dataList: Ref<D[]>;
10
+ };
@@ -0,0 +1,44 @@
1
+ import type { MaybeRef } from 'vue';
2
+ import type { LoadMoreBaseOptions, PaginationOptions } from 'vue-request';
3
+ export interface ServicePageParams {
4
+ pageSize: number;
5
+ pageNum: number;
6
+ }
7
+ export interface ServicePageRes<T> {
8
+ records: T[];
9
+ total?: number;
10
+ }
11
+ export type ServicePagination = MaybeRef<false | {
12
+ pageSize?: number;
13
+ }>;
14
+ export interface ServicePageDataType<T> {
15
+ list: T[];
16
+ page?: number;
17
+ total?: number;
18
+ }
19
+ type PageParams<T> = T extends false ? undefined : ServicePageParams;
20
+ type ServicePageLoadMoreBaseOptions<T> = LoadMoreBaseOptions<ServicePageDataType<T>>;
21
+ type ServicePaginationBaseOptions<T> = PaginationOptions<ServicePageDataType<T>, unknown[]>;
22
+ export interface ServicePageBaseOptions<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = ServicePagination> {
23
+ service: (params: TP) => Promise<R>;
24
+ manual?: boolean;
25
+ transformParams?: (params: PageParams<Pag>) => TP;
26
+ transformRes?: (res: R) => ServicePageRes<D>;
27
+ pagination?: Pag;
28
+ }
29
+ export interface ServicePageLoadMoreOptions<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = ServicePagination> extends ServicePageBaseOptions<D, R, P, TP, Pag> {
30
+ onBefore?: ServicePageLoadMoreBaseOptions<D>['onBefore'];
31
+ onAfter?: ServicePageLoadMoreBaseOptions<D>['onAfter'];
32
+ onSuccess?: ServicePageLoadMoreBaseOptions<D>['onSuccess'];
33
+ onError?: ServicePageLoadMoreBaseOptions<D>['onError'];
34
+ }
35
+ export interface ServicePaginationOptions<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = ServicePagination> extends ServicePageBaseOptions<D, R, P, TP, Pag> {
36
+ cacheKey?: ServicePaginationBaseOptions<D>['cacheKey'];
37
+ cacheTime?: ServicePaginationBaseOptions<D>['cacheTime'];
38
+ pollingInterval?: ServicePaginationBaseOptions<D>['pollingInterval'];
39
+ onBefore?: ServicePageLoadMoreBaseOptions<D>['onBefore'];
40
+ onAfter?: ServicePageLoadMoreBaseOptions<D>['onAfter'];
41
+ onSuccess?: ServicePageLoadMoreBaseOptions<D>['onSuccess'];
42
+ onError?: ServicePageLoadMoreBaseOptions<D>['onError'];
43
+ }
44
+ export {};
@@ -0,0 +1,22 @@
1
+ export declare function useTimer(type?: 'timeout' | 'interval'): {
2
+ timer: import("vue").Ref<{
3
+ close: () => NodeJS.Timeout;
4
+ hasRef: () => boolean;
5
+ ref: () => NodeJS.Timeout;
6
+ refresh: () => NodeJS.Timeout;
7
+ unref: () => NodeJS.Timeout;
8
+ _onTimeout: (...args: any[]) => void;
9
+ [Symbol.toPrimitive]: () => number;
10
+ [Symbol.dispose]: () => void;
11
+ } | null, NodeJS.Timeout | {
12
+ close: () => NodeJS.Timeout;
13
+ hasRef: () => boolean;
14
+ ref: () => NodeJS.Timeout;
15
+ refresh: () => NodeJS.Timeout;
16
+ unref: () => NodeJS.Timeout;
17
+ _onTimeout: (...args: any[]) => void;
18
+ [Symbol.toPrimitive]: () => number;
19
+ [Symbol.dispose]: () => void;
20
+ } | null>;
21
+ clearTimer: () => void;
22
+ };
@@ -0,0 +1,3 @@
1
+ export * from './directive';
2
+ export * from './hooks';
3
+ export * from './utils';