panel.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { VxeUI } from '../../../ui';
  2. import XEUtils from 'xe-utils';
  3. import { getFuncText } from '../../../ui/src/utils';
  4. import { getSlotVNs } from '../../../ui/src/vn';
  5. const { getIcon, renderEmptyElement } = VxeUI;
  6. export default {
  7. name: 'VxeTableMenuPanel',
  8. props: {
  9. ctxMenuStore: Object,
  10. ctxMenuOpts: Object
  11. },
  12. inject: {
  13. $xeTable: {
  14. default: null
  15. }
  16. },
  17. mounted() {
  18. const $xeMenuPanel = this;
  19. const $xeTable = $xeMenuPanel.$xeTable;
  20. const menuOpts = $xeTable.computeMenuOpts;
  21. const { transfer } = menuOpts;
  22. const el = this.$refs.refElem;
  23. if (transfer && el) {
  24. document.body.appendChild(el);
  25. }
  26. },
  27. beforeDestroy() {
  28. const el = this.$refs.refElem;
  29. if (el && el.parentNode) {
  30. el.parentNode.removeChild(el);
  31. }
  32. },
  33. render(h) {
  34. const $xeMenuPanel = this;
  35. const $xeTable = $xeMenuPanel.$xeTable;
  36. const tableReactData = $xeTable;
  37. const { ctxMenuStore } = tableReactData;
  38. const menuOpts = $xeTable.computeMenuOpts;
  39. const { destroyOnClose } = menuOpts;
  40. const { visible, list, className } = ctxMenuStore;
  41. return h('div', {
  42. ref: 'refElem',
  43. class: ['vxe-table--context-menu-wrapper', className, {
  44. 'is--visible': visible
  45. }],
  46. style: ctxMenuStore.style
  47. }, (destroyOnClose ? visible : true)
  48. ? list.map((options, gIndex) => {
  49. return options.every((item) => item.visible === false)
  50. ? renderEmptyElement($xeTable)
  51. : h('ul', {
  52. class: 'vxe-context-menu--option-wrapper',
  53. key: gIndex
  54. }, options.map((item, index) => {
  55. const hasChildMenus = item.children && item.children.some((child) => child.visible !== false);
  56. const prefixOpts = Object.assign({}, item.prefixConfig);
  57. const prefixIcon = prefixOpts.icon || item.prefixIcon;
  58. const suffixOpts = Object.assign({}, item.suffixConfig);
  59. const suffixIcon = suffixOpts.icon || item.suffixIcon;
  60. const menuContent = getFuncText(item.name);
  61. return item.visible === false
  62. ? renderEmptyElement($xeTable)
  63. : h('li', {
  64. class: [item.className, {
  65. 'link--disabled': item.disabled,
  66. 'link--active': item === ctxMenuStore.selected
  67. }],
  68. key: `${gIndex}_${index}`
  69. }, [
  70. h('a', {
  71. class: 'vxe-context-menu--link',
  72. on: {
  73. click(evnt) {
  74. $xeTable.ctxMenuLinkEvent(evnt, item);
  75. },
  76. mouseover(evnt) {
  77. $xeTable.ctxMenuMouseoverEvent(evnt, item);
  78. },
  79. mouseout(evnt) {
  80. $xeTable.ctxMenuMouseoutEvent(evnt, item);
  81. }
  82. }
  83. }, [
  84. h('div', {
  85. class: ['vxe-context-menu--link-prefix', prefixOpts.className || '']
  86. }, [
  87. prefixIcon && XEUtils.isFunction(prefixIcon)
  88. ? h('span', {}, getSlotVNs(prefixIcon.call($xeTable, {})))
  89. : h('i', {
  90. class: prefixIcon
  91. }),
  92. prefixOpts.content ? h('span', {}, `${prefixOpts.content}`) : renderEmptyElement($xeTable)
  93. ]),
  94. h('span', {
  95. class: 'vxe-context-menu--link-content',
  96. attrs: {
  97. title: menuContent
  98. }
  99. }, menuContent),
  100. h('div', {
  101. class: ['vxe-context-menu--link-suffix', suffixOpts.className || '']
  102. }, [
  103. suffixIcon && XEUtils.isFunction(suffixIcon)
  104. ? h('span', {}, getSlotVNs(suffixIcon.call($xeTable, {})))
  105. : h('i', {
  106. class: suffixIcon || (hasChildMenus ? getIcon().TABLE_MENU_OPTIONS : '')
  107. }),
  108. suffixOpts.content ? h('span', `${suffixOpts.content}`) : renderEmptyElement($xeTable)
  109. ])
  110. ]),
  111. hasChildMenus && item.children
  112. ? h('ul', {
  113. class: ['vxe-table--context-menu-clild-wrapper', {
  114. 'is--show': item === ctxMenuStore.selected && ctxMenuStore.showChild
  115. }]
  116. }, item.children.map((child, cIndex) => {
  117. const childPrefixOpts = Object.assign({}, child.prefixConfig);
  118. const childPrefixIcon = childPrefixOpts.icon || child.prefixIcon;
  119. const childSuffixOpts = Object.assign({}, child.suffixConfig);
  120. const childSuffixIcon = childSuffixOpts.icon || child.suffixIcon;
  121. const childMenuContent = getFuncText(child.name);
  122. return child.visible === false
  123. ? null
  124. : h('li', {
  125. class: [child.className, {
  126. 'link--disabled': child.disabled,
  127. 'link--active': child === ctxMenuStore.selectChild
  128. }],
  129. key: `${gIndex}_${index}_${cIndex}`
  130. }, [
  131. h('a', {
  132. class: 'vxe-context-menu--link',
  133. on: {
  134. click(evnt) {
  135. $xeTable.ctxMenuLinkEvent(evnt, child);
  136. },
  137. mouseover(evnt) {
  138. $xeTable.ctxMenuMouseoverEvent(evnt, item, child);
  139. },
  140. mouseout(evnt) {
  141. $xeTable.ctxMenuMouseoutEvent(evnt, item);
  142. }
  143. }
  144. }, [
  145. h('div', {
  146. class: ['vxe-context-menu--link-prefix', childPrefixOpts.className || '']
  147. }, [
  148. childPrefixIcon && XEUtils.isFunction(childPrefixIcon)
  149. ? h('span', {}, getSlotVNs(childPrefixIcon.call($xeTable, {})))
  150. : h('i', {
  151. class: childPrefixIcon
  152. }),
  153. childPrefixOpts.content ? h('span', `${childPrefixOpts.content}`) : renderEmptyElement($xeTable)
  154. ]),
  155. h('span', {
  156. class: 'vxe-context-menu--link-content',
  157. attrs: {
  158. title: childMenuContent
  159. }
  160. }, childMenuContent),
  161. h('div', {
  162. class: ['vxe-context-menu--link-suffix', childSuffixOpts.className || '']
  163. }, [
  164. childSuffixIcon && XEUtils.isFunction(childSuffixIcon)
  165. ? h('span', {}, getSlotVNs(childSuffixIcon.call($xeTable, {})))
  166. : h('i', {
  167. class: childSuffixIcon
  168. }),
  169. childSuffixOpts.content ? h('span', `${childSuffixOpts.content}`) : renderEmptyElement($xeTable)
  170. ])
  171. ])
  172. ]);
  173. }))
  174. : null
  175. ]);
  176. }));
  177. })
  178. : []);
  179. }
  180. };