@tddc/assign-modal 1.0.4 → 1.0.7

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.
@@ -54,11 +54,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
54
54
  var TreeNode = _tree.default.TreeNode;
55
55
  var path = []; // 上级机构到当前机构的路径
56
56
 
57
- var allOrgList = [];
58
-
59
57
  var AssignModal = function AssignModal(props) {
60
- var _dataItem$appCodes;
61
-
62
58
  var _props$orgList = props.orgList,
63
59
  orgList = _props$orgList === void 0 ? [] : _props$orgList,
64
60
  _props$dataItem = props.dataItem,
@@ -66,13 +62,19 @@ var AssignModal = function AssignModal(props) {
66
62
  disabled = props.disabled,
67
63
  appList = props.appList,
68
64
  onChange = props.onChange;
65
+ var _dataItem$appCodes = dataItem.appCodes,
66
+ appCodes = _dataItem$appCodes === void 0 ? [] : _dataItem$appCodes,
67
+ _dataItem$orgCodes = dataItem.orgCodes,
68
+ orgCodes = _dataItem$orgCodes === void 0 ? [] : _dataItem$orgCodes,
69
+ orgCode = dataItem.orgCode,
70
+ appCode = dataItem.appCode;
69
71
 
70
72
  var _useState = (0, _react.useState)([]),
71
73
  _useState2 = _slicedToArray(_useState, 2),
72
74
  checkedKeys = _useState2[0],
73
75
  setCheckedKeys = _useState2[1];
74
76
 
75
- var _useState3 = (0, _react.useState)((dataItem === null || dataItem === void 0 ? void 0 : (_dataItem$appCodes = dataItem.appCodes) === null || _dataItem$appCodes === void 0 ? void 0 : _dataItem$appCodes.split(',')) || []),
77
+ var _useState3 = (0, _react.useState)(appCodes || []),
76
78
  _useState4 = _slicedToArray(_useState3, 2),
77
79
  appKeys = _useState4[0],
78
80
  setAppKeys = _useState4[1];
@@ -92,17 +94,38 @@ var AssignModal = function AssignModal(props) {
92
94
  }
93
95
 
94
96
  (0, _react.useEffect)(function () {
95
- var _dataItem$orgCodes, _dataItem$appCodes2;
96
-
97
97
  // path 和 allOrgList 赋值
98
- path = (0, _utils.findSameCodePath)(orgList[0], dataItem.orgCode);
99
- allOrgList = (0, _utils.preorder)(orgList[0]);
100
- var initKeys = Array.from(new Set([].concat(_toConsumableArray((dataItem === null || dataItem === void 0 ? void 0 : (_dataItem$orgCodes = dataItem.orgCodes) === null || _dataItem$orgCodes === void 0 ? void 0 : _dataItem$orgCodes.split(',')) || []), _toConsumableArray(path))));
101
- setCheckedKeys(initKeys);
102
- setAppKeys((dataItem === null || dataItem === void 0 ? void 0 : (_dataItem$appCodes2 = dataItem.appCodes) === null || _dataItem$appCodes2 === void 0 ? void 0 : _dataItem$appCodes2.split(',')) || []);
98
+ path = (0, _utils.findSameCodePath)(orgList[0], orgCode);
99
+ var allOrg = (0, _utils.preorder)(orgList[0]);
100
+ var allApp = appList.map(function (item) {
101
+ return item.name;
102
+ }) || [];
103
+ var initOrgs = [];
104
+ var initApps = [];
105
+
106
+ if (orgCodes.includes('all')) {
107
+ initOrgs = allOrg;
108
+ } else {
109
+ initOrgs = Array.from(new Set([].concat(_toConsumableArray(orgCodes || []), _toConsumableArray(path))));
110
+ }
111
+
112
+ if (appCodes.includes('all')) {
113
+ initApps = allApp;
114
+ } else {
115
+ initApps = appCodes;
116
+ }
117
+
118
+ setCheckedKeys(initOrgs);
119
+ setAppKeys(initApps || []);
120
+ onChange && onChange({
121
+ appKeys: appCodes.includes('all') ? 'all' : appCodes || [],
122
+ checkedKeys: appCodes.includes('all') ? 'all' : orgCodes || []
123
+ });
103
124
  }, [dataItem]);
104
125
  (0, _react.useEffect)(function () {
105
126
  // 机构和应用 全选
127
+ var allOrg = (0, _utils.preorder)(orgList[0]);
128
+
106
129
  if (appList.length > 0) {
107
130
  var allApp = appList.map(function (item) {
108
131
  return item.value;
@@ -112,10 +135,18 @@ var AssignModal = function AssignModal(props) {
112
135
  return allApp.includes(item);
113
136
  });
114
137
  var org = checkedKeys.filter(function (item) {
115
- return allOrgList.includes(item);
138
+ return allOrg.includes(item);
116
139
  });
140
+
141
+ if (app.length === appList.length || org.length === allOrg.length) {
142
+ onChange && onChange({
143
+ appKeys: app.length === appList.length ? ['all'] : appKeys,
144
+ checkedKeys: org.length === allOrg.length ? ['all'] : checkedKeys
145
+ });
146
+ }
147
+
117
148
  setAllAppChecked(app.length === appList.length);
118
- setAllOrgChecked(org.length === allOrgList.length);
149
+ setAllOrgChecked(org.length === allOrg.length);
119
150
  }
120
151
  }, [checkedKeys, appKeys, appList]);
121
152
 
@@ -217,15 +248,18 @@ var AssignModal = function AssignModal(props) {
217
248
  if (e.target.checked) {
218
249
  orgKeys = (0, _utils.preorder)(orgList[0]);
219
250
  setCheckedKeys(orgKeys);
251
+ onChange({
252
+ appKeys: appKeys,
253
+ checkedKeys: ['all']
254
+ });
220
255
  } else {
221
256
  orgKeys = _toConsumableArray(path);
222
257
  setCheckedKeys(orgKeys);
258
+ onChange({
259
+ appKeys: appKeys,
260
+ checkedKeys: orgKeys
261
+ });
223
262
  }
224
-
225
- onChange && onChange({
226
- appKeys: appKeys,
227
- checkedKeys: orgKeys
228
- });
229
263
  };
230
264
 
231
265
  var checkedAllApp = function checkedAllApp(e) {
@@ -236,15 +270,18 @@ var AssignModal = function AssignModal(props) {
236
270
  return item.value;
237
271
  });
238
272
  setAppKeys(appKeys);
273
+ onChange({
274
+ appKeys: ['all'],
275
+ checkedKeys: checkedKeys
276
+ });
239
277
  } else {
240
- appKeys = [dataItem === null || dataItem === void 0 ? void 0 : dataItem.appCode];
278
+ appKeys = [appCode];
241
279
  setAppKeys(appKeys);
280
+ onChange({
281
+ appKeys: appKeys,
282
+ checkedKeys: checkedKeys
283
+ });
242
284
  }
243
-
244
- onChange && onChange({
245
- appKeys: appKeys,
246
- checkedKeys: checkedKeys
247
- });
248
285
  };
249
286
 
250
287
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -259,7 +296,7 @@ var AssignModal = function AssignModal(props) {
259
296
  onChange: checkAllOrg,
260
297
  checked: allOrgChecked,
261
298
  disabled: disabled
262
- }, "\u5168\u9009"))), /*#__PURE__*/_react.default.createElement(_tree.default, {
299
+ }, "\u5168\u5C40"))), /*#__PURE__*/_react.default.createElement(_tree.default, {
263
300
  blockNode: true,
264
301
  className: "tree-list",
265
302
  checkable: true,
@@ -278,11 +315,11 @@ var AssignModal = function AssignModal(props) {
278
315
  onChange: checkedAllApp,
279
316
  checked: allAppChecked,
280
317
  disabled: disabled
281
- }, "\u5168\u9009"))), /*#__PURE__*/_react.default.createElement("div", {
318
+ }, "\u5168\u5C40"))), /*#__PURE__*/_react.default.createElement("div", {
282
319
  className: "menu-body"
283
320
  }, appList.map(function (item, index) {
284
321
  var isCheck = appKeys === null || appKeys === void 0 ? void 0 : appKeys.includes(item.value);
285
- var isOwnAppCode = (dataItem === null || dataItem === void 0 ? void 0 : dataItem.appCode) === item.value;
322
+ var isOwnAppCode = appCode === item.value;
286
323
  return /*#__PURE__*/_react.default.createElement(_checkbox.default, {
287
324
  checked: isCheck,
288
325
  disabled: disabled || isOwnAppCode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tddc/assign-modal",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
4
4
  "description": "Layout",
5
5
  "author": "zj <jun.zhang002383@tongdun.net>",
6
6
  "license": "ISC",
@@ -18,5 +18,5 @@
18
18
  "dependencies": {
19
19
  "jsencrypt": "^3.2.1"
20
20
  },
21
- "gitHead": "dc24855b156049b5700bf1c84f33bfda3c6c5791"
21
+ "gitHead": "0a8dc3240d2f48e01f835300e8af780917797aff"
22
22
  }