@wzyjs/hooks 0.1.0 → 0.2.2

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.
Files changed (45) hide show
  1. package/dist/cjs/index.d.ts +11 -0
  2. package/dist/cjs/index.d.ts.map +1 -0
  3. package/dist/cjs/index.js +63 -0
  4. package/dist/cjs/useDateRange.d.ts +23 -0
  5. package/dist/cjs/useDateRange.d.ts.map +1 -0
  6. package/dist/cjs/useDateRange.js +131 -0
  7. package/dist/cjs/useEffectValue.d.ts +3 -0
  8. package/dist/cjs/useEffectValue.d.ts.map +1 -0
  9. package/dist/cjs/useEffectValue.js +34 -0
  10. package/dist/cjs/useElementScrollVisible.d.ts +6 -0
  11. package/dist/cjs/useElementScrollVisible.d.ts.map +1 -0
  12. package/dist/cjs/useElementScrollVisible.js +61 -0
  13. package/dist/cjs/useHideFooter.d.ts +2 -0
  14. package/dist/cjs/useHideFooter.d.ts.map +1 -0
  15. package/dist/cjs/useHideFooter.js +38 -0
  16. package/dist/cjs/useOptions.d.ts +14 -0
  17. package/dist/cjs/useOptions.d.ts.map +1 -0
  18. package/dist/cjs/useOptions.js +60 -0
  19. package/dist/cjs/useRequestPro.d.ts +12 -0
  20. package/dist/cjs/useRequestPro.d.ts.map +1 -0
  21. package/dist/cjs/useRequestPro.js +76 -0
  22. package/dist/cjs/useVisibleInfo.d.ts +6 -0
  23. package/dist/cjs/useVisibleInfo.d.ts.map +1 -0
  24. package/dist/cjs/useVisibleInfo.js +45 -0
  25. package/dist/esm/index.d.ts +11 -0
  26. package/dist/esm/index.d.ts.map +1 -0
  27. package/dist/esm/index.js +4 -1
  28. package/dist/esm/useDateRange.d.ts +23 -0
  29. package/dist/esm/useDateRange.d.ts.map +1 -0
  30. package/dist/esm/useDateRange.js +113 -0
  31. package/dist/esm/useEffectValue.d.ts +3 -0
  32. package/dist/esm/useEffectValue.d.ts.map +1 -0
  33. package/dist/esm/useElementScrollVisible.d.ts +6 -0
  34. package/dist/esm/useElementScrollVisible.d.ts.map +1 -0
  35. package/dist/esm/useHideFooter.d.ts +2 -0
  36. package/dist/esm/useHideFooter.d.ts.map +1 -0
  37. package/dist/esm/useOptions.d.ts +14 -0
  38. package/dist/esm/useOptions.d.ts.map +1 -0
  39. package/dist/esm/useOptions.js +60 -0
  40. package/dist/esm/useRequestPro.d.ts +12 -0
  41. package/dist/esm/useRequestPro.d.ts.map +1 -0
  42. package/dist/esm/useRequestPro.js +0 -2
  43. package/dist/esm/useVisibleInfo.d.ts +6 -0
  44. package/dist/esm/useVisibleInfo.d.ts.map +1 -0
  45. package/package.json +6 -4
