@v2coding/ui 0.1.0
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 +6 -0
- package/dist/v2coding-ui.esm.js +10840 -0
- package/dist/v2coding-ui.min.js +1 -0
- package/dist/v2coding-ui.ssr.js +10747 -0
- package/package.json +54 -0
- package/src/components/dialog/dialog.vue +179 -0
- package/src/components/drawer/drawer.vue +523 -0
- package/src/components/exports/index.vue +53 -0
- package/src/components/exports/remote-exports-dialog.vue +202 -0
- package/src/components/field/field.autocomplete.vue +21 -0
- package/src/components/field/field.calendar.vue +117 -0
- package/src/components/field/field.cascade.vue +233 -0
- package/src/components/field/field.checkbox.vue +134 -0
- package/src/components/field/field.color.vue +24 -0
- package/src/components/field/field.date.vue +145 -0
- package/src/components/field/field.icons.vue +123 -0
- package/src/components/field/field.number.vue +43 -0
- package/src/components/field/field.radio.vue +100 -0
- package/src/components/field/field.rate.vue +37 -0
- package/src/components/field/field.rich.vue +165 -0
- package/src/components/field/field.select.vue +210 -0
- package/src/components/field/field.slider.vue +66 -0
- package/src/components/field/field.switch.vue +14 -0
- package/src/components/field/field.text.vue +66 -0
- package/src/components/field/field.timepicker.vue +70 -0
- package/src/components/field/field.timeselect.vue +24 -0
- package/src/components/field/field.trigger.dialog.vue +50 -0
- package/src/components/field/field.trigger.popover.vue +63 -0
- package/src/components/field/field.upload.file.vue +241 -0
- package/src/components/field/field.upload.image.vue +125 -0
- package/src/components/field/field.upload.portrait.vue +304 -0
- package/src/components/fill-view/index.vue +43 -0
- package/src/components/form/form.dialog.vue +174 -0
- package/src/components/form/form.drawer.vue +246 -0
- package/src/components/form/form.fieldset.vue +110 -0
- package/src/components/form/form.item.vue +213 -0
- package/src/components/form/form.vue +293 -0
- package/src/components/head-menu/index.vue +188 -0
- package/src/components/head-menu/menu-item.vue +84 -0
- package/src/components/history/index.vue +360 -0
- package/src/components/icon/icon.vue +63 -0
- package/src/components/minimize/index.vue +342 -0
- package/src/components/page/page.vue +43 -0
- package/src/components/provider/provider.vue +15 -0
- package/src/components/scroll-view/scroll-view.vue +384 -0
- package/src/components/table/column.vue +262 -0
- package/src/components/table/table.pagination.vue +71 -0
- package/src/components/table/table.select.vue +165 -0
- package/src/components/table/table.vue +805 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="['scroll-nav__nav-wrap', `is-${direction}`]">
|
|
3
|
+
<div :class="['scroll-nav__nav-control scroll-nav__nav-prev', scrollable ? 'scroll-nav__nav-active' : '', scrollable && scrollable.prev ? '' : 'is-disabled']" @click="scrollPrev">
|
|
4
|
+
<slot name="prev" :disabled="scrollable && !scrollable.prev"><div class="menu-nav-control"></div></slot>
|
|
5
|
+
</div>
|
|
6
|
+
<div ref="navScroll" class="scroll-nav__nav-scroll">
|
|
7
|
+
<div ref="nav" :class="['scroll-nav__nav', `is-${direction}`]" :style="navStyle">
|
|
8
|
+
<slot></slot>
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
<div :class="['scroll-nav__nav-control scroll-nav__nav-next', scrollable ? 'scroll-nav__nav-active' : '', scrollable && scrollable.next ? '' : 'is-disabled']" @click="scrollNext">
|
|
12
|
+
<slot name="next" :disabled="scrollable && !scrollable.next"><div class="menu-nav-control"></div></slot>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
import {addResizeListener, removeResizeListener} from 'element-ui/lib/utils/resize-event';
|
|
19
|
+
|
|
20
|
+
const firstUpperCase = str => {
|
|
21
|
+
return str.toLowerCase().replace(/( |^)[a-z]/g, (L) => L.toUpperCase());
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
name: 'ScrollNav',
|
|
26
|
+
props: {
|
|
27
|
+
direction: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: 'row',
|
|
30
|
+
validator: val => ['column', 'row'].includes(val),
|
|
31
|
+
},
|
|
32
|
+
childActiveCls: {
|
|
33
|
+
type: String,
|
|
34
|
+
default: '.is-active',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
data() {
|
|
38
|
+
return {
|
|
39
|
+
scrollable: false,
|
|
40
|
+
navOffset: 0,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
computed: {
|
|
44
|
+
navStyle() {
|
|
45
|
+
const dir = this.direction === 'row' ? 'X' : 'Y';
|
|
46
|
+
return {
|
|
47
|
+
transform: `translate${dir}(-${this.navOffset}px)`,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
sizeName() {
|
|
51
|
+
return this.direction === 'row' ? 'width' : 'height';
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
mounted() {
|
|
55
|
+
addResizeListener(this.$el, this.update);
|
|
56
|
+
addResizeListener(this.$refs.nav, this.update);
|
|
57
|
+
const mo = new MutationObserver(this.update);
|
|
58
|
+
mo.observe(this.$el, {childList: true, subtree: true});
|
|
59
|
+
setTimeout(() => {
|
|
60
|
+
this.scrollToActiveItem();
|
|
61
|
+
}, 0);
|
|
62
|
+
|
|
63
|
+
this.$once('hook:beforeDestroy', () => {
|
|
64
|
+
if (this.$el && this.update) removeResizeListener(this.$el, this.update);
|
|
65
|
+
if (this.$refs.nav && this.update) removeResizeListener(this.$refs.nav, this.update);
|
|
66
|
+
mo.disconnect();
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
methods: {
|
|
70
|
+
scrollPrev() {
|
|
71
|
+
const containerSize = this.$refs.navScroll[`offset${firstUpperCase(this.sizeName)}`];
|
|
72
|
+
const currentOffset = this.navOffset;
|
|
73
|
+
|
|
74
|
+
if (!currentOffset) return;
|
|
75
|
+
|
|
76
|
+
let newOffset = currentOffset > containerSize
|
|
77
|
+
? currentOffset - containerSize
|
|
78
|
+
: 0;
|
|
79
|
+
|
|
80
|
+
this.navOffset = newOffset;
|
|
81
|
+
this.update();
|
|
82
|
+
},
|
|
83
|
+
scrollNext() {
|
|
84
|
+
const navSize = this.$refs.nav[`offset${firstUpperCase(this.sizeName)}`];
|
|
85
|
+
const containerSize = this.$refs.navScroll[`offset${firstUpperCase(this.sizeName)}`];
|
|
86
|
+
const currentOffset = this.navOffset;
|
|
87
|
+
|
|
88
|
+
if (navSize - currentOffset <= containerSize) return;
|
|
89
|
+
|
|
90
|
+
let newOffset = navSize - currentOffset > containerSize * 2
|
|
91
|
+
? currentOffset + containerSize
|
|
92
|
+
: (navSize - containerSize);
|
|
93
|
+
|
|
94
|
+
this.navOffset = newOffset;
|
|
95
|
+
this.update();
|
|
96
|
+
},
|
|
97
|
+
scrollToActiveItem() {
|
|
98
|
+
if (!this.scrollable) return;
|
|
99
|
+
const nav = this.$refs.nav;
|
|
100
|
+
const activeItem = this.$el.querySelector(this.childActiveCls);
|
|
101
|
+
if (!activeItem) return;
|
|
102
|
+
const navScroll = this.$refs.navScroll;
|
|
103
|
+
const isHorizontal = this.direction === 'row';
|
|
104
|
+
const activeItemBounding = activeItem.getBoundingClientRect();
|
|
105
|
+
const navScrollBounding = navScroll.getBoundingClientRect();
|
|
106
|
+
const maxOffset = isHorizontal
|
|
107
|
+
? nav.offsetWidth - navScrollBounding.width
|
|
108
|
+
: nav.offsetHeight - navScrollBounding.height;
|
|
109
|
+
const currentOffset = this.navOffset;
|
|
110
|
+
let newOffset = currentOffset;
|
|
111
|
+
|
|
112
|
+
if (isHorizontal) {
|
|
113
|
+
if (activeItemBounding.left < navScrollBounding.left) {
|
|
114
|
+
newOffset = currentOffset - (navScrollBounding.left - activeItemBounding.left);
|
|
115
|
+
}
|
|
116
|
+
if (activeItemBounding.right > navScrollBounding.right) {
|
|
117
|
+
newOffset = currentOffset + activeItemBounding.right - navScrollBounding.right;
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
if (activeItemBounding.top < navScrollBounding.top) {
|
|
121
|
+
newOffset = currentOffset - (navScrollBounding.top - activeItemBounding.top);
|
|
122
|
+
}
|
|
123
|
+
if (activeItemBounding.bottom > navScrollBounding.bottom) {
|
|
124
|
+
newOffset = currentOffset + (activeItemBounding.bottom - navScrollBounding.bottom);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
newOffset = Math.max(newOffset, 0);
|
|
128
|
+
this.navOffset = Math.min(newOffset, maxOffset);
|
|
129
|
+
this.update();
|
|
130
|
+
},
|
|
131
|
+
update() {
|
|
132
|
+
if (!this.$refs.nav) return;
|
|
133
|
+
const sizeName = this.sizeName;
|
|
134
|
+
const navSize = this.$refs.nav[`offset${firstUpperCase(sizeName)}`];
|
|
135
|
+
const containerSize = this.$refs.navScroll[`offset${firstUpperCase(sizeName)}`];
|
|
136
|
+
const currentOffset = this.navOffset;
|
|
137
|
+
|
|
138
|
+
if (containerSize < navSize) {
|
|
139
|
+
this.scrollable = {};
|
|
140
|
+
this.scrollable.prev = currentOffset > 0;
|
|
141
|
+
this.scrollable.next = currentOffset + containerSize < navSize;
|
|
142
|
+
if (navSize - currentOffset < containerSize) {
|
|
143
|
+
this.navOffset = navSize - containerSize;
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
this.scrollable = false;
|
|
147
|
+
if (currentOffset > 0) {
|
|
148
|
+
this.navOffset = 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
</script>
|
|
155
|
+
|
|
156
|
+
<style lang="less">
|
|
157
|
+
.scroll-nav__nav-wrap {
|
|
158
|
+
overflow: hidden;
|
|
159
|
+
position: relative;
|
|
160
|
+
display: flex;
|
|
161
|
+
align-items: center;
|
|
162
|
+
flex-wrap: nowrap;
|
|
163
|
+
|
|
164
|
+
&.is-row {
|
|
165
|
+
flex-direction: row;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&.is-column {
|
|
169
|
+
flex-direction: column;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.scroll-nav__nav-scroll {
|
|
173
|
+
overflow: hidden;
|
|
174
|
+
|
|
175
|
+
.scroll-nav__nav {
|
|
176
|
+
position: relative;
|
|
177
|
+
transition: transform .3s;
|
|
178
|
+
display: flex;
|
|
179
|
+
flex-wrap: nowrap;
|
|
180
|
+
float: left;
|
|
181
|
+
|
|
182
|
+
&.is-row {
|
|
183
|
+
flex-direction: row;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
&.is-column {
|
|
187
|
+
flex-direction: column;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
&.is-row .scroll-nav__nav-control {
|
|
193
|
+
flex: none;
|
|
194
|
+
width: 50px;
|
|
195
|
+
height: 100%;
|
|
196
|
+
cursor: pointer;
|
|
197
|
+
display: flex;
|
|
198
|
+
flex-direction: column;
|
|
199
|
+
align-items: center;
|
|
200
|
+
justify-content: center;
|
|
201
|
+
visibility: hidden;
|
|
202
|
+
|
|
203
|
+
&.scroll-nav__nav-active {
|
|
204
|
+
visibility: visible;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.menu-nav-control {
|
|
208
|
+
width: 25px;
|
|
209
|
+
height: 70px;
|
|
210
|
+
display: flex;
|
|
211
|
+
align-items: center;
|
|
212
|
+
justify-content: center;
|
|
213
|
+
flex-direction: column;
|
|
214
|
+
|
|
215
|
+
&::before,
|
|
216
|
+
&::after {
|
|
217
|
+
content: '';
|
|
218
|
+
display: block;
|
|
219
|
+
position: relative;
|
|
220
|
+
width: 6px;
|
|
221
|
+
height: 50px;
|
|
222
|
+
background-color: #fff;
|
|
223
|
+
transition: all 300ms ease-in-out;
|
|
224
|
+
border-radius: 3px;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
&::before {
|
|
228
|
+
bottom: -4px;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
&::after {
|
|
232
|
+
top: -4px;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
&.scroll-nav__nav-prev {
|
|
237
|
+
.menu-nav-control::before {
|
|
238
|
+
transform: rotate(18deg);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.menu-nav-control::after {
|
|
242
|
+
transform: rotate(-18deg);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
&.scroll-nav__nav-next {
|
|
247
|
+
.menu-nav-control::before {
|
|
248
|
+
transform: rotate(-18deg);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.menu-nav-control::after {
|
|
252
|
+
transform: rotate(18deg);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
&.scroll-nav__nav-prev:hover {
|
|
257
|
+
.menu-nav-control::before {
|
|
258
|
+
transform: rotate(30deg);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.menu-nav-control::after {
|
|
262
|
+
transform: rotate(-30deg);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
&.scroll-nav__nav-next:hover {
|
|
267
|
+
.menu-nav-control::before {
|
|
268
|
+
transform: rotate(-30deg);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.menu-nav-control::after {
|
|
272
|
+
transform: rotate(30deg);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
&.is-disabled {
|
|
277
|
+
pointer-events: none;
|
|
278
|
+
|
|
279
|
+
.menu-nav-control::before,
|
|
280
|
+
.menu-nav-control::after {
|
|
281
|
+
background-color: #ccc;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
&.is-column {
|
|
287
|
+
height: 100%;
|
|
288
|
+
|
|
289
|
+
.scroll-nav__nav-control {
|
|
290
|
+
flex: none;
|
|
291
|
+
width: 100%;
|
|
292
|
+
height: 35px;
|
|
293
|
+
cursor: pointer;
|
|
294
|
+
display: flex;
|
|
295
|
+
flex-direction: column;
|
|
296
|
+
align-items: center;
|
|
297
|
+
justify-content: center;
|
|
298
|
+
visibility: hidden;
|
|
299
|
+
|
|
300
|
+
&.scroll-nav__nav-active {
|
|
301
|
+
visibility: visible;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.menu-nav-control {
|
|
305
|
+
width: 40px;
|
|
306
|
+
height: 17px;
|
|
307
|
+
display: flex;
|
|
308
|
+
align-items: center;
|
|
309
|
+
justify-content: center;
|
|
310
|
+
flex-direction: row;
|
|
311
|
+
|
|
312
|
+
&::before,
|
|
313
|
+
&::after {
|
|
314
|
+
content: '';
|
|
315
|
+
display: block;
|
|
316
|
+
position: relative;
|
|
317
|
+
width: 17px;
|
|
318
|
+
height: 4px;
|
|
319
|
+
background-color: #fff;
|
|
320
|
+
transition: all 300ms ease-in-out;
|
|
321
|
+
border-radius: 3px;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
&::before {
|
|
325
|
+
right: -2.5px;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
&::after {
|
|
329
|
+
left: -2.5px;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
&.scroll-nav__nav-prev {
|
|
334
|
+
.menu-nav-control::before {
|
|
335
|
+
transform: rotate(-18deg);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.menu-nav-control::after {
|
|
339
|
+
transform: rotate(18deg);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
&.scroll-nav__nav-next {
|
|
344
|
+
.menu-nav-control::before {
|
|
345
|
+
transform: rotate(18deg);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.menu-nav-control::after {
|
|
349
|
+
transform: rotate(-18deg);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
&.scroll-nav__nav-prev:hover {
|
|
354
|
+
.menu-nav-control::before {
|
|
355
|
+
transform: rotate(-30deg);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.menu-nav-control::after {
|
|
359
|
+
transform: rotate(30deg);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
&.scroll-nav__nav-next:hover {
|
|
364
|
+
.menu-nav-control::before {
|
|
365
|
+
transform: rotate(30deg);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.menu-nav-control::after {
|
|
369
|
+
transform: rotate(-30deg);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
&.is-disabled {
|
|
374
|
+
pointer-events: none;
|
|
375
|
+
|
|
376
|
+
.menu-nav-control::before,
|
|
377
|
+
.menu-nav-control::after {
|
|
378
|
+
background-color: #ccc;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
</style>
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
<script type="text/jsx">
|
|
2
|
+
import {TableColumn} from 'element-ui';
|
|
3
|
+
import {getPropByPath} from 'element-ui/lib/utils/util';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ui-table-column 内置组件.
|
|
7
|
+
* 在 element-ui 的 el-table-column 组件上拓展出 tree 类型
|
|
8
|
+
*/
|
|
9
|
+
export default {
|
|
10
|
+
name: 'ui-column',
|
|
11
|
+
mixins: [TableColumn],
|
|
12
|
+
inject: {
|
|
13
|
+
uiTable: {
|
|
14
|
+
default: null,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
props: {
|
|
18
|
+
identifyKey: {
|
|
19
|
+
type: String,
|
|
20
|
+
default: 'id',
|
|
21
|
+
},
|
|
22
|
+
parentKey: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: 'upId',
|
|
25
|
+
},
|
|
26
|
+
childrenKey: {
|
|
27
|
+
type: String,
|
|
28
|
+
default: 'children',
|
|
29
|
+
},
|
|
30
|
+
// lazy 动态加载时需要通过判断 isLeaf 来渲染 展开/收起 状态
|
|
31
|
+
leafKey: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: 'isLeaf'
|
|
34
|
+
},
|
|
35
|
+
// tree 是否动态加载
|
|
36
|
+
lazy: {
|
|
37
|
+
type: [Boolean, String],
|
|
38
|
+
},
|
|
39
|
+
/**
|
|
40
|
+
* tree 动态加载返回children方法
|
|
41
|
+
*
|
|
42
|
+
* row {Object} 点击展开的 node 数据
|
|
43
|
+
* resolve {Function} 调用此方法返回 children 数据. eg: resolve(row.children);
|
|
44
|
+
* - 使用自定义 loadData 时可先判断 row 的 children 是否已经加载过, 已经加载过则直接 resolve.
|
|
45
|
+
*/
|
|
46
|
+
loadData: {
|
|
47
|
+
type: Function,
|
|
48
|
+
default(row, resolve) {
|
|
49
|
+
if (!this.lazy) {
|
|
50
|
+
resolve(row[this.childrenKey]);
|
|
51
|
+
} else if (Array.isArray(row[this.childrenKey]) && row[this.childrenKey].length) {
|
|
52
|
+
resolve(row[this.childrenKey]);
|
|
53
|
+
} else {
|
|
54
|
+
// extra
|
|
55
|
+
const hasCurrentUrl = typeof this.lazy === 'string';
|
|
56
|
+
const url = hasCurrentUrl ? this.lazy : (this.uiTable && this.uiTable.url || '');
|
|
57
|
+
if (!url) {
|
|
58
|
+
console.warn(`no lazy url config, please config ui-table -> url or ui-table-column -> lazy(string url)`);
|
|
59
|
+
resolve(row[this.childrenKey]);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let params = {};
|
|
63
|
+
// 使用 uiTable 配置的 url 时也要同时使用 uiTable 的 params
|
|
64
|
+
if (!hasCurrentUrl && this.uiTable) {
|
|
65
|
+
params = {...this.uiTable.params};
|
|
66
|
+
}
|
|
67
|
+
params[this.identifyKey] = row[this.identifyKey];
|
|
68
|
+
this.$axios.get(url, {params}).then(resolve).catch(() => resolve([]));
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
treeCls: {
|
|
73
|
+
type: Object,
|
|
74
|
+
default: () => ({
|
|
75
|
+
expand: 'el-icon-caret-bottom',
|
|
76
|
+
collapse: 'el-icon-caret-right',
|
|
77
|
+
loading: 'el-icon-loading',
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
},
|
|
82
|
+
created() {
|
|
83
|
+
if (this.type === 'tree') {
|
|
84
|
+
this.$renderTree();
|
|
85
|
+
this.initTreeTableMethods(this.uiTable);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
methods: {
|
|
89
|
+
$getLevel(data, level = 0) {
|
|
90
|
+
const parent = this.owner.data.find(row => row[this.identifyKey] === data[this.parentKey]);
|
|
91
|
+
if (parent && parent[this.identifyKey] !== parent[this.parentKey]) {
|
|
92
|
+
return this.$getLevel(parent, ++level);
|
|
93
|
+
}
|
|
94
|
+
return level;
|
|
95
|
+
},
|
|
96
|
+
$collapse(row) {
|
|
97
|
+
const {data} = this.owner;
|
|
98
|
+
const rowIndex = data.findIndex(item => item[this.identifyKey] === row[this.identifyKey]);
|
|
99
|
+
if (rowIndex === -1) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const children = data[rowIndex][this.childrenKey];
|
|
103
|
+
if (!Array.isArray(children) || !children.length) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
children.forEach(child => {
|
|
107
|
+
// 下级同时收起
|
|
108
|
+
this.$collapse(child);
|
|
109
|
+
const index = this.owner.data.findIndex(item => item[this.identifyKey] === child[this.identifyKey]);
|
|
110
|
+
if (index === -1) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.owner.data.splice(index, 1);
|
|
114
|
+
});
|
|
115
|
+
// this.owner.data
|
|
116
|
+
},
|
|
117
|
+
$expand(row) {
|
|
118
|
+
const {data} = this.owner;
|
|
119
|
+
const isExpand = data.some(item => item[this.parentKey] === row[this.identifyKey]);
|
|
120
|
+
if (isExpand) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const rowIndex = data.findIndex(item => item[this.identifyKey] === row[this.identifyKey]);
|
|
124
|
+
if (rowIndex === -1) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const children = data[rowIndex][this.childrenKey];
|
|
128
|
+
if (Array.isArray(children)) {
|
|
129
|
+
data.splice(rowIndex + 1, 0, ...children);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
$renderTree() {
|
|
133
|
+
let renderCell = this.$renderTreeCell;
|
|
134
|
+
let _self = this;
|
|
135
|
+
this.columnConfig.renderCell = function(h, data) {
|
|
136
|
+
return _self.showOverflowTooltip || _self.showTooltipWhenOverflow
|
|
137
|
+
? h('div', {
|
|
138
|
+
attrs: {class: 'cell el-tooltip'},
|
|
139
|
+
style: {width: (data.column.realWidth || data.column.width) - 1 + 'px'},
|
|
140
|
+
}, [renderCell(h, data)])
|
|
141
|
+
: h('div', {attrs: {class: 'cell'}}, [renderCell(h, data)]);
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
$renderTreeCell(h, data) {
|
|
145
|
+
const {row} = data;
|
|
146
|
+
const {expand, collapse, loading} = this.treeCls;
|
|
147
|
+
const isExpand = this.owner.data.some(item => item[this.parentKey] === row[this.identifyKey]);
|
|
148
|
+
let triggerCls = isExpand ? expand : collapse;
|
|
149
|
+
if (row.$$loading) {
|
|
150
|
+
triggerCls = loading;
|
|
151
|
+
}
|
|
152
|
+
const level = this.$getLevel(row);
|
|
153
|
+
const children = row[this.childrenKey];
|
|
154
|
+
let hasChildren = false;
|
|
155
|
+
if (this.lazy) {
|
|
156
|
+
hasChildren = !row[this.leafKey];
|
|
157
|
+
} else {
|
|
158
|
+
hasChildren = Array.isArray(children) && !!children.length
|
|
159
|
+
}
|
|
160
|
+
const toggleCollapse = () => {
|
|
161
|
+
if (!hasChildren) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (isExpand) {
|
|
165
|
+
this.$collapse(data.row);
|
|
166
|
+
} else {
|
|
167
|
+
new Promise(resolve => {
|
|
168
|
+
row.$$loading = true;
|
|
169
|
+
this.$refreshRow(row);
|
|
170
|
+
this.loadData(row, resolve);
|
|
171
|
+
}).then(children => {
|
|
172
|
+
row[this.childrenKey] = children;
|
|
173
|
+
row.$$loading = false;
|
|
174
|
+
this.$refreshRow(row);
|
|
175
|
+
this.$expand(data.row);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
return h('div', {attrs: {class: 'tree-cell-wrapper'}, style: {paddingLeft: `${level * 15}px`}}, [
|
|
180
|
+
h('div', {attrs: {class: `tree-toggle ${hasChildren ? 'pointer' : ''}`}, on: {click: toggleCollapse}}, [
|
|
181
|
+
hasChildren ? h('i', {attrs: {class: triggerCls}}) : null,
|
|
182
|
+
]),
|
|
183
|
+
this.$renderTreeCellBody(h, data),
|
|
184
|
+
]);
|
|
185
|
+
},
|
|
186
|
+
$refreshRow(row) {
|
|
187
|
+
const index = this.owner.data.findIndex(item => item[this.identifyKey] === row[this.identifyKey]);
|
|
188
|
+
this.owner.data.splice(index, 1, {...row});
|
|
189
|
+
},
|
|
190
|
+
$renderTreeCellBody(h, data) {
|
|
191
|
+
if (this.$scopedSlots.default) {
|
|
192
|
+
return this.$scopedSlots.default(data);
|
|
193
|
+
}
|
|
194
|
+
const {row, column, $index} = data;
|
|
195
|
+
const property = column.property;
|
|
196
|
+
const value = property && getPropByPath(row, property).v;
|
|
197
|
+
if (column && column.formatter) {
|
|
198
|
+
return column.formatter(row, column, value, $index);
|
|
199
|
+
}
|
|
200
|
+
return value;
|
|
201
|
+
},
|
|
202
|
+
async expandAll(row) {
|
|
203
|
+
await this.uiTable.$nextTick();
|
|
204
|
+
if (row === undefined) {
|
|
205
|
+
this.owner.data.forEach(item => this.expandAll(item));
|
|
206
|
+
} else if (row && row[this.identifyKey]) {
|
|
207
|
+
this.$expand(row);
|
|
208
|
+
const children = row[this.childrenKey];
|
|
209
|
+
if (Array.isArray(children)) {
|
|
210
|
+
children.forEach(child => this.expandAll(child));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
initTreeTableMethods(treeTable) {
|
|
215
|
+
if (!treeTable) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
treeTable.expand = this.$expand;
|
|
219
|
+
treeTable.collapse = this.$collapse;
|
|
220
|
+
treeTable.expandAll = (row) => {
|
|
221
|
+
if (row === undefined) {
|
|
222
|
+
this.expandAll();
|
|
223
|
+
} else if (row && row[this.identifyKey]) {
|
|
224
|
+
const tableRow = this.owner.data.find(item => item[this.identifyKey] === row[this.identifyKey]);
|
|
225
|
+
this.expandAll(tableRow);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
treeTable.removeRow = (row) => {
|
|
229
|
+
const rowIndex = this.owner.data.findIndex(item => item[this.identifyKey] === row[this.identifyKey]);
|
|
230
|
+
if (rowIndex === -1) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
// 1. 收起节点
|
|
234
|
+
this.$collapse(row);
|
|
235
|
+
// 2. 从table中删除该条数据
|
|
236
|
+
this.owner.data.splice(rowIndex, 1);
|
|
237
|
+
// 3. 从父级的children中删除该数据(展开父级时是把父级的children填充到table数据中)
|
|
238
|
+
// 如果父级的父级未展开即父级还不在this.owner.data中时会有问题, 但这里暂不处理若之后有这样的逻辑后再处理(递归从this.owner.data中一级一级的查找到父级)
|
|
239
|
+
const parent = this.owner.data.find(item => item[this.identifyKey] === row[this.parentKey]);
|
|
240
|
+
const childIndex = (parent[this.childrenKey] || []).findIndex(child => child[this.identifyKey] === row[this.identifyKey]);
|
|
241
|
+
if (childIndex === -1) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
parent[this.childrenKey].splice(childIndex, 1);
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
</script>
|
|
250
|
+
|
|
251
|
+
<style lang="less">
|
|
252
|
+
.tree-toggle {
|
|
253
|
+
display: inline-flex;
|
|
254
|
+
width: 24px;
|
|
255
|
+
align-items: center;
|
|
256
|
+
justify-content: center;
|
|
257
|
+
|
|
258
|
+
&.pointer {
|
|
259
|
+
cursor: pointer;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
</style>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-pagination
|
|
3
|
+
v-bind="$attrs"
|
|
4
|
+
:layout="layout"
|
|
5
|
+
:page-sizes="pageSizes"
|
|
6
|
+
:total="page.total || 0"
|
|
7
|
+
:page-size="page.size"
|
|
8
|
+
:background="background"
|
|
9
|
+
:current-page="page.no || 1"
|
|
10
|
+
@size-change="onSizeChange"
|
|
11
|
+
@current-change="onCurrentChange"
|
|
12
|
+
>
|
|
13
|
+
<slot></slot>
|
|
14
|
+
</el-pagination>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
export default {
|
|
19
|
+
name: 'ui-table-pagination',
|
|
20
|
+
inject: ['uiTable'],
|
|
21
|
+
props: {
|
|
22
|
+
layout: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: 'prev, pager, next',
|
|
25
|
+
},
|
|
26
|
+
pageSizes: {
|
|
27
|
+
type: Array,
|
|
28
|
+
default: () => [20, 30, 50, 80],
|
|
29
|
+
},
|
|
30
|
+
background: {
|
|
31
|
+
type: Boolean,
|
|
32
|
+
default: true,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
computed: {
|
|
36
|
+
page() {
|
|
37
|
+
if (!this.uiTable.remoteData) {
|
|
38
|
+
return {total: 0, ...this.getInitParams()};
|
|
39
|
+
}
|
|
40
|
+
return this.uiTable.remoteData;
|
|
41
|
+
},
|
|
42
|
+
size() {
|
|
43
|
+
return this.pageSizes[0] || 10;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
created() {
|
|
47
|
+
this.uiTable.registerPagination(this);
|
|
48
|
+
},
|
|
49
|
+
destroyed() {
|
|
50
|
+
this.uiTable.unRegisterPagination();
|
|
51
|
+
},
|
|
52
|
+
methods: {
|
|
53
|
+
getInitParams() {
|
|
54
|
+
return {no: 1, size: this.size};
|
|
55
|
+
},
|
|
56
|
+
onChange(no, size) {
|
|
57
|
+
this.uiTable.changePage({no, size});
|
|
58
|
+
},
|
|
59
|
+
onSizeChange(size) {
|
|
60
|
+
this.onChange(1, size);
|
|
61
|
+
},
|
|
62
|
+
onCurrentChange(no) {
|
|
63
|
+
this.onChange(no, this.page.size);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<style scoped>
|
|
70
|
+
|
|
71
|
+
</style>
|