a2eb0287
zhigang.li
add layout compon...
|
1
2
3
|
<template>
<div
:class="wrapClasses"
|
76db49cd
zhigang.li
replay class attr...
|
4
|
:style="wrapStyles">
|
a2eb0287
zhigang.li
add layout compon...
|
5
6
7
|
<span v-show="showZeroTrigger" @click="toggleCollapse" :class="zeroWidthTriggerClasses">
<i class="ivu-icon ivu-icon-navicon-round"></i>
</span>
|
76db49cd
zhigang.li
replay class attr...
|
8
|
<div :class="childClasses">
|
a2eb0287
zhigang.li
add layout compon...
|
9
10
|
<slot></slot>
</div>
|
716d151a
zhigang.li
make it will not ...
|
11
12
13
14
15
|
<slot name="trigger">
<div v-show="showBottomTrigger" :class="triggerClasses" @click="toggleCollapse" :style="{width: siderWidth + 'px'}">
<i :class="triggerIconClasses"></i>
</div>
</slot>
|
a2eb0287
zhigang.li
add layout compon...
|
16
17
18
19
|
</div>
</template>
<script>
import { on, off } from '../../utils/dom';
|
d85e5726
zhigang.li
create setMatchMe...
|
20
|
import { oneOf, dimensionMap, setMatchMedia } from '../../utils/assist';
|
a2eb0287
zhigang.li
add layout compon...
|
21
|
const prefixCls = 'ivu-layout-sider';
|
d85e5726
zhigang.li
create setMatchMe...
|
22
|
setMatchMedia();
|
a2eb0287
zhigang.li
add layout compon...
|
23
24
25
26
27
28
29
|
export default {
name: 'Sider',
props: {
value: { // if it's collpased now
type: Boolean,
default: false
},
|
a2eb0287
zhigang.li
add layout compon...
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
width: {
type: [Number, String],
default: 200
},
collapsedWidth: {
type: [Number, String],
default: 64
},
hideTrigger: {
type: Boolean,
default: false
},
breakpoint: {
type: String,
|
a2eb0287
zhigang.li
add layout compon...
|
44
45
46
47
|
validator (val) {
return oneOf(val, ['xs', 'sm', 'md', 'lg', 'xl']);
}
},
|
1c26d05c
zhigang.li
add 'collapsible'...
|
48
49
50
51
|
collapsible: {
type: Boolean,
default: false
},
|
a2eb0287
zhigang.li
add layout compon...
|
52
53
54
55
56
57
58
59
60
61
62
63
|
defaultCollapsed: {
type: Boolean,
default: false
},
reverseArrow: {
type: Boolean,
default: false
}
},
data () {
return {
prefixCls: prefixCls,
|
1f7c24bc
zhigang.li
fixed https://git...
|
64
|
mediaMatched: false
|
a2eb0287
zhigang.li
add layout compon...
|
65
66
67
68
69
70
|
};
},
computed: {
wrapClasses () {
return [
`${prefixCls}`,
|
a2eb0287
zhigang.li
add layout compon...
|
71
|
this.siderWidth ? '' : `${prefixCls}-zero-width`,
|
1f7c24bc
zhigang.li
fixed https://git...
|
72
|
this.value ? `${prefixCls}-collapsed` : ''
|
a2eb0287
zhigang.li
add layout compon...
|
73
74
|
];
},
|
76db49cd
zhigang.li
replay class attr...
|
75
76
77
78
79
80
81
82
|
wrapStyles () {
return {
width: `${this.siderWidth}px`,
minWidth: `${this.siderWidth}px`,
maxWidth: `${this.siderWidth}px`,
flex: `0 0 ${this.siderWidth}px`
};
},
|
a2eb0287
zhigang.li
add layout compon...
|
83
84
85
|
triggerClasses () {
return [
`${prefixCls}-trigger`,
|
1f7c24bc
zhigang.li
fixed https://git...
|
86
|
this.value ? `${prefixCls}-trigger-collapsed` : '',
|
a2eb0287
zhigang.li
add layout compon...
|
87
88
|
];
},
|
76db49cd
zhigang.li
replay class attr...
|
89
90
91
|
childClasses () {
return `${this.prefixCls}-children`;
},
|
a2eb0287
zhigang.li
add layout compon...
|
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
zeroWidthTriggerClasses () {
return [
`${prefixCls}-zero-width-trigger`,
this.reverseArrow ? `${prefixCls}-zero-width-trigger-left` : ''
];
},
triggerIconClasses () {
return [
'ivu-icon',
`ivu-icon-chevron-${this.reverseArrow ? 'right' : 'left'}`,
`${prefixCls}-trigger-icon`,
];
},
siderWidth () {
|
1f7c24bc
zhigang.li
fixed https://git...
|
106
|
return this.collapsible ? (this.value ? (this.mediaMatched ? 0 : parseInt(this.collapsedWidth)) : parseInt(this.width)) : this.width;
|
a2eb0287
zhigang.li
add layout compon...
|
107
108
|
},
showZeroTrigger () {
|
1f7c24bc
zhigang.li
fixed https://git...
|
109
|
return this.collapsible ? (this.mediaMatched && !this.hideTrigger || (parseInt(this.collapsedWidth) === 0) && this.value && !this.hideTrigger) : false;
|
1c26d05c
zhigang.li
add 'collapsible'...
|
110
111
112
|
},
showBottomTrigger () {
return this.collapsible ? !this.mediaMatched && !this.hideTrigger : false;
|
a2eb0287
zhigang.li
add layout compon...
|
113
114
115
116
|
}
},
methods: {
toggleCollapse () {
|
1f7c24bc
zhigang.li
fixed https://git...
|
117
118
|
let value = this.collapsible ? !this.value : false;
this.$emit('input', value);
|
a2eb0287
zhigang.li
add layout compon...
|
119
120
121
122
123
124
125
126
|
},
matchMedia () {
let matchMedia;
if (window.matchMedia) {
matchMedia = window.matchMedia;
}
let mediaMatched = this.mediaMatched;
this.mediaMatched = matchMedia(`(max-width: ${dimensionMap[this.breakpoint]})`).matches;
|
47ea7cc2
zhigang.li
fixed bug about s...
|
127
|
|
a2eb0287
zhigang.li
add layout compon...
|
128
|
if (this.mediaMatched !== mediaMatched) {
|
a2eb0287
zhigang.li
add layout compon...
|
129
|
this.$emit('input', this.mediaMatched);
|
a2eb0287
zhigang.li
add layout compon...
|
130
131
132
133
134
135
|
}
},
onWindowResize () {
this.matchMedia();
}
},
|
1f7c24bc
zhigang.li
fixed https://git...
|
136
137
138
139
140
|
watch: {
value (stat) {
this.$emit('on-collapse', stat);
}
},
|
a2eb0287
zhigang.li
add layout compon...
|
141
|
mounted () {
|
76db49cd
zhigang.li
replay class attr...
|
142
|
if (this.defaultCollapsed) {
|
ad74efbc
zhigang.li
fixed the bug abo...
|
143
|
this.$emit('input', this.defaultCollapsed);
|
76db49cd
zhigang.li
replay class attr...
|
144
|
}
|
716d151a
zhigang.li
make it will not ...
|
145
146
147
148
|
if (this.breakpoint !== undefined) {
on(window, 'resize', this.onWindowResize);
this.matchMedia();
}
|
a2eb0287
zhigang.li
add layout compon...
|
149
|
},
|
c2d603d0
zhigang.li
update sider
|
150
|
beforeDestroy () {
|
716d151a
zhigang.li
make it will not ...
|
151
152
153
|
if (this.breakpoint !== undefined) {
off(window, 'resize', this.onWindowResize);
}
|
a2eb0287
zhigang.li
add layout compon...
|
154
155
156
|
}
};
</script>
|