tabs.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(318);
  37. /***/ },
  38. /***/ 3:
  39. /***/ function(module, exports) {
  40. module.exports = function normalizeComponent (
  41. rawScriptExports,
  42. compiledTemplate,
  43. scopeId,
  44. cssModules
  45. ) {
  46. var esModule
  47. var scriptExports = rawScriptExports = rawScriptExports || {}
  48. // ES6 modules interop
  49. var type = typeof rawScriptExports.default
  50. if (type === 'object' || type === 'function') {
  51. esModule = rawScriptExports
  52. scriptExports = rawScriptExports.default
  53. }
  54. // Vue.extend constructor export interop
  55. var options = typeof scriptExports === 'function'
  56. ? scriptExports.options
  57. : scriptExports
  58. // render functions
  59. if (compiledTemplate) {
  60. options.render = compiledTemplate.render
  61. options.staticRenderFns = compiledTemplate.staticRenderFns
  62. }
  63. // scopedId
  64. if (scopeId) {
  65. options._scopeId = scopeId
  66. }
  67. // inject cssModules
  68. if (cssModules) {
  69. var computed = options.computed || (options.computed = {})
  70. Object.keys(cssModules).forEach(function (key) {
  71. var module = cssModules[key]
  72. computed[key] = function () { return module }
  73. })
  74. }
  75. return {
  76. esModule: esModule,
  77. exports: scriptExports,
  78. options: options
  79. }
  80. }
  81. /***/ },
  82. /***/ 47:
  83. /***/ function(module, exports) {
  84. module.exports = require("element-ui/lib/utils/resize-event");
  85. /***/ },
  86. /***/ 318:
  87. /***/ function(module, exports, __webpack_require__) {
  88. 'use strict';
  89. exports.__esModule = true;
  90. var _tabs = __webpack_require__(319);
  91. var _tabs2 = _interopRequireDefault(_tabs);
  92. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  93. /* istanbul ignore next */
  94. _tabs2.default.install = function (Vue) {
  95. Vue.component(_tabs2.default.name, _tabs2.default);
  96. };
  97. exports.default = _tabs2.default;
  98. /***/ },
  99. /***/ 319:
  100. /***/ function(module, exports, __webpack_require__) {
  101. var Component = __webpack_require__(3)(
  102. /* script */
  103. __webpack_require__(320),
  104. /* template */
  105. null,
  106. /* scopeId */
  107. null,
  108. /* cssModules */
  109. null
  110. )
  111. module.exports = Component.exports
  112. /***/ },
  113. /***/ 320:
  114. /***/ function(module, exports, __webpack_require__) {
  115. 'use strict';
  116. exports.__esModule = true;
  117. var _tabNav = __webpack_require__(321);
  118. var _tabNav2 = _interopRequireDefault(_tabNav);
  119. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  120. exports.default = {
  121. name: 'ElTabs',
  122. components: {
  123. TabNav: _tabNav2.default
  124. },
  125. props: {
  126. type: String,
  127. activeName: String,
  128. closable: Boolean,
  129. addable: Boolean,
  130. value: {},
  131. editable: Boolean
  132. },
  133. data: function data() {
  134. return {
  135. currentName: this.value || this.activeName,
  136. panes: []
  137. };
  138. },
  139. watch: {
  140. activeName: function activeName(value) {
  141. this.setCurrentName(value);
  142. },
  143. value: function value(_value) {
  144. this.setCurrentName(_value);
  145. },
  146. currentName: function currentName(value) {
  147. var _this = this;
  148. if (this.$refs.nav) {
  149. this.$nextTick(function (_) {
  150. _this.$refs.nav.scrollToActiveTab();
  151. });
  152. }
  153. }
  154. },
  155. methods: {
  156. handleTabClick: function handleTabClick(tab, tabName, event) {
  157. if (tab.disabled) return;
  158. this.setCurrentName(tabName);
  159. this.$emit('tab-click', tab, event);
  160. },
  161. handleTabRemove: function handleTabRemove(pane, ev) {
  162. ev.stopPropagation();
  163. this.$emit('edit', pane.name, 'remove');
  164. this.$emit('tab-remove', pane.name);
  165. },
  166. handleTabAdd: function handleTabAdd() {
  167. this.$emit('edit', null, 'add');
  168. this.$emit('tab-add');
  169. },
  170. setCurrentName: function setCurrentName(value) {
  171. this.currentName = value;
  172. this.$emit('input', value);
  173. },
  174. addPanes: function addPanes(item) {
  175. var index = this.$slots.default.indexOf(item.$vnode);
  176. this.panes.splice(index, 0, item);
  177. },
  178. removePanes: function removePanes(item) {
  179. var panes = this.panes;
  180. var index = panes.indexOf(item);
  181. if (index > -1) {
  182. panes.splice(index, 1);
  183. }
  184. }
  185. },
  186. render: function render(h) {
  187. var type = this.type,
  188. handleTabClick = this.handleTabClick,
  189. handleTabRemove = this.handleTabRemove,
  190. handleTabAdd = this.handleTabAdd,
  191. currentName = this.currentName,
  192. panes = this.panes,
  193. editable = this.editable,
  194. addable = this.addable;
  195. var newButton = editable || addable ? h(
  196. 'span',
  197. {
  198. 'class': 'el-tabs__new-tab',
  199. on: {
  200. 'click': handleTabAdd
  201. }
  202. },
  203. [h(
  204. 'i',
  205. { 'class': 'el-icon-plus' },
  206. []
  207. )]
  208. ) : null;
  209. var navData = {
  210. props: {
  211. currentName: currentName,
  212. onTabClick: handleTabClick,
  213. onTabRemove: handleTabRemove,
  214. editable: editable,
  215. type: type,
  216. panes: panes
  217. },
  218. ref: 'nav'
  219. };
  220. return h(
  221. 'div',
  222. { 'class': {
  223. 'el-tabs': true,
  224. 'el-tabs--card': type === 'card',
  225. 'el-tabs--border-card': type === 'border-card'
  226. } },
  227. [h(
  228. 'div',
  229. { 'class': 'el-tabs__header' },
  230. [newButton, h(
  231. 'tab-nav',
  232. navData,
  233. []
  234. )]
  235. ), h(
  236. 'div',
  237. { 'class': 'el-tabs__content' },
  238. [this.$slots.default]
  239. )]
  240. );
  241. },
  242. created: function created() {
  243. if (!this.currentName) {
  244. this.setCurrentName('0');
  245. }
  246. }
  247. };
  248. /***/ },
  249. /***/ 321:
  250. /***/ function(module, exports, __webpack_require__) {
  251. var Component = __webpack_require__(3)(
  252. /* script */
  253. __webpack_require__(322),
  254. /* template */
  255. null,
  256. /* scopeId */
  257. null,
  258. /* cssModules */
  259. null
  260. )
  261. module.exports = Component.exports
  262. /***/ },
  263. /***/ 322:
  264. /***/ function(module, exports, __webpack_require__) {
  265. 'use strict';
  266. exports.__esModule = true;
  267. var _tabBar = __webpack_require__(323);
  268. var _tabBar2 = _interopRequireDefault(_tabBar);
  269. var _resizeEvent = __webpack_require__(47);
  270. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  271. function noop() {}
  272. exports.default = {
  273. name: 'TabNav',
  274. components: {
  275. TabBar: _tabBar2.default
  276. },
  277. props: {
  278. panes: Array,
  279. currentName: String,
  280. editable: Boolean,
  281. onTabClick: {
  282. type: Function,
  283. default: noop
  284. },
  285. onTabRemove: {
  286. type: Function,
  287. default: noop
  288. },
  289. type: String
  290. },
  291. data: function data() {
  292. return {
  293. scrollable: false,
  294. navStyle: {
  295. transform: ''
  296. }
  297. };
  298. },
  299. methods: {
  300. scrollPrev: function scrollPrev() {
  301. var containerWidth = this.$refs.navScroll.offsetWidth;
  302. var currentOffset = this.getCurrentScrollOffset();
  303. if (!currentOffset) return;
  304. var newOffset = currentOffset > containerWidth ? currentOffset - containerWidth : 0;
  305. this.setOffset(newOffset);
  306. },
  307. scrollNext: function scrollNext() {
  308. var navWidth = this.$refs.nav.offsetWidth;
  309. var containerWidth = this.$refs.navScroll.offsetWidth;
  310. var currentOffset = this.getCurrentScrollOffset();
  311. if (navWidth - currentOffset <= containerWidth) return;
  312. var newOffset = navWidth - currentOffset > containerWidth * 2 ? currentOffset + containerWidth : navWidth - containerWidth;
  313. this.setOffset(newOffset);
  314. },
  315. scrollToActiveTab: function scrollToActiveTab() {
  316. if (!this.scrollable) return;
  317. var nav = this.$refs.nav;
  318. var activeTab = this.$el.querySelector('.is-active');
  319. var navScroll = this.$refs.navScroll;
  320. var activeTabBounding = activeTab.getBoundingClientRect();
  321. var navScrollBounding = navScroll.getBoundingClientRect();
  322. var navBounding = nav.getBoundingClientRect();
  323. var currentOffset = this.getCurrentScrollOffset();
  324. var newOffset = currentOffset;
  325. if (activeTabBounding.left < navScrollBounding.left) {
  326. newOffset = currentOffset - (navScrollBounding.left - activeTabBounding.left);
  327. }
  328. if (activeTabBounding.right > navScrollBounding.right) {
  329. newOffset = currentOffset + activeTabBounding.right - navScrollBounding.right;
  330. }
  331. if (navBounding.right < navScrollBounding.right) {
  332. newOffset = nav.offsetWidth - navScrollBounding.width;
  333. }
  334. this.setOffset(Math.max(newOffset, 0));
  335. },
  336. getCurrentScrollOffset: function getCurrentScrollOffset() {
  337. var navStyle = this.navStyle;
  338. return navStyle.transform ? Number(navStyle.transform.match(/translateX\(-(\d+(\.\d+)*)px\)/)[1]) : 0;
  339. },
  340. setOffset: function setOffset(value) {
  341. this.navStyle.transform = 'translateX(-' + value + 'px)';
  342. },
  343. update: function update() {
  344. var navWidth = this.$refs.nav.offsetWidth;
  345. var containerWidth = this.$refs.navScroll.offsetWidth;
  346. var currentOffset = this.getCurrentScrollOffset();
  347. if (containerWidth < navWidth) {
  348. var _currentOffset = this.getCurrentScrollOffset();
  349. this.scrollable = this.scrollable || {};
  350. this.scrollable.prev = _currentOffset;
  351. this.scrollable.next = _currentOffset + containerWidth < navWidth;
  352. if (navWidth - _currentOffset < containerWidth) {
  353. this.setOffset(navWidth - containerWidth);
  354. }
  355. } else {
  356. this.scrollable = false;
  357. if (currentOffset > 0) {
  358. this.setOffset(0);
  359. }
  360. }
  361. }
  362. },
  363. updated: function updated() {
  364. this.update();
  365. },
  366. render: function render(h) {
  367. var type = this.type,
  368. panes = this.panes,
  369. editable = this.editable,
  370. onTabClick = this.onTabClick,
  371. onTabRemove = this.onTabRemove,
  372. navStyle = this.navStyle,
  373. scrollable = this.scrollable,
  374. scrollNext = this.scrollNext,
  375. scrollPrev = this.scrollPrev;
  376. var scrollBtn = scrollable ? [h(
  377. 'span',
  378. { 'class': ['el-tabs__nav-prev', scrollable.prev ? '' : 'is-disabled'], on: {
  379. 'click': scrollPrev
  380. }
  381. },
  382. [h(
  383. 'i',
  384. { 'class': 'el-icon-arrow-left' },
  385. []
  386. )]
  387. ), h(
  388. 'span',
  389. { 'class': ['el-tabs__nav-next', scrollable.next ? '' : 'is-disabled'], on: {
  390. 'click': scrollNext
  391. }
  392. },
  393. [h(
  394. 'i',
  395. { 'class': 'el-icon-arrow-right' },
  396. []
  397. )]
  398. )] : null;
  399. var tabs = this._l(panes, function (pane, index) {
  400. var tabName = pane.name || pane.index || index;
  401. var closable = pane.isClosable || editable;
  402. pane.index = '' + index;
  403. var btnClose = closable ? h(
  404. 'span',
  405. { 'class': 'el-icon-close', on: {
  406. 'click': function click(ev) {
  407. onTabRemove(pane, ev);
  408. }
  409. }
  410. },
  411. []
  412. ) : null;
  413. var tabLabelContent = pane.$slots.label || pane.label;
  414. return h(
  415. 'div',
  416. {
  417. 'class': {
  418. 'el-tabs__item': true,
  419. 'is-active': pane.active,
  420. 'is-disabled': pane.disabled,
  421. 'is-closable': closable
  422. },
  423. ref: 'tabs',
  424. refInFor: true,
  425. on: {
  426. 'click': function click(ev) {
  427. onTabClick(pane, tabName, ev);
  428. }
  429. }
  430. },
  431. [tabLabelContent, btnClose]
  432. );
  433. });
  434. return h(
  435. 'div',
  436. { 'class': ['el-tabs__nav-wrap', scrollable ? 'is-scrollable' : ''] },
  437. [scrollBtn, h(
  438. 'div',
  439. { 'class': ['el-tabs__nav-scroll'], ref: 'navScroll' },
  440. [h(
  441. 'div',
  442. { 'class': 'el-tabs__nav', ref: 'nav', style: navStyle },
  443. [!type ? h(
  444. 'tab-bar',
  445. {
  446. attrs: { tabs: panes }
  447. },
  448. []
  449. ) : null, tabs]
  450. )]
  451. )]
  452. );
  453. },
  454. mounted: function mounted() {
  455. (0, _resizeEvent.addResizeListener)(this.$el, this.update);
  456. },
  457. beforeDestroy: function beforeDestroy() {
  458. if (this.$el && this.update) (0, _resizeEvent.removeResizeListener)(this.$el, this.update);
  459. }
  460. };
  461. /***/ },
  462. /***/ 323:
  463. /***/ function(module, exports, __webpack_require__) {
  464. var Component = __webpack_require__(3)(
  465. /* script */
  466. __webpack_require__(324),
  467. /* template */
  468. __webpack_require__(325),
  469. /* scopeId */
  470. null,
  471. /* cssModules */
  472. null
  473. )
  474. module.exports = Component.exports
  475. /***/ },
  476. /***/ 324:
  477. /***/ function(module, exports) {
  478. 'use strict';
  479. exports.__esModule = true;
  480. //
  481. //
  482. //
  483. exports.default = {
  484. name: 'TabBar',
  485. props: {
  486. tabs: Array
  487. },
  488. computed: {
  489. barStyle: {
  490. cache: false,
  491. get: function get() {
  492. var _this = this;
  493. if (!this.$parent.$refs.tabs) return {};
  494. var style = {};
  495. var offset = 0;
  496. var tabWidth = 0;
  497. this.tabs.every(function (tab, index) {
  498. var $el = _this.$parent.$refs.tabs[index];
  499. if (!$el) {
  500. return false;
  501. }
  502. if (!tab.active) {
  503. offset += $el.clientWidth;
  504. return true;
  505. } else {
  506. tabWidth = $el.clientWidth;
  507. return false;
  508. }
  509. });
  510. var transform = 'translateX(' + offset + 'px)';
  511. style.width = tabWidth + 'px';
  512. style.transform = transform;
  513. style.msTransform = transform;
  514. style.webkitTransform = transform;
  515. return style;
  516. }
  517. }
  518. }
  519. };
  520. /***/ },
  521. /***/ 325:
  522. /***/ function(module, exports) {
  523. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  524. return _c('div', {
  525. staticClass: "el-tabs__active-bar",
  526. style: (_vm.barStyle)
  527. })
  528. },staticRenderFns: []}
  529. /***/ }
  530. /******/ });