-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCell.vue
139 lines (126 loc) · 2.39 KB
/
Cell.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<style lang="stylus">
.CellBox {
background-color: #fff;
}
.Cell--active {
&:active {
background-color: #f5f5f5;
}
}
.Cell {
position: relative;
display: flex;
align-items: center;
min-height: 48px;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 15px;
padding-right: 15px;
box-sizing: border-box;
}
.Cell--bd {
padding-left: 5px;
overflow: hidden;
word-break: break-all;
font-size: 15px;
color: #8e8e90;
}
.Cell--hd {
flex: 1;
display: flex;
align-items: center;
}
.Cell--title {
flex: 1;
font-size: 15px;
color: #333;
}
.Cell--icon {
width: 22px;
height: 22px;
padding-right: 8px;
line-height: 1;
overflow: hidden;
}
.Cell--icon > * {
width: 100%;
height: 100%;
}
.Cell--arrow {
display: block;
width: 10px;
height: 10px;
border-top-color: #ccc;
border-right-color: #ccc;
border-top-style: solid;
border-right-style: solid;
border-top-width: 1px;
border-right-width: 1px;
transform: rotate(45deg);
}
</style>
<template>
<div class="CellBox" @click="handleClick" :class="{'Cell--active': active !== undefined}">
<div class="Cell smart-border-bottom">
<div class="Cell--icon" v-if="hasIcon">
<slot name="icon"></slot>
</div>
<slot name="header">
<div class="Cell--hd" v-if="title">
<span class="Cell--title">{{title}}</span>
</div>
</slot>
<slot name="body">
<div class="Cell--bd">{{content}}</div>
</slot>
<i v-if="hasArrow" class="Cell--arrow"></i>
</div>
</div>
</template>
<script>
export default {
name: 'Cell',
props: {
title: undefined,
content: undefined,
// whether display arrow icon
arrow: undefined,
// navigate to another URL by Router
to: {
type: [String, Object]
},
// active style
active: undefined
},
computed: {
hasIcon() {
return !!this.$slots.icon
},
hasArrow() {
return this.arrow === false ? false
: this.to ? true : typeof this.arrow !== 'undefined'
}
},
methods: {
handleClick() {
if (this.to) {
// is standard URL
if (/^https?\:/.test(this.to)) {
window.location = this.to
}
else {
if (this.$router) {
this.$router.push(this.to)
}
else {
this.$emit('click')
}
}
}
else {
this.$emit('click')
}
}
}
}
</script>