@@ -0,0 +1,11 @@
1
+ export * from 'ahooks';
2
+ export { default as useUrlState } from '@ahooksjs/use-url-state';
3
+ export { useCopyToClipboard, useCookie, useUpdate } from 'react-use';
4
+ export * from './useRequestPro';
5
+ export * from './useEffectValue';
6
+ export * from './useElementScrollVisible';
7
+ export * from './useHideFooter';
8
+ export * from './useVisibleInfo';
9
+ export * from './useDateRange';
10
+ export * from './useOptions';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AAEtB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAEhE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAEpE,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA;AACzC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA"}
@@ -0,0 +1,63 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ useCookie: () => import_react_use.useCookie,
34
+ useCopyToClipboard: () => import_react_use.useCopyToClipboard,
35
+ useUpdate: () => import_react_use.useUpdate,
36
+ useUrlState: () => import_use_url_state.default
37
+ });
38
+ module.exports = __toCommonJS(src_exports);
39
+ __reExport(src_exports, require("ahooks"), module.exports);
40
+ var import_use_url_state = __toESM(require("@ahooksjs/use-url-state"));
41
+ var import_react_use = require("react-use");
42
+ __reExport(src_exports, require("./useRequestPro"), module.exports);
43
+ __reExport(src_exports, require("./useEffectValue"), module.exports);
44
+ __reExport(src_exports, require("./useElementScrollVisible"), module.exports);
45
+ __reExport(src_exports, require("./useHideFooter"), module.exports);
46
+ __reExport(src_exports, require("./useVisibleInfo"), module.exports);
47
+ __reExport(src_exports, require("./useDateRange"), module.exports);
48
+ __reExport(src_exports, require("./useOptions"), module.exports);
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ useCookie,
52
+ useCopyToClipboard,
53
+ useUpdate,
54
+ useUrlState,
55
+ ...require("ahooks"),
56
+ ...require("./useRequestPro"),
57
+ ...require("./useEffectValue"),
58
+ ...require("./useElementScrollVisible"),
59
+ ...require("./useHideFooter"),
60
+ ...require("./useVisibleInfo"),
61
+ ...require("./useDateRange"),
62
+ ...require("./useOptions")
63
+ });
@@ -0,0 +1,23 @@
1
+ import { dayjs, Dayjs } from '@wzyjs/utils';
2
+ export declare enum PresetType {
3
+ TODAY = "\u4ECA\u5929",
4
+ THIS_WEEK = "\u672C\u5468",
5
+ LAST_WEEK = "\u4E0A\u5468",
6
+ THIS_MONTH = "\u672C\u6708",
7
+ LAST_MONTH = "\u4E0A\u6708"
8
+ }
9
+ export declare const rangePresets: {
10
+ label: string;
11
+ value: [Dayjs, Dayjs];
12
+ }[];
13
+ interface Config {
14
+ defaultDateRange?: PresetType | [Dayjs, Dayjs];
15
+ }
16
+ export declare const useDateRange: (config: Config) => {
17
+ dateRange: [dayjs.Dayjs, dayjs.Dayjs];
18
+ onChange: (dateRange?: any) => void;
19
+ onClickPrev: () => void;
20
+ onClickNext: () => void;
21
+ };
22
+ export {};
23
+ //# sourceMappingURL=useDateRange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDateRange.d.ts","sourceRoot":"","sources":["../src/useDateRange.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAE3C,oBAAY,UAAU;IACpB,KAAK,iBAAO;IACZ,SAAS,iBAAO;IAChB,SAAS,iBAAO;IAChB,UAAU,iBAAO;IACjB,UAAU,iBAAO;CAClB;AAED,eAAO,MAAM,YAAY,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;CAAE,EAqBlE,CAAA;AA4BD,UAAU,MAAM;IACd,gBAAgB,CAAC,EAAE,UAAU,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;CAC/C;AAED,eAAO,MAAM,YAAY,WAAY,MAAM;;2BAgBhB,GAAG;;;CAyC7B,CAAA"}
@@ -0,0 +1,131 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/useDateRange.ts
20
+ var useDateRange_exports = {};
21
+ __export(useDateRange_exports, {
22
+ PresetType: () => PresetType,
23
+ rangePresets: () => rangePresets,
24
+ useDateRange: () => useDateRange
25
+ });
26
+ module.exports = __toCommonJS(useDateRange_exports);
27
+ var import_react = require("react");
28
+ var import_utils = require("@wzyjs/utils");
29
+ var PresetType = /* @__PURE__ */ ((PresetType2) => {
30
+ PresetType2["TODAY"] = "今天";
31
+ PresetType2["THIS_WEEK"] = "本周";
32
+ PresetType2["LAST_WEEK"] = "上周";
33
+ PresetType2["THIS_MONTH"] = "本月";
34
+ PresetType2["LAST_MONTH"] = "上月";
35
+ return PresetType2;
36
+ })(PresetType || {});
37
+ var rangePresets = [
38
+ {
39
+ label: "今天" /* TODAY */,
40
+ value: [(0, import_utils.dayjs)().startOf("day"), (0, import_utils.dayjs)().endOf("day")]
41
+ },
42
+ {
43
+ label: "本周" /* THIS_WEEK */,
44
+ value: [(0, import_utils.dayjs)().startOf("week"), (0, import_utils.dayjs)().endOf("week")]
45
+ },
46
+ {
47
+ label: "上周" /* LAST_WEEK */,
48
+ value: [(0, import_utils.dayjs)().subtract(1, "week").startOf("week"), (0, import_utils.dayjs)().subtract(1, "week").endOf("week")]
49
+ },
50
+ {
51
+ label: "本月" /* THIS_MONTH */,
52
+ value: [(0, import_utils.dayjs)().startOf("month"), (0, import_utils.dayjs)().endOf("month")]
53
+ },
54
+ {
55
+ label: "上月" /* LAST_MONTH */,
56
+ value: [(0, import_utils.dayjs)().subtract(1, "month").startOf("month"), (0, import_utils.dayjs)().subtract(1, "month").endOf("month")]
57
+ }
58
+ ];
59
+ var checkDateRules = (dateRange) => {
60
+ const [date1, date2] = dateRange;
61
+ if (date1.isSame(date2, "day")) {
62
+ return 1;
63
+ }
64
+ if (date1.day() === 1 && date2.day() === 0 || date1.day() === 0 && date2.day() === 1) {
65
+ return 2;
66
+ }
67
+ const isStartOrEndOfMonth = (date) => {
68
+ return date.date() === 1 || date.date() === date.daysInMonth();
69
+ };
70
+ if (isStartOrEndOfMonth(date1) && isStartOrEndOfMonth(date2)) {
71
+ return 3;
72
+ }
73
+ return 0;
74
+ };
75
+ var useDateRange = (config) => {
76
+ var _a;
77
+ const { defaultDateRange = "今天" /* TODAY */ } = config;
78
+ const [dateRange, setDateRange] = (0, import_react.useState)(
79
+ Array.isArray(defaultDateRange) ? defaultDateRange : ((_a = rangePresets.find((item) => item.label === defaultDateRange)) == null ? void 0 : _a.value) || [(0, import_utils.dayjs)().startOf("day"), (0, import_utils.dayjs)().endOf("day")]
80
+ );
81
+ const rangeType = checkDateRules(dateRange);
82
+ return {
83
+ dateRange,
84
+ // 这里的 any 实际应该是 antd 的 RangeValue<Dayjs> 类型,
85
+ // 但是这个类型不好获取,所以这里先用 any 代替
86
+ onChange: (dateRange2) => {
87
+ if (!dateRange2) {
88
+ return;
89
+ }
90
+ setDateRange(dateRange2);
91
+ },
92
+ onClickPrev: () => {
93
+ switch (rangeType) {
94
+ case 1:
95
+ setDateRange([dateRange[0].subtract(1, "day"), dateRange[1].subtract(1, "day")]);
96
+ break;
97
+ case 2:
98
+ setDateRange([dateRange[0].subtract(1, "week"), dateRange[1].subtract(1, "week")]);
99
+ break;
100
+ case 3:
101
+ setDateRange([dateRange[0].subtract(1, "month").startOf("month"), dateRange[1].subtract(1, "month").endOf("month")]);
102
+ break;
103
+ default:
104
+ setDateRange([dateRange[0].subtract(1, "day"), dateRange[1]]);
105
+ break;
106
+ }
107
+ },
108
+ onClickNext: () => {
109
+ switch (rangeType) {
110
+ case 1:
111
+ setDateRange([dateRange[0].add(1, "day"), dateRange[1].add(1, "day")]);
112
+ break;
113
+ case 2:
114
+ setDateRange([dateRange[0].add(1, "week"), dateRange[1].add(1, "week")]);
115
+ break;
116
+ case 3:
117
+ setDateRange([dateRange[0].add(1, "month").startOf("month"), dateRange[1].add(1, "month").endOf("month")]);
118
+ break;
119
+ default:
120
+ setDateRange([dateRange[0], dateRange[1].add(1, "day")]);
121
+ break;
122
+ }
123
+ }
124
+ };
125
+ };
126
+ // Annotate the CommonJS export names for ESM import in node:
127
+ 0 && (module.exports = {
128
+ PresetType,
129
+ rangePresets,
130
+ useDateRange
131
+ });
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare const useEffectValue: (fn: any, deps?: never[]) => (import("react").Dispatch<import("react").SetStateAction<undefined>> | undefined)[];
3
+ //# sourceMappingURL=useEffectValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEffectValue.d.ts","sourceRoot":"","sources":["../src/useEffectValue.ts"],"names":[],"mappings":";AAEA,eAAO,MAAM,cAAc,OAAQ,GAAG,wGAIrC,CAAA"}
@@ -0,0 +1,34 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/useEffectValue.ts
20
+ var useEffectValue_exports = {};
21
+ __export(useEffectValue_exports, {
22
+ useEffectValue: () => useEffectValue
23
+ });
24
+ module.exports = __toCommonJS(useEffectValue_exports);
25
+ var import_react = require("react");
26
+ var useEffectValue = (fn, deps = []) => {
27
+ const [value, setValue] = (0, import_react.useState)();
28
+ (0, import_react.useEffect)(() => setValue(fn()), deps);
29
+ return [value, setValue];
30
+ };
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ useEffectValue
34
+ });
@@ -0,0 +1,6 @@
1
+ export declare const useElementScrollVisible: (scroll: any, target: any) => {
2
+ visible: boolean;
3
+ direction: string;
4
+ rect: string;
5
+ };
6
+ //# sourceMappingURL=useElementScrollVisible.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useElementScrollVisible.d.ts","sourceRoot":"","sources":["../src/useElementScrollVisible.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,WAAY,GAAG,UAAU,GAAG;;;;CAwC/D,CAAA"}
@@ -0,0 +1,61 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/useElementScrollVisible.ts
20
+ var useElementScrollVisible_exports = {};
21
+ __export(useElementScrollVisible_exports, {
22
+ useElementScrollVisible: () => useElementScrollVisible
23
+ });
24
+ module.exports = __toCommonJS(useElementScrollVisible_exports);
25
+ var import_react = require("react");
26
+ var useElementScrollVisible = (scroll, target) => {
27
+ const $scroll = document.querySelector(scroll) || {};
28
+ const $scrollRect = $scroll.getBoundingClientRect();
29
+ const [visible, setVisible] = (0, import_react.useState)(false);
30
+ const [direction, setDirection] = (0, import_react.useState)("");
31
+ const [rect, setRect] = (0, import_react.useState)("");
32
+ (0, import_react.useEffect)(() => {
33
+ const fn = () => {
34
+ const $target = document.querySelector(target) || {};
35
+ const rect2 = $target.getBoundingClientRect();
36
+ setRect(rect2);
37
+ if (rect2.bottom < $scrollRect.top) {
38
+ setDirection("top");
39
+ setVisible(false);
40
+ } else if (rect2.top > $scrollRect.bottom) {
41
+ setDirection("bottom");
42
+ setVisible(false);
43
+ } else {
44
+ setDirection("show");
45
+ setVisible(true);
46
+ }
47
+ };
48
+ fn();
49
+ $scroll.addEventListener("scroll", fn);
50
+ return () => $scroll.removeEventListener("scroll", fn);
51
+ }, []);
52
+ return {
53
+ visible,
54
+ direction,
55
+ rect
56
+ };
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ useElementScrollVisible
61
+ });
@@ -0,0 +1,2 @@
1
+ export declare const useHideFooter: (el?: string) => void;
2
+ //# sourceMappingURL=useHideFooter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHideFooter.d.ts","sourceRoot":"","sources":["../src/useHideFooter.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,uBAQzB,CAAA"}
@@ -0,0 +1,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/useHideFooter.ts
20
+ var useHideFooter_exports = {};
21
+ __export(useHideFooter_exports, {
22
+ useHideFooter: () => useHideFooter
23
+ });
24
+ module.exports = __toCommonJS(useHideFooter_exports);
25
+ var import_react = require("react");
26
+ var useHideFooter = (el = ".ant-layout-footer") => {
27
+ (0, import_react.useEffect)(() => {
28
+ const e = document.querySelector(el);
29
+ e.style.display = "none";
30
+ return () => {
31
+ e.style.display = "block";
32
+ };
33
+ }, []);
34
+ };
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ useHideFooter
38
+ });
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ interface Option {
3
+ apis: any;
4
+ onChange?: (data?: any) => void;
5
+ }
6
+ export declare const useOptions: (option: Option) => {
7
+ loading: boolean;
8
+ options: any;
9
+ value: string | undefined;
10
+ onChange: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
11
+ currentData: any;
12
+ };
13
+ export {};
14
+ //# sourceMappingURL=useOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOptions.d.ts","sourceRoot":"","sources":["../src/useOptions.ts"],"names":[],"mappings":";AAGA,UAAU,MAAM;IACd,IAAI,EAAE,GAAG,CAAA;IACT,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;CAChC;AAED,eAAO,MAAM,UAAU,WAAY,MAAM;;;;;;CAqCxC,CAAA"}
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/useOptions.ts
20
+ var useOptions_exports = {};
21
+ __export(useOptions_exports, {
22
+ useOptions: () => useOptions
23
+ });
24
+ module.exports = __toCommonJS(useOptions_exports);
25
+ var import_react = require("react");
26
+ var import_useRequestPro = require("./useRequestPro");
27
+ var useOptions = (option) => {
28
+ const { apis } = option;
29
+ const [value, setValue] = (0, import_react.useState)();
30
+ const { data, loading } = (0, import_useRequestPro.useRequestPro)(apis.list, {
31
+ onSuccess: (res) => {
32
+ var _a;
33
+ const [first] = ((_a = res.data) == null ? void 0 : _a.data) || [];
34
+ if (first) {
35
+ setValue(first == null ? void 0 : first.id);
36
+ }
37
+ }
38
+ });
39
+ const options = (0, import_react.useMemo)(() => {
40
+ return (data == null ? void 0 : data.data.map((item) => ({ label: item.name, value: item.id }))) || [];
41
+ }, [data]);
42
+ const currentData = (0, import_react.useMemo)(() => {
43
+ return data == null ? void 0 : data.data.find((item) => item.id === value);
44
+ }, [data, value]);
45
+ (0, import_react.useEffect)(() => {
46
+ var _a;
47
+ (_a = option.onChange) == null ? void 0 : _a.call(option, currentData);
48
+ }, [currentData]);
49
+ return {
50
+ loading,
51
+ options,
52
+ value,
53
+ onChange: setValue,
54
+ currentData
55
+ };
56
+ };
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ useOptions
60
+ });
@@ -0,0 +1,12 @@
1
+ import { RequestRes } from '@wzyjs/types';
2
+ import { Options, Result, Service } from 'ahooks/lib/useRequest/src/types';
3
+ interface UserOptions<P extends any[], R> extends Options<R, P> {
4
+ alertErrorMessage?: false | string;
5
+ alertSuccessMessage?: true | string;
6
+ }
7
+ interface IResult<R extends RequestRes, P extends any[]> extends Omit<Result<R, P>, 'data'> {
8
+ data?: R['data'];
9
+ }
10
+ export declare const useRequestPro: <P extends any[], R extends RequestRes<any>>(reqPromise?: Service<R, P> | undefined, userOptions?: UserOptions<P, R> | undefined) => IResult<R, P>;
11
+ export {};
12
+ //# sourceMappingURL=useRequestPro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRequestPro.d.ts","sourceRoot":"","sources":["../src/useRequestPro.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AAG1E,UAAU,WAAW,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,CAAE,SAAQ,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7D,iBAAiB,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACnC,mBAAmB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CACrC;AAGD,UAAU,OAAO,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,GAAG,EAAE,CAAE,SAAQ,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC;IACzF,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;CAClB;AAeD,eAAO,MAAM,aAAa,oJA0CzB,CAAA"}
@@ -0,0 +1,76 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/useRequestPro.ts
20
+ var useRequestPro_exports = {};
21
+ __export(useRequestPro_exports, {
22
+ useRequestPro: () => useRequestPro
23
+ });
24
+ module.exports = __toCommonJS(useRequestPro_exports);
25
+ var import_antd = require("antd");
26
+ var import_ahooks = require("ahooks");
27
+ var import_utils = require("@wzyjs/utils");
28
+ var defaultResult = {
29
+ loading: false,
30
+ data: void 0,
31
+ error: void 0,
32
+ params: [],
33
+ cancel: import_utils.noop,
34
+ refresh: import_utils.noop,
35
+ refreshAsync: import_utils.noop,
36
+ run: import_utils.noop,
37
+ runAsync: import_utils.noop,
38
+ mutate: import_utils.noop
39
+ };
40
+ var useRequestPro = (reqPromise, userOptions) => {
41
+ var _a;
42
+ if (!reqPromise) {
43
+ return defaultResult;
44
+ }
45
+ const { alertErrorMessage = true, alertSuccessMessage = false } = userOptions || {};
46
+ const defaultOptions = {
47
+ debounceWait: 300,
48
+ throttleWait: 300,
49
+ onError: (err, params) => {
50
+ var _a2;
51
+ if (alertErrorMessage) {
52
+ import_antd.message.error(typeof alertErrorMessage === "string" ? alertErrorMessage : err.message || "请求失败");
53
+ }
54
+ (_a2 = userOptions == null ? void 0 : userOptions.onError) == null ? void 0 : _a2.call(userOptions, err, params);
55
+ },
56
+ onSuccess: (res, params) => {
57
+ var _a2;
58
+ if (!(res == null ? void 0 : res.success)) {
59
+ defaultOptions.onError(new Error(res == null ? void 0 : res.message), params);
60
+ return;
61
+ }
62
+ if (alertSuccessMessage) {
63
+ import_antd.message.success(typeof alertSuccessMessage === "string" ? alertSuccessMessage : res.message || "请求成功");
64
+ }
65
+ (_a2 = userOptions == null ? void 0 : userOptions.onSuccess) == null ? void 0 : _a2.call(userOptions, res, params);
66
+ }
67
+ };
68
+ const options = Object.assign(defaultOptions, (0, import_utils.omit)(userOptions, ["onSuccess", "onError"]));
69
+ const state = (0, import_ahooks.useRequest)(reqPromise, options);
70
+ state.data = (_a = state.data) == null ? void 0 : _a.data;
71
+ return state;
72
+ };
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ useRequestPro
76
+ });
@@ -0,0 +1,6 @@
1
+ export declare const useVisibleInfo: (v: boolean | undefined, i: any) => (boolean | any[] | {
2
+ setTrue: () => void;
3
+ setFalse: () => void;
4
+ toggle: () => void;
5
+ })[];
6
+ //# sourceMappingURL=useVisibleInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVisibleInfo.d.ts","sourceRoot":"","sources":["../src/useVisibleInfo.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,8BAAkB,GAAG;;;;IAe/C,CAAA"}
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/useVisibleInfo.ts
20
+ var useVisibleInfo_exports = {};
21
+ __export(useVisibleInfo_exports, {
22
+ useVisibleInfo: () => useVisibleInfo
23
+ });
24
+ module.exports = __toCommonJS(useVisibleInfo_exports);
25
+ var import_react = require("react");
26
+ var useVisibleInfo = (v = false, i) => {
27
+ const [visible, setVisible] = (0, import_react.useState)(v);
28
+ const [info, setInfo] = (0, import_react.useState)(i);
29
+ return [
30
+ visible,
31
+ {
32
+ setTrue: () => setVisible(true),
33
+ setFalse: () => setVisible(false),
34
+ toggle: () => setVisible(!visible)
35
+ },
36
+ [
37
+ info,
38
+ setInfo
39
+ ]
40
+ ];
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ useVisibleInfo
45
+ });
@@ -0,0 +1,11 @@
1
+ export * from 'ahooks';
2
+ export { default as useUrlState } from '@ahooksjs/use-url-state';
3
+ export { useCopyToClipboard, useCookie, useUpdate } from 'react-use';
4
+ export * from './useRequestPro';
5
+ export * from './useEffectValue';
6
+ export * from './useElementScrollVisible';
7
+ export * from './useHideFooter';
8
+ export * from './useVisibleInfo';
9
+ export * from './useDateRange';
10
+ export * from './useOptions';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AAEtB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAEhE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAEpE,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,2BAA2B,CAAA;AACzC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA"}
package/dist/esm/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  export * from 'ahooks';
2
+ export { default as useUrlState } from '@ahooksjs/use-url-state';
2
3
  export { useCopyToClipboard, useCookie, useUpdate } from 'react-use';
