submenu.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, {
  41. /******/ configurable: false,
  42. /******/ enumerable: true,
  43. /******/ get: getter
  44. /******/ });
  45. /******/ }
  46. /******/ };
  47. /******/
  48. /******/ // getDefaultExport function for compatibility with non-harmony modules
  49. /******/ __webpack_require__.n = function(module) {
  50. /******/ var getter = module && module.__esModule ?
  51. /******/ function getDefault() { return module['default']; } :
  52. /******/ function getModuleExports() { return module; };
  53. /******/ __webpack_require__.d(getter, 'a', getter);
  54. /******/ return getter;
  55. /******/ };
  56. /******/
  57. /******/ // Object.prototype.hasOwnProperty.call
  58. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  59. /******/
  60. /******/ // __webpack_public_path__
  61. /******/ __webpack_require__.p = "/dist/";
  62. /******/
  63. /******/ // Load entry module and return exports
  64. /******/ return __webpack_require__(__webpack_require__.s = 90);
  65. /******/ })
  66. /************************************************************************/
  67. /******/ ({
  68. /***/ 0:
  69. /***/ (function(module, exports) {
  70. /* globals __VUE_SSR_CONTEXT__ */
  71. // IMPORTANT: Do NOT use ES2015 features in this file.
  72. // This module is a runtime utility for cleaner component module output and will
  73. // be included in the final webpack user bundle.
  74. module.exports = function normalizeComponent (
  75. rawScriptExports,
  76. compiledTemplate,
  77. functionalTemplate,
  78. injectStyles,
  79. scopeId,
  80. moduleIdentifier /* server only */
  81. ) {
  82. var esModule
  83. var scriptExports = rawScriptExports = rawScriptExports || {}
  84. // ES6 modules interop
  85. var type = typeof rawScriptExports.default
  86. if (type === 'object' || type === 'function') {
  87. esModule = rawScriptExports
  88. scriptExports = rawScriptExports.default
  89. }
  90. // Vue.extend constructor export interop
  91. var options = typeof scriptExports === 'function'
  92. ? scriptExports.options
  93. : scriptExports
  94. // render functions
  95. if (compiledTemplate) {
  96. options.render = compiledTemplate.render
  97. options.staticRenderFns = compiledTemplate.staticRenderFns
  98. options._compiled = true
  99. }
  100. // functional template
  101. if (functionalTemplate) {
  102. options.functional = true
  103. }
  104. // scopedId
  105. if (scopeId) {
  106. options._scopeId = scopeId
  107. }
  108. var hook
  109. if (moduleIdentifier) { // server build
  110. hook = function (context) {
  111. // 2.3 injection
  112. context =
  113. context || // cached call
  114. (this.$vnode && this.$vnode.ssrContext) || // stateful
  115. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  116. // 2.2 with runInNewContext: true
  117. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  118. context = __VUE_SSR_CONTEXT__
  119. }
  120. // inject component styles
  121. if (injectStyles) {
  122. injectStyles.call(this, context)
  123. }
  124. // register component module identifier for async chunk inferrence
  125. if (context && context._registeredComponents) {
  126. context._registeredComponents.add(moduleIdentifier)
  127. }
  128. }
  129. // used by ssr in case component is cached and beforeCreate
  130. // never gets called
  131. options._ssrRegister = hook
  132. } else if (injectStyles) {
  133. hook = injectStyles
  134. }
  135. if (hook) {
  136. var functional = options.functional
  137. var existing = functional
  138. ? options.render
  139. : options.beforeCreate
  140. if (!functional) {
  141. // inject component registration as beforeCreate hook
  142. options.beforeCreate = existing
  143. ? [].concat(existing, hook)
  144. : [hook]
  145. } else {
  146. // for template-only hot-reload because in that case the render fn doesn't
  147. // go through the normalizer
  148. options._injectStyles = hook
  149. // register for functioal component in vue file
  150. options.render = function renderWithStyleInjection (h, context) {
  151. hook.call(context)
  152. return existing(h, context)
  153. }
  154. }
  155. }
  156. return {
  157. esModule: esModule,
  158. exports: scriptExports,
  159. options: options
  160. }
  161. }
  162. /***/ }),
  163. /***/ 1:
  164. /***/ (function(module, exports) {
  165. module.exports = require("element-ui/lib/mixins/emitter");
  166. /***/ }),
  167. /***/ 21:
  168. /***/ (function(module, exports) {
  169. module.exports = require("element-ui/lib/transitions/collapse-transition");
  170. /***/ }),
  171. /***/ 34:
  172. /***/ (function(module, exports, __webpack_require__) {
  173. "use strict";
  174. exports.__esModule = true;
  175. exports.default = {
  176. inject: ['rootMenu'],
  177. computed: {
  178. indexPath: function indexPath() {
  179. var path = [this.index];
  180. var parent = this.$parent;
  181. while (parent.$options.componentName !== 'ElMenu') {
  182. if (parent.index) {
  183. path.unshift(parent.index);
  184. }
  185. parent = parent.$parent;
  186. }
  187. return path;
  188. },
  189. parentMenu: function parentMenu() {
  190. var parent = this.$parent;
  191. while (parent && ['ElMenu', 'ElSubmenu'].indexOf(parent.$options.componentName) === -1) {
  192. parent = parent.$parent;
  193. }
  194. return parent;
  195. },
  196. paddingStyle: function paddingStyle() {
  197. if (this.rootMenu.mode !== 'vertical') return {};
  198. var padding = 20;
  199. var parent = this.$parent;
  200. if (this.rootMenu.collapse) {
  201. padding = 20;
  202. } else {
  203. while (parent && parent.$options.componentName !== 'ElMenu') {
  204. if (parent.$options.componentName === 'ElSubmenu') {
  205. padding += 20;
  206. }
  207. parent = parent.$parent;
  208. }
  209. }
  210. return { paddingLeft: padding + 'px' };
  211. }
  212. }
  213. };
  214. /***/ }),
  215. /***/ 7:
  216. /***/ (function(module, exports) {
  217. module.exports = require("element-ui/lib/utils/vue-popper");
  218. /***/ }),
  219. /***/ 90:
  220. /***/ (function(module, exports, __webpack_require__) {
  221. "use strict";
  222. exports.__esModule = true;
  223. var _submenu = __webpack_require__(91);
  224. var _submenu2 = _interopRequireDefault(_submenu);
  225. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  226. /* istanbul ignore next */
  227. _submenu2.default.install = function (Vue) {
  228. Vue.component(_submenu2.default.name, _submenu2.default);
  229. };
  230. exports.default = _submenu2.default;
  231. /***/ }),
  232. /***/ 91:
  233. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  234. "use strict";
  235. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  236. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_submenu_vue__ = __webpack_require__(92);
  237. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_submenu_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_submenu_vue__);
  238. var normalizeComponent = __webpack_require__(0)
  239. /* script */
  240. /* template */
  241. var __vue_template__ = null
  242. /* template functional */
  243. var __vue_template_functional__ = false
  244. /* styles */
  245. var __vue_styles__ = null
  246. /* scopeId */
  247. var __vue_scopeId__ = null
  248. /* moduleIdentifier (server only) */
  249. var __vue_module_identifier__ = null
  250. var Component = normalizeComponent(
  251. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_submenu_vue___default.a,
  252. __vue_template__,
  253. __vue_template_functional__,
  254. __vue_styles__,
  255. __vue_scopeId__,
  256. __vue_module_identifier__
  257. )
  258. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  259. /***/ }),
  260. /***/ 92:
  261. /***/ (function(module, exports, __webpack_require__) {
  262. "use strict";
  263. exports.__esModule = true;
  264. var _collapseTransition = __webpack_require__(21);
  265. var _collapseTransition2 = _interopRequireDefault(_collapseTransition);
  266. var _menuMixin = __webpack_require__(34);
  267. var _menuMixin2 = _interopRequireDefault(_menuMixin);
  268. var _emitter = __webpack_require__(1);
  269. var _emitter2 = _interopRequireDefault(_emitter);
  270. var _vuePopper = __webpack_require__(7);
  271. var _vuePopper2 = _interopRequireDefault(_vuePopper);
  272. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  273. var poperMixins = {
  274. props: {
  275. transformOrigin: {
  276. type: [Boolean, String],
  277. default: false
  278. },
  279. offset: _vuePopper2.default.props.offset,
  280. boundariesPadding: _vuePopper2.default.props.boundariesPadding,
  281. popperOptions: _vuePopper2.default.props.popperOptions
  282. },
  283. data: _vuePopper2.default.data,
  284. methods: _vuePopper2.default.methods,
  285. beforeDestroy: _vuePopper2.default.beforeDestroy,
  286. deactivated: _vuePopper2.default.deactivated
  287. };
  288. exports.default = {
  289. name: 'ElSubmenu',
  290. componentName: 'ElSubmenu',
  291. mixins: [_menuMixin2.default, _emitter2.default, poperMixins],
  292. components: { ElCollapseTransition: _collapseTransition2.default },
  293. props: {
  294. index: {
  295. type: String,
  296. required: true
  297. },
  298. showTimeout: {
  299. type: Number,
  300. default: 300
  301. },
  302. hideTimeout: {
  303. type: Number,
  304. default: 300
  305. },
  306. popperClass: String,
  307. disabled: Boolean,
  308. popperAppendToBody: {
  309. type: Boolean,
  310. default: undefined
  311. }
  312. },
  313. data: function data() {
  314. return {
  315. popperJS: null,
  316. timeout: null,
  317. items: {},
  318. submenus: {},
  319. mouseInChild: false
  320. };
  321. },
  322. watch: {
  323. opened: function opened(val) {
  324. var _this = this;
  325. if (this.isMenuPopup) {
  326. this.$nextTick(function (_) {
  327. _this.updatePopper();
  328. });
  329. }
  330. }
  331. },
  332. computed: {
  333. // popper option
  334. appendToBody: function appendToBody() {
  335. return this.popperAppendToBody === undefined ? this.isFirstLevel : this.popperAppendToBody;
  336. },
  337. menuTransitionName: function menuTransitionName() {
  338. return this.rootMenu.collapse ? 'el-zoom-in-left' : 'el-zoom-in-top';
  339. },
  340. opened: function opened() {
  341. return this.rootMenu.openedMenus.indexOf(this.index) > -1;
  342. },
  343. active: function active() {
  344. var isActive = false;
  345. var submenus = this.submenus;
  346. var items = this.items;
  347. Object.keys(items).forEach(function (index) {
  348. if (items[index].active) {
  349. isActive = true;
  350. }
  351. });
  352. Object.keys(submenus).forEach(function (index) {
  353. if (submenus[index].active) {
  354. isActive = true;
  355. }
  356. });
  357. return isActive;
  358. },
  359. hoverBackground: function hoverBackground() {
  360. return this.rootMenu.hoverBackground;
  361. },
  362. backgroundColor: function backgroundColor() {
  363. return this.rootMenu.backgroundColor || '';
  364. },
  365. activeTextColor: function activeTextColor() {
  366. return this.rootMenu.activeTextColor || '';
  367. },
  368. textColor: function textColor() {
  369. return this.rootMenu.textColor || '';
  370. },
  371. mode: function mode() {
  372. return this.rootMenu.mode;
  373. },
  374. isMenuPopup: function isMenuPopup() {
  375. return this.rootMenu.isMenuPopup;
  376. },
  377. titleStyle: function titleStyle() {
  378. if (this.mode !== 'horizontal') {
  379. return {
  380. color: this.textColor
  381. };
  382. }
  383. return {
  384. borderBottomColor: this.active ? this.rootMenu.activeTextColor ? this.activeTextColor : '' : 'transparent',
  385. color: this.active ? this.activeTextColor : this.textColor
  386. };
  387. },
  388. isFirstLevel: function isFirstLevel() {
  389. var isFirstLevel = true;
  390. var parent = this.$parent;
  391. while (parent && parent !== this.rootMenu) {
  392. if (['ElSubmenu', 'ElMenuItemGroup'].indexOf(parent.$options.componentName) > -1) {
  393. isFirstLevel = false;
  394. break;
  395. } else {
  396. parent = parent.$parent;
  397. }
  398. }
  399. return isFirstLevel;
  400. }
  401. },
  402. methods: {
  403. handleCollapseToggle: function handleCollapseToggle(value) {
  404. if (value) {
  405. this.initPopper();
  406. } else {
  407. this.doDestroy();
  408. }
  409. },
  410. addItem: function addItem(item) {
  411. this.$set(this.items, item.index, item);
  412. },
  413. removeItem: function removeItem(item) {
  414. delete this.items[item.index];
  415. },
  416. addSubmenu: function addSubmenu(item) {
  417. this.$set(this.submenus, item.index, item);
  418. },
  419. removeSubmenu: function removeSubmenu(item) {
  420. delete this.submenus[item.index];
  421. },
  422. handleClick: function handleClick() {
  423. var rootMenu = this.rootMenu,
  424. disabled = this.disabled;
  425. if (rootMenu.menuTrigger === 'hover' && rootMenu.mode === 'horizontal' || rootMenu.collapse && rootMenu.mode === 'vertical' || disabled) {
  426. return;
  427. }
  428. this.dispatch('ElMenu', 'submenu-click', this);
  429. },
  430. handleMouseenter: function handleMouseenter() {
  431. var _this2 = this;
  432. var rootMenu = this.rootMenu,
  433. disabled = this.disabled;
  434. if (rootMenu.menuTrigger === 'click' && rootMenu.mode === 'horizontal' || !rootMenu.collapse && rootMenu.mode === 'vertical' || disabled) {
  435. return;
  436. }
  437. this.dispatch('ElSubmenu', 'mouse-enter-child');
  438. clearTimeout(this.timeout);
  439. this.timeout = setTimeout(function () {
  440. _this2.rootMenu.openMenu(_this2.index, _this2.indexPath);
  441. }, this.showTimeout);
  442. },
  443. handleMouseleave: function handleMouseleave() {
  444. var _this3 = this;
  445. var rootMenu = this.rootMenu;
  446. if (rootMenu.menuTrigger === 'click' && rootMenu.mode === 'horizontal' || !rootMenu.collapse && rootMenu.mode === 'vertical') {
  447. return;
  448. }
  449. this.dispatch('ElSubmenu', 'mouse-leave-child');
  450. clearTimeout(this.timeout);
  451. this.timeout = setTimeout(function () {
  452. !_this3.mouseInChild && _this3.rootMenu.closeMenu(_this3.index);
  453. }, this.hideTimeout);
  454. },
  455. handleTitleMouseenter: function handleTitleMouseenter() {
  456. if (this.mode === 'horizontal' && !this.rootMenu.backgroundColor) return;
  457. var title = this.$refs['submenu-title'];
  458. title && (title.style.backgroundColor = this.rootMenu.hoverBackground);
  459. },
  460. handleTitleMouseleave: function handleTitleMouseleave() {
  461. if (this.mode === 'horizontal' && !this.rootMenu.backgroundColor) return;
  462. var title = this.$refs['submenu-title'];
  463. title && (title.style.backgroundColor = this.rootMenu.backgroundColor || '');
  464. },
  465. updatePlacement: function updatePlacement() {
  466. this.currentPlacement = this.mode === 'horizontal' && this.isFirstLevel ? 'bottom-start' : 'right-start';
  467. },
  468. initPopper: function initPopper() {
  469. this.referenceElm = this.$el;
  470. this.popperElm = this.$refs.menu;
  471. this.updatePlacement();
  472. }
  473. },
  474. created: function created() {
  475. var _this4 = this;
  476. this.$on('toggle-collapse', this.handleCollapseToggle);
  477. this.$on('mouse-enter-child', function () {
  478. _this4.mouseInChild = true;
  479. clearTimeout(_this4.timeout);
  480. });
  481. this.$on('mouse-leave-child', function () {
  482. _this4.mouseInChild = false;
  483. clearTimeout(_this4.timeout);
  484. });
  485. },
  486. mounted: function mounted() {
  487. this.parentMenu.addSubmenu(this);
  488. this.rootMenu.addSubmenu(this);
  489. this.initPopper();
  490. },
  491. beforeDestroy: function beforeDestroy() {
  492. this.parentMenu.removeSubmenu(this);
  493. this.rootMenu.removeSubmenu(this);
  494. },
  495. render: function render(h) {
  496. var active = this.active,
  497. opened = this.opened,
  498. paddingStyle = this.paddingStyle,
  499. titleStyle = this.titleStyle,
  500. backgroundColor = this.backgroundColor,
  501. rootMenu = this.rootMenu,
  502. currentPlacement = this.currentPlacement,
  503. menuTransitionName = this.menuTransitionName,
  504. mode = this.mode,
  505. disabled = this.disabled,
  506. popperClass = this.popperClass,
  507. $slots = this.$slots,
  508. isFirstLevel = this.isFirstLevel;
  509. var popupMenu = h(
  510. 'transition',
  511. {
  512. attrs: { name: menuTransitionName }
  513. },
  514. [h(
  515. 'div',
  516. {
  517. ref: 'menu',
  518. directives: [{
  519. name: 'show',
  520. value: opened
  521. }],
  522. 'class': ['el-menu--' + mode, popperClass],
  523. on: {
  524. 'mouseenter': this.handleMouseenter,
  525. 'mouseleave': this.handleMouseleave,
  526. 'focus': this.handleMouseenter
  527. }
  528. },
  529. [h(
  530. 'ul',
  531. {
  532. attrs: {
  533. role: 'menu'
  534. },
  535. 'class': ['el-menu el-menu--popup', 'el-menu--popup-' + currentPlacement],
  536. style: { backgroundColor: rootMenu.backgroundColor || '' } },
  537. [$slots.default]
  538. )]
  539. )]
  540. );
  541. var inlineMenu = h(
  542. 'el-collapse-transition',
  543. null,
  544. [h(
  545. 'ul',
  546. {
  547. attrs: {
  548. role: 'menu'
  549. },
  550. 'class': 'el-menu el-menu--inline',
  551. directives: [{
  552. name: 'show',
  553. value: opened
  554. }],
  555. style: { backgroundColor: rootMenu.backgroundColor || '' } },
  556. [$slots.default]
  557. )]
  558. );
  559. var submenuTitleIcon = rootMenu.mode === 'horizontal' && isFirstLevel || rootMenu.mode === 'vertical' && !rootMenu.collapse ? 'el-icon-arrow-down' : 'el-icon-arrow-right';
  560. return h(
  561. 'li',
  562. {
  563. 'class': {
  564. 'el-submenu': true,
  565. 'is-active': active,
  566. 'is-opened': opened,
  567. 'is-disabled': disabled
  568. },
  569. attrs: { role: 'menuitem',
  570. 'aria-haspopup': 'true',
  571. 'aria-expanded': opened
  572. },
  573. on: {
  574. 'mouseenter': this.handleMouseenter,
  575. 'mouseleave': this.handleMouseleave,
  576. 'focus': this.handleMouseenter
  577. }
  578. },
  579. [h(
  580. 'div',
  581. {
  582. 'class': 'el-submenu__title',
  583. ref: 'submenu-title',
  584. on: {
  585. 'click': this.handleClick,
  586. 'mouseenter': this.handleTitleMouseenter,
  587. 'mouseleave': this.handleTitleMouseleave
  588. },
  589. style: [paddingStyle, titleStyle, { backgroundColor: backgroundColor }]
  590. },
  591. [$slots.title, h(
  592. 'i',
  593. { 'class': ['el-submenu__icon-arrow', submenuTitleIcon] },
  594. []
  595. )]
  596. ), this.isMenuPopup ? popupMenu : inlineMenu]
  597. );
  598. }
  599. };
  600. /***/ })
  601. /******/ });