tree.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532
  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__(342);
  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. /***/ 14:
  83. /***/ function(module, exports) {
  84. module.exports = require("element-ui/lib/mixins/emitter");
  85. /***/ },
  86. /***/ 61:
  87. /***/ function(module, exports) {
  88. module.exports = require("element-ui/lib/locale");
  89. /***/ },
  90. /***/ 80:
  91. /***/ function(module, exports) {
  92. module.exports = require("element-ui/lib/transitions/collapse-transition");
  93. /***/ },
  94. /***/ 164:
  95. /***/ function(module, exports) {
  96. module.exports = require("element-ui/lib/utils/merge");
  97. /***/ },
  98. /***/ 304:
  99. /***/ function(module, exports) {
  100. module.exports = require("element-ui/lib/checkbox");
  101. /***/ },
  102. /***/ 342:
  103. /***/ function(module, exports, __webpack_require__) {
  104. 'use strict';
  105. exports.__esModule = true;
  106. var _tree = __webpack_require__(343);
  107. var _tree2 = _interopRequireDefault(_tree);
  108. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  109. /* istanbul ignore next */
  110. _tree2.default.install = function (Vue) {
  111. Vue.component(_tree2.default.name, _tree2.default);
  112. };
  113. exports.default = _tree2.default;
  114. /***/ },
  115. /***/ 343:
  116. /***/ function(module, exports, __webpack_require__) {
  117. var Component = __webpack_require__(3)(
  118. /* script */
  119. __webpack_require__(344),
  120. /* template */
  121. __webpack_require__(351),
  122. /* scopeId */
  123. null,
  124. /* cssModules */
  125. null
  126. )
  127. module.exports = Component.exports
  128. /***/ },
  129. /***/ 344:
  130. /***/ function(module, exports, __webpack_require__) {
  131. 'use strict';
  132. exports.__esModule = true;
  133. var _treeStore = __webpack_require__(345);
  134. var _treeStore2 = _interopRequireDefault(_treeStore);
  135. var _locale = __webpack_require__(61);
  136. var _emitter = __webpack_require__(14);
  137. var _emitter2 = _interopRequireDefault(_emitter);
  138. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  139. exports.default = {
  140. name: 'ElTree',
  141. mixins: [_emitter2.default],
  142. components: {
  143. ElTreeNode: __webpack_require__(348)
  144. },
  145. data: function data() {
  146. return {
  147. store: null,
  148. root: null,
  149. currentNode: null
  150. };
  151. },
  152. props: {
  153. data: {
  154. type: Array
  155. },
  156. emptyText: {
  157. type: String,
  158. default: function _default() {
  159. return (0, _locale.t)('el.tree.emptyText');
  160. }
  161. },
  162. nodeKey: String,
  163. checkStrictly: Boolean,
  164. defaultExpandAll: Boolean,
  165. expandOnClickNode: {
  166. type: Boolean,
  167. default: true
  168. },
  169. autoExpandParent: {
  170. type: Boolean,
  171. default: true
  172. },
  173. defaultCheckedKeys: Array,
  174. defaultExpandedKeys: Array,
  175. renderContent: Function,
  176. showCheckbox: {
  177. type: Boolean,
  178. default: false
  179. },
  180. props: {
  181. default: function _default() {
  182. return {
  183. children: 'children',
  184. label: 'label',
  185. icon: 'icon'
  186. };
  187. }
  188. },
  189. lazy: {
  190. type: Boolean,
  191. default: false
  192. },
  193. highlightCurrent: Boolean,
  194. currentNodeKey: [String, Number],
  195. load: Function,
  196. filterNodeMethod: Function,
  197. accordion: Boolean,
  198. indent: {
  199. type: Number,
  200. default: 16
  201. }
  202. },
  203. computed: {
  204. children: {
  205. set: function set(value) {
  206. this.data = value;
  207. },
  208. get: function get() {
  209. return this.data;
  210. }
  211. }
  212. },
  213. watch: {
  214. defaultCheckedKeys: function defaultCheckedKeys(newVal) {
  215. this.store.defaultCheckedKeys = newVal;
  216. this.store.setDefaultCheckedKey(newVal);
  217. },
  218. defaultExpandedKeys: function defaultExpandedKeys(newVal) {
  219. this.store.defaultExpandedKeys = newVal;
  220. this.store.setDefaultExpandedKeys(newVal);
  221. },
  222. currentNodeKey: function currentNodeKey(newVal) {
  223. this.store.setCurrentNodeKey(newVal);
  224. this.store.currentNodeKey = newVal;
  225. },
  226. data: function data(newVal) {
  227. this.store.setData(newVal);
  228. }
  229. },
  230. methods: {
  231. filter: function filter(value) {
  232. if (!this.filterNodeMethod) throw new Error('[Tree] filterNodeMethod is required when filter');
  233. this.store.filter(value);
  234. },
  235. getNodeKey: function getNodeKey(node, index) {
  236. var nodeKey = this.nodeKey;
  237. if (nodeKey && node) {
  238. return node.data[nodeKey];
  239. }
  240. return index;
  241. },
  242. getCheckedNodes: function getCheckedNodes(leafOnly) {
  243. return this.store.getCheckedNodes(leafOnly);
  244. },
  245. getCheckedKeys: function getCheckedKeys(leafOnly) {
  246. return this.store.getCheckedKeys(leafOnly);
  247. },
  248. setCheckedNodes: function setCheckedNodes(nodes, leafOnly) {
  249. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
  250. this.store.setCheckedNodes(nodes, leafOnly);
  251. },
  252. setCheckedKeys: function setCheckedKeys(keys, leafOnly) {
  253. if (!this.nodeKey) throw new Error('[Tree] nodeKey is required in setCheckedNodes');
  254. this.store.setCheckedKeys(keys, leafOnly);
  255. },
  256. setChecked: function setChecked(data, checked, deep) {
  257. this.store.setChecked(data, checked, deep);
  258. },
  259. handleNodeExpand: function handleNodeExpand(nodeData, node, instance) {
  260. this.broadcast('ElTreeNode', 'tree-node-expand', node);
  261. this.$emit('node-expand', nodeData, node, instance);
  262. }
  263. },
  264. created: function created() {
  265. this.isTree = true;
  266. this.store = new _treeStore2.default({
  267. key: this.nodeKey,
  268. data: this.data,
  269. lazy: this.lazy,
  270. props: this.props,
  271. load: this.load,
  272. currentNodeKey: this.currentNodeKey,
  273. checkStrictly: this.checkStrictly,
  274. defaultCheckedKeys: this.defaultCheckedKeys,
  275. defaultExpandedKeys: this.defaultExpandedKeys,
  276. autoExpandParent: this.autoExpandParent,
  277. defaultExpandAll: this.defaultExpandAll,
  278. filterNodeMethod: this.filterNodeMethod
  279. });
  280. this.root = this.store.root;
  281. }
  282. }; //
  283. //
  284. //
  285. //
  286. //
  287. //
  288. //
  289. //
  290. //
  291. //
  292. //
  293. //
  294. //
  295. //
  296. //
  297. //
  298. /***/ },
  299. /***/ 345:
  300. /***/ function(module, exports, __webpack_require__) {
  301. 'use strict';
  302. exports.__esModule = true;
  303. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  304. var _node = __webpack_require__(346);
  305. var _node2 = _interopRequireDefault(_node);
  306. var _util = __webpack_require__(347);
  307. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  308. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  309. var TreeStore = function () {
  310. function TreeStore(options) {
  311. var _this = this;
  312. _classCallCheck(this, TreeStore);
  313. this.currentNode = null;
  314. this.currentNodeKey = null;
  315. for (var option in options) {
  316. if (options.hasOwnProperty(option)) {
  317. this[option] = options[option];
  318. }
  319. }
  320. this.nodesMap = {};
  321. this.root = new _node2.default({
  322. data: this.data,
  323. store: this
  324. });
  325. if (this.lazy && this.load) {
  326. var loadFn = this.load;
  327. loadFn(this.root, function (data) {
  328. _this.root.doCreateChildren(data);
  329. _this._initDefaultCheckedNodes();
  330. });
  331. } else {
  332. this._initDefaultCheckedNodes();
  333. }
  334. }
  335. TreeStore.prototype.filter = function filter(value) {
  336. var filterNodeMethod = this.filterNodeMethod;
  337. var traverse = function traverse(node) {
  338. var childNodes = node.root ? node.root.childNodes : node.childNodes;
  339. childNodes.forEach(function (child) {
  340. child.visible = filterNodeMethod.call(child, value, child.data, child);
  341. traverse(child);
  342. });
  343. if (!node.visible && childNodes.length) {
  344. var allHidden = true;
  345. childNodes.forEach(function (child) {
  346. if (child.visible) allHidden = false;
  347. });
  348. if (node.root) {
  349. node.root.visible = allHidden === false;
  350. } else {
  351. node.visible = allHidden === false;
  352. }
  353. }
  354. if (node.visible && !node.isLeaf) node.expand();
  355. };
  356. traverse(this);
  357. };
  358. TreeStore.prototype.setData = function setData(newVal) {
  359. var instanceChanged = newVal !== this.root.data;
  360. this.root.setData(newVal);
  361. if (instanceChanged) {
  362. this._initDefaultCheckedNodes();
  363. }
  364. };
  365. TreeStore.prototype.getNode = function getNode(data) {
  366. var key = (typeof data === 'undefined' ? 'undefined' : _typeof(data)) !== 'object' ? data : (0, _util.getNodeKey)(this.key, data);
  367. return this.nodesMap[key];
  368. };
  369. TreeStore.prototype.insertBefore = function insertBefore(data, refData) {
  370. var refNode = this.getNode(refData);
  371. refNode.parent.insertBefore({ data: data }, refNode);
  372. };
  373. TreeStore.prototype.insertAfter = function insertAfter(data, refData) {
  374. var refNode = this.getNode(refData);
  375. refNode.parent.insertAfter({ data: data }, refNode);
  376. };
  377. TreeStore.prototype.remove = function remove(data) {
  378. var node = this.getNode(data);
  379. if (node) {
  380. node.parent.removeChild(node);
  381. }
  382. };
  383. TreeStore.prototype.append = function append(data, parentData) {
  384. var parentNode = parentData ? this.getNode(parentData) : this.root;
  385. if (parentNode) {
  386. parentNode.insertChild({ data: data });
  387. }
  388. };
  389. TreeStore.prototype._initDefaultCheckedNodes = function _initDefaultCheckedNodes() {
  390. var _this2 = this;
  391. var defaultCheckedKeys = this.defaultCheckedKeys || [];
  392. var nodesMap = this.nodesMap;
  393. defaultCheckedKeys.forEach(function (checkedKey) {
  394. var node = nodesMap[checkedKey];
  395. if (node) {
  396. node.setChecked(true, !_this2.checkStrictly);
  397. }
  398. });
  399. };
  400. TreeStore.prototype._initDefaultCheckedNode = function _initDefaultCheckedNode(node) {
  401. var defaultCheckedKeys = this.defaultCheckedKeys || [];
  402. if (defaultCheckedKeys.indexOf(node.key) !== -1) {
  403. node.setChecked(true, !this.checkStrictly);
  404. }
  405. };
  406. TreeStore.prototype.setDefaultCheckedKey = function setDefaultCheckedKey(newVal) {
  407. if (newVal !== this.defaultCheckedKeys) {
  408. this.defaultCheckedKeys = newVal;
  409. this._initDefaultCheckedNodes();
  410. }
  411. };
  412. TreeStore.prototype.registerNode = function registerNode(node) {
  413. var key = this.key;
  414. if (!key || !node || !node.data) return;
  415. var nodeKey = node.key;
  416. if (nodeKey) this.nodesMap[node.key] = node;
  417. };
  418. TreeStore.prototype.deregisterNode = function deregisterNode(node) {
  419. var key = this.key;
  420. if (!key || !node || !node.data) return;
  421. delete this.nodesMap[node.key];
  422. };
  423. TreeStore.prototype.getCheckedNodes = function getCheckedNodes() {
  424. var leafOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  425. var checkedNodes = [];
  426. var traverse = function traverse(node) {
  427. var childNodes = node.root ? node.root.childNodes : node.childNodes;
  428. childNodes.forEach(function (child) {
  429. if (!leafOnly && child.checked || leafOnly && child.isLeaf && child.checked) {
  430. checkedNodes.push(child.data);
  431. }
  432. traverse(child);
  433. });
  434. };
  435. traverse(this);
  436. return checkedNodes;
  437. };
  438. TreeStore.prototype.getCheckedKeys = function getCheckedKeys() {
  439. var leafOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  440. var key = this.key;
  441. var allNodes = this._getAllNodes();
  442. var keys = [];
  443. allNodes.forEach(function (node) {
  444. if (!leafOnly || leafOnly && node.isLeaf) {
  445. if (node.checked) {
  446. keys.push((node.data || {})[key]);
  447. }
  448. }
  449. });
  450. return keys;
  451. };
  452. TreeStore.prototype._getAllNodes = function _getAllNodes() {
  453. var allNodes = [];
  454. var nodesMap = this.nodesMap;
  455. for (var nodeKey in nodesMap) {
  456. if (nodesMap.hasOwnProperty(nodeKey)) {
  457. allNodes.push(nodesMap[nodeKey]);
  458. }
  459. }
  460. return allNodes;
  461. };
  462. TreeStore.prototype._setCheckedKeys = function _setCheckedKeys(key) {
  463. var _this3 = this;
  464. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  465. var checkedKeys = arguments[2];
  466. var allNodes = this._getAllNodes();
  467. allNodes.sort(function (a, b) {
  468. return a.level < b.level;
  469. });
  470. var keys = Object.keys(checkedKeys);
  471. allNodes.forEach(function (node) {
  472. var checked = keys.indexOf(node.data[key] + '') > -1;
  473. if (!node.isLeaf) {
  474. if (!_this3.checkStrictly) {
  475. var childNodes = node.childNodes;
  476. var all = true;
  477. var none = true;
  478. for (var i = 0, j = childNodes.length; i < j; i++) {
  479. var child = childNodes[i];
  480. if (child.checked !== true || child.indeterminate) {
  481. all = false;
  482. }
  483. if (child.checked !== false || child.indeterminate) {
  484. none = false;
  485. }
  486. }
  487. if (all) {
  488. node.setChecked(true, !_this3.checkStrictly);
  489. } else if (!all && !none) {
  490. checked = checked ? true : 'half';
  491. node.setChecked(checked, !_this3.checkStrictly && checked === true);
  492. } else if (none) {
  493. node.setChecked(checked, !_this3.checkStrictly);
  494. }
  495. } else {
  496. node.setChecked(checked, false);
  497. }
  498. if (leafOnly) {
  499. (function () {
  500. node.setChecked(false, false);
  501. var traverse = function traverse(node) {
  502. var childNodes = node.childNodes;
  503. childNodes.forEach(function (child) {
  504. if (!child.isLeaf) {
  505. child.setChecked(false, false);
  506. }
  507. traverse(child);
  508. });
  509. };
  510. traverse(node);
  511. })();
  512. }
  513. } else {
  514. node.setChecked(checked, false);
  515. }
  516. });
  517. };
  518. TreeStore.prototype.setCheckedNodes = function setCheckedNodes(array) {
  519. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  520. var key = this.key;
  521. var checkedKeys = {};
  522. array.forEach(function (item) {
  523. checkedKeys[(item || {})[key]] = true;
  524. });
  525. this._setCheckedKeys(key, leafOnly, checkedKeys);
  526. };
  527. TreeStore.prototype.setCheckedKeys = function setCheckedKeys(keys) {
  528. var leafOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  529. this.defaultCheckedKeys = keys;
  530. var key = this.key;
  531. var checkedKeys = {};
  532. keys.forEach(function (key) {
  533. checkedKeys[key] = true;
  534. });
  535. this._setCheckedKeys(key, leafOnly, checkedKeys);
  536. };
  537. TreeStore.prototype.setDefaultExpandedKeys = function setDefaultExpandedKeys(keys) {
  538. var _this4 = this;
  539. keys = keys || [];
  540. this.defaultExpandedKeys = keys;
  541. keys.forEach(function (key) {
  542. var node = _this4.getNode(key);
  543. if (node) node.expand(null, _this4.autoExpandParent);
  544. });
  545. };
  546. TreeStore.prototype.setChecked = function setChecked(data, checked, deep) {
  547. var node = this.getNode(data);
  548. if (node) {
  549. node.setChecked(!!checked, deep);
  550. }
  551. };
  552. TreeStore.prototype.getCurrentNode = function getCurrentNode() {
  553. return this.currentNode;
  554. };
  555. TreeStore.prototype.setCurrentNode = function setCurrentNode(node) {
  556. this.currentNode = node;
  557. };
  558. TreeStore.prototype.setCurrentNodeKey = function setCurrentNodeKey(key) {
  559. var node = this.getNode(key);
  560. if (node) {
  561. this.currentNode = node;
  562. }
  563. };
  564. return TreeStore;
  565. }();
  566. exports.default = TreeStore;
  567. ;
  568. /***/ },
  569. /***/ 346:
  570. /***/ function(module, exports, __webpack_require__) {
  571. 'use strict';
  572. exports.__esModule = true;
  573. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  574. var _merge = __webpack_require__(164);
  575. var _merge2 = _interopRequireDefault(_merge);
  576. var _util = __webpack_require__(347);
  577. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  578. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  579. var reInitChecked = function reInitChecked(node) {
  580. var siblings = node.childNodes;
  581. var all = true;
  582. var none = true;
  583. for (var i = 0, j = siblings.length; i < j; i++) {
  584. var sibling = siblings[i];
  585. if (sibling.checked !== true || sibling.indeterminate) {
  586. all = false;
  587. }
  588. if (sibling.checked !== false || sibling.indeterminate) {
  589. none = false;
  590. }
  591. }
  592. if (all) {
  593. node.setChecked(true);
  594. } else if (!all && !none) {
  595. node.setChecked('half');
  596. } else if (none) {
  597. node.setChecked(false);
  598. }
  599. };
  600. var getPropertyFromData = function getPropertyFromData(node, prop) {
  601. var props = node.store.props;
  602. var data = node.data || {};
  603. var config = props[prop];
  604. if (typeof config === 'function') {
  605. return config(data, node);
  606. } else if (typeof config === 'string') {
  607. return data[config];
  608. } else if (typeof config === 'undefined') {
  609. return '';
  610. }
  611. };
  612. var nodeIdSeed = 0;
  613. var Node = function () {
  614. function Node(options) {
  615. _classCallCheck(this, Node);
  616. this.id = nodeIdSeed++;
  617. this.text = null;
  618. this.checked = false;
  619. this.indeterminate = false;
  620. this.data = null;
  621. this.expanded = false;
  622. this.parent = null;
  623. this.visible = true;
  624. for (var name in options) {
  625. if (options.hasOwnProperty(name)) {
  626. this[name] = options[name];
  627. }
  628. }
  629. // internal
  630. this.level = 0;
  631. this.loaded = false;
  632. this.childNodes = [];
  633. this.loading = false;
  634. if (this.parent) {
  635. this.level = this.parent.level + 1;
  636. }
  637. var store = this.store;
  638. if (!store) {
  639. throw new Error('[Node]store is required!');
  640. }
  641. store.registerNode(this);
  642. var props = store.props;
  643. if (props && typeof props.isLeaf !== 'undefined') {
  644. var isLeaf = getPropertyFromData(this, 'isLeaf');
  645. if (typeof isLeaf === 'boolean') {
  646. this.isLeafByUser = isLeaf;
  647. }
  648. }
  649. if (store.lazy !== true && this.data) {
  650. this.setData(this.data);
  651. if (store.defaultExpandAll) {
  652. this.expanded = true;
  653. }
  654. } else if (this.level > 0 && store.lazy && store.defaultExpandAll) {
  655. this.expand();
  656. }
  657. if (!this.data) return;
  658. var defaultExpandedKeys = store.defaultExpandedKeys;
  659. var key = store.key;
  660. if (key && defaultExpandedKeys && defaultExpandedKeys.indexOf(this.key) !== -1) {
  661. this.expand(null, store.autoExpandParent);
  662. }
  663. if (key && store.currentNodeKey && this.key === store.currentNodeKey) {
  664. store.currentNode = this;
  665. }
  666. if (store.lazy) {
  667. store._initDefaultCheckedNode(this);
  668. }
  669. this.updateLeafState();
  670. }
  671. Node.prototype.setData = function setData(data) {
  672. if (!Array.isArray(data)) {
  673. (0, _util.markNodeData)(this, data);
  674. }
  675. this.data = data;
  676. this.childNodes = [];
  677. var children = void 0;
  678. if (this.level === 0 && this.data instanceof Array) {
  679. children = this.data;
  680. } else {
  681. children = getPropertyFromData(this, 'children') || [];
  682. }
  683. for (var i = 0, j = children.length; i < j; i++) {
  684. this.insertChild({ data: children[i] });
  685. }
  686. };
  687. Node.prototype.insertChild = function insertChild(child, index) {
  688. if (!child) throw new Error('insertChild error: child is required.');
  689. if (!(child instanceof Node)) {
  690. (0, _merge2.default)(child, {
  691. parent: this,
  692. store: this.store
  693. });
  694. child = new Node(child);
  695. }
  696. child.level = this.level + 1;
  697. if (typeof index === 'undefined' || index < 0) {
  698. this.childNodes.push(child);
  699. } else {
  700. this.childNodes.splice(index, 0, child);
  701. }
  702. this.updateLeafState();
  703. };
  704. Node.prototype.insertBefore = function insertBefore(child, ref) {
  705. var index = void 0;
  706. if (ref) {
  707. index = this.childNodes.indexOf(ref);
  708. }
  709. this.insertChild(child, index);
  710. };
  711. Node.prototype.insertAfter = function insertAfter(child, ref) {
  712. var index = void 0;
  713. if (ref) {
  714. index = this.childNodes.indexOf(ref);
  715. if (index !== -1) index += 1;
  716. }
  717. this.insertChild(child, index);
  718. };
  719. Node.prototype.removeChild = function removeChild(child) {
  720. var index = this.childNodes.indexOf(child);
  721. if (index > -1) {
  722. this.store && this.store.deregisterNode(child);
  723. child.parent = null;
  724. this.childNodes.splice(index, 1);
  725. }
  726. this.updateLeafState();
  727. };
  728. Node.prototype.removeChildByData = function removeChildByData(data) {
  729. var targetNode = null;
  730. this.childNodes.forEach(function (node) {
  731. if (node.data === data) {
  732. targetNode = node;
  733. }
  734. });
  735. if (targetNode) {
  736. this.removeChild(targetNode);
  737. }
  738. };
  739. Node.prototype.expand = function expand(callback, expandParent) {
  740. var _this = this;
  741. var done = function done() {
  742. if (expandParent) {
  743. var parent = _this.parent;
  744. while (parent.level > 0) {
  745. parent.expanded = true;
  746. parent = parent.parent;
  747. }
  748. }
  749. _this.expanded = true;
  750. if (callback) callback();
  751. };
  752. if (this.shouldLoadData()) {
  753. this.loadData(function (data) {
  754. if (data instanceof Array) {
  755. done();
  756. }
  757. });
  758. } else {
  759. done();
  760. }
  761. };
  762. Node.prototype.doCreateChildren = function doCreateChildren(array) {
  763. var _this2 = this;
  764. var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  765. array.forEach(function (item) {
  766. _this2.insertChild((0, _merge2.default)({ data: item }, defaultProps));
  767. });
  768. };
  769. Node.prototype.collapse = function collapse() {
  770. this.expanded = false;
  771. };
  772. Node.prototype.shouldLoadData = function shouldLoadData() {
  773. return this.store.lazy === true && this.store.load && !this.loaded;
  774. };
  775. Node.prototype.updateLeafState = function updateLeafState() {
  776. if (this.store.lazy === true && this.loaded !== true && typeof this.isLeafByUser !== 'undefined') {
  777. this.isLeaf = this.isLeafByUser;
  778. return;
  779. }
  780. var childNodes = this.childNodes;
  781. if (!this.store.lazy || this.store.lazy === true && this.loaded === true) {
  782. this.isLeaf = !childNodes || childNodes.length === 0;
  783. return;
  784. }
  785. this.isLeaf = false;
  786. };
  787. Node.prototype.setChecked = function setChecked(value, deep) {
  788. var _this3 = this;
  789. this.indeterminate = value === 'half';
  790. this.checked = value === true;
  791. var handleDescendants = function handleDescendants() {
  792. if (deep) {
  793. var childNodes = _this3.childNodes;
  794. for (var i = 0, j = childNodes.length; i < j; i++) {
  795. var child = childNodes[i];
  796. child.setChecked(value !== false, deep);
  797. }
  798. }
  799. };
  800. if (!this.store.checkStrictly && this.shouldLoadData()) {
  801. // Only work on lazy load data.
  802. this.loadData(function () {
  803. handleDescendants();
  804. }, {
  805. checked: value !== false
  806. });
  807. } else {
  808. handleDescendants();
  809. }
  810. var parent = this.parent;
  811. if (!parent || parent.level === 0) return;
  812. if (!this.store.checkStrictly) {
  813. reInitChecked(parent);
  814. }
  815. };
  816. Node.prototype.getChildren = function getChildren() {
  817. // this is data
  818. var data = this.data;
  819. if (!data) return null;
  820. var props = this.store.props;
  821. var children = 'children';
  822. if (props) {
  823. children = props.children || 'children';
  824. }
  825. if (data[children] === undefined) {
  826. data[children] = null;
  827. }
  828. return data[children];
  829. };
  830. Node.prototype.updateChildren = function updateChildren() {
  831. var _this4 = this;
  832. var newData = this.getChildren() || [];
  833. var oldData = this.childNodes.map(function (node) {
  834. return node.data;
  835. });
  836. var newDataMap = {};
  837. var newNodes = [];
  838. newData.forEach(function (item, index) {
  839. if (item[_util.NODE_KEY]) {
  840. newDataMap[item[_util.NODE_KEY]] = { index: index, data: item };
  841. } else {
  842. newNodes.push({ index: index, data: item });
  843. }
  844. });
  845. oldData.forEach(function (item) {
  846. if (!newDataMap[item[_util.NODE_KEY]]) _this4.removeChildByData(item);
  847. });
  848. newNodes.forEach(function (_ref) {
  849. var index = _ref.index,
  850. data = _ref.data;
  851. _this4.insertChild({ data: data }, index);
  852. });
  853. this.updateLeafState();
  854. };
  855. Node.prototype.loadData = function loadData(callback) {
  856. var _this5 = this;
  857. var defaultProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  858. if (this.store.lazy === true && this.store.load && !this.loaded && !this.loading) {
  859. this.loading = true;
  860. var resolve = function resolve(children) {
  861. _this5.loaded = true;
  862. _this5.loading = false;
  863. _this5.childNodes = [];
  864. _this5.doCreateChildren(children, defaultProps);
  865. _this5.updateLeafState();
  866. if (callback) {
  867. callback.call(_this5, children);
  868. }
  869. };
  870. this.store.load(this, resolve);
  871. } else {
  872. if (callback) {
  873. callback.call(this);
  874. }
  875. }
  876. };
  877. _createClass(Node, [{
  878. key: 'label',
  879. get: function get() {
  880. return getPropertyFromData(this, 'label');
  881. }
  882. }, {
  883. key: 'icon',
  884. get: function get() {
  885. return getPropertyFromData(this, 'icon');
  886. }
  887. }, {
  888. key: 'key',
  889. get: function get() {
  890. var nodeKey = this.store.key;
  891. if (this.data) return this.data[nodeKey];
  892. return null;
  893. }
  894. }]);
  895. return Node;
  896. }();
  897. exports.default = Node;
  898. /***/ },
  899. /***/ 347:
  900. /***/ function(module, exports) {
  901. 'use strict';
  902. exports.__esModule = true;
  903. var NODE_KEY = exports.NODE_KEY = '$treeNodeId';
  904. var markNodeData = exports.markNodeData = function markNodeData(node, data) {
  905. if (data[NODE_KEY]) return;
  906. Object.defineProperty(data, NODE_KEY, {
  907. value: node.id,
  908. enumerable: false,
  909. configurable: false,
  910. writable: false
  911. });
  912. };
  913. var getNodeKey = exports.getNodeKey = function getNodeKey(key, data) {
  914. if (!key) return data[NODE_KEY];
  915. return data[key];
  916. };
  917. /***/ },
  918. /***/ 348:
  919. /***/ function(module, exports, __webpack_require__) {
  920. var Component = __webpack_require__(3)(
  921. /* script */
  922. __webpack_require__(349),
  923. /* template */
  924. __webpack_require__(350),
  925. /* scopeId */
  926. null,
  927. /* cssModules */
  928. null
  929. )
  930. module.exports = Component.exports
  931. /***/ },
  932. /***/ 349:
  933. /***/ function(module, exports, __webpack_require__) {
  934. 'use strict';
  935. exports.__esModule = true;
  936. var _collapseTransition = __webpack_require__(80);
  937. var _collapseTransition2 = _interopRequireDefault(_collapseTransition);
  938. var _checkbox = __webpack_require__(304);
  939. var _checkbox2 = _interopRequireDefault(_checkbox);
  940. var _emitter = __webpack_require__(14);
  941. var _emitter2 = _interopRequireDefault(_emitter);
  942. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  943. exports.default = {
  944. name: 'ElTreeNode',
  945. componentName: 'ElTreeNode',
  946. mixins: [_emitter2.default],
  947. props: {
  948. node: {
  949. default: function _default() {
  950. return {};
  951. }
  952. },
  953. props: {},
  954. renderContent: Function
  955. },
  956. components: {
  957. ElCheckbox: _checkbox2.default,
  958. CollapseTransition: _collapseTransition2.default,
  959. NodeContent: {
  960. props: {
  961. node: {
  962. required: true
  963. }
  964. },
  965. render: function render(h) {
  966. var parent = this.$parent;
  967. var node = this.node;
  968. var data = node.data;
  969. var store = node.store;
  970. return parent.renderContent ? parent.renderContent.call(parent._renderProxy, h, { _self: parent.tree.$vnode.context, node: node, data: data, store: store }) : h(
  971. 'span',
  972. { 'class': 'el-tree-node__label' },
  973. [this.node.label]
  974. );
  975. }
  976. }
  977. },
  978. data: function data() {
  979. return {
  980. tree: null,
  981. expanded: false,
  982. childNodeRendered: false,
  983. showCheckbox: false,
  984. oldChecked: null,
  985. oldIndeterminate: null
  986. };
  987. },
  988. watch: {
  989. 'node.indeterminate': function nodeIndeterminate(val) {
  990. this.handleSelectChange(this.node.checked, val);
  991. },
  992. 'node.checked': function nodeChecked(val) {
  993. this.handleSelectChange(val, this.node.indeterminate);
  994. },
  995. 'node.expanded': function nodeExpanded(val) {
  996. this.expanded = val;
  997. if (val) {
  998. this.childNodeRendered = true;
  999. }
  1000. }
  1001. },
  1002. methods: {
  1003. getNodeKey: function getNodeKey(node, index) {
  1004. var nodeKey = this.tree.nodeKey;
  1005. if (nodeKey && node) {
  1006. return node.data[nodeKey];
  1007. }
  1008. return index;
  1009. },
  1010. handleSelectChange: function handleSelectChange(checked, indeterminate) {
  1011. if (this.oldChecked !== checked && this.oldIndeterminate !== indeterminate) {
  1012. this.tree.$emit('check-change', this.node.data, checked, indeterminate);
  1013. }
  1014. this.oldChecked = checked;
  1015. this.indeterminate = indeterminate;
  1016. },
  1017. handleClick: function handleClick() {
  1018. var store = this.tree.store;
  1019. store.setCurrentNode(this.node);
  1020. this.tree.$emit('current-change', store.currentNode ? store.currentNode.data : null, store.currentNode);
  1021. this.tree.currentNode = this;
  1022. if (this.tree.expandOnClickNode) {
  1023. this.handleExpandIconClick();
  1024. }
  1025. this.tree.$emit('node-click', this.node.data, this.node, this);
  1026. },
  1027. handleExpandIconClick: function handleExpandIconClick() {
  1028. if (this.node.isLeaf) return;
  1029. if (this.expanded) {
  1030. this.tree.$emit('node-collapse', this.node.data, this.node, this);
  1031. this.node.collapse();
  1032. } else {
  1033. this.node.expand();
  1034. this.$emit('node-expand', this.node.data, this.node, this);
  1035. }
  1036. },
  1037. handleUserClick: function handleUserClick() {
  1038. if (this.node.indeterminate) {
  1039. this.node.setChecked(this.node.checked, !this.tree.checkStrictly);
  1040. }
  1041. },
  1042. handleCheckChange: function handleCheckChange(ev) {
  1043. if (!this.node.indeterminate) {
  1044. this.node.setChecked(ev.target.checked, !this.tree.checkStrictly);
  1045. }
  1046. },
  1047. handleChildNodeExpand: function handleChildNodeExpand(nodeData, node, instance) {
  1048. this.broadcast('ElTreeNode', 'tree-node-expand', node);
  1049. this.tree.$emit('node-expand', nodeData, node, instance);
  1050. }
  1051. },
  1052. created: function created() {
  1053. var _this = this;
  1054. var parent = this.$parent;
  1055. if (parent.isTree) {
  1056. this.tree = parent;
  1057. } else {
  1058. this.tree = parent.tree;
  1059. }
  1060. var tree = this.tree;
  1061. if (!tree) {
  1062. console.warn('Can not find node\'s tree.');
  1063. }
  1064. var props = tree.props || {};
  1065. var childrenKey = props['children'] || 'children';
  1066. this.$watch('node.data.' + childrenKey, function () {
  1067. _this.node.updateChildren();
  1068. });
  1069. this.showCheckbox = tree.showCheckbox;
  1070. if (this.node.expanded) {
  1071. this.expanded = true;
  1072. this.childNodeRendered = true;
  1073. }
  1074. if (this.tree.accordion) {
  1075. this.$on('tree-node-expand', function (node) {
  1076. if (_this.node !== node) {
  1077. _this.node.collapse();
  1078. }
  1079. });
  1080. }
  1081. }
  1082. }; //
  1083. //
  1084. //
  1085. //
  1086. //
  1087. //
  1088. //
  1089. //
  1090. //
  1091. //
  1092. //
  1093. //
  1094. //
  1095. //
  1096. //
  1097. //
  1098. //
  1099. //
  1100. //
  1101. //
  1102. //
  1103. //
  1104. //
  1105. //
  1106. //
  1107. //
  1108. //
  1109. //
  1110. //
  1111. //
  1112. //
  1113. //
  1114. //
  1115. //
  1116. //
  1117. //
  1118. //
  1119. //
  1120. //
  1121. //
  1122. //
  1123. //
  1124. //
  1125. //
  1126. //
  1127. /***/ },
  1128. /***/ 350:
  1129. /***/ function(module, exports) {
  1130. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  1131. return _c('div', {
  1132. directives: [{
  1133. name: "show",
  1134. rawName: "v-show",
  1135. value: (_vm.node.visible),
  1136. expression: "node.visible"
  1137. }],
  1138. staticClass: "el-tree-node",
  1139. class: {
  1140. 'is-expanded': _vm.childNodeRendered && _vm.expanded,
  1141. 'is-current': _vm.tree.store.currentNode === _vm.node,
  1142. 'is-hidden': !_vm.node.visible
  1143. },
  1144. on: {
  1145. "click": function($event) {
  1146. $event.stopPropagation();
  1147. _vm.handleClick($event)
  1148. }
  1149. }
  1150. }, [_c('div', {
  1151. staticClass: "el-tree-node__content",
  1152. style: ({
  1153. 'padding-left': (_vm.node.level - 1) * _vm.tree.indent + 'px'
  1154. })
  1155. }, [_c('span', {
  1156. staticClass: "el-tree-node__expand-icon",
  1157. class: {
  1158. 'is-leaf': _vm.node.isLeaf, expanded: !_vm.node.isLeaf && _vm.expanded
  1159. },
  1160. on: {
  1161. "click": function($event) {
  1162. $event.stopPropagation();
  1163. _vm.handleExpandIconClick($event)
  1164. }
  1165. }
  1166. }), (_vm.showCheckbox) ? _c('el-checkbox', {
  1167. directives: [{
  1168. name: "model",
  1169. rawName: "v-model",
  1170. value: (_vm.node.checked),
  1171. expression: "node.checked"
  1172. }],
  1173. attrs: {
  1174. "indeterminate": _vm.node.indeterminate
  1175. },
  1176. domProps: {
  1177. "value": (_vm.node.checked)
  1178. },
  1179. on: {
  1180. "change": _vm.handleCheckChange,
  1181. "input": function($event) {
  1182. _vm.node.checked = $event
  1183. }
  1184. },
  1185. nativeOn: {
  1186. "click": function($event) {
  1187. $event.stopPropagation();
  1188. _vm.handleUserClick($event)
  1189. }
  1190. }
  1191. }) : _vm._e(), (_vm.node.loading) ? _c('span', {
  1192. staticClass: "el-tree-node__loading-icon el-icon-loading"
  1193. }) : _vm._e(), _c('node-content', {
  1194. attrs: {
  1195. "node": _vm.node
  1196. }
  1197. })], 1), _c('collapse-transition', [_c('div', {
  1198. directives: [{
  1199. name: "show",
  1200. rawName: "v-show",
  1201. value: (_vm.expanded),
  1202. expression: "expanded"
  1203. }],
  1204. staticClass: "el-tree-node__children"
  1205. }, _vm._l((_vm.node.childNodes), function(child) {
  1206. return _c('el-tree-node', {
  1207. key: _vm.getNodeKey(child),
  1208. attrs: {
  1209. "render-content": _vm.renderContent,
  1210. "node": child
  1211. },
  1212. on: {
  1213. "node-expand": _vm.handleChildNodeExpand
  1214. }
  1215. })
  1216. }))])], 1)
  1217. },staticRenderFns: []}
  1218. /***/ },
  1219. /***/ 351:
  1220. /***/ function(module, exports) {
  1221. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  1222. return _c('div', {
  1223. staticClass: "el-tree",
  1224. class: {
  1225. 'el-tree--highlight-current': _vm.highlightCurrent
  1226. }
  1227. }, [_vm._l((_vm.root.childNodes), function(child) {
  1228. return _c('el-tree-node', {
  1229. key: _vm.getNodeKey(child),
  1230. attrs: {
  1231. "node": child,
  1232. "props": _vm.props,
  1233. "render-content": _vm.renderContent
  1234. },
  1235. on: {
  1236. "node-expand": _vm.handleNodeExpand
  1237. }
  1238. })
  1239. }), (!_vm.root.childNodes || _vm.root.childNodes.length === 0) ? _c('div', {
  1240. staticClass: "el-tree__empty-block"
  1241. }, [_c('span', {
  1242. staticClass: "el-tree__empty-text"
  1243. }, [_vm._v(_vm._s(_vm.emptyText))])]) : _vm._e()], 2)
  1244. },staticRenderFns: []}
  1245. /***/ }
  1246. /******/ });