v2.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. if(zui.VisionSwitchMenu) return;
  2. const {Component, ReactComponent, ComponentFromReact, jsx, signal, computed} = zui;
  3. const {Menu, DropmenuPop} = zui.reactComponents;
  4. const emptyFn = () => {};
  5. if(!DropmenuPop) return;
  6. class WorkspaceMenuJSX extends DropmenuPop
  7. {
  8. componentDidMount()
  9. {
  10. super.componentDidMount();
  11. $(this.base).closest('.vision-workspace-menu').toggleClass('is-expanded', !!this.state.expanded);
  12. }
  13. render(props)
  14. {
  15. return this._renderPop(props);
  16. }
  17. _getData()
  18. {
  19. const data = super._getData();
  20. if (this.state.active === undefined && !data.activeTab.items.length)
  21. {
  22. const tab = data.tabs.find(x => x.items.length);
  23. if(tab) data.activeTab = tab;
  24. }
  25. return data;
  26. }
  27. _handleItemClick = (info) =>
  28. {
  29. const $target = $(info.event.target);
  30. if ($target.closest('.tree-toggle').length || !$target.closest('.is-link').length) return;
  31. info.event.preventDefault();
  32. window.enterWorkspace(info.renderedItem['data-type'], info.renderedItem['data-url']);
  33. zui.Dropdown.query('#versionSwitchBtn').hide();
  34. };
  35. expand = (expand) =>
  36. {
  37. const newExpand = typeof expand === 'undefined' ? !this.state.expanded : expand;
  38. this.setState({expanded: newExpand});
  39. $(this.base).closest('.vision-workspace-menu').toggleClass('is-expanded', !!newExpand);
  40. };
  41. }
  42. class VisionSwitchMenuJSX extends ReactComponent
  43. {
  44. spaceType$ = signal('');
  45. hidden$ = signal(false);
  46. spcae$ = computed(() =>
  47. {
  48. const spaces = this.props.spaces;
  49. if(!spaces || !spaces.length) return null;
  50. const spaceType = this.spaceType$.value;
  51. if(!spaceType) return null;
  52. return spaces.find(space => space.key === spaceType);
  53. });
  54. _minHeight = 0;
  55. constructor(props)
  56. {
  57. super(props);
  58. this.spaceType$.value = props.currentSpace || '';
  59. }
  60. componentDidMount()
  61. {
  62. $('#versionSwitchBtn').on('show.visionSwitchMenu', () => {
  63. this.hidden$.value = false;
  64. }).on('hide.visionSwitchMenu', () => {
  65. this.hidden$.value = true;
  66. });
  67. }
  68. componentWillUnmount()
  69. {
  70. $('#versionSwitchBtn').off('.visionSwitchMenu');
  71. }
  72. componentWillUpdate()
  73. {
  74. this._minHeight = Math.max(this._minHeight, $(this.base).height());
  75. }
  76. _handleClickVision(vision)
  77. {
  78. window.selectVision(vision);
  79. }
  80. _handleClickWorkspace(spaceType)
  81. {
  82. this.spaceType$.value = spaceType;
  83. }
  84. _renderMenu(props)
  85. {
  86. const {visions, currentVision, spaces, switchVisionText, switchWorkspaceText} = props;
  87. const items = [{type: 'heading', text: switchVisionText}];
  88. visions.forEach(vision => items.push({
  89. key : vision.key,
  90. text : vision.text,
  91. selected: vision.key === currentVision,
  92. icon : `${vision.icon} vision-icon`,
  93. onClick : () => this._handleClickVision(vision.key),
  94. }));
  95. if(spaces.length)
  96. {
  97. const currentSpace = this.spaceType$.value;
  98. items.push({type: 'heading', text: switchWorkspaceText});
  99. spaces.forEach(space => items.push({
  100. key : space.key,
  101. text : space.text,
  102. selected: space.key === currentSpace,
  103. icon : `${space.icon} workspace-icon`,
  104. trailingIcon: 'icon-angle-right',
  105. onClick : () => this._handleClickWorkspace(space.key),
  106. }));
  107. }
  108. return jsx`<div class="vision-vision-menu-main flex-none"><${Menu} items=${items} /></div>`;
  109. }
  110. _renderWorkspace(props)
  111. {
  112. const space = this.spcae$.value;
  113. const hidden = this.hidden$.value;
  114. if(!space || hidden) return null;
  115. const url = space.fetcher || $.createLink(space.key, 'ajaxGetDropMenu', `${space.key}ID=0`);
  116. const state = {value: '', data: {search: false}};
  117. return jsx`<div class="vision-workspace-menu border-l"><${WorkspaceMenuJSX} key=${space.key} fetcher=${url} state=${state} togglePop=${emptyFn} searchBox=${false} /></div>`;
  118. }
  119. render(props)
  120. {
  121. return jsx`<div class="vision-switch-menu flex-auto min-h-0 h-full not-hide-menu row items-stretch" style="min-height: ${this._minHeight}px;">
  122. ${this._renderMenu(props)}
  123. ${this._renderWorkspace(props)}
  124. </div>`;
  125. }
  126. }
  127. class VisionSwitchMenu extends ComponentFromReact
  128. {
  129. static NAME = 'VisionSwitchMenu';
  130. static Component = VisionSwitchMenuJSX;
  131. }
  132. zui.VisionSwitchMenu = VisionSwitchMenu;
  133. VisionSwitchMenu.register();