qidian-shared 1.0.11 → 1.0.13

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.
@@ -1,3 +1,3 @@
1
1
  export * from './loadMore';
2
2
  export * from './pagination';
3
- export type { ServicePageParams, ServicePagination, ServicePageRes, ServicePageDataType, ServicePageBaseOptions, ServicePageLoadMoreOptions, ServicePaginationOptions } from './types';
3
+ export type { ServicePageParams, ServicePagination, ServicePageRes, ServicePageDataType, ServiceMaybePageParams, ServicePageBaseOptions, ServicePageLoadMoreOptions, ServicePaginationOptions } from './types';
@@ -1,10 +1,2 @@
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
- };
1
+ import type { ServicePageLoadMoreOptions, ServicePageParams, ServicePagination, UseServicePageLoadMoreResult } from './types';
2
+ export declare function useServiceLoadMore<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = ServicePagination>({ service, manual, transformParams, transformRes, pagination, onBefore, onAfter, onSuccess, onError }: ServicePageLoadMoreOptions<D, R, P, TP, Pag>): UseServicePageLoadMoreResult;
@@ -1,10 +1,2 @@
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
- };
1
+ import type { ServicePaginationOptions, ServicePageParams, ServicePagination, UseServicePaginationResult } from './types';
2
+ export declare function useServicePagination<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = ServicePagination>({ service, manual, cacheKey, cacheTime, pollingInterval, transformParams, transformRes, pagination, onBefore, onAfter, onSuccess, onError }: ServicePaginationOptions<D, R, P, TP, Pag> & {}): UseServicePaginationResult;
@@ -1,5 +1,5 @@
1
- import type { MaybeRef } from 'vue';
2
- import type { LoadMoreBaseOptions, PaginationOptions } from 'vue-request';
1
+ import type { MaybeRef, Ref, UnwrapRef } from 'vue';
2
+ import type { LoadMoreBaseOptions, LoadMoreQueryResult, PaginationOptions, PaginationQueryResult } from 'vue-request';
3
3
  export interface ServicePageParams {
4
4
  pageSize: number;
5
5
  pageNum: number;
@@ -17,13 +17,13 @@ export interface ServicePageDataType<T> {
17
17
  size?: number;
18
18
  total?: number;
19
19
  }
20
- type PageParams<T> = T extends false ? undefined : ServicePageParams;
20
+ export type ServiceMaybePageParams<T> = UnwrapRef<T> extends false ? undefined : ServicePageParams;
21
21
  type ServicePageLoadMoreBaseOptions<T> = LoadMoreBaseOptions<ServicePageDataType<T>>;
22
22
  type ServicePaginationBaseOptions<T> = PaginationOptions<ServicePageDataType<T>, unknown[]>;
23
23
  export interface ServicePageBaseOptions<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = ServicePagination> {
24
24
  service: (params: TP) => Promise<R>;
25
25
  manual?: boolean;
26
- transformParams?: (params: PageParams<Pag>) => TP | Promise<TP>;
26
+ transformParams?: (params: ServiceMaybePageParams<Pag>) => TP | Promise<TP>;
27
27
  transformRes?: (res: R) => ServicePageRes<D> | Promise<ServicePageRes<D>>;
28
28
  pagination?: Pag;
29
29
  }
@@ -33,6 +33,11 @@ export interface ServicePageLoadMoreOptions<D = unknown, R = unknown, P = Servic
33
33
  onSuccess?: ServicePageLoadMoreBaseOptions<D>['onSuccess'];
34
34
  onError?: ServicePageLoadMoreBaseOptions<D>['onError'];
35
35
  }
36
+ export interface UseServicePageLoadMoreResult<D = unknown> extends Omit<LoadMoreQueryResult<ServicePageDataType<D>>, 'dataList'> {
37
+ firstLoad: Ref<boolean>;
38
+ manualTriggerLoad: Ref<boolean>;
39
+ dataList: Ref<D[]>;
40
+ }
36
41
  export interface ServicePaginationOptions<D = unknown, R = unknown, P = ServicePageParams, TP = P, Pag extends ServicePagination = ServicePagination> extends ServicePageBaseOptions<D, R, P, TP, Pag> {
37
42
  cacheKey?: ServicePaginationBaseOptions<D>['cacheKey'];
38
43
  cacheTime?: ServicePaginationBaseOptions<D>['cacheTime'];
@@ -42,4 +47,9 @@ export interface ServicePaginationOptions<D = unknown, R = unknown, P = ServiceP
42
47
  onSuccess?: ServicePageLoadMoreBaseOptions<D>['onSuccess'];
43
48
  onError?: ServicePageLoadMoreBaseOptions<D>['onError'];
44
49
  }
50
+ export interface UseServicePaginationResult<D = unknown> extends PaginationQueryResult<ServicePageDataType<D>, unknown[]> {
51
+ firstLoad: Ref<boolean>;
52
+ manualTriggerLoad: Ref<boolean>;
53
+ dataList: Ref<D[]>;
54
+ }
45
55
  export {};
