框架源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

869 lines
24 KiB

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