buttonVisibilityControl.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { CARD, CARD_BUTTON, STATUS, PRIMARY_KEY, FIELD, CARD_DISABLED_BUTTON } from '../../constant';
  2. /**
  3. * @description: 卡片按钮可见性
  4. */
  5. export function buttonVisibilityControl(props) {
  6. /**
  7. * 此处应根据实际情况自由发挥
  8. * 目标就是将某个状态下的某些按钮展示或隐藏
  9. * 示例代码可能过于繁琐且难以理解
  10. *
  11. * 可调用如下方法实现
  12. * props.button.setButtonVisible();
  13. * props.button.setButtonDisabled();
  14. *
  15. * 例如
  16. * let btn1 = [ 编辑态下显示的按钮 ];
  17. * let btn2 = [ 编辑态下不显示的按钮 ];
  18. *
  19. * props.button.setButtonVisible(btn1,true);
  20. * props.button.setButtonVisible(btn2,false);
  21. * 即可控制编辑态下的显示按钮。
  22. */
  23. let buttons = props.button.getButtons();
  24. if (!buttons || buttons.length == 0) {
  25. //模板没渲染完成,暂不渲染按钮
  26. return;
  27. }
  28. let status = props.getUrlParam(STATUS.status);
  29. let id = props.getUrlParam(PRIMARY_KEY.id);
  30. let isBrowse = status === STATUS.browse;
  31. //单据状态
  32. let billStatus = props.form.getFormItemsValue(CARD.form_id, FIELD.billStatus) && props.form.getFormItemsValue(CARD.form_id, FIELD.billStatus).value;
  33. //pcy
  34. let islouout = props.form.getFormItemsValue(CARD.form_id, "vdef4") && props.form.getFormItemsValue(CARD.form_id, "vdef4").value;
  35. let btnObj = {};
  36. //将要显示的按钮
  37. let showBtn = [];
  38. //编辑态显示按钮
  39. let editBtn = [CARD_BUTTON.save, CARD_BUTTON.saveAdd, CARD_BUTTON.saveCommit, CARD_BUTTON.cancel,
  40. CARD_BUTTON.addRow, CARD_BUTTON.deleteRow, CARD_BUTTON.copyRows,
  41. CARD_BUTTON.insertRow, CARD_BUTTON.delRow, CARD_BUTTON.copyRow, CARD_BUTTON.pasteHere, CARD_BUTTON.expand];
  42. //联查按钮
  43. let unionBtn = [CARD_BUTTON.billTrack, CARD_BUTTON.approvalLink];
  44. //获得所有的按钮的编码(不包括按钮组下的按钮)
  45. let parentButtons = buttons.map(item => item.key);
  46. //(有重复的按钮编码,但无妨)
  47. let allBtns = [...parentButtons, ...editBtn, ...unionBtn, CARD_BUTTON.create, CARD_BUTTON.update, CARD_BUTTON.delete, CARD_BUTTON.copy, CARD_BUTTON.output];
  48. if (!isBrowse) { //编辑态
  49. showBtn = editBtn;
  50. } else { //浏览态
  51. if (!id) {//点击新增然后点击取消后
  52. showBtn = [CARD_BUTTON.create];
  53. } else {//单据浏览态
  54. let commonBtn = [CARD_BUTTON.create, CARD_BUTTON.copy, CARD_BUTTON.attachment, ...unionBtn, CARD_BUTTON.print, CARD_BUTTON.output, CARD_BUTTON.refresh, CARD_BUTTON.fold, CARD_BUTTON.unfold];
  55. switch (billStatus) {
  56. case STATUS.NOSTATE:
  57. showBtn = [CARD_BUTTON.update, CARD_BUTTON.delete, CARD_BUTTON.commit, ...commonBtn];
  58. break;
  59. case STATUS.PASSING:
  60. case STATUS.COMMIT:
  61. case STATUS.GOINGON:
  62. showBtn = [CARD_BUTTON.unCommit, ...commonBtn];
  63. break;
  64. default:
  65. showBtn = [...commonBtn];
  66. break;
  67. }
  68. }
  69. }
  70. for (let item of allBtns) {
  71. btnObj[item] = showBtn.includes(item);
  72. }
  73. //控制按钮显示与否
  74. props.button.setButtonVisible(btnObj);
  75. //设置按钮禁用
  76. props.button.setButtonDisabled(CARD_DISABLED_BUTTON, true);
  77. if(islouout == true){
  78. props.button.setButtonVisible([CARD_BUTTON.update,CARD_BUTTON.Modify, CARD_BUTTON.queryVersion ,CARD_BUTTON.delete,CARD_BUTTON.logout,CARD_BUTTON.commit], false);
  79. };
  80. //设置卡片状态
  81. props.cardTable.setStatus(CARD.table_code, isBrowse ? STATUS.browse : STATUS.edit);
  82. props.form.setFormStatus(CARD.form_id, status);
  83. }