md-iview 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -0
- package/package.json +116 -0
- package/src/components/libs/util.js +117 -0
- package/src/components/md-error-page/403.less +92 -0
- package/src/components/md-error-page/403.vue +34 -0
- package/src/components/md-error-page/404.less +60 -0
- package/src/components/md-error-page/404.vue +34 -0
- package/src/components/md-error-page/500.less +73 -0
- package/src/components/md-error-page/500.vue +36 -0
- package/src/components/md-error-page/demo/index.less +22 -0
- package/src/components/md-error-page/demo/index.vue +97 -0
- package/src/components/md-form-item/index.js +3 -0
- package/src/components/md-icon/icon.vue +77 -0
- package/src/components/md-icon/icons.js +5 -0
- package/src/components/md-icon/index.js +11 -0
- package/src/components/md-icon/style/index.less +1 -0
- package/src/components/md-loading/index.js +55 -0
- package/src/components/md-loading/index.vue +53 -0
- package/src/components/md-loading/md-loading.js +38 -0
- package/src/components/md-print/demo/index.vue +260 -0
- package/src/components/md-print/index.js +123 -0
- package/src/components/md-rich-editor/index.vue +69 -0
- package/src/components/md-rich-editor/module/image-extend/index.js +216 -0
- package/src/components/md-scroll-bar/demo/index.vue +102 -0
- package/src/components/md-scroll-bar/index.js +3 -0
- package/src/components/md-scroll-bar/index.less +90 -0
- package/src/components/md-scroll-bar/index.vue +250 -0
- package/src/components/md-select/index.js +7 -0
- package/src/components/md-select/select.vue +841 -0
- package/src/components/md-shrinkable-menu/components/sidebarMenu.vue +167 -0
- package/src/components/md-shrinkable-menu/components/sidebarMenuShrink.vue +119 -0
- package/src/components/md-shrinkable-menu/demo/data/cachePage.js +1 -0
- package/src/components/md-shrinkable-menu/demo/data/currentPath.js +9 -0
- package/src/components/md-shrinkable-menu/demo/data/menu.js +575 -0
- package/src/components/md-shrinkable-menu/demo/data/menu2.js +1017 -0
- package/src/components/md-shrinkable-menu/demo/data/pageTagsList.js +153 -0
- package/src/components/md-shrinkable-menu/demo/index.less +297 -0
- package/src/components/md-shrinkable-menu/demo/index.vue +285 -0
- package/src/components/md-shrinkable-menu/index.vue +112 -0
- package/src/components/md-shrinkable-menu/sidebar.vue +195 -0
- package/src/components/md-shrinkable-menu/styles/menu.less +5 -0
- package/src/components/md-shrinkable-menu/styles/sidebar.less +363 -0
- package/src/components/md-split-pane/demo/index.vue +101 -0
- package/src/components/md-split-pane/index.js +3 -0
- package/src/components/md-split-pane/index.less +93 -0
- package/src/components/md-split-pane/index.vue +230 -0
- package/src/components/md-table/action-tooltip.vue +45 -0
- package/src/components/md-table/can-edit-v2.vue +823 -0
- package/src/components/md-table/can-edit.vue +723 -0
- package/src/components/md-table/custom-cell.vue +71 -0
- package/src/components/md-table/date-picker-cell-v2.vue +48 -0
- package/src/components/md-table/date-picker-cell.vue +39 -0
- package/src/components/md-table/demo/data/search.js +67 -0
- package/src/components/md-table/demo/data/table2csv.js +200 -0
- package/src/components/md-table/demo/data/table2excel.js +239 -0
- package/src/components/md-table/demo/data/table_data.js +251 -0
- package/src/components/md-table/demo/editable-table.vue +144 -0
- package/src/components/md-table/demo/exportable-table.vue +124 -0
- package/src/components/md-table/demo/widgets/header-search.vue +88 -0
- package/src/components/md-table/drop-down-cell-v2.vue +87 -0
- package/src/components/md-table/drop-down-cell.vue +81 -0
- package/src/components/md-table/editable-expand.vue +143 -0
- package/src/components/md-table/expand.vue +97 -0
- package/src/components/md-table/index.vue +53 -0
- package/src/components/md-table/iview-table/cell.vue +99 -0
- package/src/components/md-table/iview-table/expand.js +21 -0
- package/src/components/md-table/iview-table/export-csv.js +76 -0
- package/src/components/md-table/iview-table/header.js +16 -0
- package/src/components/md-table/iview-table/index.js +2 -0
- package/src/components/md-table/iview-table/mixin.js +31 -0
- package/src/components/md-table/iview-table/table-body.vue +101 -0
- package/src/components/md-table/iview-table/table-head.vue +311 -0
- package/src/components/md-table/iview-table/table-tr.vue +31 -0
- package/src/components/md-table/iview-table/table.vue +1026 -0
- package/src/components/md-table/iview-table/util.js +93 -0
- package/src/components/md-table/libs/table2excel.js +100 -0
- package/src/components/md-table/select-cell-v2.vue +64 -0
- package/src/components/md-table/select-cell.vue +46 -0
- package/src/components/md-table/table.less +76 -0
- package/src/components/md-toolbar/index.vue +171 -0
- package/src/components/md-tree/index.js +2 -0
- package/src/components/md-tree/node.vue +238 -0
- package/src/components/md-tree/render.js +17 -0
- package/src/components/md-tree/tree.vue +241 -0
- package/src/components/utilities/can.js +35 -0
- package/src/directives/index.js +34 -0
- package/src/directives/resize.js +27 -0
- package/src/directives/scroll.js +27 -0
- package/src/directives/style/bg-color.js +23 -0
- package/src/directives/style/color.js +23 -0
- package/src/directives/style/font-size.js +23 -0
- package/src/directives/style/height.js +23 -0
- package/src/directives/style/lineHeight.js +23 -0
- package/src/directives/style/margin.js +48 -0
- package/src/directives/style/opacity.js +23 -0
- package/src/directives/style/padding.js +48 -0
- package/src/directives/style/width.js +24 -0
- package/src/index.js +442 -0
- package/src/locale/lang.js +5 -0
- package/src/mixins/colorable.js +51 -0
- package/src/style/color/bezierEasing.less +110 -0
- package/src/style/color/colorPalette.less +75 -0
- package/src/style/color/colors.less +146 -0
- package/src/style/color/tinyColor.less +1184 -0
- package/src/style/common.less +72 -0
- package/src/style/components/_ripple.less +60 -0
- package/src/style/components/_shrinkable-menu.less +46 -0
- package/src/style/components/_toolbar.less +96 -0
- package/src/style/components/index.less +3 -0
- package/src/style/components/rich-editor.less +6 -0
- package/src/style/index.less +10 -0
- package/src/style/theme.less +155 -0
- package/src/utils/color.js +46 -0
- package/src/utils/console.js +105 -0
- package/src/utils/load.js +79 -0
- package/src/utils/mask.js +139 -0
- package/src/utils/mixins.js +5 -0
- package/src/utils/validate.js +271 -0
@@ -0,0 +1,238 @@
|
|
1
|
+
<template>
|
2
|
+
<collapse-transition :appear="appear">
|
3
|
+
<ul :class="classes" :draggable="draggable"
|
4
|
+
@dragover="allowDrop($event)"
|
5
|
+
@dragstart="handleDrag($event,data)"
|
6
|
+
@drop="handleDrop($event,data)">
|
7
|
+
<li>
|
8
|
+
<span :class="arrowClasses" @click="handleExpand">
|
9
|
+
<Icon v-if="showArrow" :type="arrowType" :custom="customArrowType" :size="arrowSize"/>
|
10
|
+
<Icon v-if="showLoading" type="ios-loading" class="ivu-load-loop"/>
|
11
|
+
</span>
|
12
|
+
<Checkbox
|
13
|
+
v-if="showCheckbox"
|
14
|
+
:value="data.checked"
|
15
|
+
:indeterminate="data.indeterminate"
|
16
|
+
:disabled="data.disabled || data.disableCheckbox"
|
17
|
+
@click.native.prevent="handleCheck"></Checkbox>
|
18
|
+
<Render v-if="data.render" :render="data.render" :data="data" :node="node"></Render>
|
19
|
+
<Render v-else-if="isParentRender" :render="parentRender" :data="data" :node="node"></Render>
|
20
|
+
<span v-else :class="titleClasses" @click="handleSelect">{{ data.title }}</span>
|
21
|
+
<Tree-node
|
22
|
+
v-if="data.expand"
|
23
|
+
:appear="appearByClickArrow"
|
24
|
+
v-for="(item, i) in children"
|
25
|
+
:key="i"
|
26
|
+
:data="item"
|
27
|
+
:multiple="multiple"
|
28
|
+
:show-checkbox="showCheckbox"
|
29
|
+
:children-key="childrenKey"
|
30
|
+
>
|
31
|
+
</Tree-node>
|
32
|
+
</li>
|
33
|
+
</ul>
|
34
|
+
</collapse-transition>
|
35
|
+
</template>
|
36
|
+
<script>
|
37
|
+
/* import Checkbox from '../checkbox/checkbox.vue';
|
38
|
+
import Icon from '../icon/icon.vue';*/
|
39
|
+
import Render from './render';
|
40
|
+
// import CollapseTransition from '../base/collapse-transition';
|
41
|
+
import CollapseTransition from 'iview/src/components/base/collapse-transition'
|
42
|
+
import Emitter from 'iview/src/mixins/emitter';
|
43
|
+
import {findComponentUpward} from 'iview/src/utils/assist';
|
44
|
+
|
45
|
+
const prefixCls = 'ivu-tree';
|
46
|
+
|
47
|
+
export default {
|
48
|
+
name: 'TreeNode',
|
49
|
+
mixins: [Emitter],
|
50
|
+
inject: ['TreeInstance', 'draggable'],
|
51
|
+
// components: { Checkbox, Icon, CollapseTransition, Render },
|
52
|
+
components: {CollapseTransition, Render},
|
53
|
+
props: {
|
54
|
+
data: {
|
55
|
+
type: Object,
|
56
|
+
default() {
|
57
|
+
return {};
|
58
|
+
}
|
59
|
+
},
|
60
|
+
multiple: {
|
61
|
+
type: Boolean,
|
62
|
+
default: false
|
63
|
+
},
|
64
|
+
childrenKey: {
|
65
|
+
type: String,
|
66
|
+
default: 'children'
|
67
|
+
},
|
68
|
+
showCheckbox: {
|
69
|
+
type: Boolean,
|
70
|
+
default: false
|
71
|
+
},
|
72
|
+
appear: {
|
73
|
+
type: Boolean,
|
74
|
+
default: false
|
75
|
+
}
|
76
|
+
},
|
77
|
+
data() {
|
78
|
+
return {
|
79
|
+
prefixCls: prefixCls,
|
80
|
+
appearByClickArrow: false
|
81
|
+
};
|
82
|
+
},
|
83
|
+
computed: {
|
84
|
+
classes() {
|
85
|
+
return [
|
86
|
+
`${prefixCls}-children`
|
87
|
+
];
|
88
|
+
},
|
89
|
+
selectedCls() {
|
90
|
+
return [
|
91
|
+
{
|
92
|
+
[`${prefixCls}-node-selected`]: this.data.selected
|
93
|
+
}
|
94
|
+
];
|
95
|
+
},
|
96
|
+
arrowClasses() {
|
97
|
+
return [
|
98
|
+
`${prefixCls}-arrow`,
|
99
|
+
{
|
100
|
+
[`${prefixCls}-arrow-disabled`]: this.data.disabled,
|
101
|
+
[`${prefixCls}-arrow-open`]: this.data.expand
|
102
|
+
}
|
103
|
+
];
|
104
|
+
},
|
105
|
+
titleClasses() {
|
106
|
+
return [
|
107
|
+
`${prefixCls}-title`,
|
108
|
+
{
|
109
|
+
[`${prefixCls}-title-selected`]: this.data.selected
|
110
|
+
}
|
111
|
+
];
|
112
|
+
},
|
113
|
+
showArrow() {
|
114
|
+
return (this.data[this.childrenKey] && this.data[this.childrenKey].length) || ('loading' in this.data && !this.data.loading);
|
115
|
+
},
|
116
|
+
showLoading() {
|
117
|
+
return 'loading' in this.data && this.data.loading;
|
118
|
+
},
|
119
|
+
isParentRender() {
|
120
|
+
const Tree = findComponentUpward(this, 'Tree');
|
121
|
+
return Tree && Tree.render;
|
122
|
+
},
|
123
|
+
parentRender() {
|
124
|
+
const Tree = findComponentUpward(this, 'Tree');
|
125
|
+
if (Tree && Tree.render) {
|
126
|
+
return Tree.render;
|
127
|
+
} else {
|
128
|
+
return null;
|
129
|
+
}
|
130
|
+
},
|
131
|
+
node() {
|
132
|
+
const Tree = findComponentUpward(this, 'Tree');
|
133
|
+
if (Tree) {
|
134
|
+
// 将所有的 node(即flatState)和当前 node 都传递
|
135
|
+
return [Tree.flatState, Tree.flatState.find(item => item.nodeKey === this.data.nodeKey)];
|
136
|
+
} else {
|
137
|
+
return [];
|
138
|
+
}
|
139
|
+
},
|
140
|
+
children() {
|
141
|
+
return this.data[this.childrenKey];
|
142
|
+
},
|
143
|
+
// 3.4.0, global setting customArrow 有值时,arrow 赋值空
|
144
|
+
arrowType() {
|
145
|
+
let type = 'ios-arrow-forward';
|
146
|
+
|
147
|
+
if (this.$IVIEW) {
|
148
|
+
if (this.$IVIEW.tree.customArrow) {
|
149
|
+
type = '';
|
150
|
+
} else if (this.$IVIEW.tree.arrow) {
|
151
|
+
type = this.$IVIEW.tree.arrow;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
return type;
|
155
|
+
},
|
156
|
+
// 3.4.0, global setting
|
157
|
+
customArrowType() {
|
158
|
+
let type = '';
|
159
|
+
|
160
|
+
if (this.$IVIEW) {
|
161
|
+
if (this.$IVIEW.tree.customArrow) {
|
162
|
+
type = this.$IVIEW.tree.customArrow;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
return type;
|
166
|
+
},
|
167
|
+
// 3.4.0, global setting
|
168
|
+
arrowSize() {
|
169
|
+
let size = '';
|
170
|
+
|
171
|
+
if (this.$IVIEW) {
|
172
|
+
if (this.$IVIEW.tree.arrowSize) {
|
173
|
+
size = this.$IVIEW.tree.arrowSize;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
return size;
|
177
|
+
}
|
178
|
+
},
|
179
|
+
methods: {
|
180
|
+
allowDrop (e) {
|
181
|
+
e.preventDefault()
|
182
|
+
},
|
183
|
+
handleDrag(e, item) {
|
184
|
+
e.dataTransfer.setData('nodeKey', item.nodeKey);
|
185
|
+
e.stopPropagation()
|
186
|
+
},
|
187
|
+
handleDrop(e, item) {
|
188
|
+
const dragKey = parseInt(e.dataTransfer.getData('nodeKey'));
|
189
|
+
this.TreeInstance.dragAndDrop(item, dragKey, item.nodeKey);
|
190
|
+
e.stopPropagation();
|
191
|
+
},
|
192
|
+
handleExpand() {
|
193
|
+
const item = this.data;
|
194
|
+
if (item.disabled) return;
|
195
|
+
|
196
|
+
// Vue.js 2.6.9 对 transition 的 appear 进行了调整,导致 iView 初始化时无动画,加此方法来判断通过点击箭头展开时,加 appear,否则初始渲染时 appear 为 false
|
197
|
+
this.appearByClickArrow = true;
|
198
|
+
|
199
|
+
// async loading
|
200
|
+
if (item[this.childrenKey].length === 0) {
|
201
|
+
const tree = findComponentUpward(this, 'Tree');
|
202
|
+
if (tree && tree.loadData) {
|
203
|
+
this.$set(this.data, 'loading', true);
|
204
|
+
tree.loadData(item, children => {
|
205
|
+
this.$set(this.data, 'loading', false);
|
206
|
+
if (children.length) {
|
207
|
+
this.$set(this.data, this.childrenKey, children);
|
208
|
+
this.$nextTick(() => this.handleExpand());
|
209
|
+
}
|
210
|
+
});
|
211
|
+
return;
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
if (item[this.childrenKey] && item[this.childrenKey].length) {
|
216
|
+
this.$set(this.data, 'expand', !this.data.expand);
|
217
|
+
this.dispatch('Tree', 'toggle-expand', this.data);
|
218
|
+
}
|
219
|
+
},
|
220
|
+
handleSelect() {
|
221
|
+
if (this.data.disabled) return;
|
222
|
+
if (this.TreeInstance.showCheckbox && this.TreeInstance.checkDirectly) {
|
223
|
+
this.handleCheck();
|
224
|
+
} else {
|
225
|
+
this.dispatch('Tree', 'on-selected', this.data.nodeKey);
|
226
|
+
}
|
227
|
+
},
|
228
|
+
handleCheck() {
|
229
|
+
if (this.data.disabled) return;
|
230
|
+
const changes = {
|
231
|
+
checked: !this.data.checked && !this.data.indeterminate,
|
232
|
+
nodeKey: this.data.nodeKey
|
233
|
+
};
|
234
|
+
this.dispatch('Tree', 'on-check', changes);
|
235
|
+
}
|
236
|
+
}
|
237
|
+
};
|
238
|
+
</script>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export default {
|
2
|
+
name: 'RenderCell',
|
3
|
+
functional: true,
|
4
|
+
props: {
|
5
|
+
render: Function,
|
6
|
+
data: Object,
|
7
|
+
node: Array
|
8
|
+
},
|
9
|
+
render: (h, ctx) => {
|
10
|
+
const params = {
|
11
|
+
root: ctx.props.node[0],
|
12
|
+
node: ctx.props.node[1],
|
13
|
+
data: ctx.props.data
|
14
|
+
};
|
15
|
+
return ctx.props.render(h, params);
|
16
|
+
}
|
17
|
+
};
|
@@ -0,0 +1,241 @@
|
|
1
|
+
<template>
|
2
|
+
<div :class="prefixCls">
|
3
|
+
<Tree-node
|
4
|
+
v-for="(item, i) in stateTree"
|
5
|
+
:key="i"
|
6
|
+
:data="item"
|
7
|
+
visible
|
8
|
+
:multiple="multiple"
|
9
|
+
:show-checkbox="showCheckbox"
|
10
|
+
:children-key="childrenKey"
|
11
|
+
>
|
12
|
+
</Tree-node>
|
13
|
+
<div :class="[prefixCls + '-empty']" v-if="!stateTree.length">{{ localeEmptyText }}</div>
|
14
|
+
</div>
|
15
|
+
</template>
|
16
|
+
<script>
|
17
|
+
import TreeNode from './node.vue';
|
18
|
+
import Emitter from 'iview/src/mixins/emitter';
|
19
|
+
import Locale from 'iview/src/mixins/locale';
|
20
|
+
|
21
|
+
const prefixCls = 'ivu-tree';
|
22
|
+
|
23
|
+
export default {
|
24
|
+
name: 'Tree',
|
25
|
+
mixins: [Emitter, Locale],
|
26
|
+
components: {TreeNode},
|
27
|
+
provide() {
|
28
|
+
return {TreeInstance: this, draggable: this.draggable};
|
29
|
+
},
|
30
|
+
props: {
|
31
|
+
draggable: {
|
32
|
+
type: Boolean,
|
33
|
+
default: false
|
34
|
+
},
|
35
|
+
allowGetParentNode: {
|
36
|
+
type: Boolean,
|
37
|
+
default: false
|
38
|
+
},
|
39
|
+
data: {
|
40
|
+
type: Array,
|
41
|
+
default() {
|
42
|
+
return [];
|
43
|
+
}
|
44
|
+
},
|
45
|
+
multiple: {
|
46
|
+
type: Boolean,
|
47
|
+
default: false
|
48
|
+
},
|
49
|
+
showCheckbox: {
|
50
|
+
type: Boolean,
|
51
|
+
default: false
|
52
|
+
},
|
53
|
+
checkStrictly: {
|
54
|
+
type: Boolean,
|
55
|
+
default: false
|
56
|
+
},
|
57
|
+
// 当开启 showCheckbox 时,如果开启 checkDirectly,select 将强制转为 check 事件
|
58
|
+
checkDirectly: {
|
59
|
+
type: Boolean,
|
60
|
+
default: false
|
61
|
+
},
|
62
|
+
emptyText: {
|
63
|
+
type: String
|
64
|
+
},
|
65
|
+
childrenKey: {
|
66
|
+
type: String,
|
67
|
+
default: 'children'
|
68
|
+
},
|
69
|
+
loadData: {
|
70
|
+
type: Function
|
71
|
+
},
|
72
|
+
render: {
|
73
|
+
type: Function
|
74
|
+
},
|
75
|
+
|
76
|
+
},
|
77
|
+
data() {
|
78
|
+
return {
|
79
|
+
prefixCls: prefixCls,
|
80
|
+
stateTree: this.data,
|
81
|
+
flatState: [],
|
82
|
+
};
|
83
|
+
},
|
84
|
+
watch: {
|
85
|
+
data: {
|
86
|
+
deep: true,
|
87
|
+
handler() {
|
88
|
+
this.stateTree = this.data;
|
89
|
+
this.flatState = this.compileFlatState();
|
90
|
+
this.rebuildTree();
|
91
|
+
}
|
92
|
+
}
|
93
|
+
},
|
94
|
+
computed: {
|
95
|
+
localeEmptyText() {
|
96
|
+
if (typeof this.emptyText === 'undefined') {
|
97
|
+
return this.t('i.tree.emptyText');
|
98
|
+
} else {
|
99
|
+
return this.emptyText;
|
100
|
+
}
|
101
|
+
},
|
102
|
+
},
|
103
|
+
methods: {
|
104
|
+
dragAndDrop(item, dragKey, dropKey) {
|
105
|
+
let dragNode = JSON.parse(JSON.stringify(this.flatState[dragKey]));
|
106
|
+
if (item[this.childrenKey] && item[this.childrenKey].length) {
|
107
|
+
dragNode.parent = item.nodeKey;
|
108
|
+
}
|
109
|
+
let childrenKey = this.childrenKey;
|
110
|
+
let flattenChildren = (node, /*parent*/) =>{
|
111
|
+
if (node[childrenKey]) {
|
112
|
+
node[childrenKey] = node[childrenKey].filter(child => child.nodeKey !== dragKey)
|
113
|
+
if(node[childrenKey].length<=0) {
|
114
|
+
this.$delete(node, 'expand');
|
115
|
+
}
|
116
|
+
node[childrenKey].forEach(child => flattenChildren(child, node));
|
117
|
+
}
|
118
|
+
}
|
119
|
+
this.stateTree.forEach(rootNode => {
|
120
|
+
flattenChildren(rootNode);
|
121
|
+
});
|
122
|
+
console.log(this.stateTree);
|
123
|
+
item[this.childrenKey] = item[this.childrenKey]||[]
|
124
|
+
item[this.childrenKey].push(dragNode.node);
|
125
|
+
this.$set(item, 'expand', true);
|
126
|
+
|
127
|
+
this.$emit('on-drag-drop', dragKey, dropKey);
|
128
|
+
},
|
129
|
+
compileFlatState() { // so we have always a relation parent/children of each node
|
130
|
+
let keyCounter = 0;
|
131
|
+
let childrenKey = this.childrenKey;
|
132
|
+
const flatTree = [];
|
133
|
+
|
134
|
+
function flattenChildren(node, parent) {
|
135
|
+
node.nodeKey = keyCounter++;
|
136
|
+
flatTree[node.nodeKey] = {node: node, nodeKey: node.nodeKey};
|
137
|
+
if (typeof parent != 'undefined') {
|
138
|
+
flatTree[node.nodeKey].parent = parent.nodeKey;
|
139
|
+
flatTree[parent.nodeKey][childrenKey].push(node.nodeKey);
|
140
|
+
}
|
141
|
+
|
142
|
+
if (node[childrenKey]) {
|
143
|
+
flatTree[node.nodeKey][childrenKey] = [];
|
144
|
+
node[childrenKey].forEach(child => flattenChildren(child, node));
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
this.stateTree.forEach(rootNode => {
|
149
|
+
flattenChildren(rootNode);
|
150
|
+
});
|
151
|
+
return flatTree;
|
152
|
+
},
|
153
|
+
updateTreeUp(nodeKey) {
|
154
|
+
const parentKey = this.flatState[nodeKey].parent;
|
155
|
+
if (typeof parentKey == 'undefined' || this.checkStrictly) return;
|
156
|
+
|
157
|
+
const node = this.flatState[nodeKey].node;
|
158
|
+
const parent = this.flatState[parentKey].node;
|
159
|
+
if (node.checked == parent.checked && node.indeterminate == parent.indeterminate) return; // no need to update upwards
|
160
|
+
|
161
|
+
if (node.checked == true) {
|
162
|
+
this.$set(parent, 'checked', parent[this.childrenKey].every(node => node.checked));
|
163
|
+
this.$set(parent, 'indeterminate', !parent.checked);
|
164
|
+
} else {
|
165
|
+
this.$set(parent, 'checked', false);
|
166
|
+
this.$set(parent, 'indeterminate', parent[this.childrenKey].some(node => node.checked || node.indeterminate));
|
167
|
+
}
|
168
|
+
this.updateTreeUp(parentKey);
|
169
|
+
},
|
170
|
+
rebuildTree() { // only called when `data` prop changes
|
171
|
+
const checkedNodes = this.getCheckedNodes();
|
172
|
+
checkedNodes.forEach(node => {
|
173
|
+
this.updateTreeDown(node, {checked: true});
|
174
|
+
// propagate upwards
|
175
|
+
const parentKey = this.flatState[node.nodeKey].parent;
|
176
|
+
if (!parentKey && parentKey !== 0) return;
|
177
|
+
const parent = this.flatState[parentKey].node;
|
178
|
+
const childHasCheckSetter = typeof node.checked != 'undefined' && node.checked;
|
179
|
+
if (childHasCheckSetter && parent.checked != node.checked) {
|
180
|
+
this.updateTreeUp(node.nodeKey); // update tree upwards
|
181
|
+
}
|
182
|
+
});
|
183
|
+
},
|
184
|
+
|
185
|
+
getSelectedNodes() {
|
186
|
+
/* public API */
|
187
|
+
return this.flatState.filter(obj => obj.node.selected).map(obj => obj.node);
|
188
|
+
},
|
189
|
+
getCheckedNodes() {
|
190
|
+
/* public API */
|
191
|
+
return this.flatState.filter(obj => obj.node.checked).map(obj => obj.node);
|
192
|
+
},
|
193
|
+
getCheckedAndIndeterminateNodes() {
|
194
|
+
/* public API */
|
195
|
+
return this.flatState.filter(obj => (obj.node.checked || obj.node.indeterminate)).map(obj => obj.node);
|
196
|
+
},
|
197
|
+
updateTreeDown(node, changes = {}) {
|
198
|
+
if (this.checkStrictly) return;
|
199
|
+
|
200
|
+
for (let key in changes) {
|
201
|
+
this.$set(node, key, changes[key]);
|
202
|
+
}
|
203
|
+
if (node[this.childrenKey]) {
|
204
|
+
node[this.childrenKey].forEach(child => {
|
205
|
+
this.updateTreeDown(child, changes);
|
206
|
+
});
|
207
|
+
}
|
208
|
+
},
|
209
|
+
handleSelect(nodeKey) {
|
210
|
+
const node = this.flatState[nodeKey].node;
|
211
|
+
if (!this.multiple) { // reset previously selected node
|
212
|
+
const currentSelectedKey = this.flatState.findIndex(obj => obj.node.selected);
|
213
|
+
if (currentSelectedKey >= 0 && currentSelectedKey !== nodeKey) this.$set(this.flatState[currentSelectedKey].node, 'selected', false);
|
214
|
+
}
|
215
|
+
this.$set(node, 'selected', !node.selected);
|
216
|
+
|
217
|
+
this.$emit('on-select-change', this.getSelectedNodes(), node);
|
218
|
+
},
|
219
|
+
handleCheck({checked, nodeKey}) {
|
220
|
+
const node = this.flatState[nodeKey].node;
|
221
|
+
this.$set(node, 'checked', checked);
|
222
|
+
this.$set(node, 'indeterminate', false);
|
223
|
+
|
224
|
+
this.updateTreeUp(nodeKey); // propagate up
|
225
|
+
this.updateTreeDown(node, {checked, indeterminate: false}); // reset `indeterminate` when going down
|
226
|
+
|
227
|
+
this.$emit('on-check-change', this.getCheckedNodes(), node);
|
228
|
+
}
|
229
|
+
},
|
230
|
+
created() {
|
231
|
+
this.flatState = this.compileFlatState();
|
232
|
+
this.rebuildTree();
|
233
|
+
// console.log(this.stateTree);
|
234
|
+
},
|
235
|
+
mounted() {
|
236
|
+
this.$on('on-check', this.handleCheck);
|
237
|
+
this.$on('on-selected', this.handleSelect);
|
238
|
+
this.$on('toggle-expand', node => this.$emit('on-toggle-expand', node));
|
239
|
+
}
|
240
|
+
};
|
241
|
+
</script>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
export default {
|
2
|
+
name: 'Can',
|
3
|
+
functional: true,
|
4
|
+
props: {
|
5
|
+
I: String,
|
6
|
+
a: [String, Array, Object],
|
7
|
+
of: [String, Array, Object],
|
8
|
+
not: Boolean,
|
9
|
+
},
|
10
|
+
watch:{
|
11
|
+
of(to) {
|
12
|
+
this.can(this.I, to, this.not)
|
13
|
+
},
|
14
|
+
I(to) {
|
15
|
+
this.can(to, this.of || this.a, this.not)
|
16
|
+
},
|
17
|
+
},
|
18
|
+
render(h, { props, children, parent, data }) {
|
19
|
+
const action = props.I;
|
20
|
+
const subject = props.of || props.a;
|
21
|
+
|
22
|
+
if (!action) {
|
23
|
+
throw new Error('[Vue Can]: neither `I` nor `do` property exist');
|
24
|
+
}
|
25
|
+
if (!subject) {
|
26
|
+
throw new Error('[Vue Can]: neither `of` nor `a` nor `this` nor `on` property exist');
|
27
|
+
}
|
28
|
+
const hasAction = (action, subject)=>{
|
29
|
+
return action === subject || Array.isArray(subject) && subject.indexOf(action) !== -1;
|
30
|
+
}
|
31
|
+
const allowed = !!(props.not ^ hasAction(action, subject));
|
32
|
+
|
33
|
+
return allowed ? children : null;
|
34
|
+
},
|
35
|
+
};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import Resize from './resize'
|
2
|
+
import Scroll from './scroll'
|
3
|
+
import Margin from './style/margin'
|
4
|
+
import Padding from './style/padding'
|
5
|
+
import Width from './style/width'
|
6
|
+
import Height from './style/height'
|
7
|
+
import LineHeight from './style/lineHeight'
|
8
|
+
import Color from './style/color'
|
9
|
+
import BgColor from './style/bg-color'
|
10
|
+
import Opacity from './style/opacity'
|
11
|
+
import FontSize from './style/font-size'
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
export {
|
16
|
+
Resize,
|
17
|
+
Scroll,
|
18
|
+
Width,
|
19
|
+
Height
|
20
|
+
}
|
21
|
+
|
22
|
+
export default {
|
23
|
+
Resize,
|
24
|
+
Scroll,
|
25
|
+
Margin,
|
26
|
+
Padding,
|
27
|
+
Width,
|
28
|
+
Height,
|
29
|
+
LineHeight,
|
30
|
+
Color,
|
31
|
+
FontSize,
|
32
|
+
BgColor,
|
33
|
+
Opacity
|
34
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
function inserted(el, binding) {
|
2
|
+
const callback = binding.value
|
3
|
+
const options = binding.options || { passive: true }
|
4
|
+
|
5
|
+
window.addEventListener('resize', callback, options)
|
6
|
+
el._onResize = {
|
7
|
+
callback,
|
8
|
+
options
|
9
|
+
}
|
10
|
+
|
11
|
+
if (!binding.modifiers || !binding.modifiers.quiet) {
|
12
|
+
callback()
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
function unbind(el) {
|
17
|
+
if (!el._onResize) return
|
18
|
+
|
19
|
+
const { callback, options } = el._onResize
|
20
|
+
window.removeEventListener('resize', callback, options)
|
21
|
+
delete el._onResize
|
22
|
+
}
|
23
|
+
|
24
|
+
export default {
|
25
|
+
inserted,
|
26
|
+
unbind
|
27
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
function inserted(el, binding) {
|
2
|
+
const callback = binding.value;
|
3
|
+
const options = binding.options || { passive: true };
|
4
|
+
const target = binding.arg ? document.querySelector(binding.arg) : window;
|
5
|
+
if (!target) return;
|
6
|
+
|
7
|
+
target.addEventListener('scroll', callback, options);
|
8
|
+
|
9
|
+
el._onScroll = {
|
10
|
+
callback,
|
11
|
+
options,
|
12
|
+
target
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
function unbind(el) {
|
17
|
+
if (!el._onScroll) return;
|
18
|
+
|
19
|
+
const { callback, options, target } = el._onScroll;
|
20
|
+
target.removeEventListener('scroll', callback, options);
|
21
|
+
delete el._onScroll
|
22
|
+
}
|
23
|
+
|
24
|
+
export default {
|
25
|
+
inserted,
|
26
|
+
unbind
|
27
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
function bind(el, binding, vnode) {
|
2
|
+
const callback = binding.value;
|
3
|
+
const options = binding.options || { passive: true};
|
4
|
+
const target = binding.arg
|
5
|
+
|
6
|
+
el.style.backgroundColor = callback;
|
7
|
+
el._bgColor = {
|
8
|
+
callback,
|
9
|
+
options,
|
10
|
+
target
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
|
15
|
+
function unbind(el) {
|
16
|
+
if (!el._bgColor) return;
|
17
|
+
delete el._bgColor
|
18
|
+
}
|
19
|
+
|
20
|
+
export default {
|
21
|
+
bind,
|
22
|
+
unbind
|
23
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
function bind(el, binding, vnode) {
|
2
|
+
const callback = binding.value;
|
3
|
+
const options = binding.options || { passive: true};
|
4
|
+
const target = binding.arg
|
5
|
+
|
6
|
+
el.style.color = callback;
|
7
|
+
el._color = {
|
8
|
+
callback,
|
9
|
+
options,
|
10
|
+
target
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
|
15
|
+
function unbind(el) {
|
16
|
+
if (!el._color) return;
|
17
|
+
delete el._color
|
18
|
+
}
|
19
|
+
|
20
|
+
export default {
|
21
|
+
bind,
|
22
|
+
unbind
|
23
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
function bind(el, binding, vnode) {
|
2
|
+
const callback = binding.value;
|
3
|
+
const options = binding.options || { passive: true};
|
4
|
+
const target = binding.arg
|
5
|
+
|
6
|
+
el.style.fontSize = callback;
|
7
|
+
el._fontSize = {
|
8
|
+
callback,
|
9
|
+
options,
|
10
|
+
target
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
|
15
|
+
function unbind(el) {
|
16
|
+
if (!el._fontSize) return;
|
17
|
+
delete el._fontSize
|
18
|
+
}
|
19
|
+
|
20
|
+
export default {
|
21
|
+
bind,
|
22
|
+
unbind
|
23
|
+
}
|