tabs.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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 = 232);
  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. /***/ 18:
  164. /***/ (function(module, exports) {
  165. module.exports = require("element-ui/lib/utils/resize-event");
  166. /***/ }),
  167. /***/ 232:
  168. /***/ (function(module, exports, __webpack_require__) {
  169. "use strict";
  170. exports.__esModule = true;
  171. var _tabs = __webpack_require__(233);
  172. var _tabs2 = _interopRequireDefault(_tabs);
  173. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  174. /* istanbul ignore next */
  175. _tabs2.default.install = function (Vue) {
  176. Vue.component(_tabs2.default.name, _tabs2.default);
  177. };
  178. exports.default = _tabs2.default;
  179. /***/ }),
  180. /***/ 233:
  181. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  182. "use strict";
  183. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  184. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tabs_vue__ = __webpack_require__(234);
  185. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tabs_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tabs_vue__);
  186. var normalizeComponent = __webpack_require__(0)
  187. /* script */
  188. /* template */
  189. var __vue_template__ = null
  190. /* template functional */
  191. var __vue_template_functional__ = false
  192. /* styles */
  193. var __vue_styles__ = null
  194. /* scopeId */
  195. var __vue_scopeId__ = null
  196. /* moduleIdentifier (server only) */
  197. var __vue_module_identifier__ = null
  198. var Component = normalizeComponent(
  199. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tabs_vue___default.a,
  200. __vue_template__,
  201. __vue_template_functional__,
  202. __vue_styles__,
  203. __vue_scopeId__,
  204. __vue_module_identifier__
  205. )
  206. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  207. /***/ }),
  208. /***/ 234:
  209. /***/ (function(module, exports, __webpack_require__) {
  210. "use strict";
  211. exports.__esModule = true;
  212. var _tabNav = __webpack_require__(235);
  213. var _tabNav2 = _interopRequireDefault(_tabNav);
  214. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  215. exports.default = {
  216. name: 'ElTabs',
  217. components: {
  218. TabNav: _tabNav2.default
  219. },
  220. props: {
  221. type: String,
  222. activeName: String,
  223. closable: Boolean,
  224. addable: Boolean,
  225. value: {},
  226. editable: Boolean,
  227. tabPosition: {
  228. type: String,
  229. default: 'top'
  230. },
  231. beforeLeave: Function,
  232. stretch: Boolean
  233. },
  234. provide: function provide() {
  235. return {
  236. rootTabs: this
  237. };
  238. },
  239. data: function data() {
  240. return {
  241. currentName: this.value || this.activeName,
  242. panes: []
  243. };
  244. },
  245. watch: {
  246. activeName: function activeName(value) {
  247. this.setCurrentName(value);
  248. },
  249. value: function value(_value) {
  250. this.setCurrentName(_value);
  251. },
  252. currentName: function currentName(value) {
  253. var _this = this;
  254. if (this.$refs.nav) {
  255. this.$nextTick(function () {
  256. _this.$refs.nav.$nextTick(function (_) {
  257. _this.$refs.nav.scrollToActiveTab();
  258. });
  259. });
  260. }
  261. }
  262. },
  263. methods: {
  264. calcPaneInstances: function calcPaneInstances() {
  265. var _this2 = this;
  266. if (this.$slots.default) {
  267. var paneSlots = this.$slots.default.filter(function (vnode) {
  268. return vnode.tag && vnode.componentOptions && vnode.componentOptions.Ctor.options.name === 'ElTabPane';
  269. });
  270. // update indeed
  271. var panes = paneSlots.map(function (_ref) {
  272. var componentInstance = _ref.componentInstance;
  273. return componentInstance;
  274. });
  275. if (!(panes.length === this.panes.length && panes.every(function (pane, index) {
  276. return pane === _this2.panes[index];
  277. }))) {
  278. this.panes = panes;
  279. }
  280. } else if (this.panes.length !== 0) {
  281. this.panes = [];
  282. }
  283. },
  284. handleTabClick: function handleTabClick(tab, tabName, event) {
  285. if (tab.disabled) return;
  286. this.setCurrentName(tabName);
  287. this.$emit('tab-click', tab, event);
  288. },
  289. handleTabRemove: function handleTabRemove(pane, ev) {
  290. if (pane.disabled) return;
  291. ev.stopPropagation();
  292. this.$emit('edit', pane.name, 'remove');
  293. this.$emit('tab-remove', pane.name);
  294. },
  295. handleTabAdd: function handleTabAdd() {
  296. this.$emit('edit', null, 'add');
  297. this.$emit('tab-add');
  298. },
  299. setCurrentName: function setCurrentName(value) {
  300. var _this3 = this;
  301. var changeCurrentName = function changeCurrentName() {
  302. _this3.currentName = value;
  303. _this3.$emit('input', value);
  304. };
  305. if (this.currentName !== value && this.beforeLeave) {
  306. var before = this.beforeLeave(value, this.currentName);
  307. if (before && before.then) {
  308. before.then(function () {
  309. changeCurrentName();
  310. _this3.$refs.nav && _this3.$refs.nav.removeFocus();
  311. });
  312. } else if (before !== false) {
  313. changeCurrentName();
  314. }
  315. } else {
  316. changeCurrentName();
  317. }
  318. }
  319. },
  320. render: function render(h) {
  321. var _ref2;
  322. var type = this.type,
  323. handleTabClick = this.handleTabClick,
  324. handleTabRemove = this.handleTabRemove,
  325. handleTabAdd = this.handleTabAdd,
  326. currentName = this.currentName,
  327. panes = this.panes,
  328. editable = this.editable,
  329. addable = this.addable,
  330. tabPosition = this.tabPosition,
  331. stretch = this.stretch;
  332. var newButton = editable || addable ? h(
  333. 'span',
  334. {
  335. 'class': 'el-tabs__new-tab',
  336. on: {
  337. 'click': handleTabAdd,
  338. 'keydown': function keydown(ev) {
  339. if (ev.keyCode === 13) {
  340. handleTabAdd();
  341. }
  342. }
  343. },
  344. attrs: {
  345. tabindex: '0'
  346. }
  347. },
  348. [h(
  349. 'i',
  350. { 'class': 'el-icon-plus' },
  351. []
  352. )]
  353. ) : null;
  354. var navData = {
  355. props: {
  356. currentName: currentName,
  357. onTabClick: handleTabClick,
  358. onTabRemove: handleTabRemove,
  359. editable: editable,
  360. type: type,
  361. panes: panes,
  362. stretch: stretch
  363. },
  364. ref: 'nav'
  365. };
  366. var header = h(
  367. 'div',
  368. { 'class': ['el-tabs__header', 'is-' + tabPosition] },
  369. [newButton, h(
  370. 'tab-nav',
  371. navData,
  372. []
  373. )]
  374. );
  375. var panels = h(
  376. 'div',
  377. { 'class': 'el-tabs__content' },
  378. [this.$slots.default]
  379. );
  380. return h(
  381. 'div',
  382. { 'class': (_ref2 = {
  383. 'el-tabs': true,
  384. 'el-tabs--card': type === 'card'
  385. }, _ref2['el-tabs--' + tabPosition] = true, _ref2['el-tabs--border-card'] = type === 'border-card', _ref2) },
  386. [tabPosition !== 'bottom' ? [header, panels] : [panels, header]]
  387. );
  388. },
  389. created: function created() {
  390. if (!this.currentName) {
  391. this.setCurrentName('0');
  392. }
  393. },
  394. mounted: function mounted() {
  395. this.calcPaneInstances();
  396. },
  397. updated: function updated() {
  398. this.calcPaneInstances();
  399. }
  400. };
  401. /***/ }),
  402. /***/ 235:
  403. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  404. "use strict";
  405. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  406. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tab_nav_vue__ = __webpack_require__(236);
  407. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tab_nav_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tab_nav_vue__);
  408. var normalizeComponent = __webpack_require__(0)
  409. /* script */
  410. /* template */
  411. var __vue_template__ = null
  412. /* template functional */
  413. var __vue_template_functional__ = false
  414. /* styles */
  415. var __vue_styles__ = null
  416. /* scopeId */
  417. var __vue_scopeId__ = null
  418. /* moduleIdentifier (server only) */
  419. var __vue_module_identifier__ = null
  420. var Component = normalizeComponent(
  421. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tab_nav_vue___default.a,
  422. __vue_template__,
  423. __vue_template_functional__,
  424. __vue_styles__,
  425. __vue_scopeId__,
  426. __vue_module_identifier__
  427. )
  428. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  429. /***/ }),
  430. /***/ 236:
  431. /***/ (function(module, exports, __webpack_require__) {
  432. "use strict";
  433. exports.__esModule = true;
  434. var _tabBar = __webpack_require__(237);
  435. var _tabBar2 = _interopRequireDefault(_tabBar);
  436. var _resizeEvent = __webpack_require__(18);
  437. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  438. function noop() {}
  439. var firstUpperCase = function firstUpperCase(str) {
  440. return str.toLowerCase().replace(/( |^)[a-z]/g, function (L) {
  441. return L.toUpperCase();
  442. });
  443. };
  444. exports.default = {
  445. name: 'TabNav',
  446. components: {
  447. TabBar: _tabBar2.default
  448. },
  449. inject: ['rootTabs'],
  450. props: {
  451. panes: Array,
  452. currentName: String,
  453. editable: Boolean,
  454. onTabClick: {
  455. type: Function,
  456. default: noop
  457. },
  458. onTabRemove: {
  459. type: Function,
  460. default: noop
  461. },
  462. type: String,
  463. stretch: Boolean
  464. },
  465. data: function data() {
  466. return {
  467. scrollable: false,
  468. navOffset: 0,
  469. isFocus: false,
  470. focusable: true
  471. };
  472. },
  473. computed: {
  474. navStyle: function navStyle() {
  475. var dir = ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1 ? 'X' : 'Y';
  476. return {
  477. transform: 'translate' + dir + '(-' + this.navOffset + 'px)'
  478. };
  479. },
  480. sizeName: function sizeName() {
  481. return ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1 ? 'width' : 'height';
  482. }
  483. },
  484. methods: {
  485. scrollPrev: function scrollPrev() {
  486. var containerSize = this.$refs.navScroll['offset' + firstUpperCase(this.sizeName)];
  487. var currentOffset = this.navOffset;
  488. if (!currentOffset) return;
  489. var newOffset = currentOffset > containerSize ? currentOffset - containerSize : 0;
  490. this.navOffset = newOffset;
  491. },
  492. scrollNext: function scrollNext() {
  493. var navSize = this.$refs.nav['offset' + firstUpperCase(this.sizeName)];
  494. var containerSize = this.$refs.navScroll['offset' + firstUpperCase(this.sizeName)];
  495. var currentOffset = this.navOffset;
  496. if (navSize - currentOffset <= containerSize) return;
  497. var newOffset = navSize - currentOffset > containerSize * 2 ? currentOffset + containerSize : navSize - containerSize;
  498. this.navOffset = newOffset;
  499. },
  500. scrollToActiveTab: function scrollToActiveTab() {
  501. if (!this.scrollable) return;
  502. var nav = this.$refs.nav;
  503. var activeTab = this.$el.querySelector('.is-active');
  504. if (!activeTab) return;
  505. var navScroll = this.$refs.navScroll;
  506. var activeTabBounding = activeTab.getBoundingClientRect();
  507. var navScrollBounding = navScroll.getBoundingClientRect();
  508. var maxOffset = nav.offsetWidth - navScrollBounding.width;
  509. var currentOffset = this.navOffset;
  510. var newOffset = currentOffset;
  511. if (activeTabBounding.left < navScrollBounding.left) {
  512. newOffset = currentOffset - (navScrollBounding.left - activeTabBounding.left);
  513. }
  514. if (activeTabBounding.right > navScrollBounding.right) {
  515. newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
  516. }
  517. newOffset = Math.max(newOffset, 0);
  518. this.navOffset = Math.min(newOffset, maxOffset);
  519. },
  520. update: function update() {
  521. if (!this.$refs.nav) return;
  522. var sizeName = this.sizeName;
  523. var navSize = this.$refs.nav['offset' + firstUpperCase(sizeName)];
  524. var containerSize = this.$refs.navScroll['offset' + firstUpperCase(sizeName)];
  525. var currentOffset = this.navOffset;
  526. if (containerSize < navSize) {
  527. var _currentOffset = this.navOffset;
  528. this.scrollable = this.scrollable || {};
  529. this.scrollable.prev = _currentOffset;
  530. this.scrollable.next = _currentOffset + containerSize < navSize;
  531. if (navSize - _currentOffset < containerSize) {
  532. this.navOffset = navSize - containerSize;
  533. }
  534. } else {
  535. this.scrollable = false;
  536. if (currentOffset > 0) {
  537. this.navOffset = 0;
  538. }
  539. }
  540. },
  541. changeTab: function changeTab(e) {
  542. var keyCode = e.keyCode;
  543. var nextIndex = void 0;
  544. var currentIndex = void 0,
  545. tabList = void 0;
  546. if ([37, 38, 39, 40].indexOf(keyCode) !== -1) {
  547. // 左右上下键更换tab
  548. tabList = e.currentTarget.querySelectorAll('[role=tab]');
  549. currentIndex = Array.prototype.indexOf.call(tabList, e.target);
  550. } else {
  551. return;
  552. }
  553. if (keyCode === 37 || keyCode === 38) {
  554. // left
  555. if (currentIndex === 0) {
  556. // first
  557. nextIndex = tabList.length - 1;
  558. } else {
  559. nextIndex = currentIndex - 1;
  560. }
  561. } else {
  562. // right
  563. if (currentIndex < tabList.length - 1) {
  564. // not last
  565. nextIndex = currentIndex + 1;
  566. } else {
  567. nextIndex = 0;
  568. }
  569. }
  570. tabList[nextIndex].focus(); // 改变焦点元素
  571. tabList[nextIndex].click(); // 选中下一个tab
  572. this.setFocus();
  573. },
  574. setFocus: function setFocus() {
  575. if (this.focusable) {
  576. this.isFocus = true;
  577. }
  578. },
  579. removeFocus: function removeFocus() {
  580. this.isFocus = false;
  581. },
  582. visibilityChangeHandler: function visibilityChangeHandler() {
  583. var _this = this;
  584. var visibility = document.visibilityState;
  585. if (visibility === 'hidden') {
  586. this.focusable = false;
  587. } else if (visibility === 'visible') {
  588. setTimeout(function () {
  589. _this.focusable = true;
  590. }, 50);
  591. }
  592. },
  593. windowBlurHandler: function windowBlurHandler() {
  594. this.focusable = false;
  595. },
  596. windowFocusHandler: function windowFocusHandler() {
  597. var _this2 = this;
  598. setTimeout(function () {
  599. _this2.focusable = true;
  600. }, 50);
  601. }
  602. },
  603. updated: function updated() {
  604. this.update();
  605. },
  606. render: function render(h) {
  607. var _this3 = this;
  608. var type = this.type,
  609. panes = this.panes,
  610. editable = this.editable,
  611. stretch = this.stretch,
  612. onTabClick = this.onTabClick,
  613. onTabRemove = this.onTabRemove,
  614. navStyle = this.navStyle,
  615. scrollable = this.scrollable,
  616. scrollNext = this.scrollNext,
  617. scrollPrev = this.scrollPrev,
  618. changeTab = this.changeTab,
  619. setFocus = this.setFocus,
  620. removeFocus = this.removeFocus;
  621. var scrollBtn = scrollable ? [h(
  622. 'span',
  623. { 'class': ['el-tabs__nav-prev', scrollable.prev ? '' : 'is-disabled'], on: {
  624. 'click': scrollPrev
  625. }
  626. },
  627. [h(
  628. 'i',
  629. { 'class': 'el-icon-arrow-left' },
  630. []
  631. )]
  632. ), h(
  633. 'span',
  634. { 'class': ['el-tabs__nav-next', scrollable.next ? '' : 'is-disabled'], on: {
  635. 'click': scrollNext
  636. }
  637. },
  638. [h(
  639. 'i',
  640. { 'class': 'el-icon-arrow-right' },
  641. []
  642. )]
  643. )] : null;
  644. var tabs = this._l(panes, function (pane, index) {
  645. var _ref;
  646. var tabName = pane.name || pane.index || index;
  647. var closable = pane.isClosable || editable;
  648. pane.index = '' + index;
  649. var btnClose = closable ? h(
  650. 'span',
  651. { 'class': 'el-icon-close', on: {
  652. 'click': function click(ev) {
  653. onTabRemove(pane, ev);
  654. }
  655. }
  656. },
  657. []
  658. ) : null;
  659. var tabLabelContent = pane.$slots.label || pane.label;
  660. var tabindex = pane.active ? 0 : -1;
  661. return h(
  662. 'div',
  663. {
  664. 'class': (_ref = {
  665. 'el-tabs__item': true
  666. }, _ref['is-' + _this3.rootTabs.tabPosition] = true, _ref['is-active'] = pane.active, _ref['is-disabled'] = pane.disabled, _ref['is-closable'] = closable, _ref['is-focus'] = _this3.isFocus, _ref),
  667. attrs: { id: 'tab-' + tabName,
  668. 'aria-controls': 'pane-' + tabName,
  669. role: 'tab',
  670. 'aria-selected': pane.active,
  671. tabindex: tabindex
  672. },
  673. key: 'tab-' + tabName, ref: 'tabs', refInFor: true,
  674. on: {
  675. 'focus': function focus() {
  676. setFocus();
  677. },
  678. 'blur': function blur() {
  679. removeFocus();
  680. },
  681. 'click': function click(ev) {
  682. removeFocus();onTabClick(pane, tabName, ev);
  683. },
  684. 'keydown': function keydown(ev) {
  685. if (closable && (ev.keyCode === 46 || ev.keyCode === 8)) {
  686. onTabRemove(pane, ev);
  687. }
  688. }
  689. }
  690. },
  691. [tabLabelContent, btnClose]
  692. );
  693. });
  694. return h(
  695. 'div',
  696. { 'class': ['el-tabs__nav-wrap', scrollable ? 'is-scrollable' : '', 'is-' + this.rootTabs.tabPosition] },
  697. [scrollBtn, h(
  698. 'div',
  699. { 'class': ['el-tabs__nav-scroll'], ref: 'navScroll' },
  700. [h(
  701. 'div',
  702. {
  703. 'class': ['el-tabs__nav', 'is-' + this.rootTabs.tabPosition, stretch && ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1 ? 'is-stretch' : ''],
  704. ref: 'nav',
  705. style: navStyle,
  706. attrs: { role: 'tablist'
  707. },
  708. on: {
  709. 'keydown': changeTab
  710. }
  711. },
  712. [!type ? h(
  713. 'tab-bar',
  714. {
  715. attrs: { tabs: panes }
  716. },
  717. []
  718. ) : null, tabs]
  719. )]
  720. )]
  721. );
  722. },
  723. mounted: function mounted() {
  724. (0, _resizeEvent.addResizeListener)(this.$el, this.update);
  725. document.addEventListener('visibilitychange', this.visibilityChangeHandler);
  726. window.addEventListener('blur', this.windowBlurHandler);
  727. window.addEventListener('focus', this.windowFocusHandler);
  728. },
  729. beforeDestroy: function beforeDestroy() {
  730. if (this.$el && this.update) (0, _resizeEvent.removeResizeListener)(this.$el, this.update);
  731. document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
  732. window.removeEventListener('blur', this.windowBlurHandler);
  733. window.removeEventListener('focus', this.windowFocusHandler);
  734. }
  735. };
  736. /***/ }),
  737. /***/ 237:
  738. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  739. "use strict";
  740. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  741. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tab_bar_vue__ = __webpack_require__(238);
  742. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tab_bar_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tab_bar_vue__);
  743. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_969dc580_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_tab_bar_vue__ = __webpack_require__(239);
  744. var normalizeComponent = __webpack_require__(0)
  745. /* script */
  746. /* template */
  747. /* template functional */
  748. var __vue_template_functional__ = false
  749. /* styles */
  750. var __vue_styles__ = null
  751. /* scopeId */
  752. var __vue_scopeId__ = null
  753. /* moduleIdentifier (server only) */
  754. var __vue_module_identifier__ = null
  755. var Component = normalizeComponent(
  756. __WEBPACK_IMPORTED_MODULE_0__babel_loader_node_modules_vue_loader_lib_selector_type_script_index_0_tab_bar_vue___default.a,
  757. __WEBPACK_IMPORTED_MODULE_1__node_modules_vue_loader_lib_template_compiler_index_id_data_v_969dc580_hasScoped_false_preserveWhitespace_false_buble_transforms_node_modules_vue_loader_lib_selector_type_template_index_0_tab_bar_vue__["a" /* default */],
  758. __vue_template_functional__,
  759. __vue_styles__,
  760. __vue_scopeId__,
  761. __vue_module_identifier__
  762. )
  763. /* harmony default export */ __webpack_exports__["default"] = (Component.exports);
  764. /***/ }),
  765. /***/ 238:
  766. /***/ (function(module, exports, __webpack_require__) {
  767. "use strict";
  768. exports.__esModule = true;
  769. //
  770. //
  771. //
  772. exports.default = {
  773. name: 'TabBar',
  774. props: {
  775. tabs: Array
  776. },
  777. inject: ['rootTabs'],
  778. computed: {
  779. barStyle: {
  780. cache: false,
  781. get: function get() {
  782. var _this = this;
  783. if (!this.$parent.$refs.tabs) return {};
  784. var style = {};
  785. var offset = 0;
  786. var tabSize = 0;
  787. var sizeName = ['top', 'bottom'].indexOf(this.rootTabs.tabPosition) !== -1 ? 'width' : 'height';
  788. var sizeDir = sizeName === 'width' ? 'x' : 'y';
  789. var firstUpperCase = function firstUpperCase(str) {
  790. return str.toLowerCase().replace(/( |^)[a-z]/g, function (L) {
  791. return L.toUpperCase();
  792. });
  793. };
  794. this.tabs.every(function (tab, index) {
  795. var $el = _this.$parent.$refs.tabs[index];
  796. if (!$el) {
  797. return false;
  798. }
  799. if (!tab.active) {
  800. offset += $el['client' + firstUpperCase(sizeName)];
  801. return true;
  802. } else {
  803. tabSize = $el['client' + firstUpperCase(sizeName)];
  804. if (sizeName === 'width' && _this.tabs.length > 1) {
  805. tabSize -= index === 0 || index === _this.tabs.length - 1 ? 20 : 40;
  806. }
  807. return false;
  808. }
  809. });
  810. if (sizeName === 'width' && offset !== 0) {
  811. offset += 20;
  812. }
  813. var transform = 'translate' + firstUpperCase(sizeDir) + '(' + offset + 'px)';
  814. style[sizeName] = tabSize + 'px';
  815. style.transform = transform;
  816. style.msTransform = transform;
  817. style.webkitTransform = transform;
  818. return style;
  819. }
  820. }
  821. }
  822. };
  823. /***/ }),
  824. /***/ 239:
  825. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  826. "use strict";
  827. var render = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"el-tabs__active-bar",class:("is-" + (_vm.rootTabs.tabPosition)),style:(_vm.barStyle)})}
  828. var staticRenderFns = []
  829. var esExports = { render: render, staticRenderFns: staticRenderFns }
  830. /* harmony default export */ __webpack_exports__["a"] = (esExports);
  831. /***/ })
  832. /******/ });