ls-pro-common 1.0.59 → 1.0.61

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.
@@ -32,6 +32,10 @@ export declare type DtlLyaoutProps = Record<string, any> & {
32
32
  headerStyle?: React.CSSProperties;
33
33
  /** 表单ref */
34
34
  formRef?: React.MutableRefObject<ProFormInstance | undefined>;
35
+ /**状态字段 */
36
+ statusField?: string;
37
+ /** 审核状态值 */
38
+ auditStatus?: number;
35
39
  };
36
40
  declare function DtlLayout(props: DtlLyaoutProps): JSX.Element;
37
41
  export default DtlLayout;
@@ -2,12 +2,12 @@ import "antd/es/button/style";
2
2
  import _Button from "antd/es/button";
3
3
  import React, { useMemo } from 'react';
4
4
  import classNames from 'classnames';
5
- import { ArrowLeftOutlined, SaveOutlined, CheckOutlined } from '@ant-design/icons';
5
+ import { ArrowLeftOutlined, SaveOutlined, AuditOutlined } from '@ant-design/icons';
6
6
  import './common.less';
7
+ import usePermission from '../hooks/usePermission';
7
8
 
8
9
  function DtlLayout(props) {
9
- var renderButton = props.renderButton,
10
- title = props.title,
10
+ var title = props.title,
11
11
  _props$keyField = props.keyField,
12
12
  keyField = _props$keyField === void 0 ? 'id' : _props$keyField,
13
13
  masterObject = props.masterObject,
@@ -21,49 +21,78 @@ function DtlLayout(props) {
21
21
  btnSaveText = _props$btnSaveText === void 0 ? '保存' : _props$btnSaveText,
22
22
  _props$btnExitText = props.btnExitText,
23
23
  btnExitText = _props$btnExitText === void 0 ? '返回' : _props$btnExitText,
24
- btnStatus = props.btnStatus;
24
+ btnStatus = props.btnStatus,
25
+ statusField = props.statusField,
26
+ auditStatus = props.auditStatus;
27
+
28
+ var _usePermission = usePermission(),
29
+ checkRight = _usePermission.checkRight;
30
+
25
31
  var dtlTitle = useMemo(function () {
26
32
  if (title) return title;
27
33
  if (!masterObject) return '';
28
34
  return masterObject[keyField] ? '编辑' : '新增';
29
35
  }, [title, masterObject, keyField]);
30
- var btns = useMemo(function () {
31
- var b = [/*#__PURE__*/React.createElement(_Button, {
32
- key: "btnSave",
33
- onClick: function onClick() {
34
- var _formRef$current;
35
36
 
36
- if (props.onSave) {
37
- return props.onSave();
38
- }
37
+ var isAudit = function isAudit() {
38
+ if (masterObject && statusField && auditStatus) {
39
+ return Number(masterObject[statusField] || 0) >= auditStatus;
40
+ }
39
41
 
40
- formRef === null || formRef === void 0 ? void 0 : (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.submit();
41
- },
42
- disabled: btnStatus ? btnStatus('btnSave') || false : false,
43
- icon: /*#__PURE__*/React.createElement(SaveOutlined, null)
44
- }, btnSaveText), /*#__PURE__*/React.createElement(_Button, {
42
+ return false;
43
+ };
44
+
45
+ var btnDisabled = function btnDisabled(btnKey) {
46
+ // 优先处理自定义的状态
47
+ if (btnStatus && typeof btnStatus(btnKey) === 'boolean') {
48
+ return btnStatus(btnKey) || false;
49
+ }
50
+
51
+ return isAudit();
52
+ };
53
+
54
+ var btns = useMemo(function () {
55
+ var b = [/*#__PURE__*/React.createElement(_Button, {
45
56
  key: "btnBack",
46
57
  onClick: function onClick() {
47
58
  return props.onExit(false);
48
59
  },
49
60
  icon: /*#__PURE__*/React.createElement(ArrowLeftOutlined, null)
50
- }, btnExitText)];
61
+ }, btnExitText)]; // 有新增或更改权限且未审核,开放出保存按钮
62
+
63
+ if ((checkRight(2) || checkRight(4)) && !isAudit()) {
64
+ b.unshift( /*#__PURE__*/React.createElement(_Button, {
65
+ key: "btnSave",
66
+ onClick: function onClick() {
67
+ var _formRef$current;
68
+
69
+ if (props.onSave) {
70
+ return props.onSave();
71
+ }
72
+
73
+ formRef === null || formRef === void 0 ? void 0 : (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.submit();
74
+ },
75
+ disabled: btnDisabled('btnSave'),
76
+ icon: /*#__PURE__*/React.createElement(SaveOutlined, null)
77
+ }, btnSaveText));
78
+ } // 转入onAudit方法且有审核权限,数据未审核,开放出审核按钮
79
+
51
80
 
52
- if (props.onAudit) {
81
+ if (props.onAudit && checkRight(64) && !isAudit()) {
53
82
  b.unshift( /*#__PURE__*/React.createElement(_Button, {
54
83
  key: "btnAudit",
55
- disabled: btnStatus ? btnStatus('btnAudit') || false : false,
84
+ disabled: btnDisabled('btnAudit'),
56
85
  onClick: function onClick() {
57
86
  if (!props.onAudit) return;
58
87
  props.onAudit();
59
88
  },
60
- icon: /*#__PURE__*/React.createElement(CheckOutlined, null)
89
+ icon: /*#__PURE__*/React.createElement(AuditOutlined, null)
61
90
  }, "\u5BA1\u6838"));
62
91
  }
63
92
 
93
+ if (props.renderButton) return props.renderButton(b);
64
94
  return b;
65
95
  }, [props]);
66
- var buttons = renderButton ? renderButton(btns) : btns;
67
96
  return /*#__PURE__*/React.createElement("div", {
68
97
  className: "dtl-layout"
69
98
  }, /*#__PURE__*/React.createElement("div", {
@@ -73,7 +102,7 @@ function DtlLayout(props) {
73
102
  className: "dtl-title"
74
103
  }, dtlTitle), /*#__PURE__*/React.createElement("div", {
75
104
  className: "dtl-btns"
76
- }, buttons)), /*#__PURE__*/React.createElement("div", {
105
+ }, btns)), /*#__PURE__*/React.createElement("div", {
77
106
  className: classNames('dtl-body', bodyClass),
78
107
  style: bodyStyle
79
108
  }, children));
@@ -11,6 +11,7 @@ import { useState, useRef, useCallback, useMemo } from 'react';
11
11
  import { PlusCircleOutlined, EditOutlined, DeleteOutlined, ImportOutlined, ExportOutlined } from '@ant-design/icons';
12
12
  import { showConfirm, showWarn, showError, showSuccess } from '../../utils';
13
13
  import { httpPost } from '../../http';
14
+ import usePermission from '../usePermission';
14
15
 
15
16
  function useDtl(dtlParam) {
16
17
  var mstService = dtlParam.service,
@@ -33,8 +34,16 @@ function useDtl(dtlParam) {
33
34
  btnStatus = dtlParam.btnStatus,
34
35
  beforeAudit = dtlParam.beforeAudit,
35
36
  afterAudit = dtlParam.afterAudit;
37
+
38
+ var _usePermission = usePermission(),
39
+ canAdd = _usePermission.canAdd,
40
+ canEdit = _usePermission.canEdit,
41
+ canDelete = _usePermission.canDelete,
42
+ canImport = _usePermission.canImport,
43
+ canExport = _usePermission.canExport;
36
44
  /** @name 选中行数据 */
37
45
 
46
+
38
47
  var _useState = useState([]),
39
48
  _useState2 = _slicedToArray(_useState, 2),
40
49
  selectedRows = _useState2[0],
@@ -962,21 +971,21 @@ function useDtl(dtlParam) {
962
971
  };
963
972
 
964
973
  var tableTools = useMemo(function () {
965
- return [(toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) && !isAudit() ? /*#__PURE__*/React.createElement(_Button, {
974
+ return [(toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) && !isAudit() && canAdd ? /*#__PURE__*/React.createElement(_Button, {
966
975
  key: "add",
967
976
  onClick: function onClick() {
968
977
  return onAddDtl();
969
978
  },
970
979
  disabled: btnDisabled('add'),
971
980
  icon: /*#__PURE__*/React.createElement(PlusCircleOutlined, null)
972
- }, "\u65B0\u589E") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.edit) && !isAudit() ? /*#__PURE__*/React.createElement(_Button, {
981
+ }, "\u65B0\u589E") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.edit) && !isAudit() && (canAdd || canEdit) ? /*#__PURE__*/React.createElement(_Button, {
973
982
  key: "edit",
974
983
  disabled: btnDisabled('edit'),
975
984
  onClick: function onClick() {
976
985
  return onEditDtl();
977
986
  },
978
987
  icon: /*#__PURE__*/React.createElement(EditOutlined, null)
979
- }, "\u7F16\u8F91") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.remove) && !isAudit() ? /*#__PURE__*/React.createElement(_Button, {
988
+ }, "\u7F16\u8F91") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.remove) && !isAudit() && (canAdd || canEdit || canDelete) ? /*#__PURE__*/React.createElement(_Button, {
980
989
  key: "remove",
981
990
  onClick: function onClick() {
982
991
  return onRemoveDtl();
@@ -984,14 +993,14 @@ function useDtl(dtlParam) {
984
993
  danger: true,
985
994
  disabled: btnDisabled('remove'),
986
995
  icon: /*#__PURE__*/React.createElement(DeleteOutlined, null)
987
- }, "\u5220\u9664") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) ? /*#__PURE__*/React.createElement(_Button, {
996
+ }, "\u5220\u9664") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) && !isAudit() && (canAdd || canEdit || canImport) ? /*#__PURE__*/React.createElement(_Button, {
988
997
  key: "import",
989
998
  onClick: function onClick() {
990
999
  onImport();
991
1000
  },
992
1001
  disabled: btnDisabled('import'),
993
1002
  icon: /*#__PURE__*/React.createElement(ImportOutlined, null)
994
- }, "\u5BFC\u5165") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) ? /*#__PURE__*/React.createElement(_Button, {
1003
+ }, "\u5BFC\u5165") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) && canExport ? /*#__PURE__*/React.createElement(_Button, {
995
1004
  key: "export",
996
1005
  onClick: function onClick() {
997
1006
  onExport();
@@ -1001,7 +1010,7 @@ function useDtl(dtlParam) {
1001
1010
  }, "\u5BFC\u51FA") : false].filter(function (o) {
1002
1011
  return o !== false;
1003
1012
  });
1004
- }, [selectedRows]);
1013
+ }, [selectedRows, auditStatus, statusField, masterObject]);
1005
1014
  return {
1006
1015
  formRef: formRef,
1007
1016
  tableRef: tableRef,
@@ -3,5 +3,12 @@ declare function usePermission(): {
3
3
  permissionVal: number;
4
4
  resRightVal: number;
5
5
  checkRight: (val: number) => boolean;
6
+ canAdd: boolean;
7
+ canEdit: boolean;
8
+ canDelete: boolean;
9
+ canAudit: boolean;
10
+ canImport: boolean;
11
+ canExport: boolean;
12
+ canPrint: boolean;
6
13
  };
7
14
  export default usePermission;
@@ -4,7 +4,7 @@ import { getUrlQuery, getResourceProps, getCache } from '../../utils';
4
4
  function usePermission() {
5
5
  /** @name 资源ID */
6
6
  var resourceId = useMemo(function () {
7
- return getUrlQuery('resCode') || getResourceProps('resourceId');
7
+ return getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId');
8
8
  }, []);
9
9
  /** @name 用户权限 */
10
10
 
@@ -30,7 +30,14 @@ function usePermission() {
30
30
  resourceId: resourceId,
31
31
  permissionVal: permissionVal,
32
32
  resRightVal: resRightVal,
33
- checkRight: checkRight
33
+ checkRight: checkRight,
34
+ canAdd: checkRight(2),
35
+ canEdit: checkRight(4),
36
+ canDelete: checkRight(8) || checkRight(32),
37
+ canAudit: checkRight(64),
38
+ canImport: checkRight(128),
39
+ canExport: checkRight(256),
40
+ canPrint: checkRight(512)
34
41
  };
35
42
  }
36
43
 
@@ -24,7 +24,13 @@ import usePermission from '../usePermission';
24
24
  function useSingle(inParam) {
25
25
  var _usePermission = usePermission(),
26
26
  resourceId = _usePermission.resourceId,
27
- checkRight = _usePermission.checkRight;
27
+ checkRight = _usePermission.checkRight,
28
+ canAdd = _usePermission.canAdd,
29
+ canEdit = _usePermission.canEdit,
30
+ canDelete = _usePermission.canDelete,
31
+ canAudit = _usePermission.canAudit,
32
+ canImport = _usePermission.canImport,
33
+ canExport = _usePermission.canExport;
28
34
 
29
35
  var service = inParam.service,
30
36
  toolConfig = inParam.toolConfig,
@@ -712,21 +718,21 @@ function useSingle(inParam) {
712
718
  }, [auditStatus, statusField, selectedRows]); // 处理内置 table 按钮,新增,编辑,删除,审核,导入,导出
713
719
 
714
720
  var tableTools = useMemo(function () {
715
- return [(toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) && checkRight(2) ? /*#__PURE__*/React.createElement(_Button, {
721
+ return [(toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) && canAdd ? /*#__PURE__*/React.createElement(_Button, {
716
722
  key: "add",
717
723
  onClick: function onClick() {
718
724
  return onAdd(null);
719
725
  },
720
726
  disabled: btnDisabled('add'),
721
727
  icon: /*#__PURE__*/React.createElement(PlusCircleOutlined, null)
722
- }, "\u65B0\u589E") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.edit) && checkRight(4) ? /*#__PURE__*/React.createElement(_Button, {
728
+ }, "\u65B0\u589E") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.edit) && canEdit ? /*#__PURE__*/React.createElement(_Button, {
723
729
  key: "edit",
724
730
  disabled: btnDisabled('edit'),
725
731
  onClick: function onClick() {
726
732
  return onEdit(null);
727
733
  },
728
734
  icon: /*#__PURE__*/React.createElement(EditOutlined, null)
729
- }, "\u7F16\u8F91") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.remove) && (checkRight(8) || checkRight(32)) ? /*#__PURE__*/React.createElement(_Button, {
735
+ }, "\u7F16\u8F91") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.remove) && canDelete ? /*#__PURE__*/React.createElement(_Button, {
730
736
  key: "remove",
731
737
  onClick: function onClick() {
732
738
  return onRemove(null);
@@ -734,14 +740,14 @@ function useSingle(inParam) {
734
740
  danger: true,
735
741
  disabled: btnDisabled('remove'),
736
742
  icon: /*#__PURE__*/React.createElement(DeleteOutlined, null)
737
- }, "\u5220\u9664") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.audit) && checkRight(64) ? /*#__PURE__*/React.createElement(_Button, {
743
+ }, "\u5220\u9664") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.audit) && canAudit ? /*#__PURE__*/React.createElement(_Button, {
738
744
  key: "audit",
739
745
  onClick: function onClick() {
740
746
  return onAudit(null);
741
747
  },
742
748
  disabled: btnDisabled('audit'),
743
749
  icon: /*#__PURE__*/React.createElement(AuditOutlined, null)
744
- }, "\u5BA1\u6838") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) && checkRight(128) ? /*#__PURE__*/React.createElement(_Button, {
750
+ }, "\u5BA1\u6838") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) && canImport ? /*#__PURE__*/React.createElement(_Button, {
745
751
  key: "import",
746
752
  onClick: function onClick() {
747
753
  var _tableRef$current2, _tableRef$current2$sh;
@@ -750,7 +756,7 @@ function useSingle(inParam) {
750
756
  },
751
757
  disabled: btnDisabled('import'),
752
758
  icon: /*#__PURE__*/React.createElement(ImportOutlined, null)
753
- }, "\u5BFC\u5165") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) && checkRight(256) ? /*#__PURE__*/React.createElement(_Button, {
759
+ }, "\u5BFC\u5165") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) && canExport ? /*#__PURE__*/React.createElement(_Button, {
754
760
  key: "export",
755
761
  onClick: function onClick() {
756
762
  var _tableRef$current3, _tableRef$current3$sh;
package/es/http/index.js CHANGED
@@ -14,7 +14,7 @@ request.interceptors.request.use(function (url, options) {
14
14
 
15
15
  var opts = _objectSpread({}, options);
16
16
 
17
- if (token) {
17
+ if (token && url.indexOf('noToken=1') === -1) {
18
18
  Object.assign(opts, {
19
19
  headers: {
20
20
  token: token
@@ -22,6 +22,7 @@ request.interceptors.request.use(function (url, options) {
22
22
  });
23
23
  }
24
24
 
25
+ url = url.replace('noToken=1', '').replace('&&', '&').replace('?&', '?');
25
26
  var param = {
26
27
  resCode: getUrlQuery('resCode') || getUrlQuery('resourceId') || getResourceProps('resourceId'),
27
28
  _t1: Date.now()
@@ -66,7 +66,7 @@ export declare const getCookie: (name: string) => string | null;
66
66
  * @param {*} value Cookie 值
67
67
  * @param { Number } day 有效天数 默认1天,
68
68
  */
69
- export declare const setCookie: (key: string, value: string | number, day?: number) => void;
69
+ export declare const setCookie: (key: string, value: string | number, day?: number, sameSite?: boolean) => void;
70
70
  /**
71
71
  * 判断是否登录
72
72
  * @returns
@@ -86,6 +86,12 @@ export declare const setCache: (key: string, data: any, session?: boolean) => vo
86
86
  * @returns 关键字对应的值
87
87
  */
88
88
  export declare const getCache: (key: string, session?: boolean) => string | null;
89
+ /**
90
+ *
91
+ * @param key 关键字,不传清除所有
92
+ * @param session 是否session storage , 默认 localStorage
93
+ */
94
+ export declare const clearCache: (key?: string | undefined, session?: boolean) => void;
89
95
  /** @name 显示错误 */
90
96
  export declare const showError: (text: string) => void;
91
97
  /** @name 显示警示 */
package/es/utils/index.js CHANGED
@@ -145,12 +145,22 @@ export var getCookie = function getCookie(name) {
145
145
 
146
146
  export var setCookie = function setCookie(key, value) {
147
147
  var day = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
148
+ var sameSite = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
148
149
 
149
150
  if (day !== 0) {
150
151
  var d = new Date(Date.now() + day * 24 * 60 * 60 * 1000);
151
- document.cookie = "".concat(key, "=").concat(value, ";expires=").concat(d.toUTCString(), ";path=/");
152
+
153
+ if (sameSite) {
154
+ document.cookie = "".concat(key, "=").concat(value, ";expires=").concat(d.toUTCString(), ";path=/;sameSite=None;secure=true");
155
+ } else {
156
+ document.cookie = "".concat(key, "=").concat(value, ";expires=").concat(d.toUTCString(), ";path=/");
157
+ }
152
158
  } else {
153
- document.cookie = key + "=" + value + ";path=/";
159
+ if (sameSite) {
160
+ document.cookie = key + "=" + value + ";path=/;sameSite=None;secure=true";
161
+ } else {
162
+ document.cookie = key + "=" + value + ";path=/";
163
+ }
154
164
  }
155
165
  };
156
166
  /**
@@ -194,6 +204,21 @@ export var getCache = function getCache(key) {
194
204
 
195
205
  return data;
196
206
  };
207
+ /**
208
+ *
209
+ * @param key 关键字,不传清除所有
210
+ * @param session 是否session storage , 默认 localStorage
211
+ */
212
+
213
+ export var clearCache = function clearCache(key) {
214
+ var session = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
215
+
216
+ if (key) {
217
+ session ? sessionStorage.removeItem(key) : localStorage.removeItem(key);
218
+ } else {
219
+ session ? sessionStorage.clear() : localStorage.clear();
220
+ }
221
+ };
197
222
  /** @name 显示错误 */
198
223
 
199
224
  export var showError = function showError(text) {
@@ -245,7 +270,7 @@ export var reLogin = function reLogin() {
245
270
  maskClosable: false,
246
271
  afterClose: function afterClose() {
247
272
  timeout = false;
248
- location.href = '/login?redirect=' + encodeURI(location.href);
273
+ location.href = location.pathname === '/' ? '/login' : '/login?redirect=' + encodeURI(location.href);
249
274
  }
250
275
  });
251
276
  };
@@ -32,6 +32,10 @@ export declare type DtlLyaoutProps = Record<string, any> & {
32
32
  headerStyle?: React.CSSProperties;
33
33
  /** 表单ref */
34
34
  formRef?: React.MutableRefObject<ProFormInstance | undefined>;
35
+ /**状态字段 */
36
+ statusField?: string;
37
+ /** 审核状态值 */
38
+ auditStatus?: number;
35
39
  };
36
40
  declare function DtlLayout(props: DtlLyaoutProps): JSX.Element;
37
41
  export default DtlLayout;
@@ -21,9 +21,10 @@ var _icons = require("@ant-design/icons");
21
21
 
22
22
  require("./common.less");
23
23
 
24
+ var _usePermission2 = _interopRequireDefault(require("../hooks/usePermission"));
25
+
24
26
  function DtlLayout(props) {
25
- var renderButton = props.renderButton,
26
- title = props.title,
27
+ var title = props.title,
27
28
  _props$keyField = props.keyField,
28
29
  keyField = _props$keyField === void 0 ? 'id' : _props$keyField,
29
30
  masterObject = props.masterObject,
@@ -37,49 +38,78 @@ function DtlLayout(props) {
37
38
  btnSaveText = _props$btnSaveText === void 0 ? '保存' : _props$btnSaveText,
38
39
  _props$btnExitText = props.btnExitText,
39
40
  btnExitText = _props$btnExitText === void 0 ? '返回' : _props$btnExitText,
40
- btnStatus = props.btnStatus;
41
+ btnStatus = props.btnStatus,
42
+ statusField = props.statusField,
43
+ auditStatus = props.auditStatus;
44
+
45
+ var _usePermission = (0, _usePermission2.default)(),
46
+ checkRight = _usePermission.checkRight;
47
+
41
48
  var dtlTitle = (0, _react.useMemo)(function () {
42
49
  if (title) return title;
43
50
  if (!masterObject) return '';
44
51
  return masterObject[keyField] ? '编辑' : '新增';
45
52
  }, [title, masterObject, keyField]);
46
- var btns = (0, _react.useMemo)(function () {
47
- var b = [/*#__PURE__*/_react.default.createElement(_button.default, {
48
- key: "btnSave",
49
- onClick: function onClick() {
50
- var _formRef$current;
51
53
 
52
- if (props.onSave) {
53
- return props.onSave();
54
- }
54
+ var isAudit = function isAudit() {
55
+ if (masterObject && statusField && auditStatus) {
56
+ return Number(masterObject[statusField] || 0) >= auditStatus;
57
+ }
55
58
 
56
- formRef === null || formRef === void 0 ? void 0 : (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.submit();
57
- },
58
- disabled: btnStatus ? btnStatus('btnSave') || false : false,
59
- icon: /*#__PURE__*/_react.default.createElement(_icons.SaveOutlined, null)
60
- }, btnSaveText), /*#__PURE__*/_react.default.createElement(_button.default, {
59
+ return false;
60
+ };
61
+
62
+ var btnDisabled = function btnDisabled(btnKey) {
63
+ // 优先处理自定义的状态
64
+ if (btnStatus && typeof btnStatus(btnKey) === 'boolean') {
65
+ return btnStatus(btnKey) || false;
66
+ }
67
+
68
+ return isAudit();
69
+ };
70
+
71
+ var btns = (0, _react.useMemo)(function () {
72
+ var b = [/*#__PURE__*/_react.default.createElement(_button.default, {
61
73
  key: "btnBack",
62
74
  onClick: function onClick() {
63
75
  return props.onExit(false);
64
76
  },
65
77
  icon: /*#__PURE__*/_react.default.createElement(_icons.ArrowLeftOutlined, null)
66
- }, btnExitText)];
78
+ }, btnExitText)]; // 有新增或更改权限且未审核,开放出保存按钮
79
+
80
+ if ((checkRight(2) || checkRight(4)) && !isAudit()) {
81
+ b.unshift( /*#__PURE__*/_react.default.createElement(_button.default, {
82
+ key: "btnSave",
83
+ onClick: function onClick() {
84
+ var _formRef$current;
85
+
86
+ if (props.onSave) {
87
+ return props.onSave();
88
+ }
89
+
90
+ formRef === null || formRef === void 0 ? void 0 : (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.submit();
91
+ },
92
+ disabled: btnDisabled('btnSave'),
93
+ icon: /*#__PURE__*/_react.default.createElement(_icons.SaveOutlined, null)
94
+ }, btnSaveText));
95
+ } // 转入onAudit方法且有审核权限,数据未审核,开放出审核按钮
96
+
67
97
 
68
- if (props.onAudit) {
98
+ if (props.onAudit && checkRight(64) && !isAudit()) {
69
99
  b.unshift( /*#__PURE__*/_react.default.createElement(_button.default, {
70
100
  key: "btnAudit",
71
- disabled: btnStatus ? btnStatus('btnAudit') || false : false,
101
+ disabled: btnDisabled('btnAudit'),
72
102
  onClick: function onClick() {
73
103
  if (!props.onAudit) return;
74
104
  props.onAudit();
75
105
  },
76
- icon: /*#__PURE__*/_react.default.createElement(_icons.CheckOutlined, null)
106
+ icon: /*#__PURE__*/_react.default.createElement(_icons.AuditOutlined, null)
77
107
  }, "\u5BA1\u6838"));
78
108
  }
79
109
 
110
+ if (props.renderButton) return props.renderButton(b);
80
111
  return b;
81
112
  }, [props]);
82
- var buttons = renderButton ? renderButton(btns) : btns;
83
113
  return /*#__PURE__*/_react.default.createElement("div", {
84
114
  className: "dtl-layout"
85
115
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -89,7 +119,7 @@ function DtlLayout(props) {
89
119
  className: "dtl-title"
90
120
  }, dtlTitle), /*#__PURE__*/_react.default.createElement("div", {
91
121
  className: "dtl-btns"
92
- }, buttons)), /*#__PURE__*/_react.default.createElement("div", {
122
+ }, btns)), /*#__PURE__*/_react.default.createElement("div", {
93
123
  className: (0, _classnames.default)('dtl-body', bodyClass),
94
124
  style: bodyStyle
95
125
  }, children));
@@ -31,6 +31,8 @@ var _utils = require("../../utils");
31
31
 
32
32
  var _http = require("../../http");
33
33
 
34
+ var _usePermission2 = _interopRequireDefault(require("../usePermission"));
35
+
34
36
  var _excluded = ["current", "pageSize"];
35
37
 
36
38
  function useDtl(dtlParam) {
@@ -54,8 +56,16 @@ function useDtl(dtlParam) {
54
56
  btnStatus = dtlParam.btnStatus,
55
57
  beforeAudit = dtlParam.beforeAudit,
56
58
  afterAudit = dtlParam.afterAudit;
59
+
60
+ var _usePermission = (0, _usePermission2.default)(),
61
+ canAdd = _usePermission.canAdd,
62
+ canEdit = _usePermission.canEdit,
63
+ canDelete = _usePermission.canDelete,
64
+ canImport = _usePermission.canImport,
65
+ canExport = _usePermission.canExport;
57
66
  /** @name 选中行数据 */
58
67
 
68
+
59
69
  var _useState = (0, _react.useState)([]),
60
70
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
61
71
  selectedRows = _useState2[0],
@@ -983,21 +993,21 @@ function useDtl(dtlParam) {
983
993
  };
984
994
 
985
995
  var tableTools = (0, _react.useMemo)(function () {
986
- return [(toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) && !isAudit() ? /*#__PURE__*/_react.default.createElement(_button.default, {
996
+ return [(toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) && !isAudit() && canAdd ? /*#__PURE__*/_react.default.createElement(_button.default, {
987
997
  key: "add",
988
998
  onClick: function onClick() {
989
999
  return onAddDtl();
990
1000
  },
991
1001
  disabled: btnDisabled('add'),
992
1002
  icon: /*#__PURE__*/_react.default.createElement(_icons.PlusCircleOutlined, null)
993
- }, "\u65B0\u589E") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.edit) && !isAudit() ? /*#__PURE__*/_react.default.createElement(_button.default, {
1003
+ }, "\u65B0\u589E") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.edit) && !isAudit() && (canAdd || canEdit) ? /*#__PURE__*/_react.default.createElement(_button.default, {
994
1004
  key: "edit",
995
1005
  disabled: btnDisabled('edit'),
996
1006
  onClick: function onClick() {
997
1007
  return onEditDtl();
998
1008
  },
999
1009
  icon: /*#__PURE__*/_react.default.createElement(_icons.EditOutlined, null)
1000
- }, "\u7F16\u8F91") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.remove) && !isAudit() ? /*#__PURE__*/_react.default.createElement(_button.default, {
1010
+ }, "\u7F16\u8F91") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.remove) && !isAudit() && (canAdd || canEdit || canDelete) ? /*#__PURE__*/_react.default.createElement(_button.default, {
1001
1011
  key: "remove",
1002
1012
  onClick: function onClick() {
1003
1013
  return onRemoveDtl();
@@ -1005,14 +1015,14 @@ function useDtl(dtlParam) {
1005
1015
  danger: true,
1006
1016
  disabled: btnDisabled('remove'),
1007
1017
  icon: /*#__PURE__*/_react.default.createElement(_icons.DeleteOutlined, null)
1008
- }, "\u5220\u9664") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) ? /*#__PURE__*/_react.default.createElement(_button.default, {
1018
+ }, "\u5220\u9664") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) && !isAudit() && (canAdd || canEdit || canImport) ? /*#__PURE__*/_react.default.createElement(_button.default, {
1009
1019
  key: "import",
1010
1020
  onClick: function onClick() {
1011
1021
  onImport();
1012
1022
  },
1013
1023
  disabled: btnDisabled('import'),
1014
1024
  icon: /*#__PURE__*/_react.default.createElement(_icons.ImportOutlined, null)
1015
- }, "\u5BFC\u5165") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) ? /*#__PURE__*/_react.default.createElement(_button.default, {
1025
+ }, "\u5BFC\u5165") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) && canExport ? /*#__PURE__*/_react.default.createElement(_button.default, {
1016
1026
  key: "export",
1017
1027
  onClick: function onClick() {
1018
1028
  onExport();
@@ -1022,7 +1032,7 @@ function useDtl(dtlParam) {
1022
1032
  }, "\u5BFC\u51FA") : false].filter(function (o) {
1023
1033
  return o !== false;
1024
1034
  });
1025
- }, [selectedRows]);
1035
+ }, [selectedRows, auditStatus, statusField, masterObject]);
1026
1036
  return {
1027
1037
  formRef: formRef,
1028
1038
  tableRef: tableRef,
@@ -3,5 +3,12 @@ declare function usePermission(): {
3
3
  permissionVal: number;
4
4
  resRightVal: number;
5
5
  checkRight: (val: number) => boolean;
6
+ canAdd: boolean;
7
+ canEdit: boolean;
8
+ canDelete: boolean;
9
+ canAudit: boolean;
10
+ canImport: boolean;
11
+ canExport: boolean;
12
+ canPrint: boolean;
6
13
  };
7
14
  export default usePermission;
@@ -12,7 +12,7 @@ var _utils = require("../../utils");
12
12
  function usePermission() {
13
13
  /** @name 资源ID */
14
14
  var resourceId = (0, _react.useMemo)(function () {
15
- return (0, _utils.getUrlQuery)('resCode') || (0, _utils.getResourceProps)('resourceId');
15
+ return (0, _utils.getUrlQuery)('resCode') || (0, _utils.getUrlQuery)('resourceId') || (0, _utils.getResourceProps)('resourceId');
16
16
  }, []);
17
17
  /** @name 用户权限 */
18
18
 
@@ -38,7 +38,14 @@ function usePermission() {
38
38
  resourceId: resourceId,
39
39
  permissionVal: permissionVal,
40
40
  resRightVal: resRightVal,
41
- checkRight: checkRight
41
+ checkRight: checkRight,
42
+ canAdd: checkRight(2),
43
+ canEdit: checkRight(4),
44
+ canDelete: checkRight(8) || checkRight(32),
45
+ canAudit: checkRight(64),
46
+ canImport: checkRight(128),
47
+ canExport: checkRight(256),
48
+ canPrint: checkRight(512)
42
49
  };
43
50
  }
44
51