hookehuyr

字段权限选中功能优化

Showing 1 changed file with 92 additions and 51 deletions
...@@ -412,7 +412,7 @@ export default { ...@@ -412,7 +412,7 @@ export default {
412 { 412 {
413 name: '字段3', 413 name: '字段3',
414 visible: { 414 visible: {
415 - checked: false, 415 + checked: true,
416 disabled: false, 416 disabled: false,
417 }, 417 },
418 editable: { 418 editable: {
...@@ -452,22 +452,58 @@ export default { ...@@ -452,22 +452,58 @@ export default {
452 } 452 }
453 453
454 /************** 字段权限操作 ***************/ 454 /************** 字段权限操作 ***************/
455 - const onAuthVisibleChange = (val: any, index: number) => { 455 + const checkAuthAll = (type: string) => {
456 - // 可见按钮回调 456 + if (type === 'visible') {
457 - console.log('onAuthVisibleChange', val, index); 457 + let total_count = state.field_auths.filter((ele) => {
458 - let count = state.field_auths.filter((ele) => { 458 + if (!ele.visible.disabled) {
459 - if (ele.visible.checked && !ele.visible.disabled) { 459 + return ele;
460 - return ele; 460 + }
461 + }).length;
462 + let avail_count = state.field_auths.filter((ele) => {
463 + if (ele.visible.checked && !ele.visible.disabled) {
464 + return ele;
465 + }
466 + });
467 + if (avail_count.length === total_count) {
468 + state.auth_all_checked = true;
469 + } else {
470 + state.auth_all_checked = false;
471 + }
472 + }
473 + if (type === 'editable') {
474 + let total_count = state.field_auths.filter((ele) => {
475 + if (!ele.editable.disabled) {
476 + return ele;
477 + }
478 + }).length;
479 + let avail_count = state.field_auths.filter((ele) => {
480 + if (ele.editable.checked && !ele.editable.disabled) {
481 + return ele;
482 + }
483 + });
484 + if (avail_count.length === total_count) {
485 + state.auth_all_edit = true;
486 + } else {
487 + state.auth_all_edit = false;
461 } 488 }
462 - });
463 - if (count.length === state.field_auths.length) {
464 - state.auth_all_checked = true;
465 - } else {
466 - state.auth_all_checked = false;
467 } 489 }
468 } 490 }
469 - const onAuthEditChange = (val: any, index: number) => { 491 + /**
470 - console.log('onAuthEditChange', val, index) 492 + * 点击可见按钮回调
493 + * @param val
494 + * @param index
495 + */
496 + const onAuthVisibleChange = (val: any, index: number) => {
497 + checkAuthAll('visible')
498 + }
499 +
500 + /**
501 + * 点击可编辑按钮回调
502 + * @param val
503 + * @param index
504 + */
505 + const onAuthEditableChange = (val: any, index: number) => {
506 + checkAuthAll('editable')
471 } 507 }
472 508
473 const onAuthAllChange = (val: any) => { 509 const onAuthAllChange = (val: any) => {
...@@ -475,18 +511,40 @@ export default { ...@@ -475,18 +511,40 @@ export default {
475 if (val) { 511 if (val) {
476 // 全部选中 512 // 全部选中
477 state.field_auths.forEach((ele) => { 513 state.field_auths.forEach((ele) => {
514 + if (ele.visible.disabled) {
515 + return;
516 + }
478 ele.visible.checked = true 517 ele.visible.checked = true
479 }) 518 })
480 } else { 519 } else {
481 // 全部取消选中 520 // 全部取消选中
482 state.field_auths.forEach((ele) => { 521 state.field_auths.forEach((ele) => {
522 + if (ele.visible.disabled) {
523 + return;
524 + }
483 ele.visible.checked = false 525 ele.visible.checked = false
484 }) 526 })
485 } 527 }
486 } 528 }
487 const onAuthAllEditChange = (val: any) => { 529 const onAuthAllEditChange = (val: any) => {
488 // 全选可编辑按钮回调 530 // 全选可编辑按钮回调
489 - console.warn(val) 531 + if (val) {
532 + // 全部选中
533 + state.field_auths.forEach((ele) => {
534 + if (ele.editable.disabled) {
535 + return;
536 + }
537 + ele.editable.checked = true
538 + })
539 + } else {
540 + // 全部取消选中
541 + state.field_auths.forEach((ele) => {
542 + if (ele.editable.disabled) {
543 + return;
544 + }
545 + ele.editable.checked = false
546 + })
547 + }
490 } 548 }
491 /******************* END *******************/ 549 /******************* END *******************/
492 550
...@@ -525,18 +583,18 @@ export default { ...@@ -525,18 +583,18 @@ export default {
525 * @param {Object} e - The event object 583 * @param {Object} e - The event object
526 */ 584 */
527 function onDblClickNode(e: myEvent) { 585 function onDblClickNode(e: myEvent) {
528 - const model = G6.Util.clone(e.item.get('model')) 586 + // const model = G6.Util.clone(e.item.get('model'))
529 - model.style = model.style || {} 587 + // model.style = model.style || {}
530 - model.labelCfg = model.labelCfg || { style: {} } 588 + // model.labelCfg = model.labelCfg || { style: {} }
531 589
532 - model.data = model.data ? model.data : {} 590 + // model.data = model.data ? model.data : {}
533 591
534 - // 判断是否是流程节点 592 + // // 判断是否是流程节点
535 - let model_id = model.id 593 + // let model_id = model.id
536 - if (model_id !== 'start-node' && model_id!== 'end-node') { 594 + // if (model_id !== 'start-node' && model_id!== 'end-node') {
537 - state.detailModel = model 595 + // state.detailModel = model
538 - editor.openModel() 596 + // editor.openModel()
539 - } 597 + // }
540 598
541 } 599 }
542 600
...@@ -555,32 +613,13 @@ export default { ...@@ -555,32 +613,13 @@ export default {
555 613
556 // 判断是否是流程节点 614 // 判断是否是流程节点
557 let model_id = model.id 615 let model_id = model.id
558 - if (model_id !== 'start-node' && model_id!== 'end-node') { 616 + if (model_id!== 'end-node') {
559 state.detailModel = model; 617 state.detailModel = model;
560 // 获取节点名称 618 // 获取节点名称
561 state.node_name = state.detailModel.text; 619 state.node_name = state.detailModel.text;
562 - // // 检查字段权限选中情况 620 + // 检查字段权限选中情况
563 - // let checked_count = state.field_auths.filter((ele) => { 621 + checkAuthAll('visible');
564 - // if (ele.visible.checked && !ele.visible.disabled) { 622 + checkAuthAll('editable');
565 - // return ele;
566 - // }
567 - // });
568 - // if (checked_count.length === state.field_auths.length) {
569 - // state.auth_all_checked = true;
570 - // } else {
571 - // state.auth_all_checked = false;
572 - // }
573 - // let edit_count = state.field_auths.filter((ele) => {
574 - // if (ele.editable.checked && !ele.editable.disabled) {
575 - // return ele;
576 - // }
577 - // });
578 - // if (edit_count.length === state.field_auths.length) {
579 - // state.auth_all_edit = true;
580 - // } else {
581 - // state.auth_all_edit = false;
582 - // }
583 -
584 // 打开属性表单 623 // 打开属性表单
585 editor.openModel() 624 editor.openModel()
586 } else { 625 } else {
...@@ -704,10 +743,12 @@ export default { ...@@ -704,10 +743,12 @@ export default {
704 * @param {string} type - The type of the model being deleted. 743 * @param {string} type - The type of the model being deleted.
705 */ 744 */
706 function handleAfterDelete(model: myObj, type: string) { 745 function handleAfterDelete(model: myObj, type: string) {
746 + if (type === 'node') {
747 + // 关闭编辑器
748 + editor.closeModel();
749 + }
707 if (type === 'edge') { 750 if (type === 'edge') {
708 console.log('delete edge') 751 console.log('delete edge')
709 - } else {
710 - console.log('after delete', model.label, { ...model })
711 } 752 }
712 } 753 }
713 754
...@@ -869,7 +910,7 @@ export default { ...@@ -869,7 +910,7 @@ export default {
869 910
870 handleActiveChange, 911 handleActiveChange,
871 onAuthVisibleChange, 912 onAuthVisibleChange,
872 - onAuthEditChange, 913 + onAuthEditableChange,
873 onAuthAllChange, 914 onAuthAllChange,
874 onAuthAllEditChange, 915 onAuthAllEditChange,
875 916
......