heitu 1.0.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.
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/dist/canvas/constant/index.d.ts +12 -0
- package/dist/canvas/constant/index.js +4 -0
- package/dist/canvas/element/Circle.d.ts +2 -0
- package/dist/canvas/element/Circle.js +38 -0
- package/dist/canvas/element/Line.d.ts +13 -0
- package/dist/canvas/element/Line.js +45 -0
- package/dist/canvas/element/Rect.d.ts +10 -0
- package/dist/canvas/element/Rect.js +37 -0
- package/dist/canvas/element/Sector.d.ts +2 -0
- package/dist/canvas/element/Sector.js +41 -0
- package/dist/canvas/element/Stage.d.ts +11 -0
- package/dist/canvas/element/Stage.js +40 -0
- package/dist/canvas/element/Trapezoid.d.ts +10 -0
- package/dist/canvas/element/Trapezoid.js +38 -0
- package/dist/canvas/index.d.ts +7 -0
- package/dist/canvas/index.js +7 -0
- package/dist/canvas/instance/api/api.d.ts +13 -0
- package/dist/canvas/instance/api/api.js +66 -0
- package/dist/canvas/instance/api/scheduler.d.ts +6 -0
- package/dist/canvas/instance/api/scheduler.js +26 -0
- package/dist/canvas/instance/circle.d.ts +17 -0
- package/dist/canvas/instance/circle.js +42 -0
- package/dist/canvas/instance/line.d.ts +16 -0
- package/dist/canvas/instance/line.js +28 -0
- package/dist/canvas/instance/rect.d.ts +16 -0
- package/dist/canvas/instance/rect.js +28 -0
- package/dist/canvas/instance/shape.d.ts +42 -0
- package/dist/canvas/instance/shape.js +70 -0
- package/dist/canvas/instance/stage.d.ts +21 -0
- package/dist/canvas/instance/stage.js +88 -0
- package/dist/canvas/instance/trapezoid.d.ts +12 -0
- package/dist/canvas/instance/trapezoid.js +24 -0
- package/dist/canvas/store/index.d.ts +3 -0
- package/dist/canvas/store/index.js +2 -0
- package/dist/canvas/type.d.ts +25 -0
- package/dist/canvas/utils/hooks/usePropertyChange.d.ts +1 -0
- package/dist/canvas/utils/hooks/usePropertyChange.js +23 -0
- package/dist/canvas/utils/index.d.ts +1 -0
- package/dist/canvas/utils/index.js +7 -0
- package/dist/canvas/utils/renderShape/common.d.ts +3 -0
- package/dist/canvas/utils/renderShape/common.js +55 -0
- package/dist/canvas/utils/renderShape/index.d.ts +1 -0
- package/dist/canvas/utils/renderShape/index.js +47 -0
- package/dist/canvas/utils/renderShape/renderCircle.d.ts +8 -0
- package/dist/canvas/utils/renderShape/renderCircle.js +88 -0
- package/dist/canvas/utils/renderShape/renderLine.d.ts +0 -0
- package/dist/canvas/utils/renderShape/renderLine.js +86 -0
- package/dist/canvas/utils/renderShape/renderRect.d.ts +2 -0
- package/dist/canvas/utils/renderShape/renderRect.js +28 -0
- package/dist/canvas/utils/renderShape/renderTrapezoid.d.ts +2 -0
- package/dist/canvas/utils/renderShape/renderTrapezoid.js +26 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useCookie/index.d.ts +4 -0
- package/dist/hooks/useCookie/index.js +52 -0
- package/dist/hooks/useCookie/interface.d.ts +41 -0
- package/dist/hooks/useCookie/utils.d.ts +2 -0
- package/dist/hooks/useCookie/utils.js +16 -0
- package/dist/hooks/useCountDown/index.d.ts +2 -0
- package/dist/hooks/useCountDown/index.js +43 -0
- package/dist/hooks/useElementSize/index.d.ts +5 -0
- package/dist/hooks/useElementSize/index.js +33 -0
- package/dist/hooks/useHtAxios/constants.d.ts +2 -0
- package/dist/hooks/useHtAxios/constants.js +2 -0
- package/dist/hooks/useHtAxios/defaultConfig.d.ts +49 -0
- package/dist/hooks/useHtAxios/defaultConfig.js +43 -0
- package/dist/hooks/useHtAxios/index.d.ts +13 -0
- package/dist/hooks/useHtAxios/index.js +60 -0
- package/dist/hooks/useHtAxios/interface.d.ts +0 -0
- package/dist/hooks/useHtAxios/request.interceptor.d.ts +8 -0
- package/dist/hooks/useHtAxios/request.interceptor.js +66 -0
- package/dist/hooks/useHtAxios/response.interceptor.d.ts +9 -0
- package/dist/hooks/useHtAxios/response.interceptor.js +74 -0
- package/dist/hooks/useHtAxios/typings.d.ts +15 -0
- package/dist/hooks/useHtAxios/utils.d.ts +4 -0
- package/dist/hooks/useHtAxios/utils.js +40 -0
- package/dist/hooks/useInView/index.d.ts +3 -0
- package/dist/hooks/useInView/index.js +44 -0
- package/dist/hooks/useInView/interface.d.ts +2 -0
- package/dist/hooks/useInfiniteScroll/index.d.ts +26 -0
- package/dist/hooks/useInfiniteScroll/index.js +111 -0
- package/dist/hooks/usePrevious/index.d.ts +2 -0
- package/dist/hooks/usePrevious/index.js +14 -0
- package/dist/hooks/useResizeObserver/index.d.ts +2 -0
- package/dist/hooks/useResizeObserver/index.js +19 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/utils/defaults.d.ts +1 -0
- package/dist/utils/defaults.js +1 -0
- package/dist/utils/is.d.ts +14 -0
- package/dist/utils/is.js +31 -0
- package/dist/utils/types.d.ts +1 -0
- package/dist/utils/types.js +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// import { Line } from 'heitu/canvas/instance/line';
|
|
2
|
+
|
|
3
|
+
// export function convertToNormalPoints(points: number[]): ICoord[] {
|
|
4
|
+
// return points
|
|
5
|
+
// .reduce((acc, item, index) => {
|
|
6
|
+
// const tarIndex = Math.floor(index / 2);
|
|
7
|
+
// if (index % 2 == 0) acc.push([item]);
|
|
8
|
+
// else acc[tarIndex].push(item);
|
|
9
|
+
// return acc;
|
|
10
|
+
// }, [])
|
|
11
|
+
// .map(([x, y]) => ({ x, y }));
|
|
12
|
+
// }
|
|
13
|
+
// export function calcSmoothPath2D(points: number[], percent) {
|
|
14
|
+
// const [start_x, start_y, ...restPoints] = points;
|
|
15
|
+
|
|
16
|
+
// const path2D = new Path2D();
|
|
17
|
+
|
|
18
|
+
// if (percent === 0) {
|
|
19
|
+
// return path2D;
|
|
20
|
+
// }
|
|
21
|
+
|
|
22
|
+
// const normalPoints = convertToNormalPoints(points);
|
|
23
|
+
// const allControlPoint = calcAllControlPoint(normalPoints);
|
|
24
|
+
|
|
25
|
+
// const percentSeg = allControlPoint.length * percent;
|
|
26
|
+
|
|
27
|
+
// const elapsedIndex = Math.floor(percentSeg);
|
|
28
|
+
// const t = percentSeg - elapsedIndex;
|
|
29
|
+
|
|
30
|
+
// const percentControlPoint = allControlPoint[Math.ceil(percentSeg) - 1];
|
|
31
|
+
|
|
32
|
+
// const tempAns = calculateControlPoint(t, percentControlPoint);
|
|
33
|
+
|
|
34
|
+
// const ans = allControlPoint.slice(0, elapsedIndex);
|
|
35
|
+
// if (percent !== 1) {
|
|
36
|
+
// ans.push({
|
|
37
|
+
// start: percentControlPoint.start,
|
|
38
|
+
// end: tempAns.tempEnd,
|
|
39
|
+
// cp1: tempAns.cp1,
|
|
40
|
+
// cp2: tempAns.cp2,
|
|
41
|
+
// });
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
// path2D.moveTo(start_x, start_y);
|
|
45
|
+
// ans.forEach((item) => {
|
|
46
|
+
// path2D.bezierCurveTo(
|
|
47
|
+
// item.cp1.x,
|
|
48
|
+
// item.cp1.y,
|
|
49
|
+
// item.cp2.x,
|
|
50
|
+
// item.cp2.y,
|
|
51
|
+
// item.end.x,
|
|
52
|
+
// item.end.y,
|
|
53
|
+
// );
|
|
54
|
+
// });
|
|
55
|
+
|
|
56
|
+
// return path2D;
|
|
57
|
+
// }
|
|
58
|
+
// export function calcStraightPath2D(points: number[], percent) {
|
|
59
|
+
// const path2D = new Path2D();
|
|
60
|
+
|
|
61
|
+
// const pts = calcPointsByPercent(points, percent);
|
|
62
|
+
|
|
63
|
+
// const [start_x, start_y, ...restPoints] = pts;
|
|
64
|
+
// const restNormalPoints = convertToNormalPoints(restPoints);
|
|
65
|
+
// path2D.moveTo(start_x, start_y);
|
|
66
|
+
|
|
67
|
+
// restNormalPoints.forEach(({ x, y }) => {
|
|
68
|
+
// path2D.lineTo(x, y);
|
|
69
|
+
// });
|
|
70
|
+
|
|
71
|
+
// return path2D;
|
|
72
|
+
// }
|
|
73
|
+
|
|
74
|
+
// export function createLinePath2D(data: Line['data']) {
|
|
75
|
+
// const { points, closed, smooth, percent } = data;
|
|
76
|
+
|
|
77
|
+
// const path2D = smooth
|
|
78
|
+
// ? calcSmoothPath2D(points, percent)
|
|
79
|
+
// : calcStraightPath2D(points, percent);
|
|
80
|
+
|
|
81
|
+
// if (closed) {
|
|
82
|
+
// path2D.closePath();
|
|
83
|
+
// }
|
|
84
|
+
|
|
85
|
+
// return path2D;
|
|
86
|
+
// }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// 用于绘制 长方形
|
|
2
|
+
|
|
3
|
+
// 使用 Path2D 创建 rect 路径
|
|
4
|
+
export var createRectPath2D = function createRectPath2D(data) {
|
|
5
|
+
var x = data.x,
|
|
6
|
+
y = data.y,
|
|
7
|
+
width = data.width,
|
|
8
|
+
height = data.height,
|
|
9
|
+
_data$cornerRadius = data.cornerRadius,
|
|
10
|
+
cornerRadius = _data$cornerRadius === void 0 ? 0 : _data$cornerRadius;
|
|
11
|
+
var path2D = new Path2D();
|
|
12
|
+
path2D.moveTo(x + cornerRadius, y);
|
|
13
|
+
path2D.lineTo(x + width - cornerRadius, y);
|
|
14
|
+
path2D.arc(x + width - cornerRadius, y + cornerRadius, cornerRadius, Math.PI / 2 * 3, 0);
|
|
15
|
+
path2D.lineTo(x + width, y + height - cornerRadius);
|
|
16
|
+
path2D.arc(x + width - cornerRadius, y + height - cornerRadius, cornerRadius, 0, Math.PI / 2);
|
|
17
|
+
path2D.lineTo(x + cornerRadius, y + height);
|
|
18
|
+
path2D.arc(x + cornerRadius, y + height - cornerRadius, cornerRadius, Math.PI / 2, Math.PI);
|
|
19
|
+
path2D.lineTo(x, y + cornerRadius);
|
|
20
|
+
path2D.arc(x + cornerRadius, y + cornerRadius, cornerRadius, Math.PI, Math.PI / 2 * 3);
|
|
21
|
+
path2D.closePath();
|
|
22
|
+
console.log(path2D, 'path2D');
|
|
23
|
+
return path2D;
|
|
24
|
+
};
|
|
25
|
+
// 设置 rect 路径 到 elementItem
|
|
26
|
+
export var setRectPath2D = function setRectPath2D(elementItem) {
|
|
27
|
+
elementItem.path2D = createRectPath2D(elementItem.data);
|
|
28
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function setTrapezoidPath2D(elementItem) {
|
|
2
|
+
var _elementItem$data = elementItem.data,
|
|
3
|
+
_elementItem$data$x = _elementItem$data.x,
|
|
4
|
+
x = _elementItem$data$x === void 0 ? 0 : _elementItem$data$x,
|
|
5
|
+
_elementItem$data$y = _elementItem$data.y,
|
|
6
|
+
y = _elementItem$data$y === void 0 ? 0 : _elementItem$data$y,
|
|
7
|
+
_elementItem$data$wid = _elementItem$data.width,
|
|
8
|
+
width = _elementItem$data$wid === void 0 ? 0 : _elementItem$data$wid,
|
|
9
|
+
_elementItem$data$hei = _elementItem$data.height,
|
|
10
|
+
height = _elementItem$data$hei === void 0 ? 0 : _elementItem$data$hei,
|
|
11
|
+
_elementItem$data$sho = _elementItem$data.shortLength,
|
|
12
|
+
shortLength = _elementItem$data$sho === void 0 ? 0 : _elementItem$data$sho;
|
|
13
|
+
var path2D = new Path2D();
|
|
14
|
+
var _shortLength = 0;
|
|
15
|
+
if (typeof shortLength === 'number') {
|
|
16
|
+
_shortLength = shortLength;
|
|
17
|
+
} else if (typeof shortLength === 'string') {
|
|
18
|
+
_shortLength = parseFloat(shortLength) / 100 * width;
|
|
19
|
+
}
|
|
20
|
+
path2D.moveTo(x + (width / 2 - _shortLength / 2), y);
|
|
21
|
+
path2D.lineTo(x + (width / 2 - _shortLength / 2) + _shortLength, y);
|
|
22
|
+
path2D.lineTo(x + width, y + height);
|
|
23
|
+
path2D.lineTo(x, y + height);
|
|
24
|
+
path2D.closePath();
|
|
25
|
+
elementItem.path2D = path2D;
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as useCookie } from './useCookie';
|
|
2
|
+
export { default as useCountDown } from './useCountDown';
|
|
3
|
+
export { default as useElementSize } from './useElementSize';
|
|
4
|
+
export { default as useHtAxios } from './useHtAxios';
|
|
5
|
+
export { default as useInfiniteScroll } from './useInfiniteScroll';
|
|
6
|
+
export { default as useInView } from './useInView';
|
|
7
|
+
export { default as useResizeObserver } from './useResizeObserver';
|
|
8
|
+
export { default as usePrevious } from './usePrevious';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as useCookie } from "./useCookie";
|
|
2
|
+
export { default as useCountDown } from "./useCountDown";
|
|
3
|
+
export { default as useElementSize } from "./useElementSize";
|
|
4
|
+
export { default as useHtAxios } from "./useHtAxios";
|
|
5
|
+
export { default as useInfiniteScroll } from "./useInfiniteScroll";
|
|
6
|
+
export { default as useInView } from "./useInView";
|
|
7
|
+
export { default as useResizeObserver } from "./useResizeObserver";
|
|
8
|
+
export { default as usePrevious } from "./usePrevious";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Cookies from 'js-cookie';
|
|
2
|
+
import { UseCookieState } from './interface';
|
|
3
|
+
declare const useCookie: (key: string, options?: Cookies.CookieAttributes, defaultValue?: string) => (UseCookieState | ((newValue: UseCookieState | ((prevState: UseCookieState) => UseCookieState)) => void))[];
|
|
4
|
+
export default useCookie;
|
|
@@ -0,0 +1,52 @@
|
|
|
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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { defaultOptions } from "../../utils/defaults";
|
|
8
|
+
import { isFunction, isString } from "../../utils/is";
|
|
9
|
+
import Cookies from 'js-cookie';
|
|
10
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
11
|
+
import { getInitialState } from "./utils";
|
|
12
|
+
var useCookie = function useCookie(key) {
|
|
13
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
|
|
14
|
+
var defaultValue = arguments.length > 2 ? arguments[2] : undefined;
|
|
15
|
+
var _useState = useState(getInitialState(key, defaultValue)),
|
|
16
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
17
|
+
cookieValue = _useState2[0],
|
|
18
|
+
setCookieValue = _useState2[1];
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
var getStoredValue = function getStoredValue() {
|
|
21
|
+
var raw = Cookies.get(key);
|
|
22
|
+
if (raw !== undefined && raw !== null) {
|
|
23
|
+
return raw;
|
|
24
|
+
} else {
|
|
25
|
+
if (defaultValue === undefined) {
|
|
26
|
+
Cookies.remove(key);
|
|
27
|
+
} else {
|
|
28
|
+
Cookies.set(key, defaultValue, options);
|
|
29
|
+
}
|
|
30
|
+
return defaultValue;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
setCookieValue(getStoredValue());
|
|
34
|
+
}, [defaultValue, key, JSON.stringify(options)]);
|
|
35
|
+
var updateCookie = useCallback(function (newValue) {
|
|
36
|
+
var value = isFunction(newValue) ? newValue(cookieValue) : newValue;
|
|
37
|
+
if (value === undefined) {
|
|
38
|
+
Cookies.remove(key);
|
|
39
|
+
} else {
|
|
40
|
+
Cookies.set(key, value, options);
|
|
41
|
+
}
|
|
42
|
+
setCookieValue(value);
|
|
43
|
+
}, [key, cookieValue, JSON.stringify(options)]);
|
|
44
|
+
var refreshCookie = useCallback(function () {
|
|
45
|
+
var cookieValue = Cookies.get(key);
|
|
46
|
+
if (isString(cookieValue)) {
|
|
47
|
+
setCookieValue(cookieValue);
|
|
48
|
+
}
|
|
49
|
+
}, [key]);
|
|
50
|
+
return [cookieValue, updateCookie, refreshCookie];
|
|
51
|
+
};
|
|
52
|
+
export default useCookie;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type Cookies from 'js-cookie'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @title useCookie
|
|
5
|
+
* @returns 包含以下元素的元组:
|
|
6
|
+
* - cookie 的当前值。
|
|
7
|
+
* - 更新 cookie 值的函数。
|
|
8
|
+
* - 刷新 cookie 值的函数,以防其他事件更改它。
|
|
9
|
+
* @returns_en A tuple with the following elements:
|
|
10
|
+
* - The current value of the cookie.
|
|
11
|
+
* - A function to update the value of the cookie.
|
|
12
|
+
* - A function to refresh the value of the cookie, incase other events change it.
|
|
13
|
+
*/
|
|
14
|
+
export type UseCookie = (
|
|
15
|
+
/**
|
|
16
|
+
* @zh 键值
|
|
17
|
+
* @en key
|
|
18
|
+
*/
|
|
19
|
+
key: string,
|
|
20
|
+
/**
|
|
21
|
+
* @zh 透传给 `js-cookie` 的参数
|
|
22
|
+
* @en option pass to `js-cookie`
|
|
23
|
+
*/
|
|
24
|
+
options?: Cookies.CookieAttributes,
|
|
25
|
+
/**
|
|
26
|
+
* @zh 默认值,ssr必须传递
|
|
27
|
+
* @en defaultValue, must be required in ssr
|
|
28
|
+
*/
|
|
29
|
+
defaultValue?: string
|
|
30
|
+
) => readonly [
|
|
31
|
+
UseCookieState,
|
|
32
|
+
(
|
|
33
|
+
newValue: UseCookieState | ((prevState: UseCookieState) => UseCookieState)
|
|
34
|
+
) => void,
|
|
35
|
+
() => void,
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @title useCookieState
|
|
40
|
+
*/
|
|
41
|
+
export type UseCookieState = string | undefined
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isBrowser } from "../../utils/is";
|
|
2
|
+
import Cookies from 'js-cookie';
|
|
3
|
+
function getInitialState(key, defaultValue) {
|
|
4
|
+
// Prevent a React hydration mismatch when a default value is provided.
|
|
5
|
+
if (defaultValue !== undefined) {
|
|
6
|
+
return defaultValue;
|
|
7
|
+
}
|
|
8
|
+
if (isBrowser) {
|
|
9
|
+
return Cookies.get(key);
|
|
10
|
+
}
|
|
11
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
12
|
+
console.warn('`useCookie` When server side rendering, defaultValue should be defined to prevent a hydration mismatches.');
|
|
13
|
+
}
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
export { getInitialState };
|
|
@@ -0,0 +1,43 @@
|
|
|
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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useEffect, useState } from 'react';
|
|
8
|
+
var useCountDown = function useCountDown() {
|
|
9
|
+
var _useState = useState(0),
|
|
10
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
11
|
+
seconds = _useState2[0],
|
|
12
|
+
setSeconds = _useState2[1];
|
|
13
|
+
var timer;
|
|
14
|
+
var stopCountDown = function stopCountDown() {
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
};
|
|
17
|
+
var startCountDown = function startCountDown(num) {
|
|
18
|
+
stopCountDown();
|
|
19
|
+
if (num) {
|
|
20
|
+
setSeconds(num);
|
|
21
|
+
} else {
|
|
22
|
+
setSeconds(function (prevSeconds) {
|
|
23
|
+
return prevSeconds - 1;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
timer = setTimeout(function () {
|
|
29
|
+
if (seconds > 0) {
|
|
30
|
+
setSeconds(function (prevSeconds) {
|
|
31
|
+
return prevSeconds - 1;
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
stopCountDown();
|
|
35
|
+
}
|
|
36
|
+
}, 1000);
|
|
37
|
+
return function () {
|
|
38
|
+
return stopCountDown();
|
|
39
|
+
};
|
|
40
|
+
}, [seconds]);
|
|
41
|
+
return [seconds, startCountDown, stopCountDown];
|
|
42
|
+
};
|
|
43
|
+
export default useCountDown;
|
|
@@ -0,0 +1,33 @@
|
|
|
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(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import useResizeObserver from "../useResizeObserver";
|
|
8
|
+
import { defaultOptions } from "../../utils/defaults";
|
|
9
|
+
import { useState } from 'react';
|
|
10
|
+
var useElementSize = function useElementSize(containerRef) {
|
|
11
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
|
|
12
|
+
var _useState = useState({
|
|
13
|
+
width: 0,
|
|
14
|
+
height: 0
|
|
15
|
+
}),
|
|
16
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
17
|
+
size = _useState2[0],
|
|
18
|
+
setSize = _useState2[1];
|
|
19
|
+
useResizeObserver(containerRef, function (entries) {
|
|
20
|
+
if (entries.length === 0) return;
|
|
21
|
+
var _entries = _slicedToArray(entries, 1),
|
|
22
|
+
entry = _entries[0];
|
|
23
|
+
var _entry$contentRect = entry.contentRect,
|
|
24
|
+
width = _entry$contentRect.width,
|
|
25
|
+
height = _entry$contentRect.height;
|
|
26
|
+
setSize({
|
|
27
|
+
width: width,
|
|
28
|
+
height: height
|
|
29
|
+
});
|
|
30
|
+
}, options);
|
|
31
|
+
return size;
|
|
32
|
+
};
|
|
33
|
+
export default useElementSize;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* config
|
|
4
|
+
* 1. baseURL: 作用:设置请求的基础 URL,用于所有请求的 URL 前缀。
|
|
5
|
+
* 2. timeout: 作用:指定请求超时的毫秒数。如果请求超过这个时间,请求将被中止。
|
|
6
|
+
* 3. headers: 作用:设置默认的请求头,可以包含每个请求都需要的默认 headers。
|
|
7
|
+
* 4. paramsSerializer: 作用:定义对 params 的序列化处理函数,用于自定义序列化过程。
|
|
8
|
+
* 5. withCredentials: 作用:指示是否跨站点访问控制请求应该使用凭据(如 cookie 或授权头)。
|
|
9
|
+
* 6. transformRequest: 定义转换请求数据的函数。只能用于 POST、PUT、PATCH 方法,且 Content-Type 是 application/x-www-form-urlencoded, application/json 或 multipart/form-data。
|
|
10
|
+
* 7. transformResponse: 作用:定义转换响应数据的函数。这些函数会在数据被传递给 then 或 catch 之前调用。
|
|
11
|
+
* 8. validateStatus:作用:定义转换响应数据的函数。这些函数会在数据被传递给 then 或 catch 之前调用。
|
|
12
|
+
* 9. maxContentLength: 作用:指定接收响应数据的最大字节大小。
|
|
13
|
+
*/
|
|
14
|
+
export interface HtRequestConfig extends AxiosRequestConfig {
|
|
15
|
+
/**
|
|
16
|
+
* 是否要过滤Null值与Undefined值
|
|
17
|
+
*/
|
|
18
|
+
filter?: boolean;
|
|
19
|
+
/** 是否要添加防缓存随机数 */
|
|
20
|
+
cache?: boolean;
|
|
21
|
+
/** 是否自动转换 put 和 delete 请求为 post 请求 */
|
|
22
|
+
transformMethod?: boolean;
|
|
23
|
+
message?: any;
|
|
24
|
+
responseInterceptor?: (response: AxiosResponse) => any;
|
|
25
|
+
requestInterceptor?: (config: HtRequestConfig) => HtRequestConfig;
|
|
26
|
+
/** 是否将传入的 RequestInterceptor 覆盖掉默认的 RequestInterceptor */
|
|
27
|
+
overrideDefaultRequestInterceptor?: boolean;
|
|
28
|
+
/** 是否将传入的 ResponseInterceptor 覆盖掉默认的 ResponseInterceptor */
|
|
29
|
+
overrideDefaultResponseInterceptor?: boolean;
|
|
30
|
+
errorNotice?: Record<string, {
|
|
31
|
+
msg: string;
|
|
32
|
+
path: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* 是否添加 gzip 压缩, 触发条件为 post/put 请求 & content-type 为 json. 默认从 common-env 中获取
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
gzip?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* 当大于这个大小时, 才会开启压缩, 默认从 common-env 中获取
|
|
41
|
+
* @default 8KB
|
|
42
|
+
*/
|
|
43
|
+
gzipThresholdSize?: number;
|
|
44
|
+
/** 是否开启 base64 编码 */
|
|
45
|
+
base64?: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare const headers: Record<string, string>;
|
|
48
|
+
export declare const defaultConfig: () => HtRequestConfig;
|
|
49
|
+
export { headers };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { HEADER_CONTENT_TYPE_APPLICATION_JSON } from "./constants";
|
|
2
|
+
// import { getEnvToken } from './utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* config
|
|
6
|
+
* 1. baseURL: 作用:设置请求的基础 URL,用于所有请求的 URL 前缀。
|
|
7
|
+
* 2. timeout: 作用:指定请求超时的毫秒数。如果请求超过这个时间,请求将被中止。
|
|
8
|
+
* 3. headers: 作用:设置默认的请求头,可以包含每个请求都需要的默认 headers。
|
|
9
|
+
* 4. paramsSerializer: 作用:定义对 params 的序列化处理函数,用于自定义序列化过程。
|
|
10
|
+
* 5. withCredentials: 作用:指示是否跨站点访问控制请求应该使用凭据(如 cookie 或授权头)。
|
|
11
|
+
* 6. transformRequest: 定义转换请求数据的函数。只能用于 POST、PUT、PATCH 方法,且 Content-Type 是 application/x-www-form-urlencoded, application/json 或 multipart/form-data。
|
|
12
|
+
* 7. transformResponse: 作用:定义转换响应数据的函数。这些函数会在数据被传递给 then 或 catch 之前调用。
|
|
13
|
+
* 8. validateStatus:作用:定义转换响应数据的函数。这些函数会在数据被传递给 then 或 catch 之前调用。
|
|
14
|
+
* 9. maxContentLength: 作用:指定接收响应数据的最大字节大小。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
var headers = {
|
|
18
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
19
|
+
'Cache-Control': 'no-cache',
|
|
20
|
+
'Content-Type': HEADER_CONTENT_TYPE_APPLICATION_JSON,
|
|
21
|
+
Accept: 'application/json;version=3.0;compress=false;'
|
|
22
|
+
};
|
|
23
|
+
export var defaultConfig = function defaultConfig() {
|
|
24
|
+
// const reqConfig = getCommonEnv<Window['__env__']['request']>('request');
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
method: 'get',
|
|
28
|
+
baseURL: '/',
|
|
29
|
+
withCredentials: true,
|
|
30
|
+
transformMethod: false,
|
|
31
|
+
timeout: 30 * 1000,
|
|
32
|
+
responseType: 'json',
|
|
33
|
+
maxContentLength: 1024 * 1024 * 1024,
|
|
34
|
+
filter: false,
|
|
35
|
+
cache: false,
|
|
36
|
+
overrideDefaultRequestInterceptor: false,
|
|
37
|
+
overrideDefaultResponseInterceptor: false
|
|
38
|
+
// gzip: reqConfig?.gzip ?? false,
|
|
39
|
+
// gzipThresholdSize: reqConfig?.gzipThresholdSize ?? 8000,
|
|
40
|
+
// base64: reqConfig?.base64 ?? false,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export { headers };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
declare const useHtAxios: ({ config, requestInterceptorsCallback, responseInterceptorOnSuccessCallback, responseInterceptorOnErrorCallback, }: {
|
|
3
|
+
config: AxiosRequestConfig;
|
|
4
|
+
requestInterceptorsCallback?: ((config: AxiosRequestConfig) => AxiosRequestConfig) | undefined;
|
|
5
|
+
responseInterceptorOnSuccessCallback?: ((response: AxiosResponse) => AxiosResponse) | undefined;
|
|
6
|
+
responseInterceptorOnErrorCallback?: ((error: any) => any) | undefined;
|
|
7
|
+
}) => {
|
|
8
|
+
get: <T, R>(url: string, data: T, config?: AxiosRequestConfig) => AxiosPromise<R>;
|
|
9
|
+
post: <T_1, R_1>(url: string, data?: T_1 | undefined, config?: AxiosRequestConfig) => AxiosPromise<R_1>;
|
|
10
|
+
del: <T_2, R_2>(url: string, data: T_2, config?: AxiosRequestConfig) => AxiosPromise<R_2>;
|
|
11
|
+
put: <T_3, R_3>(url: string, data?: T_3 | undefined, config?: AxiosRequestConfig) => AxiosPromise<R_3>;
|
|
12
|
+
};
|
|
13
|
+
export default useHtAxios;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
import { merge } from 'lodash-es';
|
|
9
|
+
import { defaultConfig } from "./defaultConfig";
|
|
10
|
+
import { requestInterceptorUse } from "./request.interceptor";
|
|
11
|
+
import { responseInterceptorUse } from "./response.interceptor";
|
|
12
|
+
var useHtAxios = function useHtAxios(_ref) {
|
|
13
|
+
var _ref$config = _ref.config,
|
|
14
|
+
config = _ref$config === void 0 ? {} : _ref$config,
|
|
15
|
+
requestInterceptorsCallback = _ref.requestInterceptorsCallback,
|
|
16
|
+
responseInterceptorOnSuccessCallback = _ref.responseInterceptorOnSuccessCallback,
|
|
17
|
+
responseInterceptorOnErrorCallback = _ref.responseInterceptorOnErrorCallback;
|
|
18
|
+
var mergeConfig = merge(defaultConfig(), config);
|
|
19
|
+
|
|
20
|
+
// 创建实例
|
|
21
|
+
var axiosClient = axios.create(mergeConfig);
|
|
22
|
+
requestInterceptorUse(axiosClient, requestInterceptorsCallback);
|
|
23
|
+
responseInterceptorUse(axiosClient, responseInterceptorOnSuccessCallback, responseInterceptorOnErrorCallback);
|
|
24
|
+
|
|
25
|
+
// 导出方法
|
|
26
|
+
function get(url, data, config) {
|
|
27
|
+
return axiosClient.request(_objectSpread({
|
|
28
|
+
url: url,
|
|
29
|
+
params: data
|
|
30
|
+
}, config));
|
|
31
|
+
}
|
|
32
|
+
function post(url, data, config) {
|
|
33
|
+
return axiosClient.request(_objectSpread({
|
|
34
|
+
url: url,
|
|
35
|
+
method: 'post',
|
|
36
|
+
params: data
|
|
37
|
+
}, config));
|
|
38
|
+
}
|
|
39
|
+
function put(url, data, config) {
|
|
40
|
+
return axiosClient.request(_objectSpread({
|
|
41
|
+
url: url,
|
|
42
|
+
method: 'put',
|
|
43
|
+
params: data
|
|
44
|
+
}, config));
|
|
45
|
+
}
|
|
46
|
+
function del(url, data, config) {
|
|
47
|
+
return axiosClient.request(_objectSpread({
|
|
48
|
+
url: url,
|
|
49
|
+
method: 'delete',
|
|
50
|
+
params: data
|
|
51
|
+
}, config));
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
get: get,
|
|
55
|
+
post: post,
|
|
56
|
+
del: del,
|
|
57
|
+
put: put
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export default useHtAxios;
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { HtRequestConfig } from './defaultConfig';
|
|
3
|
+
export declare const source: import("axios").CancelTokenSource;
|
|
4
|
+
export interface RequestInterceptorInterface {
|
|
5
|
+
(config: HtRequestConfig): HtRequestConfig;
|
|
6
|
+
}
|
|
7
|
+
export declare const requestInterceptor: RequestInterceptorInterface;
|
|
8
|
+
export declare const requestInterceptorUse: (axiosClient: AxiosInstance, requestInterceptorsCallback?: ((config: AxiosRequestConfig) => AxiosRequestConfig) | undefined) => void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import URI from 'urijs';
|
|
3
|
+
// import { addBase64ForConfig } from './interceptors/base64';
|
|
4
|
+
// import { addGzipForConfig } from './interceptors/gzip';
|
|
5
|
+
import { deepTrimData } from "./utils";
|
|
6
|
+
export var source = axios.CancelToken.source();
|
|
7
|
+
export var requestInterceptor = function requestInterceptor(config) {
|
|
8
|
+
config.cancelToken = source.token;
|
|
9
|
+
var uri = URI(config.url);
|
|
10
|
+
config.url = uri.query(deepTrimData(uri.query(true)) || {}).toString();
|
|
11
|
+
if (config.data) {
|
|
12
|
+
config.data = deepTrimData(config.data);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// params 处理
|
|
16
|
+
config.params = deepTrimData(config.params || {});
|
|
17
|
+
if (config.cache) {
|
|
18
|
+
config.params = config.params || {};
|
|
19
|
+
config.params.__cache__ = Math.random();
|
|
20
|
+
}
|
|
21
|
+
if (config.filter) {
|
|
22
|
+
var _config$data = config.data,
|
|
23
|
+
data = _config$data === void 0 ? {} : _config$data;
|
|
24
|
+
// 过滤假值
|
|
25
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
26
|
+
for (var key in data) {
|
|
27
|
+
if (data.hasOwnProperty(key)) {
|
|
28
|
+
var item = data[key];
|
|
29
|
+
if (item === null || item === undefined) {
|
|
30
|
+
delete data[key];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (config.method === 'get' && config.data) {
|
|
36
|
+
config.params = config.data;
|
|
37
|
+
delete config.data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// if (config.gzip) {
|
|
41
|
+
// addGzipForConfig(config, config.gzipThresholdSize);
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
// if (config.base64) {
|
|
45
|
+
// addBase64ForConfig(config);
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
return config;
|
|
49
|
+
};
|
|
50
|
+
export var requestInterceptorUse = function requestInterceptorUse(axiosClient, requestInterceptorsCallback) {
|
|
51
|
+
// 添加外部请求拦截器
|
|
52
|
+
if (requestInterceptorsCallback) {
|
|
53
|
+
// 添加请求拦截器
|
|
54
|
+
axiosClient.interceptors.request.use(function (config) {
|
|
55
|
+
return requestInterceptorsCallback(config);
|
|
56
|
+
}, function (error) {
|
|
57
|
+
return Promise.reject(error);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// 添加请求拦截器
|
|
61
|
+
axiosClient.interceptors.request.use(function (config) {
|
|
62
|
+
return requestInterceptor(config);
|
|
63
|
+
}, function (error) {
|
|
64
|
+
return Promise.reject(error);
|
|
65
|
+
});
|
|
66
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
+
import { HtRequestConfig } from './defaultConfig';
|
|
3
|
+
interface SelfResponse extends AxiosResponse {
|
|
4
|
+
config: HtRequestConfig;
|
|
5
|
+
}
|
|
6
|
+
export declare const responseInterceptorOnSuccess: (response: SelfResponse) => any;
|
|
7
|
+
export declare const responseInterceptorOnError: (error: any) => Promise<never> | undefined;
|
|
8
|
+
export declare const responseInterceptorUse: (axiosClient: AxiosInstance, responseInterceptorOnSuccessCallback?: ((response: AxiosResponse) => AxiosResponse) | undefined, responseInterceptorOnErrorCallback?: ((error: any) => any) | undefined) => void;
|
|
9
|
+
export {};
|