menu.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 62);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 10:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/mixins/migrating");
  182. /***/ }),
  183. /***/ 2:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/utils/dom");
  186. /***/ }),
  187. /***/ 3:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/mixins/emitter");
  190. /***/ }),
  191. /***/ 62:
  192. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  193. "use strict";
  194. __webpack_require__.r(__webpack_exports__);
  195. // EXTERNAL MODULE: external "element-ui/lib/mixins/emitter"
  196. var emitter_ = __webpack_require__(3);
  197. var emitter_default = /*#__PURE__*/__webpack_require__.n(emitter_);
  198. // EXTERNAL MODULE: external "element-ui/lib/mixins/migrating"
  199. var migrating_ = __webpack_require__(10);
  200. var migrating_default = /*#__PURE__*/__webpack_require__.n(migrating_);
  201. // CONCATENATED MODULE: ./src/utils/aria-utils.js
  202. var aria = aria || {};
  203. aria.Utils = aria.Utils || {};
  204. /**
  205. * @desc Set focus on descendant nodes until the first focusable element is
  206. * found.
  207. * @param element
  208. * DOM node for which to find the first focusable descendant.
  209. * @returns
  210. * true if a focusable element is found and focus is set.
  211. */
  212. aria.Utils.focusFirstDescendant = function (element) {
  213. for (var i = 0; i < element.childNodes.length; i++) {
  214. var child = element.childNodes[i];
  215. if (aria.Utils.attemptFocus(child) || aria.Utils.focusFirstDescendant(child)) {
  216. return true;
  217. }
  218. }
  219. return false;
  220. };
  221. /**
  222. * @desc Find the last descendant node that is focusable.
  223. * @param element
  224. * DOM node for which to find the last focusable descendant.
  225. * @returns
  226. * true if a focusable element is found and focus is set.
  227. */
  228. aria.Utils.focusLastDescendant = function (element) {
  229. for (var i = element.childNodes.length - 1; i >= 0; i--) {
  230. var child = element.childNodes[i];
  231. if (aria.Utils.attemptFocus(child) || aria.Utils.focusLastDescendant(child)) {
  232. return true;
  233. }
  234. }
  235. return false;
  236. };
  237. /**
  238. * @desc Set Attempt to set focus on the current node.
  239. * @param element
  240. * The node to attempt to focus on.
  241. * @returns
  242. * true if element is focused.
  243. */
  244. aria.Utils.attemptFocus = function (element) {
  245. if (!aria.Utils.isFocusable(element)) {
  246. return false;
  247. }
  248. aria.Utils.IgnoreUtilFocusChanges = true;
  249. try {
  250. element.focus();
  251. } catch (e) {}
  252. aria.Utils.IgnoreUtilFocusChanges = false;
  253. return document.activeElement === element;
  254. };
  255. aria.Utils.isFocusable = function (element) {
  256. if (element.tabIndex > 0 || element.tabIndex === 0 && element.getAttribute('tabIndex') !== null) {
  257. return true;
  258. }
  259. if (element.disabled) {
  260. return false;
  261. }
  262. switch (element.nodeName) {
  263. case 'A':
  264. return !!element.href && element.rel !== 'ignore';
  265. case 'INPUT':
  266. return element.type !== 'hidden' && element.type !== 'file';
  267. case 'BUTTON':
  268. case 'SELECT':
  269. case 'TEXTAREA':
  270. return true;
  271. default:
  272. return false;
  273. }
  274. };
  275. /**
  276. * 触发一个事件
  277. * mouseenter, mouseleave, mouseover, keyup, change, click 等
  278. * @param {Element} elm
  279. * @param {String} name
  280. * @param {*} opts
  281. */
  282. aria.Utils.triggerEvent = function (elm, name) {
  283. var eventName = void 0;
  284. if (/^mouse|click/.test(name)) {
  285. eventName = 'MouseEvents';
  286. } else if (/^key/.test(name)) {
  287. eventName = 'KeyboardEvent';
  288. } else {
  289. eventName = 'HTMLEvents';
  290. }
  291. var evt = document.createEvent(eventName);
  292. for (var _len = arguments.length, opts = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  293. opts[_key - 2] = arguments[_key];
  294. }
  295. evt.initEvent.apply(evt, [name].concat(opts));
  296. elm.dispatchEvent ? elm.dispatchEvent(evt) : elm.fireEvent('on' + name, evt);
  297. return elm;
  298. };
  299. aria.Utils.keys = {
  300. tab: 9,
  301. enter: 13,
  302. space: 32,
  303. left: 37,
  304. up: 38,
  305. right: 39,
  306. down: 40
  307. };
  308. /* harmony default export */ var aria_utils = (aria.Utils);
  309. // CONCATENATED MODULE: ./src/utils/menu/aria-submenu.js
  310. var SubMenu = function SubMenu(parent, domNode) {
  311. this.domNode = domNode;
  312. this.parent = parent;
  313. this.subMenuItems = [];
  314. this.subIndex = 0;
  315. this.init();
  316. };
  317. SubMenu.prototype.init = function () {
  318. this.subMenuItems = this.domNode.querySelectorAll('li');
  319. this.addListeners();
  320. };
  321. SubMenu.prototype.gotoSubIndex = function (idx) {
  322. if (idx === this.subMenuItems.length) {
  323. idx = 0;
  324. } else if (idx < 0) {
  325. idx = this.subMenuItems.length - 1;
  326. }
  327. this.subMenuItems[idx].focus();
  328. this.subIndex = idx;
  329. };
  330. SubMenu.prototype.addListeners = function () {
  331. var _this = this;
  332. var keys = aria_utils.keys;
  333. var parentNode = this.parent.domNode;
  334. Array.prototype.forEach.call(this.subMenuItems, function (el) {
  335. el.addEventListener('keydown', function (event) {
  336. var prevDef = false;
  337. switch (event.keyCode) {
  338. case keys.down:
  339. _this.gotoSubIndex(_this.subIndex + 1);
  340. prevDef = true;
  341. break;
  342. case keys.up:
  343. _this.gotoSubIndex(_this.subIndex - 1);
  344. prevDef = true;
  345. break;
  346. case keys.tab:
  347. aria_utils.triggerEvent(parentNode, 'mouseleave');
  348. break;
  349. case keys.enter:
  350. case keys.space:
  351. prevDef = true;
  352. event.currentTarget.click();
  353. break;
  354. }
  355. if (prevDef) {
  356. event.preventDefault();
  357. event.stopPropagation();
  358. }
  359. return false;
  360. });
  361. });
  362. };
  363. /* harmony default export */ var aria_submenu = (SubMenu);
  364. // CONCATENATED MODULE: ./src/utils/menu/aria-menuitem.js
  365. var MenuItem = function MenuItem(domNode) {
  366. this.domNode = domNode;
  367. this.submenu = null;
  368. this.init();
  369. };
  370. MenuItem.prototype.init = function () {
  371. this.domNode.setAttribute('tabindex', '0');
  372. var menuChild = this.domNode.querySelector('.el-menu');
  373. if (menuChild) {
  374. this.submenu = new aria_submenu(this, menuChild);
  375. }
  376. this.addListeners();
  377. };
  378. MenuItem.prototype.addListeners = function () {
  379. var _this = this;
  380. var keys = aria_utils.keys;
  381. this.domNode.addEventListener('keydown', function (event) {
  382. var prevDef = false;
  383. switch (event.keyCode) {
  384. case keys.down:
  385. aria_utils.triggerEvent(event.currentTarget, 'mouseenter');
  386. _this.submenu && _this.submenu.gotoSubIndex(0);
  387. prevDef = true;
  388. break;
  389. case keys.up:
  390. aria_utils.triggerEvent(event.currentTarget, 'mouseenter');
  391. _this.submenu && _this.submenu.gotoSubIndex(_this.submenu.subMenuItems.length - 1);
  392. prevDef = true;
  393. break;
  394. case keys.tab:
  395. aria_utils.triggerEvent(event.currentTarget, 'mouseleave');
  396. break;
  397. case keys.enter:
  398. case keys.space:
  399. prevDef = true;
  400. event.currentTarget.click();
  401. break;
  402. }
  403. if (prevDef) {
  404. event.preventDefault();
  405. }
  406. });
  407. };
  408. /* harmony default export */ var aria_menuitem = (MenuItem);
  409. // CONCATENATED MODULE: ./src/utils/menu/aria-menubar.js
  410. var Menu = function Menu(domNode) {
  411. this.domNode = domNode;
  412. this.init();
  413. };
  414. Menu.prototype.init = function () {
  415. var menuChildren = this.domNode.childNodes;
  416. [].filter.call(menuChildren, function (child) {
  417. return child.nodeType === 1;
  418. }).forEach(function (child) {
  419. new aria_menuitem(child); // eslint-disable-line
  420. });
  421. };
  422. /* harmony default export */ var aria_menubar = (Menu);
  423. // EXTERNAL MODULE: external "element-ui/lib/utils/dom"
  424. var dom_ = __webpack_require__(2);
  425. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/menu/src/menu.vue?vue&type=script&lang=js&
  426. /* harmony default export */ var menuvue_type_script_lang_js_ = ({
  427. name: 'ElMenu',
  428. render: function render(h) {
  429. var component = h(
  430. 'ul',
  431. {
  432. attrs: {
  433. role: 'menubar'
  434. },
  435. key: +this.collapse,
  436. style: { backgroundColor: this.backgroundColor || '' },
  437. 'class': {
  438. 'el-menu--horizontal': this.mode === 'horizontal',
  439. 'el-menu--collapse': this.collapse,
  440. "el-menu": true
  441. }
  442. },
  443. [this.$slots.default]
  444. );
  445. if (this.collapseTransition) {
  446. return h('el-menu-collapse-transition', [component]);
  447. } else {
  448. return component;
  449. }
  450. },
  451. componentName: 'ElMenu',
  452. mixins: [emitter_default.a, migrating_default.a],
  453. provide: function provide() {
  454. return {
  455. rootMenu: this
  456. };
  457. },
  458. components: {
  459. 'el-menu-collapse-transition': {
  460. functional: true,
  461. render: function render(createElement, context) {
  462. var data = {
  463. props: {
  464. mode: 'out-in'
  465. },
  466. on: {
  467. beforeEnter: function beforeEnter(el) {
  468. el.style.opacity = 0.2;
  469. },
  470. enter: function enter(el) {
  471. Object(dom_["addClass"])(el, 'el-opacity-transition');
  472. el.style.opacity = 1;
  473. },
  474. afterEnter: function afterEnter(el) {
  475. Object(dom_["removeClass"])(el, 'el-opacity-transition');
  476. el.style.opacity = '';
  477. },
  478. beforeLeave: function beforeLeave(el) {
  479. if (!el.dataset) el.dataset = {};
  480. if (Object(dom_["hasClass"])(el, 'el-menu--collapse')) {
  481. Object(dom_["removeClass"])(el, 'el-menu--collapse');
  482. el.dataset.oldOverflow = el.style.overflow;
  483. el.dataset.scrollWidth = el.clientWidth;
  484. Object(dom_["addClass"])(el, 'el-menu--collapse');
  485. } else {
  486. Object(dom_["addClass"])(el, 'el-menu--collapse');
  487. el.dataset.oldOverflow = el.style.overflow;
  488. el.dataset.scrollWidth = el.clientWidth;
  489. Object(dom_["removeClass"])(el, 'el-menu--collapse');
  490. }
  491. el.style.width = el.scrollWidth + 'px';
  492. el.style.overflow = 'hidden';
  493. },
  494. leave: function leave(el) {
  495. Object(dom_["addClass"])(el, 'horizontal-collapse-transition');
  496. el.style.width = el.dataset.scrollWidth + 'px';
  497. }
  498. }
  499. };
  500. return createElement('transition', data, context.children);
  501. }
  502. }
  503. },
  504. props: {
  505. mode: {
  506. type: String,
  507. default: 'vertical'
  508. },
  509. defaultActive: {
  510. type: String,
  511. default: ''
  512. },
  513. defaultOpeneds: Array,
  514. uniqueOpened: Boolean,
  515. router: Boolean,
  516. menuTrigger: {
  517. type: String,
  518. default: 'hover'
  519. },
  520. collapse: Boolean,
  521. backgroundColor: String,
  522. textColor: String,
  523. activeTextColor: String,
  524. collapseTransition: {
  525. type: Boolean,
  526. default: true
  527. }
  528. },
  529. data: function data() {
  530. return {
  531. activeIndex: this.defaultActive,
  532. openedMenus: this.defaultOpeneds && !this.collapse ? this.defaultOpeneds.slice(0) : [],
  533. items: {},
  534. submenus: {}
  535. };
  536. },
  537. computed: {
  538. hoverBackground: function hoverBackground() {
  539. return this.backgroundColor ? this.mixColor(this.backgroundColor, 0.2) : '';
  540. },
  541. isMenuPopup: function isMenuPopup() {
  542. return this.mode === 'horizontal' || this.mode === 'vertical' && this.collapse;
  543. }
  544. },
  545. watch: {
  546. defaultActive: function defaultActive(value) {
  547. if (!this.items[value]) {
  548. this.activeIndex = null;
  549. }
  550. this.updateActiveIndex(value);
  551. },
  552. defaultOpeneds: function defaultOpeneds(value) {
  553. if (!this.collapse) {
  554. this.openedMenus = value;
  555. }
  556. },
  557. collapse: function collapse(value) {
  558. if (value) this.openedMenus = [];
  559. this.broadcast('ElSubmenu', 'toggle-collapse', value);
  560. }
  561. },
  562. methods: {
  563. updateActiveIndex: function updateActiveIndex(val) {
  564. var item = this.items[val] || this.items[this.activeIndex] || this.items[this.defaultActive];
  565. if (item) {
  566. this.activeIndex = item.index;
  567. this.initOpenedMenu();
  568. } else {
  569. this.activeIndex = null;
  570. }
  571. },
  572. getMigratingConfig: function getMigratingConfig() {
  573. return {
  574. props: {
  575. 'theme': 'theme is removed.'
  576. }
  577. };
  578. },
  579. getColorChannels: function getColorChannels(color) {
  580. color = color.replace('#', '');
  581. if (/^[0-9a-fA-F]{3}$/.test(color)) {
  582. color = color.split('');
  583. for (var i = 2; i >= 0; i--) {
  584. color.splice(i, 0, color[i]);
  585. }
  586. color = color.join('');
  587. }
  588. if (/^[0-9a-fA-F]{6}$/.test(color)) {
  589. return {
  590. red: parseInt(color.slice(0, 2), 16),
  591. green: parseInt(color.slice(2, 4), 16),
  592. blue: parseInt(color.slice(4, 6), 16)
  593. };
  594. } else {
  595. return {
  596. red: 255,
  597. green: 255,
  598. blue: 255
  599. };
  600. }
  601. },
  602. mixColor: function mixColor(color, percent) {
  603. var _getColorChannels = this.getColorChannels(color),
  604. red = _getColorChannels.red,
  605. green = _getColorChannels.green,
  606. blue = _getColorChannels.blue;
  607. if (percent > 0) {
  608. // shade given color
  609. red *= 1 - percent;
  610. green *= 1 - percent;
  611. blue *= 1 - percent;
  612. } else {
  613. // tint given color
  614. red += (255 - red) * percent;
  615. green += (255 - green) * percent;
  616. blue += (255 - blue) * percent;
  617. }
  618. return 'rgb(' + Math.round(red) + ', ' + Math.round(green) + ', ' + Math.round(blue) + ')';
  619. },
  620. addItem: function addItem(item) {
  621. this.$set(this.items, item.index, item);
  622. },
  623. removeItem: function removeItem(item) {
  624. delete this.items[item.index];
  625. },
  626. addSubmenu: function addSubmenu(item) {
  627. this.$set(this.submenus, item.index, item);
  628. },
  629. removeSubmenu: function removeSubmenu(item) {
  630. delete this.submenus[item.index];
  631. },
  632. openMenu: function openMenu(index, indexPath) {
  633. var openedMenus = this.openedMenus;
  634. if (openedMenus.indexOf(index) !== -1) return;
  635. // 将不在该菜单路径下的其余菜单收起
  636. // collapse all menu that are not under current menu item
  637. if (this.uniqueOpened) {
  638. this.openedMenus = openedMenus.filter(function (index) {
  639. return indexPath.indexOf(index) !== -1;
  640. });
  641. }
  642. this.openedMenus.push(index);
  643. },
  644. closeMenu: function closeMenu(index) {
  645. var i = this.openedMenus.indexOf(index);
  646. if (i !== -1) {
  647. this.openedMenus.splice(i, 1);
  648. }
  649. },
  650. handleSubmenuClick: function handleSubmenuClick(submenu) {
  651. var index = submenu.index,
  652. indexPath = submenu.indexPath;
  653. var isOpened = this.openedMenus.indexOf(index) !== -1;
  654. if (isOpened) {
  655. this.closeMenu(index);
  656. this.$emit('close', index, indexPath);
  657. } else {
  658. this.openMenu(index, indexPath);
  659. this.$emit('open', index, indexPath);
  660. }
  661. },
  662. handleItemClick: function handleItemClick(item) {
  663. var _this = this;
  664. var index = item.index,
  665. indexPath = item.indexPath;
  666. var oldActiveIndex = this.activeIndex;
  667. var hasIndex = item.index !== null;
  668. if (hasIndex) {
  669. this.activeIndex = item.index;
  670. }
  671. this.$emit('select', index, indexPath, item);
  672. if (this.mode === 'horizontal' || this.collapse) {
  673. this.openedMenus = [];
  674. }
  675. if (this.router && hasIndex) {
  676. this.routeToItem(item, function (error) {
  677. _this.activeIndex = oldActiveIndex;
  678. if (error) console.error(error);
  679. });
  680. }
  681. },
  682. // 初始化展开菜单
  683. // initialize opened menu
  684. initOpenedMenu: function initOpenedMenu() {
  685. var _this2 = this;
  686. var index = this.activeIndex;
  687. var activeItem = this.items[index];
  688. if (!activeItem || this.mode === 'horizontal' || this.collapse) return;
  689. var indexPath = activeItem.indexPath;
  690. // 展开该菜单项的路径上所有子菜单
  691. // expand all submenus of the menu item
  692. indexPath.forEach(function (index) {
  693. var submenu = _this2.submenus[index];
  694. submenu && _this2.openMenu(index, submenu.indexPath);
  695. });
  696. },
  697. routeToItem: function routeToItem(item, onError) {
  698. var route = item.route || item.index;
  699. try {
  700. this.$router.push(route, function () {}, onError);
  701. } catch (e) {
  702. console.error(e);
  703. }
  704. },
  705. open: function open(index) {
  706. var _this3 = this;
  707. var indexPath = this.submenus[index.toString()].indexPath;
  708. indexPath.forEach(function (i) {
  709. return _this3.openMenu(i, indexPath);
  710. });
  711. },
  712. close: function close(index) {
  713. this.closeMenu(index);
  714. }
  715. },
  716. mounted: function mounted() {
  717. this.initOpenedMenu();
  718. this.$on('item-click', this.handleItemClick);
  719. this.$on('submenu-click', this.handleSubmenuClick);
  720. if (this.mode === 'horizontal') {
  721. new aria_menubar(this.$el); // eslint-disable-line
  722. }
  723. this.$watch('items', this.updateActiveIndex);
  724. }
  725. });
  726. // CONCATENATED MODULE: ./packages/menu/src/menu.vue?vue&type=script&lang=js&
  727. /* harmony default export */ var src_menuvue_type_script_lang_js_ = (menuvue_type_script_lang_js_);
  728. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  729. var componentNormalizer = __webpack_require__(0);
  730. // CONCATENATED MODULE: ./packages/menu/src/menu.vue
  731. var menu_render, staticRenderFns
  732. /* normalize component */
  733. var component = Object(componentNormalizer["a" /* default */])(
  734. src_menuvue_type_script_lang_js_,
  735. menu_render,
  736. staticRenderFns,
  737. false,
  738. null,
  739. null,
  740. null
  741. )
  742. /* hot reload */
  743. if (false) { var api; }
  744. component.options.__file = "packages/menu/src/menu.vue"
  745. /* harmony default export */ var menu = (component.exports);
  746. // CONCATENATED MODULE: ./packages/menu/index.js
  747. /* istanbul ignore next */
  748. menu.install = function (Vue) {
  749. Vue.component(menu.name, menu);
  750. };
  751. /* harmony default export */ var packages_menu = __webpack_exports__["default"] = (menu);
  752. /***/ })
  753. /******/ });