szld-libs 0.2.17 → 0.2.19

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
  }
@@ -0,0 +1,13 @@
1
+ interface RowSelectionProps {
2
+ dataSource: any[];
3
+ rowKey: string;
4
+ }
5
+ /**
6
+ * 表格跨页面多选
7
+ *
8
+ * @export
9
+ * @param {RowSelectionProps} props
10
+ * @return {*}
11
+ */
12
+ export default function useRowSelection(props: RowSelectionProps): any;
13
+ export {};
@@ -0,0 +1,35 @@
1
+ import { useRef, useState, useEffect } from "react";
2
+ function useRowSelection(props) {
3
+ const { dataSource, rowKey } = props;
4
+ const dataSourceRef = useRef([]);
5
+ const [selectedRows, setSelectedRows] = useState([]);
6
+ const [selectedKeys, setSelectedKeys] = useState([]);
7
+ useEffect(() => {
8
+ if (dataSource && dataSource.length > 0) {
9
+ const arr = [...dataSource, ...dataSourceRef.current];
10
+ dataSourceRef.current = arr.filter((item, index, self) => {
11
+ return self.findIndex((ele) => item[rowKey] === ele[rowKey]) === index;
12
+ });
13
+ }
14
+ }, [dataSource, rowKey]);
15
+ useEffect(() => {
16
+ if (dataSourceRef.current.length > 0) {
17
+ let list = [];
18
+ selectedKeys.forEach((key) => {
19
+ const target = dataSourceRef.current.find((v) => v[rowKey] === key);
20
+ if (target && !list.map((v) => v[rowKey]).includes(key)) {
21
+ list.push(target);
22
+ }
23
+ });
24
+ setSelectedRows(list);
25
+ }
26
+ }, [dataSourceRef.current, selectedKeys, rowKey]);
27
+ return {
28
+ selectedRows,
29
+ selectedKeys,
30
+ setSelectedKeys
31
+ };
32
+ }
33
+ export {
34
+ useRowSelection as default
35
+ };
package/es/main.d.ts CHANGED
@@ -14,5 +14,6 @@ import * as verfyCode from "./utils/verify-code";
14
14
  import useCaptcha from "./hooks/useCaptcha";
15
15
  import useChangePwd from "./hooks/useChangePwd";
16
16
  import useRemember from "./hooks/useRemember";
17
+ import useRowSelection from "./hooks/useRowSelection";
17
18
  import HmacSHA512 from './utils/hmacSHA512';
18
- export { AuthButton, BackHeader, CoralButton, CreateForm, EditTable, FormRules, HmacSHA512, SearchTable, UploadFile, download, fileType, showWorkFlow, useCaptcha, useChangePwd, useRemember, utils, verfyCode };
19
+ export { AuthButton, BackHeader, CoralButton, CreateForm, EditTable, FormRules, HmacSHA512, SearchTable, UploadFile, download, fileType, showWorkFlow, useCaptcha, useChangePwd, useRemember, useRowSelection, utils, verfyCode };
package/es/main.js CHANGED
@@ -14,7 +14,8 @@ import * as verifyCode from "./utils/verify-code";
14
14
  import { default as default10 } from "./hooks/useCaptcha";
15
15
  import { default as default11 } from "./hooks/useChangePwd";
16
16
  import { default as default12 } from "./hooks/useRemember";
