@tddc/assign-modal 1.0.7 → 1.1.0

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.
@@ -68,6 +68,10 @@ var AssignModal = function AssignModal(props) {
68
68
  orgCodes = _dataItem$orgCodes === void 0 ? [] : _dataItem$orgCodes,
69
69
  orgCode = dataItem.orgCode,
70
70
  appCode = dataItem.appCode;
71
+ var allOrg = (0, _utils.preorder)(orgList[0]);
72
+ var allApp = appList.map(function (item) {
73
+ return item.value;
74
+ });
71
75
 
72
76
  var _useState = (0, _react.useState)([]),
73
77
  _useState2 = _slicedToArray(_useState, 2),
@@ -96,20 +100,18 @@ var AssignModal = function AssignModal(props) {
96
100
  (0, _react.useEffect)(function () {
97
101
  // path 和 allOrgList 赋值
98
102
  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
103
  var initOrgs = [];
104
104
  var initApps = [];
105
105
 
106
106
  if (orgCodes.includes('all')) {
107
+ setAllOrgChecked(orgCodes.includes('all'));
107
108
  initOrgs = allOrg;
108
109
  } else {
109
110
  initOrgs = Array.from(new Set([].concat(_toConsumableArray(orgCodes || []), _toConsumableArray(path))));
110
111
  }
111
112
 
112
113
  if (appCodes.includes('all')) {
114
+ setAllAppChecked(appCodes.includes('all'));
113
115
  initApps = allApp;
114
116
  } else {
115
117
  initApps = appCodes;
@@ -117,38 +119,7 @@ var AssignModal = function AssignModal(props) {
117
119
 
118
120
  setCheckedKeys(initOrgs);
119
121
  setAppKeys(initApps || []);
120
- onChange && onChange({
121
- appKeys: appCodes.includes('all') ? 'all' : appCodes || [],
122
- checkedKeys: appCodes.includes('all') ? 'all' : orgCodes || []
123
- });
124
122
  }, [dataItem]);
125
- (0, _react.useEffect)(function () {
126
- // 机构和应用 全选
127
- var allOrg = (0, _utils.preorder)(orgList[0]);
128
-
129
- if (appList.length > 0) {
130
- var allApp = appList.map(function (item) {
131
- return item.value;
132
- }); // 判断当前用户是否具有 该机构或应用 权限
133
-
134
- var app = appKeys.filter(function (item) {
135
- return allApp.includes(item);
136
- });
137
- var org = checkedKeys.filter(function (item) {
138
- return allOrg.includes(item);
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
-
148
- setAllAppChecked(app.length === appList.length);
149
- setAllOrgChecked(org.length === allOrg.length);
150
- }
151
- }, [checkedKeys, appKeys, appList]);
152
123
 
153
124
  var loopTreeNodes = function loopTreeNodes(data) {
154
125
  var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
@@ -211,9 +182,15 @@ var AssignModal = function AssignModal(props) {
211
182
  }
212
183
 
213
184
  setCheckedKeys(checked);
214
- onChange && onChange({
215
- appKeys: appKeys,
216
- checkedKeys: checked
185
+ onChange({
186
+ appKeys: allAppChecked ? ['all'] : appKeys,
187
+ checkedKeys: checked,
188
+ appCheckAll: allAppChecked,
189
+ orgCheckAll: allOrgChecked,
190
+ checkData: {
191
+ apps: appKeys,
192
+ orgs: checked
193
+ }
217
194
  });
218
195
  };
219
196
 
@@ -224,7 +201,6 @@ var AssignModal = function AssignModal(props) {
224
201
  if (e.target.checked) {
225
202
  value = e.target.value;
226
203
  newAppKeys = [].concat(_toConsumableArray(appKeys), [value]);
227
- setAppKeys(newAppKeys);
228
204
  } else {
229
205
  value = e.target.value;
230
206
  newAppKeys = (0, _lodash.cloneDeep)(appKeys);
@@ -233,53 +209,89 @@ var AssignModal = function AssignModal(props) {
233
209
  newAppKeys.splice(index, 1);
234
210
  }
235
211
  });
236
- setAppKeys(newAppKeys);
237
212
  }
238
213
 
239
- onChange && onChange({
240
- checkedKeys: checkedKeys,
241
- appKeys: newAppKeys
214
+ setAppKeys(newAppKeys);
215
+ onChange({
216
+ appKeys: newAppKeys,
217
+ checkedKeys: allOrgChecked ? ['all'] : checkedKeys,
218
+ appCheckAll: allAppChecked,
219
+ orgCheckAll: allOrgChecked,
220
+ checkData: {
221
+ apps: newAppKeys,
222
+ orgs: checkedKeys
223
+ }
242
224
  });
243
- };
225
+ }; // org全局授权
226
+
244
227
 
245
228
  var checkAllOrg = function checkAllOrg(e) {
246
- var orgKeys = [];
229
+ var orgChecks = [];
247
230
 
248
231
  if (e.target.checked) {
249
- orgKeys = (0, _utils.preorder)(orgList[0]);
250
- setCheckedKeys(orgKeys);
232
+ setAllOrgChecked(true);
233
+ orgChecks = (0, _utils.preorder)(orgList[0]);
234
+ setCheckedKeys(orgChecks);
251
235
  onChange({
252
- appKeys: appKeys,
253
- checkedKeys: ['all']
236
+ appKeys: allAppChecked ? ['all'] : appKeys,
237
+ checkedKeys: ['all'],
238
+ appCheckAll: allOrgChecked,
239
+ orgCheckAll: true,
240
+ checkData: {
241
+ apps: appKeys,
242
+ orgs: checkedKeys
243
+ }
254
244
  });
255
245
  } else {
256
- orgKeys = _toConsumableArray(path);
257
- setCheckedKeys(orgKeys);
246
+ setAllOrgChecked(false);
247
+ orgChecks = Array.from(new Set([].concat(_toConsumableArray(orgCodes || []), _toConsumableArray(path))));
248
+ setCheckedKeys(orgChecks);
258
249
  onChange({
259
- appKeys: appKeys,
260
- checkedKeys: orgKeys
250
+ appKeys: allAppChecked ? ['all'] : appKeys,
251
+ checkedKeys: orgChecks,
252
+ appCheckAll: allOrgChecked,
253
+ orgCheckAll: false,
254
+ checkData: {
255
+ apps: appKeys,
256
+ orgs: orgChecks
257
+ }
261
258
  });
262
259
  }
263
- };
260
+ }; // app全局授权
261
+
264
262
 
265
263
  var checkedAllApp = function checkedAllApp(e) {
266
- var appKeys = [];
264
+ var appChecks = [];
267
265
 
268
266
  if (e.target.checked) {
269
- appKeys = appList.map(function (item) {
267
+ setAllAppChecked(true);
268
+ appChecks = appList.map(function (item) {
270
269
  return item.value;
271
270
  });
272
- setAppKeys(appKeys);
271
+ setAppKeys(appChecks);
273
272
  onChange({
274
273
  appKeys: ['all'],
275
- checkedKeys: checkedKeys
274
+ checkedKeys: allOrgChecked ? ['all'] : checkedKeys,
275
+ appCheckAll: true,
276
+ orgCheckAll: allOrgChecked,
277
+ checkData: {
278
+ apps: appChecks,
279
+ orgs: checkedKeys
280
+ }
276
281
  });
277
282
  } else {
278
- appKeys = [appCode];
279
- setAppKeys(appKeys);
283
+ setAllAppChecked(false);
284
+ appChecks = Array.from(new Set([].concat(_toConsumableArray(appCodes || []), [appCode])));
285
+ setAppKeys(appChecks);
280
286
  onChange({
281
- appKeys: appKeys,
282
- checkedKeys: checkedKeys
287
+ appKeys: appChecks,
288
+ checkedKeys: allOrgChecked ? ['all'] : checkedKeys,
289
+ appCheckAll: false,
290
+ orgCheckAll: allOrgChecked,
291
+ checkData: {
292
+ apps: appChecks,
293
+ orgs: checkedKeys
294
+ }
283
295
  });
284
296
  }
285
297
  };
@@ -304,7 +316,7 @@ var AssignModal = function AssignModal(props) {
304
316
  checkedKeys: checkedKeys,
305
317
  defaultExpandAll: true,
306
318
  onCheck: onCheck,
307
- disabled: disabled
319
+ disabled: disabled || allOrgChecked
308
320
  }, loopTreeNodes(orgList))), /*#__PURE__*/_react.default.createElement("div", {
309
321
  className: "right"
310
322
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -322,7 +334,7 @@ var AssignModal = function AssignModal(props) {
322
334
  var isOwnAppCode = appCode === item.value;
323
335
  return /*#__PURE__*/_react.default.createElement(_checkbox.default, {
324
336
  checked: isCheck,
325
- disabled: disabled || isOwnAppCode,
337
+ disabled: disabled || isOwnAppCode || allAppChecked,
326
338
  onChange: assignApp,
327
339
  value: item.value,
328
340
  key: index
@@ -59,6 +59,7 @@ var AssignModal = function AssignModal(props) {
59
59
  setAssignData = _useState2[1];
60
60
 
61
61
  var submit = function submit() {
62
+ console.log(assignData);
62
63
  onSubmit(assignData);
63
64
  };
64
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tddc/assign-modal",
3
- "version": "1.0.7",
3
+ "version": "1.1.0",
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": "0a8dc3240d2f48e01f835300e8af780917797aff"
21
+ "gitHead": "12ef2b028bcaddf22a2db41f05e99b6399688ca4"
22
22
  }