@@ -11980,6 +11980,18 @@ function setUrlParam(key, value, url, andString, newKey) {
11980
11980
  }
11981
11981
  return urltmp;
11982
11982
  }
11983
+ const validatorRegs = {
11984
+ cellPhone: /^1[3-9]\d{9}$/,
11985
+ telephone: /^\d{7,8}$/,
11986
+ url: /^((blob:)*(https|http|ftp|rtsp|mms|wss)?:\/\/)[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/
11987
+ };
11988
+ function validator(value, type, required = false) {
11989
+ if (type === "empty") return isEmpty(value);
11990
+ const reg = validatorRegs[type];
11991
+ if (!reg) throw new Error(`[validator] 没有 ${type} 类型`);
11992
+ if (required && isEmpty(value)) return null;
11993
+ return reg.test(value);
11994
+ }
11983
11995
  function useServiceLoadMore({
11984
11996
  service,
11985
11997
  manual,
@@ -12010,19 +12022,22 @@ function useServiceLoadMore({
12010
12022
  async (params) => {
12011
12023
  const res = { list: [], page: 1, total: 0 };
12012
12024
  const paginationV = vue.unref(pagination);
12013
- let currentParams = paginationV ? {
12025
+ const currentParams = paginationV ? {
12014
12026
  pageNum: params?.page ?? 1,
12015
12027
  pageSize: params?.size ?? paginationV?.pageSize ?? 30
12016
12028
  } : void 0;
12017
- if (!currentParams || currentParams?.pageNum === 1) {
12018
- firstLoad.value = true;
12019
- }
12029
+ if (currentParams?.pageNum === 1) firstLoad.value = true;
12030
+ let tParams;
12020
12031
  if (transformParams) {
12021
- const [tpErr, tpRes] = await suspectedWrapperPromise(transformParams(currentParams));
12032
+ const [tpErr, tpRes] = await suspectedWrapperPromise(
12033
+ transformParams(
12034
+ currentParams ? easyCopy(currentParams) : currentParams
12035
+ )
12036
+ );
12022
12037
  if (tpErr) throw tpErr;
12023
- currentParams = tpRes;
12038
+ tParams = tpRes;
12024
12039
  }
12025
- const [serviceErr, serviceRes] = await to(service(currentParams));
12040
+ const [serviceErr, serviceRes] = await to(service(tParams || currentParams));
12026
12041
  if (serviceErr) throw serviceErr;
12027
12042
  let temp;
12028
12043
  if (transformRes) {
@@ -12137,19 +12152,22 @@ function useServicePagination({
12137
12152
  async (params2) => {
12138
12153
  const res = { list: [], page: 1, total: 0 };
12139
12154
  const paginationV = vue.unref(pagination);
12140
- let currentParams = paginationV !== false ? {
12155
+ const currentParams = paginationV !== false ? {
12141
12156
  pageNum: params2?.page ?? 1,
12142
12157
  pageSize: params2?.size ?? paginationV?.pageSize ?? 10
12143
12158
  } : void 0;
12144
- if (!currentParams || currentParams?.pageNum === 1) {
12145
- firstLoad.value = true;
12146
- }
12159
+ if (currentParams?.pageNum === 1) firstLoad.value = true;
12160
+ let tParams;
12147
12161
  if (transformParams) {
12148
- const [tpErr, tpRes] = await suspectedWrapperPromise(transformParams(currentParams));
12162
+ const [tpErr, tpRes] = await suspectedWrapperPromise(
12163
+ transformParams(
12164
+ currentParams ? easyCopy(currentParams) : currentParams
12165
+ )
12166
+ );
12149
12167
  if (tpErr) throw tpErr;
12150
- currentParams = tpRes;
12168
+ tParams = tpRes;
12151
12169
  }
12152
- const [serviceErr, serviceRes] = await to(service(currentParams));
12170
+ const [serviceErr, serviceRes] = await to(service(tParams || currentParams));
12153
12171
  if (serviceErr) throw serviceErr;
12154
12172
  let temp;
12155
12173
  if (transformRes) {
@@ -12315,7 +12333,7 @@ function useCsl(module2) {
12315
12333
  function useProxy() {
12316
12334
  const instance = vue.getCurrentInstance();
12317
12335
  if (!instance || !instance.proxy) {
12318
- throw new Error("useProxy 必须在 setup 或生命周期内调用,并且组件已经挂载");
12336
+ throw new Error("[useProxy] 必须在 setup 或生命周期内调用,并且组件已经挂载");
12319
12337
  }
12320
12338
  return instance.proxy;
12321
12339
  }
@@ -12385,5 +12403,7 @@ exports.useProxy = useProxy;
12385
12403
  exports.useServiceLoadMore = useServiceLoadMore;
12386
12404
  exports.useServicePagination = useServicePagination;
12387
12405
  exports.useTimer = useTimer;
12406
+ exports.validator = validator;
12407
+ exports.validatorRegs = validatorRegs;
12388
12408
  exports.waitTime = waitTime;
12389
12409
  //# sourceMappingURL=qidian-shared.cjs.js.map