17
- import { default as default13 } from "./utils/hmacSHA512";
17
+ import { default as default13 } from "./hooks/useRowSelection";
18
+ import { default as default14 } from "./utils/hmacSHA512";
18
19
  export {
19
20
  default7 as AuthButton,
20
21
  default2 as BackHeader,
@@ -22,7 +23,7 @@ export {
22
23
  default3 as CreateForm,
23
24
  default6 as EditTable,
24
25
  formRules as FormRules,
25
- default13 as HmacSHA512,
26
+ default14 as HmacSHA512,
26
27
  default4 as SearchTable,
27
28
  default5 as UploadFile,
28
29
  download,
@@ -31,6 +32,7 @@ export {
31
32
  default10 as useCaptcha,
32
33
  default11 as useChangePwd,
33
34
  default12 as useRemember,
35
+ default13 as useRowSelection,
34
36
  index as utils,
35
37
  verifyCode as verfyCode
36
38
  };
@@ -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
  }
@@ -0,0 +1,13 @@
1
+ interface RowSelectionProps {
2
+ dataSource: any[];
3
+ rowKey: string;
4
+ }
5
+ /**
6
+ * 表格跨页面多选
7
+ *
8
+ * @export
9
+ * @param {RowSelectionProps} props
10
+ * @return {*}
11
+ */
12
+ export default function useRowSelection(props: RowSelectionProps): any;
13
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ const react = require("react");
3
+ function useRowSelection(props) {
4
+ const { dataSource, rowKey } = props;
5
+ const dataSourceRef = react.useRef([]);
6
+ const [selectedRows, setSelectedRows] = react.useState([]);
7
+ const [selectedKeys, setSelectedKeys] = react.useState([]);
8
+ react.useEffect(() => {
9
+ if (dataSource && dataSource.length > 0) {
10
+ const arr = [...dataSource, ...dataSourceRef.current];
11
+ dataSourceRef.current = arr.filter((item, index, self) => {
12
+ return self.findIndex((ele) => item[rowKey] === ele[rowKey]) === index;
13
+ });
14
+ }
15
+ }, [dataSource, rowKey]);
16
+ react.useEffect(() => {
17
+ if (dataSourceRef.current.length > 0) {
18
+ let list = [];
19
+ selectedKeys.forEach((key) => {
20
+ const target = dataSourceRef.current.find((v) => v[rowKey] === key);
21
+ if (target && !list.map((v) => v[rowKey]).includes(key)) {
22
+ list.push(target);
23
+ }
24
+ });
25
+ setSelectedRows(list);
26
+ }
27
+ }, [dataSourceRef.current, selectedKeys, rowKey]);
28
+ return {
29
+ selectedRows,
30
+ selectedKeys,
31
+ setSelectedKeys
32
+ };
33
+ }
34
+ module.exports = useRowSelection;
package/lib/main.d.ts CHANGED
@@ -14,5 +14,6 @@ import * as verfyCode from "./utils/verify-code";
14
14
  import useCaptcha from "./hooks/useCaptcha";
15
15
  import useChangePwd from "./hooks/useChangePwd";
16
16
  import useRemember from "./hooks/useRemember";
17
+ import useRowSelection from "./hooks/useRowSelection";
17
18
  import HmacSHA512 from './utils/hmacSHA512';
18
- export { AuthButton, BackHeader, CoralButton, CreateForm, EditTable, FormRules, HmacSHA512, SearchTable, UploadFile, download, fileType, showWorkFlow, useCaptcha, useChangePwd, useRemember, utils, verfyCode };
19
+ export { AuthButton, BackHeader, CoralButton, CreateForm, EditTable, FormRules, HmacSHA512, SearchTable, UploadFile, download, fileType, showWorkFlow, useCaptcha, useChangePwd, useRemember, useRowSelection, utils, verfyCode };
package/lib/main.js CHANGED
@@ -16,6 +16,7 @@ const verifyCode = require("./utils/verify-code");
16
16
  const useCaptcha = require("./hooks/useCaptcha");
17
17
  const useChangePwd = require("./hooks/useChangePwd");
18
18
  const useRemember = require("./hooks/useRemember");
19
+ const useRowSelection = require("./hooks/useRowSelection");
19
20
  const hmacSHA512 = require("./utils/hmacSHA512");
20
21
  function _interopNamespaceDefault(e) {
21
22
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -54,4 +55,5 @@ exports.verfyCode = verifyCode__namespace;
54
55
  exports.useCaptcha = useCaptcha;
55
56
  exports.useChangePwd = useChangePwd;
56
57
  exports.useRemember = useRemember;
58
+ exports.useRowSelection = useRowSelection;
57
59
  exports.HmacSHA512 = hmacSHA512;
@@ -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.17",
4
+ "version": "0.2.19",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",