misp-ui-library-test 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -0
- package/dist/theme-chalk/alert/index.scss +152 -0
- package/dist/theme-chalk/avatar/index.scss +51 -0
- package/dist/theme-chalk/backtop/index.scss +38 -0
- package/dist/theme-chalk/badge/index.scss +63 -0
- package/dist/theme-chalk/breadcrumb/index.scss +36 -0
- package/dist/theme-chalk/breadcrumb-item/index.scss +36 -0
- package/dist/theme-chalk/button/index.scss +157 -0
- package/dist/theme-chalk/card/index.scss +38 -0
- package/dist/theme-chalk/chart/index.scss +21 -0
- package/dist/theme-chalk/checkbox/index.scss +358 -0
- package/dist/theme-chalk/col/index.scss +131 -0
- package/dist/theme-chalk/container/index.scss +40 -0
- package/dist/theme-chalk/css/alert.css +484 -0
- package/dist/theme-chalk/css/avatar.css +409 -0
- package/dist/theme-chalk/css/backtop.css +401 -0
- package/dist/theme-chalk/css/badge.css +419 -0
- package/dist/theme-chalk/css/breadcrumb-item.css +395 -0
- package/dist/theme-chalk/css/breadcrumb.css +395 -0
- package/dist/theme-chalk/css/button.css +587 -0
- package/dist/theme-chalk/css/card.css +397 -0
- package/dist/theme-chalk/css/chart.css +386 -0
- package/dist/theme-chalk/css/checkbox.css +648 -0
- package/dist/theme-chalk/css/col.css +2111 -0
- package/dist/theme-chalk/css/container.css +404 -0
- package/dist/theme-chalk/css/dialog.css +505 -0
- package/dist/theme-chalk/css/divider.css +405 -0
- package/dist/theme-chalk/css/drawer.css +546 -0
- package/dist/theme-chalk/css/empty.css +394 -0
- package/dist/theme-chalk/css/form.css +561 -0
- package/dist/theme-chalk/css/icon.css +1534 -0
- package/dist/theme-chalk/css/image.css +400 -0
- package/dist/theme-chalk/css/input-number.css +424 -0
- package/dist/theme-chalk/css/input.css +721 -0
- package/dist/theme-chalk/css/link.css +424 -0
- package/dist/theme-chalk/css/loading.css +483 -0
- package/dist/theme-chalk/css/message-box.css +479 -0
- package/dist/theme-chalk/css/message.css +456 -0
- package/dist/theme-chalk/css/no-data.css +397 -0
- package/dist/theme-chalk/css/notification.css +431 -0
- package/dist/theme-chalk/css/page-header.css +396 -0
- package/dist/theme-chalk/css/pagination.css +565 -0
- package/dist/theme-chalk/css/popover.css +421 -0
- package/dist/theme-chalk/css/popper.css +454 -0
- package/dist/theme-chalk/css/progress.css +451 -0
- package/dist/theme-chalk/css/radio.css +626 -0
- package/dist/theme-chalk/css/rate.css +414 -0
- package/dist/theme-chalk/css/result.css +403 -0
- package/dist/theme-chalk/css/row.css +433 -0
- package/dist/theme-chalk/css/scrollbar.css +422 -0
- package/dist/theme-chalk/css/select.css +1897 -0
- package/dist/theme-chalk/css/skeleton-item.css +407 -0
- package/dist/theme-chalk/css/skeleton.css +390 -0
- package/dist/theme-chalk/css/slider.css +460 -0
- package/dist/theme-chalk/css/spinner.css +403 -0
- package/dist/theme-chalk/css/statistic.css +396 -0
- package/dist/theme-chalk/css/status-timeline-chart.css +388 -0
- package/dist/theme-chalk/css/step.css +496 -0
- package/dist/theme-chalk/css/steps.css +496 -0
- package/dist/theme-chalk/css/switch.css +507 -0
- package/dist/theme-chalk/css/tab-pane.css +457 -0
- package/dist/theme-chalk/css/table.css +461 -0
- package/dist/theme-chalk/css/tabs-navigation.css +925 -0
- package/dist/theme-chalk/css/tabs.css +457 -0
- package/dist/theme-chalk/css/tag.css +599 -0
- package/dist/theme-chalk/css/time-picker.css +683 -0
- package/dist/theme-chalk/css/timeline-item.css +459 -0
- package/dist/theme-chalk/css/timeline.css +459 -0
- package/dist/theme-chalk/css/tooltip.css +485 -0
- package/dist/theme-chalk/css/tree.css +473 -0
- package/dist/theme-chalk/css/upload.css +665 -0
- package/dist/theme-chalk/dialog/index.scss +168 -0
- package/dist/theme-chalk/divider/index.scss +46 -0
- package/dist/theme-chalk/drawer/index.scss +172 -0
- package/dist/theme-chalk/empty/index.scss +36 -0
- package/dist/theme-chalk/fonts/element-icons.ttf +0 -0
- package/dist/theme-chalk/fonts/element-icons.woff +0 -0
- package/dist/theme-chalk/form/index.scss +220 -0
- package/dist/theme-chalk/icon/index.scss +1171 -0
- package/dist/theme-chalk/image/index.scss +39 -0
- package/dist/theme-chalk/index.scss +127 -0
- package/dist/theme-chalk/input/index.scss +363 -0
- package/dist/theme-chalk/input-number/index.scss +71 -0
- package/dist/theme-chalk/link/index.scss +75 -0
- package/dist/theme-chalk/loading/index.scss +131 -0
- package/dist/theme-chalk/message/index.scss +100 -0
- package/dist/theme-chalk/message-box/index.scss +131 -0
- package/dist/theme-chalk/mixins.scss +203 -0
- package/dist/theme-chalk/no-data/index.scss +36 -0
- package/dist/theme-chalk/notification/index.scss +76 -0
- package/dist/theme-chalk/page-header/index.scss +36 -0
- package/dist/theme-chalk/pagination/index.scss +225 -0
- package/dist/theme-chalk/popover/index.scss +56 -0
- package/dist/theme-chalk/popper/index.scss +89 -0
- package/dist/theme-chalk/progress/index.scss +105 -0
- package/dist/theme-chalk/radio/index.scss +328 -0
- package/dist/theme-chalk/rate/index.scss +56 -0
- package/dist/theme-chalk/reset.scss +262 -0
- package/dist/theme-chalk/result/index.scss +46 -0
- package/dist/theme-chalk/row/index.scss +88 -0
- package/dist/theme-chalk/scrollbar/index.scss +67 -0
- package/dist/theme-chalk/select/index.scss +223 -0
- package/dist/theme-chalk/skeleton/index.scss +30 -0
- package/dist/theme-chalk/skeleton-item/index.scss +49 -0
- package/dist/theme-chalk/slider/index.scss +113 -0
- package/dist/theme-chalk/spinner/index.scss +40 -0
- package/dist/theme-chalk/statistic/index.scss +38 -0
- package/dist/theme-chalk/status-timeline-chart/index.scss +23 -0
- package/dist/theme-chalk/step/index.scss +160 -0
- package/dist/theme-chalk/steps/index.scss +160 -0
- package/dist/theme-chalk/switch/index.scss +153 -0
- package/dist/theme-chalk/tab-pane/index.scss +112 -0
- package/dist/theme-chalk/table/index.scss +110 -0
- package/dist/theme-chalk/tabs/index.scss +112 -0
- package/dist/theme-chalk/tabs-navigation/index.scss +631 -0
- package/dist/theme-chalk/tag/index.scss +138 -0
- package/dist/theme-chalk/themes/blue.scss +76 -0
- package/dist/theme-chalk/themes/dark.scss +99 -0
- package/dist/theme-chalk/themes/index.scss +260 -0
- package/dist/theme-chalk/themes/light.scss +99 -0
- package/dist/theme-chalk/time-picker/index.scss +332 -0
- package/dist/theme-chalk/timeline/index.scss +119 -0
- package/dist/theme-chalk/timeline-item/index.scss +119 -0
- package/dist/theme-chalk/tooltip/index.scss +122 -0
- package/dist/theme-chalk/tree/index.scss +125 -0
- package/dist/theme-chalk/upload/index.scss +348 -0
- package/dist/theme-chalk/variables.scss +93 -0
- package/dist/vue2-ui-library.cjs.temp.js.map +1 -0
- package/dist/vue2-ui-library.common.js +28 -0
- package/dist/vue2-ui-library.common.js.map +1 -0
- package/dist/vue2-ui-library.esm.js +29 -0
- package/dist/vue2-ui-library.umd.js +27 -0
- package/package.json +161 -0
- package/src/directives/clickoutside/index.js +111 -0
- package/src/directives/init/index.js +50 -0
- package/src/directives/resize/index.js +69 -0
- package/src/index.js +174 -0
- package/src/mixins/emitter.js +47 -0
- package/src/mixins/focus.js +42 -0
- package/src/mixins/locale.js +24 -0
- package/src/mixins/migrating.js +46 -0
- package/src/packages/alert/index.js +12 -0
- package/src/packages/alert/src/main.vue +98 -0
- package/src/packages/aside/index.js +12 -0
- package/src/packages/aside/src/main.vue +20 -0
- package/src/packages/auto-grid-layout/index.js +18 -0
- package/src/packages/auto-grid-layout/prop.js +92 -0
- package/src/packages/auto-grid-layout/src/components/GridItem.vue +759 -0
- package/src/packages/auto-grid-layout/src/components/GridLayout.vue +367 -0
- package/src/packages/auto-grid-layout/src/main.vue +287 -0
- package/src/packages/auto-grid-layout/src/utils/DOM.js +46 -0
- package/src/packages/auto-grid-layout/src/utils/interact.js +333 -0
- package/src/packages/auto-grid-layout/src/utils/responsiveUtils.js +75 -0
- package/src/packages/auto-grid-layout/src/utils/utils.js +339 -0
- package/src/packages/autocomplete/index.js +12 -0
- package/src/packages/autocomplete/src/main.vue +170 -0
- package/src/packages/avatar/index.js +12 -0
- package/src/packages/avatar/src/main.vue +87 -0
- package/src/packages/backtop/index.js +12 -0
- package/src/packages/backtop/src/main.vue +120 -0
- package/src/packages/badge/index.js +12 -0
- package/src/packages/badge/src/main.vue +53 -0
- package/src/packages/breadcrumb/index.js +12 -0
- package/src/packages/breadcrumb/src/main.vue +34 -0
- package/src/packages/breadcrumb-item/index.js +12 -0
- package/src/packages/breadcrumb-item/src/main.vue +41 -0
- package/src/packages/button/index.js +13 -0
- package/src/packages/button/src/main.vue +106 -0
- package/src/packages/calendar/index.js +12 -0
- package/src/packages/calendar/src/main.vue +173 -0
- package/src/packages/card/index.js +12 -0
- package/src/packages/card/src/main.vue +26 -0
- package/src/packages/carousel/index.js +12 -0
- package/src/packages/carousel/src/main.vue +186 -0
- package/src/packages/carousel-item/index.js +12 -0
- package/src/packages/carousel-item/src/main.vue +34 -0
- package/src/packages/cascader/index.js +12 -0
- package/src/packages/cascader/src/main.vue +232 -0
- package/src/packages/chart/index.js +7 -0
- package/src/packages/chart/src/axis-chart.js +700 -0
- package/src/packages/chart/src/main.vue +828 -0
- package/src/packages/chart/src/utils.js +21 -0
- package/src/packages/checkbox/index.js +44 -0
- package/src/packages/checkbox/src/main.vue +312 -0
- package/src/packages/col/index.js +12 -0
- package/src/packages/col/src/main.vue +85 -0
- package/src/packages/collapse/index.js +12 -0
- package/src/packages/collapse/src/main.vue +69 -0
- package/src/packages/collapse-item/index.js +12 -0
- package/src/packages/collapse-item/src/main.vue +75 -0
- package/src/packages/color-picker/index.js +12 -0
- package/src/packages/color-picker/src/main.vue +206 -0
- package/src/packages/container/index.js +12 -0
- package/src/packages/container/src/main.vue +33 -0
- package/src/packages/date-picker/index.js +12 -0
- package/src/packages/date-picker/src/main.vue +246 -0
- package/src/packages/descriptions/index.js +12 -0
- package/src/packages/descriptions/src/main.vue +89 -0
- package/src/packages/descriptions-item/index.js +12 -0
- package/src/packages/descriptions-item/src/main.vue +26 -0
- package/src/packages/dialog/index.js +12 -0
- package/src/packages/dialog/src/main.vue +336 -0
- package/src/packages/divider/index.js +12 -0
- package/src/packages/divider/src/main.vue +37 -0
- package/src/packages/drawer/index.js +7 -0
- package/src/packages/drawer/src/main.vue +310 -0
- package/src/packages/dropdown/index.js +12 -0
- package/src/packages/dropdown/src/main.vue +82 -0
- package/src/packages/dropdown-menu-item/index.js +12 -0
- package/src/packages/dropdown-menu-item/src/main.vue +29 -0
- package/src/packages/empty/index.js +12 -0
- package/src/packages/empty/src/img-empty.vue +12 -0
- package/src/packages/empty/src/main.vue +49 -0
- package/src/packages/footer/index.js +12 -0
- package/src/packages/footer/src/main.vue +20 -0
- package/src/packages/form/index.js +13 -0
- package/src/packages/form/src/form-field.vue +790 -0
- package/src/packages/form/src/form-item.vue +464 -0
- package/src/packages/form/src/label-wrap.vue +127 -0
- package/src/packages/form/src/main.vue +442 -0
- package/src/packages/form-item/index.js +11 -0
- package/src/packages/header/index.js +12 -0
- package/src/packages/header/src/main.vue +20 -0
- package/src/packages/icon/index.js +12 -0
- package/src/packages/icon/src/main.vue +48 -0
- package/src/packages/image/index.js +12 -0
- package/src/packages/image/src/main.vue +224 -0
- package/src/packages/input/index.js +13 -0
- package/src/packages/input/src/calcTextareaHeight.js +123 -0
- package/src/packages/input/src/main.vue +510 -0
- package/src/packages/input-number/index.js +12 -0
- package/src/packages/input-number/src/main.vue +121 -0
- package/src/packages/link/index.js +12 -0
- package/src/packages/link/src/main.vue +53 -0
- package/src/packages/loading/index.js +17 -0
- package/src/packages/loading/src/directive.js +54 -0
- package/src/packages/loading/src/main.vue +38 -0
- package/src/packages/loading/src/service.js +63 -0
- package/src/packages/main/index.js +12 -0
- package/src/packages/main/src/main.vue +12 -0
- package/src/packages/menu/index.js +12 -0
- package/src/packages/menu/src/main.vue +117 -0
- package/src/packages/menu-item/index.js +12 -0
- package/src/packages/menu-item/src/main.vue +61 -0
- package/src/packages/message/index.js +95 -0
- package/src/packages/message/src/main.vue +131 -0
- package/src/packages/message-box/index.js +75 -0
- package/src/packages/message-box/src/main.vue +207 -0
- package/src/packages/no-data/index.js +8 -0
- package/src/packages/no-data/src/main.vue +23 -0
- package/src/packages/notification/index.js +72 -0
- package/src/packages/notification/src/main.vue +139 -0
- package/src/packages/option/index.js +13 -0
- package/src/packages/page-header/index.js +12 -0
- package/src/packages/page-header/src/main.vue +27 -0
- package/src/packages/pagination/index.js +12 -0
- package/src/packages/pagination/src/main.vue +255 -0
- package/src/packages/popconfirm/index.js +12 -0
- package/src/packages/popconfirm/src/main.vue +89 -0
- package/src/packages/popover/index.js +12 -0
- package/src/packages/popover/src/main.vue +452 -0
- package/src/packages/progress/index.js +12 -0
- package/src/packages/progress/src/main.vue +236 -0
- package/src/packages/radio/index.js +44 -0
- package/src/packages/radio/src/main.vue +291 -0
- package/src/packages/rate/index.js +12 -0
- package/src/packages/rate/src/main.vue +129 -0
- package/src/packages/result/index.js +12 -0
- package/src/packages/result/src/main.vue +52 -0
- package/src/packages/row/index.js +12 -0
- package/src/packages/row/src/main.vue +57 -0
- package/src/packages/scrollbar/index.js +12 -0
- package/src/packages/scrollbar/src/bar.vue +116 -0
- package/src/packages/scrollbar/src/main.vue +124 -0
- package/src/packages/select/index.js +15 -0
- package/src/packages/select/src/clickoutside.js +20 -0
- package/src/packages/select/src/main.vue +1055 -0
- package/src/packages/select/src/navigation-mixin.js +49 -0
- package/src/packages/select/src/option.vue +249 -0
- package/src/packages/select/src/select-dropdown.vue +95 -0
- package/src/packages/select/src/utils.js +5 -0
- package/src/packages/skeleton/index.js +12 -0
- package/src/packages/skeleton/src/main.vue +76 -0
- package/src/packages/skeleton-item/index.js +12 -0
- package/src/packages/skeleton-item/src/img-placeholder.vue +13 -0
- package/src/packages/skeleton-item/src/main.vue +22 -0
- package/src/packages/slider/index.js +12 -0
- package/src/packages/slider/src/main.vue +176 -0
- package/src/packages/spinner/index.js +12 -0
- package/src/packages/spinner/src/main.vue +27 -0
- package/src/packages/statistic/index.js +12 -0
- package/src/packages/statistic/src/main.vue +100 -0
- package/src/packages/status-timeline-chart/index.js +7 -0
- package/src/packages/status-timeline-chart/src/constants.js +20 -0
- package/src/packages/status-timeline-chart/src/main.vue +499 -0
- package/src/packages/status-timeline-chart/src/option-builder.js +475 -0
- package/src/packages/step/index.js +12 -0
- package/src/packages/step/src/main.vue +183 -0
- package/src/packages/steps/index.js +12 -0
- package/src/packages/steps/src/main.vue +57 -0
- package/src/packages/submenu/index.js +12 -0
- package/src/packages/submenu/src/main.vue +68 -0
- package/src/packages/switch/index.js +12 -0
- package/src/packages/switch/src/main.vue +166 -0
- package/src/packages/tab-pane/index.js +12 -0
- package/src/packages/tab-pane/src/main.vue +74 -0
- package/src/packages/table/index.js +8 -0
- package/src/packages/table/src/components/PagePagination.vue +82 -0
- package/src/packages/table/src/main.vue +153 -0
- package/src/packages/tabs/index.js +12 -0
- package/src/packages/tabs/src/main.vue +167 -0
- package/src/packages/tabs-navigation/index.js +7 -0
- package/src/packages/tabs-navigation/src/main.vue +462 -0
- package/src/packages/tag/index.js +12 -0
- package/src/packages/tag/src/main.vue +194 -0
- package/src/packages/time-picker/index.js +17 -0
- package/src/packages/time-picker/src/date-utils.js +455 -0
- package/src/packages/time-picker/src/main.vue +321 -0
- package/src/packages/time-picker/src/pane/date-range.vue +193 -0
- package/src/packages/time-picker/src/pane/date-time-range.vue +362 -0
- package/src/packages/time-picker/src/pane/date-time.vue +362 -0
- package/src/packages/time-picker/src/pane/date.vue +441 -0
- package/src/packages/time-picker/src/pane/time.vue +260 -0
- package/src/packages/time-picker/src/time-input.vue +203 -0
- package/src/packages/time-picker/src/time-range-input.vue +170 -0
- package/src/packages/timeline/index.js +12 -0
- package/src/packages/timeline/src/main.vue +24 -0
- package/src/packages/timeline-item/index.js +12 -0
- package/src/packages/timeline-item/src/main.vue +78 -0
- package/src/packages/tooltip/index.js +12 -0
- package/src/packages/tooltip/src/main.js +367 -0
- package/src/packages/transfer/index.js +8 -0
- package/src/packages/transfer/src/main.vue +229 -0
- package/src/packages/transfer/src/transfer-panel.vue +245 -0
- package/src/packages/transitions/collapse-transition.js +75 -0
- package/src/packages/tree/index.js +12 -0
- package/src/packages/tree/src/main.vue +322 -0
- package/src/packages/tree/src/model/node.js +348 -0
- package/src/packages/tree/src/model/tree-store.js +354 -0
- package/src/packages/tree/src/model/util.js +10 -0
- package/src/packages/tree/src/tree-node.vue +262 -0
- package/src/packages/upload/index.js +9 -0
- package/src/packages/upload/src/main.vue +415 -0
- package/src/playground/mixins/element.js +98 -0
- package/src/playground/types/element.js +197 -0
- package/src/playground/types/layout.js +80 -0
- package/src/plugins/i18n.js +125 -0
- package/src/styles/fonts/element-icons.ttf +0 -0
- package/src/styles/fonts/element-icons.woff +0 -0
- package/src/styles/index.scss +138 -0
- package/src/styles/reset.scss +257 -0
- package/src/styles/themes/blue.scss +75 -0
- package/src/styles/themes/dark.scss +98 -0
- package/src/styles/themes/index.scss +34 -0
- package/src/styles/themes/light.scss +98 -0
- package/src/styles/themes/variables.scss +233 -0
- package/src/styles/variables.scss +146 -0
- package/src/utils/async-validator/index.js +659 -0
- package/src/utils/browser/index.js +39 -0
- package/src/utils/color.js +76 -0
- package/src/utils/dom/index.js +421 -0
- package/src/utils/dom/scrollbar-width.js +49 -0
- package/src/utils/draggable/core.js +379 -0
- package/src/utils/draggable/draggable.js +478 -0
- package/src/utils/draggable/index.js +61 -0
- package/src/utils/draggable/sortable.js +751 -0
- package/src/utils/lodash/index.js +2395 -0
- package/src/utils/moment/index.js +909 -0
- package/src/utils/playground/index.js +37 -0
- package/src/utils/popper/index.js +308 -0
- package/src/utils/popper/popper.js +1132 -0
- package/src/utils/popper/popup-manager.js +288 -0
- package/src/utils/popper/popup.js +344 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
|
|
3
|
+
let nodeIdSeed = 0;
|
|
4
|
+
|
|
5
|
+
export default class Node {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.id = nodeIdSeed++;
|
|
8
|
+
this.label = null;
|
|
9
|
+
this.checked = false;
|
|
10
|
+
this.indeterminate = false;
|
|
11
|
+
this.data = null;
|
|
12
|
+
this.expanded = false;
|
|
13
|
+
this.parent = null;
|
|
14
|
+
this.visible = true;
|
|
15
|
+
this.isCurrent = false;
|
|
16
|
+
this.isLeaf = false;
|
|
17
|
+
|
|
18
|
+
for (let name in options) {
|
|
19
|
+
if (Object.prototype.hasOwnProperty.call(options, name)) {
|
|
20
|
+
this[name] = options[name];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.level = 0;
|
|
25
|
+
this.loaded = false;
|
|
26
|
+
this.loading = false;
|
|
27
|
+
this.childNodes = [];
|
|
28
|
+
|
|
29
|
+
if (this.parent) {
|
|
30
|
+
this.level = this.parent.level + 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const store = this.store;
|
|
34
|
+
if (!store) {
|
|
35
|
+
throw new Error('[Node] store is required!');
|
|
36
|
+
}
|
|
37
|
+
store.registerNode(this);
|
|
38
|
+
|
|
39
|
+
const props = store.props;
|
|
40
|
+
if (props && typeof props.label === 'function') {
|
|
41
|
+
this.label = props.label(this.data, this);
|
|
42
|
+
} else if (props && typeof props.label === 'string') {
|
|
43
|
+
this.label = this.getPropByPath(this.data, props.label);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (props && typeof props.disabled === 'function') {
|
|
47
|
+
this.disabled = props.disabled(this.data, this);
|
|
48
|
+
} else if (props && typeof props.disabled === 'string') {
|
|
49
|
+
this.disabled = this.getPropByPath(this.data, props.disabled);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (store.lazy !== true && this.data) {
|
|
53
|
+
this.setData(this.data);
|
|
54
|
+
|
|
55
|
+
if (store.defaultExpandAll) {
|
|
56
|
+
this.expanded = true;
|
|
57
|
+
}
|
|
58
|
+
} else if (this.level > 0 && store.lazy && store.defaultExpandAll) {
|
|
59
|
+
this.expand();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!this.data) return;
|
|
63
|
+
|
|
64
|
+
this.updateLeafState();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setData(data) {
|
|
68
|
+
if (!Array.isArray(data)) {
|
|
69
|
+
this.markAsCheckable();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.data = data;
|
|
73
|
+
Vue.set(this, 'childNodes', []);
|
|
74
|
+
|
|
75
|
+
let children;
|
|
76
|
+
if (this.level === 0 && this.data instanceof Array) {
|
|
77
|
+
children = this.data;
|
|
78
|
+
} else {
|
|
79
|
+
children = this.getPropByPath(this.data, this.store.props.children) || [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
for (let i = 0, j = children.length; i < j; i++) {
|
|
83
|
+
this.insertChild({ data: children[i] });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (this.level !== 0) {
|
|
87
|
+
this.updateLeafState();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
getPropByPath(obj, path) {
|
|
92
|
+
if (!path) return null;
|
|
93
|
+
let tempObj = obj;
|
|
94
|
+
let key = path.split('.');
|
|
95
|
+
for (let i = 0; i < key.length; i++) {
|
|
96
|
+
if (!tempObj) break;
|
|
97
|
+
tempObj = tempObj[key[i]];
|
|
98
|
+
}
|
|
99
|
+
return tempObj;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
markAsCheckable() {
|
|
103
|
+
const store = this.store;
|
|
104
|
+
const key = store.key;
|
|
105
|
+
if (key && store.defaultCheckedKeys && store.defaultCheckedKeys.indexOf(this.data[key]) > -1) {
|
|
106
|
+
this.setChecked(true, store.checkStrictly);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
insertChild(child, index) {
|
|
111
|
+
if (!child) throw new Error('insertChild error: child is required.');
|
|
112
|
+
|
|
113
|
+
if (!(child instanceof Node)) {
|
|
114
|
+
Object.assign(child, {
|
|
115
|
+
parent: this,
|
|
116
|
+
store: this.store
|
|
117
|
+
});
|
|
118
|
+
child = new Node(child);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
child.level = this.level + 1;
|
|
122
|
+
|
|
123
|
+
if (typeof index === 'undefined' || index < 0) {
|
|
124
|
+
this.childNodes.push(child);
|
|
125
|
+
} else {
|
|
126
|
+
this.childNodes.splice(index, 0, child);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.updateLeafState();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
removeChild(child) {
|
|
133
|
+
const index = this.childNodes.indexOf(child);
|
|
134
|
+
|
|
135
|
+
if (index > -1) {
|
|
136
|
+
this.store && this.store.deregisterNode(child);
|
|
137
|
+
child.parent = null;
|
|
138
|
+
this.childNodes.splice(index, 1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this.updateLeafState();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
removeChildByData(data) {
|
|
145
|
+
let targetNode = null;
|
|
146
|
+
for (let i = 0; i < this.childNodes.length; i++) {
|
|
147
|
+
if (this.childNodes[i].data === data) {
|
|
148
|
+
targetNode = this.childNodes[i];
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (targetNode) {
|
|
154
|
+
this.removeChild(targetNode);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
expand(callback, expandParent) {
|
|
159
|
+
const done = () => {
|
|
160
|
+
if (expandParent) {
|
|
161
|
+
let parent = this.parent;
|
|
162
|
+
while (parent && parent.level !== -1) {
|
|
163
|
+
Vue.set(parent, 'expanded', true);
|
|
164
|
+
parent = parent.parent;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
Vue.set(this, 'expanded', true);
|
|
168
|
+
if (callback) callback();
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
if (this.shouldLoadData()) {
|
|
172
|
+
this.loadData((data) => {
|
|
173
|
+
if (data instanceof Array) {
|
|
174
|
+
if (this.checked) {
|
|
175
|
+
this.setChecked(true, true);
|
|
176
|
+
}
|
|
177
|
+
done();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
} else {
|
|
181
|
+
done();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
shouldLoadData() {
|
|
186
|
+
return this.store.lazy && this.store.load && !this.loaded && !this.loading;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
doCreateChildren(array, defaultProps = {}) {
|
|
190
|
+
array.forEach((item) => {
|
|
191
|
+
this.insertChild(Object.assign({ data: item }, defaultProps));
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
loadData(callback) {
|
|
196
|
+
if (this.store.lazy && this.store.load && !this.loaded && !this.loading) {
|
|
197
|
+
Vue.set(this, 'loading', true);
|
|
198
|
+
|
|
199
|
+
const done = (children) => {
|
|
200
|
+
Vue.set(this, 'loaded', true);
|
|
201
|
+
Vue.set(this, 'loading', false);
|
|
202
|
+
Vue.set(this, 'childNodes', []);
|
|
203
|
+
|
|
204
|
+
if (children instanceof Array) {
|
|
205
|
+
this.doCreateChildren(children);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
this.updateLeafState();
|
|
209
|
+
|
|
210
|
+
if (callback) {
|
|
211
|
+
callback.call(this, children);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
this.store.load(this, done);
|
|
216
|
+
} else {
|
|
217
|
+
if (callback) {
|
|
218
|
+
callback.call(this);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
collapse() {
|
|
224
|
+
Vue.set(this, 'expanded', false);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
setChecked(value, deep, recursion, passValue) {
|
|
229
|
+
Vue.set(this, 'indeterminate', value === 'half');
|
|
230
|
+
Vue.set(this, 'checked', value === true);
|
|
231
|
+
|
|
232
|
+
if (this.store.checkStrictly) return;
|
|
233
|
+
|
|
234
|
+
if (!(this.store.checkDescendants && recursion)) {
|
|
235
|
+
if (deep) {
|
|
236
|
+
const childNodes = this.childNodes;
|
|
237
|
+
for (let i = 0, j = childNodes.length; i < j; i++) {
|
|
238
|
+
const child = childNodes[i];
|
|
239
|
+
passValue = passValue !== false ? value !== false : passValue;
|
|
240
|
+
let isCheck = child.disabled ? child.checked : passValue;
|
|
241
|
+
child.setChecked(isCheck, deep, true, passValue);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const parent = this.parent;
|
|
246
|
+
if (!parent || parent.level === -1) return;
|
|
247
|
+
parent.recalculateCheckedState();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
recalculateCheckedState() {
|
|
252
|
+
if (this.store.checkStrictly) return;
|
|
253
|
+
const childNodes = this.childNodes;
|
|
254
|
+
let checkedCount = 0;
|
|
255
|
+
let indeterminateCount = 0;
|
|
256
|
+
let allCount = childNodes.length;
|
|
257
|
+
|
|
258
|
+
for (let i = 0; i < allCount; i++) {
|
|
259
|
+
const child = childNodes[i];
|
|
260
|
+
if (child.checked) {
|
|
261
|
+
checkedCount++;
|
|
262
|
+
} else if (child.indeterminate) {
|
|
263
|
+
indeterminateCount++;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (checkedCount === allCount && allCount > 0) {
|
|
268
|
+
this.checked = true;
|
|
269
|
+
this.indeterminate = false;
|
|
270
|
+
} else if (checkedCount > 0 || indeterminateCount > 0) {
|
|
271
|
+
this.checked = false;
|
|
272
|
+
this.indeterminate = true;
|
|
273
|
+
} else {
|
|
274
|
+
this.checked = false;
|
|
275
|
+
this.indeterminate = false;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const parent = this.parent;
|
|
279
|
+
if (parent && parent.level !== -1) {
|
|
280
|
+
parent.recalculateCheckedState();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
updateChildren() {
|
|
285
|
+
const newData = this.getChildren() || [];
|
|
286
|
+
const oldData = this.childNodes.map((node) => node.data);
|
|
287
|
+
|
|
288
|
+
const newDataMap = {};
|
|
289
|
+
const newNodes = [];
|
|
290
|
+
|
|
291
|
+
newData.forEach((item, index) => {
|
|
292
|
+
const key = item[this.store.key];
|
|
293
|
+
const isNodeExists = !!key && oldData.findIndex(data => data[this.store.key] === key) >= 0;
|
|
294
|
+
if (isNodeExists) {
|
|
295
|
+
newDataMap[key] = { index, data: item };
|
|
296
|
+
} else {
|
|
297
|
+
newNodes.push({ index, data: item });
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
if (!this.store.key) {
|
|
302
|
+
newNodes.length = 0;
|
|
303
|
+
newData.forEach((item, index) => {
|
|
304
|
+
newNodes.push({ index, data: item });
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
oldData.forEach((item) => {
|
|
309
|
+
if (!this.store.key) this.removeChildByData(item);
|
|
310
|
+
else {
|
|
311
|
+
const key = item[this.store.key];
|
|
312
|
+
if (!newDataMap[key]) this.removeChildByData(item);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
newNodes.forEach(({ index, data }) => {
|
|
317
|
+
this.insertChild({ data }, index);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
this.updateLeafState();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
updateLeafState() {
|
|
324
|
+
if (this.store.lazy && this.loaded && typeof this.store.props.isLeaf !== 'function') {
|
|
325
|
+
this.isLeaf = !this.childNodes || this.childNodes.length === 0;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const isLeaf = this.store.props.isLeaf ? this.getPropByPath(this.data, this.store.props.isLeaf) : undefined;
|
|
329
|
+
if (typeof isLeaf === 'boolean') {
|
|
330
|
+
this.isLeaf = isLeaf;
|
|
331
|
+
} else if (this.store.lazy && !this.loaded) {
|
|
332
|
+
this.isLeaf = false;
|
|
333
|
+
} else {
|
|
334
|
+
this.isLeaf = !this.childNodes || this.childNodes.length === 0;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
getChildren() {
|
|
339
|
+
const data = this.data;
|
|
340
|
+
if (!data) return null;
|
|
341
|
+
const props = this.store.props;
|
|
342
|
+
let children = 'children';
|
|
343
|
+
if (props) {
|
|
344
|
+
children = props.children || 'children';
|
|
345
|
+
}
|
|
346
|
+
return data[children];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
import Node from './node';
|
|
3
|
+
|
|
4
|
+
export default class TreeStore {
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.currentNode = null;
|
|
7
|
+
this.nodesMap = {};
|
|
8
|
+
this.root = null;
|
|
9
|
+
this.data = null;
|
|
10
|
+
this.props = {
|
|
11
|
+
children: 'children',
|
|
12
|
+
label: 'label',
|
|
13
|
+
disabled: 'disabled',
|
|
14
|
+
isLeaf: 'isLeaf'
|
|
15
|
+
};
|
|
16
|
+
this.lazy = false;
|
|
17
|
+
this.load = null;
|
|
18
|
+
this.filterNodeMethod = null;
|
|
19
|
+
this.key = null;
|
|
20
|
+
this.defaultExpandedKeys = [];
|
|
21
|
+
this.defaultCheckedKeys = [];
|
|
22
|
+
this.checkStrictly = false;
|
|
23
|
+
this.checkDescendants = false;
|
|
24
|
+
this.defaultIsAllExpanded = false;
|
|
25
|
+
this.expandAndLoadLevel = 0;
|
|
26
|
+
|
|
27
|
+
for (let name in options) {
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(options, name)) {
|
|
29
|
+
this[name] = options[name];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.nodesMap = {};
|
|
34
|
+
|
|
35
|
+
this.root = new Node({
|
|
36
|
+
data: this.data,
|
|
37
|
+
store: this
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (this.lazy && this.load) {
|
|
41
|
+
this.root.loadData(() => {
|
|
42
|
+
this._initDefaultCheckedNodes();
|
|
43
|
+
this.setDefaultExpandedKeys(this.defaultExpandedKeys);
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
this._initDefaultCheckedNodes();
|
|
47
|
+
this.setDefaultExpandedKeys(this.defaultExpandedKeys);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
registerNode(node) {
|
|
52
|
+
const key = this.key;
|
|
53
|
+
if (!key || !node || !node.data) return;
|
|
54
|
+
|
|
55
|
+
const nodeKey = node.data[key];
|
|
56
|
+
if (nodeKey !== undefined) this.nodesMap[nodeKey] = node;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
deregisterNode(node) {
|
|
60
|
+
const key = this.key;
|
|
61
|
+
if (!key || !node || !node.data) return;
|
|
62
|
+
|
|
63
|
+
node.childNodes.forEach(child => {
|
|
64
|
+
this.deregisterNode(child);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
delete this.nodesMap[node.data[key]];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
_initDefaultCheckedNodes() {
|
|
71
|
+
const defaultCheckedKeys = this.defaultCheckedKeys || [];
|
|
72
|
+
const nodesMap = this.nodesMap;
|
|
73
|
+
|
|
74
|
+
defaultCheckedKeys.forEach((key) => {
|
|
75
|
+
const node = nodesMap[key];
|
|
76
|
+
|
|
77
|
+
if (node) {
|
|
78
|
+
node.setChecked(true, !this.checkStrictly);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
filter(value) {
|
|
84
|
+
const filterNodeMethod = this.filterNodeMethod;
|
|
85
|
+
const traverse = function(node) {
|
|
86
|
+
const childNodes = node.root ? node.root.childNodes : node.childNodes;
|
|
87
|
+
|
|
88
|
+
childNodes.forEach((child) => {
|
|
89
|
+
child.visible = filterNodeMethod.call(child, value, child.data, child);
|
|
90
|
+
traverse(child);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (!node.visible && childNodes.length) {
|
|
94
|
+
let allHidden = true;
|
|
95
|
+
allHidden = childNodes.every(child => !child.visible);
|
|
96
|
+
|
|
97
|
+
if (node.root) {
|
|
98
|
+
node.root.visible = allHidden === false;
|
|
99
|
+
} else {
|
|
100
|
+
node.visible = allHidden === false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!value) return;
|
|
105
|
+
|
|
106
|
+
if (node.visible && !node.isLeaf && !node.root) node.expand();
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
traverse(this);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setData(newVal) {
|
|
113
|
+
const instanceChanged = newVal !== this.root.data;
|
|
114
|
+
if (instanceChanged) {
|
|
115
|
+
this.root.setData(newVal);
|
|
116
|
+
this._initDefaultCheckedNodes();
|
|
117
|
+
} else {
|
|
118
|
+
this.root.updateChildren();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getNode(data) {
|
|
123
|
+
if (data instanceof Node) return data;
|
|
124
|
+
const key = typeof data !== 'object' ? data : data[this.key];
|
|
125
|
+
return this.nodesMap[key] || null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_getAllNodes() {
|
|
129
|
+
const allNodes = [];
|
|
130
|
+
const nodesMap = this.nodesMap;
|
|
131
|
+
for (let nodeKey in nodesMap) {
|
|
132
|
+
if (Object.prototype.hasOwnProperty.call(nodesMap, nodeKey)) {
|
|
133
|
+
allNodes.push(nodesMap[nodeKey]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return allNodes;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_setCheckedKeys(key, leafOnly = false, checkedKeys) {
|
|
140
|
+
const allNodes = this._getAllNodes().sort((a, b) => b.level - a.level);
|
|
141
|
+
const cache = Object.create(null);
|
|
142
|
+
const keys = Object.keys(checkedKeys);
|
|
143
|
+
|
|
144
|
+
// First uncheck all nodes without deep propagation
|
|
145
|
+
allNodes.forEach(node => node.setChecked(false, false));
|
|
146
|
+
|
|
147
|
+
for (let i = 0, j = allNodes.length; i < j; i++) {
|
|
148
|
+
const node = allNodes[i];
|
|
149
|
+
const nodeKey = node.data[key].toString();
|
|
150
|
+
let checked = keys.indexOf(nodeKey) > -1;
|
|
151
|
+
|
|
152
|
+
if (!checked) {
|
|
153
|
+
if (node.checked && !cache[nodeKey]) {
|
|
154
|
+
node.setChecked(false, false);
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Cache parent chain to prevent them from being unchecked
|
|
160
|
+
let parent = node.parent;
|
|
161
|
+
while (parent && parent.level > 0) {
|
|
162
|
+
cache[parent.data[key]] = true;
|
|
163
|
+
parent = parent.parent;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (node.isLeaf || this.checkStrictly) {
|
|
167
|
+
node.setChecked(true, false);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
node.setChecked(true, true);
|
|
171
|
+
|
|
172
|
+
if (leafOnly) {
|
|
173
|
+
node.setChecked(false, false);
|
|
174
|
+
const traverse = function(node) {
|
|
175
|
+
const childNodes = node.childNodes;
|
|
176
|
+
childNodes.forEach((child) => {
|
|
177
|
+
if (!child.isLeaf) {
|
|
178
|
+
child.setChecked(false, false);
|
|
179
|
+
}
|
|
180
|
+
traverse(child);
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
traverse(node);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
setCheckedKeys(keys, leafOnly = false) {
|
|
189
|
+
this.defaultCheckedKeys = keys;
|
|
190
|
+
const key = this.key;
|
|
191
|
+
const checkedKeys = {};
|
|
192
|
+
keys.forEach((k) => {
|
|
193
|
+
checkedKeys[k] = true;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
this._setCheckedKeys(key, leafOnly, checkedKeys);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
setCheckedNodes(array, leafOnly = false) {
|
|
200
|
+
const key = this.key;
|
|
201
|
+
const checkedKeys = {};
|
|
202
|
+
array.forEach((item) => {
|
|
203
|
+
checkedKeys[(item || {})[key]] = true;
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
this._setCheckedKeys(key, leafOnly, checkedKeys);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
getCheckedNodes(leafOnly = false, includeHalfChecked = false) {
|
|
210
|
+
const checkedNodes = [];
|
|
211
|
+
const traverse = function(node) {
|
|
212
|
+
const childNodes = node.root ? node.root.childNodes : node.childNodes;
|
|
213
|
+
|
|
214
|
+
childNodes.forEach((child) => {
|
|
215
|
+
if ((child.checked || (includeHalfChecked && child.indeterminate)) && (!leafOnly || (leafOnly && child.isLeaf))) {
|
|
216
|
+
checkedNodes.push(child.data);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
traverse(child);
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
traverse(this);
|
|
224
|
+
|
|
225
|
+
return checkedNodes;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
getCheckedKeys(leafOnly = false) {
|
|
229
|
+
return this.getCheckedNodes(leafOnly).map((data) => (data || {})[this.key]);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
getHalfCheckedNodes() {
|
|
233
|
+
const nodes = [];
|
|
234
|
+
const traverse = function(node) {
|
|
235
|
+
const childNodes = node.root ? node.root.childNodes : node.childNodes;
|
|
236
|
+
|
|
237
|
+
childNodes.forEach((child) => {
|
|
238
|
+
if (child.indeterminate) {
|
|
239
|
+
nodes.push(child.data);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
traverse(child);
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
traverse(this);
|
|
247
|
+
|
|
248
|
+
return nodes;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
getHalfCheckedKeys() {
|
|
252
|
+
return this.getHalfCheckedNodes().map((data) => (data || {})[this.key]);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
setChecked(data, checked, deep) {
|
|
256
|
+
const node = this.getNode(data);
|
|
257
|
+
|
|
258
|
+
if (node) {
|
|
259
|
+
node.setChecked(!!checked, deep);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
setDefaultExpandedKeys(keys) {
|
|
264
|
+
this.defaultExpandedKeys = keys || [];
|
|
265
|
+
const keysMap = {};
|
|
266
|
+
this.defaultExpandedKeys.forEach((key) => {
|
|
267
|
+
keysMap[key] = true;
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const traverse = (node) => {
|
|
271
|
+
const childNodes = node.root ? node.root.childNodes : node.childNodes;
|
|
272
|
+
|
|
273
|
+
childNodes.forEach((child) => {
|
|
274
|
+
const key = child.data[this.key];
|
|
275
|
+
if (keysMap[key]) {
|
|
276
|
+
child.expand();
|
|
277
|
+
}
|
|
278
|
+
traverse(child);
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
traverse(this);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
setUserCurrentNode(node) {
|
|
286
|
+
const key = node[this.key];
|
|
287
|
+
const currNode = this.nodesMap[key];
|
|
288
|
+
this.setCurrentNode(currNode);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
setCurrentNodeKey(key) {
|
|
292
|
+
const node = this.nodesMap[key];
|
|
293
|
+
if (node) {
|
|
294
|
+
this.setCurrentNode(node);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
remove(data) {
|
|
299
|
+
const node = this.getNode(data);
|
|
300
|
+
|
|
301
|
+
if (node && node.parent) {
|
|
302
|
+
if (this.currentNode === node) {
|
|
303
|
+
this.currentNode = null;
|
|
304
|
+
}
|
|
305
|
+
node.parent.removeChild(node);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
append(data, parentData) {
|
|
310
|
+
const parentNode = parentData ? this.getNode(parentData) : this.root;
|
|
311
|
+
|
|
312
|
+
if (parentNode) {
|
|
313
|
+
parentNode.insertChild({ data });
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
insertBefore(data, refData) {
|
|
318
|
+
const refNode = this.getNode(refData);
|
|
319
|
+
|
|
320
|
+
if (refNode && refNode.parent) {
|
|
321
|
+
refNode.parent.insertChild({ data }, refNode.parent.childNodes.indexOf(refNode));
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
insertAfter(data, refData) {
|
|
326
|
+
const refNode = this.getNode(refData);
|
|
327
|
+
|
|
328
|
+
if (refNode && refNode.parent) {
|
|
329
|
+
refNode.parent.insertChild({ data }, refNode.parent.childNodes.indexOf(refNode) + 1);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
updateKeyChildren(key, data) {
|
|
334
|
+
const node = this.nodesMap[key];
|
|
335
|
+
if (!node) return;
|
|
336
|
+
|
|
337
|
+
node.setData(data);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
setCurrentNode(node) {
|
|
341
|
+
const prevCurrentNode = this.currentNode;
|
|
342
|
+
if (prevCurrentNode) {
|
|
343
|
+
Vue.set(prevCurrentNode, 'isCurrent', false);
|
|
344
|
+
}
|
|
345
|
+
this.currentNode = node;
|
|
346
|
+
if (node) {
|
|
347
|
+
Vue.set(this.currentNode, 'isCurrent', true);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
getCurrentNode() {
|
|
352
|
+
return this.currentNode ? this.currentNode.data : null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const getNodeKey = function(key, data) {
|
|
2
|
+
if (!key) return data.id || data._id;
|
|
3
|
+
const keys = key.split('.');
|
|
4
|
+
let tempObj = data;
|
|
5
|
+
for (let i = 0; i < keys.length; i++) {
|
|
6
|
+
if (!tempObj) break;
|
|
7
|
+
tempObj = tempObj[keys[i]];
|
|
8
|
+
}
|
|
9
|
+
return tempObj;
|
|
10
|
+
};
|