3
4
  export * from "./useRequestPro";
4
5
  export * from "./useEffectValue";
5
6
  export * from "./useElementScrollVisible";
6
7
  export * from "./useHideFooter";
7
- export * from "./useVisibleInfo";
8
+ export * from "./useVisibleInfo";
9
+ export * from "./useDateRange";
10
+ export * from "./useOptions";
@@ -0,0 +1,23 @@
1
+ import { Dayjs } from '@wzyjs/utils';
2
+ export declare enum PresetType {
3
+ TODAY = "\u4ECA\u5929",
4
+ THIS_WEEK = "\u672C\u5468",
5
+ LAST_WEEK = "\u4E0A\u5468",
6
+ THIS_MONTH = "\u672C\u6708",
7
+ LAST_MONTH = "\u4E0A\u6708"
8
+ }
9
+ export declare const rangePresets: {
10
+ label: string;
11
+ value: [Dayjs, Dayjs];
12
+ }[];
13
+ interface Config {
14
+ defaultDateRange?: PresetType | [Dayjs, Dayjs];
15
+ }
16
+ export declare const useDateRange: (config: Config) => {
17
+ dateRange: [Dayjs, Dayjs];
18
+ onChange: (dateRange?: any) => void;
19
+ onClickPrev: () => void;
20
+ onClickNext: () => void;
21
+ };
22
+ export {};
23
+ //# sourceMappingURL=useDateRange.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDateRange.d.ts","sourceRoot":"","sources":["../src/useDateRange.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,EAAE,MAAM,cAAc,CAAA;AAE3C,oBAAY,UAAU;IACpB,KAAK,iBAAO;IACZ,SAAS,iBAAO;IAChB,SAAS,iBAAO;IAChB,UAAU,iBAAO;IACjB,UAAU,iBAAO;CAClB;AAED,eAAO,MAAM,YAAY,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;CAAE,EAqBlE,CAAA;AA4BD,UAAU,MAAM;IACd,gBAAgB,CAAC,EAAE,UAAU,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;CAC/C;AAED,eAAO,MAAM,YAAY,WAAY,MAAM;;2BAgBhB,GAAG;;;CAyC7B,CAAA"}
@@ -0,0 +1,113 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useState } from 'react';
8
+ import { dayjs } from '@wzyjs/utils';
9
+ export var PresetType = /*#__PURE__*/function (PresetType) {
10
+ PresetType["TODAY"] = "\u4ECA\u5929";
11
+ PresetType["THIS_WEEK"] = "\u672C\u5468";
12
+ PresetType["LAST_WEEK"] = "\u4E0A\u5468";
13
+ PresetType["THIS_MONTH"] = "\u672C\u6708";
14
+ PresetType["LAST_MONTH"] = "\u4E0A\u6708";
15
+ return PresetType;
16
+ }({});
17
+ export var rangePresets = [{
18
+ label: PresetType.TODAY,
19
+ value: [dayjs().startOf('day'), dayjs().endOf('day')]
20
+ }, {
21
+ label: PresetType.THIS_WEEK,
22
+ value: [dayjs().startOf('week'), dayjs().endOf('week')]
23
+ }, {
24
+ label: PresetType.LAST_WEEK,
25
+ value: [dayjs().subtract(1, 'week').startOf('week'), dayjs().subtract(1, 'week').endOf('week')]
26
+ }, {
27
+ label: PresetType.THIS_MONTH,
28
+ value: [dayjs().startOf('month'), dayjs().endOf('month')]
29
+ }, {
30
+ label: PresetType.LAST_MONTH,
31
+ value: [dayjs().subtract(1, 'month').startOf('month'), dayjs().subtract(1, 'month').endOf('month')]
32
+ }];
33
+ var checkDateRules = function checkDateRules(dateRange) {
34
+ var _dateRange = _slicedToArray(dateRange, 2),
35
+ date1 = _dateRange[0],
36
+ date2 = _dateRange[1];
37
+
38
+ // 规则1: 判断是否为同一天
39
+ if (date1.isSame(date2, 'day')) {
40
+ return 1;
41
+ }
42
+
43
+ // 规则2: 判断是否为周一和周日
44
+ if (date1.day() === 1 && date2.day() === 0 || date1.day() === 0 && date2.day() === 1) {
45
+ return 2;
46
+ }
47
+
48
+ // 规则3: 判断是否为月初和月末
49
+ var isStartOrEndOfMonth = function isStartOrEndOfMonth(date) {
50
+ return date.date() === 1 || date.date() === date.daysInMonth();
51
+ };
52
+ if (isStartOrEndOfMonth(date1) && isStartOrEndOfMonth(date2)) {
53
+ return 3;
54
+ }
55
+
56
+ // 如果没有匹配到任何规则,可以根据需要返回默认值,这里假设返回 0
57
+ return 0;
58
+ };
59
+ export var useDateRange = function useDateRange(config) {
60
+ var _rangePresets$find;
61
+ var _config$defaultDateRa = config.defaultDateRange,
62
+ defaultDateRange = _config$defaultDateRa === void 0 ? PresetType.TODAY : _config$defaultDateRa;
63
+ var _useState = useState(Array.isArray(defaultDateRange) ? defaultDateRange : ((_rangePresets$find = rangePresets.find(function (item) {
64
+ return item.label === defaultDateRange;
65
+ })) === null || _rangePresets$find === void 0 ? void 0 : _rangePresets$find.value) || [dayjs().startOf('day'), dayjs().endOf('day')]),
66
+ _useState2 = _slicedToArray(_useState, 2),
67
+ dateRange = _useState2[0],
68
+ setDateRange = _useState2[1];
69
+ var rangeType = checkDateRules(dateRange);
70
+ return {
71
+ dateRange: dateRange,
72
+ // 这里的 any 实际应该是 antd 的 RangeValue<Dayjs> 类型,
73
+ // 但是这个类型不好获取,所以这里先用 any 代替
74
+ onChange: function onChange(dateRange) {
75
+ if (!dateRange) {
76
+ return;
77
+ }
78
+ setDateRange(dateRange);
79
+ },
80
+ onClickPrev: function onClickPrev() {
81
+ switch (rangeType) {
82
+ case 1:
83
+ setDateRange([dateRange[0].subtract(1, 'day'), dateRange[1].subtract(1, 'day')]);
84
+ break;
85
+ case 2:
86
+ setDateRange([dateRange[0].subtract(1, 'week'), dateRange[1].subtract(1, 'week')]);
87
+ break;
88
+ case 3:
89
+ setDateRange([dateRange[0].subtract(1, 'month').startOf('month'), dateRange[1].subtract(1, 'month').endOf('month')]);
90
+ break;
91
+ default:
92
+ setDateRange([dateRange[0].subtract(1, 'day'), dateRange[1]]);
93
+ break;
94
+ }
95
+ },
96
+ onClickNext: function onClickNext() {
97
+ switch (rangeType) {
98
+ case 1:
99
+ setDateRange([dateRange[0].add(1, 'day'), dateRange[1].add(1, 'day')]);
100
+ break;
101
+ case 2:
102
+ setDateRange([dateRange[0].add(1, 'week'), dateRange[1].add(1, 'week')]);
103
+ break;
104
+ case 3:
105
+ setDateRange([dateRange[0].add(1, 'month').startOf('month'), dateRange[1].add(1, 'month').endOf('month')]);
106
+ break;
107
+ default:
108
+ setDateRange([dateRange[0], dateRange[1].add(1, 'day')]);
109
+ break;
110
+ }
111
+ }
112
+ };
113
+ };
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare const useEffectValue: (fn: any, deps?: never[]) => (import("react").Dispatch<import("react").SetStateAction<undefined>> | undefined)[];
3
+ //# sourceMappingURL=useEffectValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEffectValue.d.ts","sourceRoot":"","sources":["../src/useEffectValue.ts"],"names":[],"mappings":";AAEA,eAAO,MAAM,cAAc,OAAQ,GAAG,wGAIrC,CAAA"}
@@ -0,0 +1,6 @@
1
+ export declare const useElementScrollVisible: (scroll: any, target: any) => {
2
+ visible: boolean;
3
+ direction: string;
4
+ rect: string;
5
+ };
6
+ //# sourceMappingURL=useElementScrollVisible.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useElementScrollVisible.d.ts","sourceRoot":"","sources":["../src/useElementScrollVisible.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,WAAY,GAAG,UAAU,GAAG;;;;CAwC/D,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const useHideFooter: (el?: string) => void;
2
+ //# sourceMappingURL=useHideFooter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHideFooter.d.ts","sourceRoot":"","sources":["../src/useHideFooter.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,uBAQzB,CAAA"}
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ interface Option {
3
+ apis: any;
4
+ onChange?: (data?: any) => void;
5
+ }
6
+ export declare const useOptions: (option: Option) => {
7
+ loading: boolean;
8
+ options: any;
9
+ value: string | undefined;
10
+ onChange: import("react").Dispatch<import("react").SetStateAction<string | undefined>>;
11
+ currentData: any;
12
+ };
13
+ export {};
14
+ //# sourceMappingURL=useOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOptions.d.ts","sourceRoot":"","sources":["../src/useOptions.ts"],"names":[],"mappings":";AAGA,UAAU,MAAM;IACd,IAAI,EAAE,GAAG,CAAA;IACT,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;CAChC;AAED,eAAO,MAAM,UAAU,WAAY,MAAM;;;;;;CAqCxC,CAAA"}
@@ -0,0 +1,60 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useMemo, useState } from 'react';
8
+ import { useRequestPro } from "./useRequestPro";
9
+ export var useOptions = function useOptions(option) {
10
+ var apis = option.apis;
11
+ var _useState = useState(),
12
+ _useState2 = _slicedToArray(_useState, 2),
13
+ value = _useState2[0],
14
+ setValue = _useState2[1];
15
+
16
+ // 发请求获取列表数据
17
+ var _useRequestPro = useRequestPro(apis.list, {
18
+ onSuccess: function onSuccess(res) {
19
+ var _res$data;
20
+ var _ref = ((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.data) || [],
21
+ _ref2 = _slicedToArray(_ref, 1),
22
+ first = _ref2[0];
23
+ if (first) {
24
+ setValue(first === null || first === void 0 ? void 0 : first.id);
25
+ }
26
+ }
27
+ }),
28
+ data = _useRequestPro.data,
29
+ loading = _useRequestPro.loading;
30
+
31
+ // 将列表数据转换成 options
32
+ var options = useMemo(function () {
33
+ return (data === null || data === void 0 ? void 0 : data.data.map(function (item) {
34
+ return {
35
+ label: item.name,
36
+ value: item.id
37
+ };
38
+ })) || [];
39
+ }, [data]);
40
+
41
+ // 根据 value 获取当前详细数据
42
+ var currentData = useMemo(function () {
43
+ return data === null || data === void 0 ? void 0 : data.data.find(function (item) {
44
+ return item.id === value;
45
+ });
46
+ }, [data, value]);
47
+
48
+ // value 变化时触发 onChange
49
+ useEffect(function () {
50
+ var _option$onChange;
51
+ (_option$onChange = option.onChange) === null || _option$onChange === void 0 ? void 0 : _option$onChange.call(option, currentData);
52
+ }, [currentData]);
53
+ return {
54
+ loading: loading,
55
+ options: options,
56
+ value: value,
57
+ onChange: setValue,
58
+ currentData: currentData
59
+ };
60
+ };
@@ -0,0 +1,12 @@
1
+ import { RequestRes } from '@wzyjs/types';
2
+ import { Options, Result, Service } from 'ahooks/lib/useRequest/src/types';
3
+ interface UserOptions<P extends any[], R> extends Options<R, P> {
4
+ alertErrorMessage?: false | string;
5
+ alertSuccessMessage?: true | string;
6
+ }
7
+ interface IResult<R extends RequestRes, P extends any[]> extends Omit<Result<R, P>, 'data'> {
8
+ data?: R['data'];
9
+ }
10
+ export declare const useRequestPro: <P extends any[], R extends RequestRes<any>>(reqPromise?: Service<R, P> | undefined, userOptions?: UserOptions<P, R> | undefined) => IResult<R, P>;
11
+ export {};
12
+ //# sourceMappingURL=useRequestPro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRequestPro.d.ts","sourceRoot":"","sources":["../src/useRequestPro.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AAG1E,UAAU,WAAW,CAAC,CAAC,SAAS,GAAG,EAAE,EAAE,CAAC,CAAE,SAAQ,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAC7D,iBAAiB,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACnC,mBAAmB,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;CACrC;AAGD,UAAU,OAAO,CAAC,CAAC,SAAS,UAAU,EAAE,CAAC,SAAS,GAAG,EAAE,CAAE,SAAQ,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC;IACzF,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;CAClB;AAeD,eAAO,MAAM,aAAa,oJA0CzB,CAAA"}
@@ -29,8 +29,6 @@ export var useRequestPro = function useRequestPro(reqPromise, userOptions) {
29
29
  _ref$alertSuccessMess = _ref.alertSuccessMessage,
30
30
  alertSuccessMessage = _ref$alertSuccessMess === void 0 ? false : _ref$alertSuccessMess;
31
31
  var defaultOptions = {
32
- cacheKey: String(reqPromise),
33
- staleTime: 5000,
34
32
  debounceWait: 300,
35
33
  throttleWait: 300,
36
34
  onError: function onError(err, params) {
@@ -0,0 +1,6 @@
1
+ export declare const useVisibleInfo: (v: boolean | undefined, i: any) => (boolean | any[] | {
2
+ setTrue: () => void;
3
+ setFalse: () => void;
4
+ toggle: () => void;
5
+ })[];
6
+ //# sourceMappingURL=useVisibleInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVisibleInfo.d.ts","sourceRoot":"","sources":["../src/useVisibleInfo.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,8BAAkB,GAAG;;;;IAe/C,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wzyjs/hooks",
3
- "version": "0.1.0",
3
+ "version": "0.2.2",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "license": "ISC",
@@ -8,6 +8,7 @@
8
8
  "dev": "father dev",
9
9
  "build": "father build"
10
10
  },
11
+ "typings": "./dist/esm/index.d.ts",
11
12
  "exports": {
12
13
  ".": {
13
14
  "import": "./dist/esm/index.js",
@@ -18,8 +19,9 @@
18
19
  "dist"
19
20
  ],
20
21
  "dependencies": {
21
- "@wzyjs/types": "^0.1.0",
22
- "@wzyjs/utils": "^0.1.0",
22
+ "@ahooksjs/use-url-state": "^3.5.1",
23
+ "@wzyjs/types": "^0.2.2",
24
+ "@wzyjs/utils": "^0.2.2",
23
25
  "ahooks": "^3.7.3",
24
26
  "antd": "^5.6.2",
25
27
  "react-use": "^17.4.0"
@@ -36,5 +38,5 @@
36
38
  "type": "git",
37
39
  "url": "https://gitee.com/wang-zhenyu/work.git"
38
40
  },
39
- "gitHead": "3efe774801f46de9c70693ace99d01eb7fb06da1"
41
+ "gitHead": "a9e5d6f01fbca5d85b20855a3359a48ed42b67b5"
40
42
  }