szld-libs 0.2.16 → 0.2.18

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.
@@ -3,18 +3,42 @@ import { SyncOutlined } from "@ant-design/icons";
3
3
  import { useRequest } from "ahooks";
4
4
  import { Button } from "antd";
5
5
  import _ from "lodash";
6
+ import { useMemo } from "react";
7
+ import { formatResponse } from "../utils/index";
6
8
  function useCaptcha(props) {
7
9
  const { imgKey = "Img" } = props;
8
- const { data, loading, error, refresh } = useRequest(props.request, {
10
+ const {
11
+ data: _data,
12
+ loading,
13
+ error,
14
+ refresh
15
+ } = useRequest(props.request, {
9
16
  debounceWait: 300,
10
17
  ready: true,
11
18
  retryCount: 3
12
19
  });
20
+ const data = useMemo(() => formatResponse(_data), [_data]);
13
21
  const renderCaptcha = () => {
14
22
  if (error) {
15
- return /* @__PURE__ */ jsx(Button, { type: "link", title: "验证码加载失败,请重试", icon: /* @__PURE__ */ jsx(SyncOutlined, {}), onClick: refresh, children: "点击重试" });
23
+ return /* @__PURE__ */ jsx(
24
+ Button,
25
+ {
26
+ type: "link",
27
+ title: "验证码加载失败,请重试",
28
+ icon: /* @__PURE__ */ jsx(SyncOutlined, {}),
29
+ onClick: refresh,
30
+ children: "点击重试"
31
+ }
32
+ );
16
33
  }
17
- return /* @__PURE__ */ jsx("img", { src: _.get(data, [imgKey]), style: { height: "100%", objectFit: "contain", cursor: "pointer" }, onClick: refresh });
34
+ return /* @__PURE__ */ jsx(
35
+ "img",
36
+ {
37
+ src: _.get(data, [imgKey]),
38
+ style: { height: "100%", objectFit: "contain", cursor: "pointer" },
39
+ onClick: refresh
40
+ }
41
+ );
18
42
  };
19
43
  return { data, renderCaptcha, loading, refresh };
20
44
  }
package/es/index.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { useState } from "react";
2
+ import { useEffect, useState } from "react";
3
3
  import ReactDOM from "react-dom/client";
4
4
  import { BrowserRouter } from "react-router-dom";
5
- import { EditTable } from "./main";
5
+ import { HmacSHA512, EditTable } from "./main";
6
6
  import { Form } from "antd";
7
7
  import "./utils/compression-file";
8
8
  const Demo = () => {
9
+ useEffect(() => {
10
+ new HmacSHA512("17283");
11
+ }, []);
9
12
  Form.useForm();
10
13
  const [list, setList] = useState([
11
14
  {
@@ -4,6 +4,7 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
+ import CryptoJS from "crypto-js";
7
8
  class HmacSHA512 {
8
9
  constructor(salt) {
9
10
  __publicField(this, "salt");
@@ -12,3 +12,4 @@ export declare const arrayDeduplication: (key: string, arr: any[]) => any[];
12
12
  export declare const JSONParse: (value: string) => any;
13
13
  export declare function uuid(): string;
14
14
  export declare const forceReload: () => void;
15
+ export declare const formatResponse: (res: any) => any;
package/es/utils/index.js CHANGED
@@ -111,11 +111,19 @@ const forceReload = () => {
111
111
  window.location.reload();
112
112
  }
113
113
  };
114
+ const formatResponse = (res) => {
115
+ if (typeof res === "string") {
116
+ const index = res.indexOf(",");
117
+ return JSON.parse(res.slice(index + 1));
118
+ }
119
+ return res;
120
+ };
114
121
  export {
115
122
  JSONParse,
116
123
  arrayDeduplication,
117
124
  filterObject,
118
125
  forceReload,
126
+ formatResponse,
119
127
  getBase64,
120
128
  getFileSuffix,
121
129
  getFileType,
@@ -4,18 +4,42 @@ const icons = require("@ant-design/icons");
4
4
  const ahooks = require("ahooks");
5
5
  const antd = require("antd");
6
6
  const _ = require("lodash");
7
+ const react = require("react");
8
+ const index = require("../utils/index");
7
9
  function useCaptcha(props) {
8
10
  const { imgKey = "Img" } = props;
9
- const { data, loading, error, refresh } = ahooks.useRequest(props.request, {
11
+ const {
12
+ data: _data,
13
+ loading,
14
+ error,
15
+ refresh
16
+ } = ahooks.useRequest(props.request, {
10
17
  debounceWait: 300,
11
18
  ready: true,
12
19
  retryCount: 3
13
20
  });
21
+ const data = react.useMemo(() => index.formatResponse(_data), [_data]);
14
22
  const renderCaptcha = () => {
15
23
  if (error) {
16
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "link", title: "验证码加载失败,请重试", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.SyncOutlined, {}), onClick: refresh, children: "点击重试" });
24
+ return /* @__PURE__ */ jsxRuntime.jsx(
25
+ antd.Button,
26
+ {
27
+ type: "link",
28
+ title: "验证码加载失败,请重试",
29
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.SyncOutlined, {}),
30
+ onClick: refresh,
31
+ children: "点击重试"
32
+ }
33
+ );
17
34
  }
18
- return /* @__PURE__ */ jsxRuntime.jsx("img", { src: _.get(data, [imgKey]), style: { height: "100%", objectFit: "contain", cursor: "pointer" }, onClick: refresh });
35
+ return /* @__PURE__ */ jsxRuntime.jsx(
36
+ "img",
37
+ {
38
+ src: _.get(data, [imgKey]),
39
+ style: { height: "100%", objectFit: "contain", cursor: "pointer" },
40
+ onClick: refresh
41
+ }
42
+ );
19
43
  };
20
44
  return { data, renderCaptcha, loading, refresh };
21
45
  }
package/lib/index.js CHANGED
@@ -7,6 +7,9 @@ const main = require("./main");
7
7
  const antd = require("antd");
8
8
  require("./utils/compression-file");
9
9
  const Demo = () => {
10
+ react.useEffect(() => {
11
+ new main.HmacSHA512("17283");
12
+ }, []);
10
13
  antd.Form.useForm();
11
14
  const [list, setList] = react.useState([
12
15
  {
@@ -5,6 +5,7 @@ var __publicField = (obj, key, value) => {
5
5
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
6
  return value;
7
7
  };
8
+ const CryptoJS = require("crypto-js");
8
9
  class HmacSHA512 {
9
10
  constructor(salt) {
10
11
  __publicField(this, "salt");
@@ -12,3 +12,4 @@ export declare const arrayDeduplication: (key: string, arr: any[]) => any[];
12
12
  export declare const JSONParse: (value: string) => any;
13
13
  export declare function uuid(): string;
14
14
  export declare const forceReload: () => void;
15
+ export declare const formatResponse: (res: any) => any;
@@ -113,10 +113,18 @@ const forceReload = () => {
113
113
  window.location.reload();
114
114
  }
115
115
  };
116
+ const formatResponse = (res) => {
117
+ if (typeof res === "string") {
118
+ const index = res.indexOf(",");
119
+ return JSON.parse(res.slice(index + 1));
120
+ }
121
+ return res;
122
+ };
116
123
  exports.JSONParse = JSONParse;
117
124
  exports.arrayDeduplication = arrayDeduplication;
118
125
  exports.filterObject = filterObject;
119
126
  exports.forceReload = forceReload;
127
+ exports.formatResponse = formatResponse;
120
128
  exports.getBase64 = getBase64;
121
129
  exports.getFileSuffix = getFileSuffix;
122
130
  exports.getFileType = getFileType;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "szld-libs",
3
3
  "private": false,
4
- "version": "0.2.16",
4
+ "version": "0.2.18",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",