index.vue
3.9 KB
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
<template>
<div class="content-wrap">
<!-- <el-date-picker class="rqxzDatePicker" v-model="dwqdDate" type="date" @change="changeDwqdTime" value-format="yyyy-MM-dd" placeholder="选择日期" :picker-options="pickerDwqdOptions"></el-date-picker> -->
<el-date-picker v-model="timeData" type="daterange" size="mini" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" class="data-pick" unlink-panels></el-date-picker>
<div :class="['content', expande ? 'expande' : 'close']" ref="content">思路:1、判断当前内容是否超过三行。此处可以给每行设置一个行高line-height,渲染完后超过三倍的行高即认为是内容超过了三行。2、展示/收起状态的切换可以通过data中的参数来绑定。3、在底部使用position:absolute来绝对定位展开该在的位置。4、根据业务需求来设定好展开和收起按钮需要呆的地方。</div>
<div class="expande-button-wrap" v-if="needShowExpande">
<div class="expande-button" @click="expandeClick" v-if="!expande">
<span style="color: black">...</span>
展开
</div>
<div class="expande-button" @click="expandeClick" v-else>收起</div>
</div>
</div>
</template>
<script>
export default {
name: 'App',
data() {
return {
expande: false,
needShowExpande: true,
timeData: []
}
},
created() {
// let date = new Date()
// let y = date.getFullYear()
// let m = date.getMonth() + 1
// m = m < 10 ? '0' + m : m
// let d = date.getDate()
// d = d < 10 ? '0' + d : d
// const time = y + '-' + m + '-' + d
// this.dwqdDate = time
},
methods: {
expandeClick() {
this.expande = !this.expande
},
/* 获取过去时间,并传值给现在时间 */
getPassYearFormatDate() {
var nowDate = new Date()
var date = new Date(nowDate)
date.setDate(date.getDate() - 30)
var seperator1 = '-'
var year = date.getFullYear()
var month = date.getMonth() + 1
var strDate = date.getDate()
if (month >= 1 && month <= 9) {
month = '0' + month
}
if (strDate >= 0 && strDate <= 9) {
strDate = '0' + strDate
}
var formatDate = year + seperator1 + month + seperator1 + strDate
this.getNowFormatDate(formatDate)
},
/* 获取现在时间,并接受过去时间的值 */
getNowFormatDate(formatDate) {
var date = new Date()
var seperator1 = '-'
var year = date.getFullYear()
var month = date.getMonth() + 1
var strDate = date.getDate()
if (month >= 1 && month <= 9) {
month = '0' + month
}
if (strDate >= 0 && strDate <= 9) {
strDate = '0' + strDate
}
var nowData = year + seperator1 + month + seperator1 + strDate
this.timeData = [formatDate, nowData] // 默认赋值一年时间
}
},
mounted() {
this.getPassYearFormatDate()
this.$nextTick(() => {
let lineHeight = 22
if (this.$refs.content.offsetHeight > lineHeight * 3) {
this.expande = false
this.needShowExpande = true
} else {
this.expande = true
}
})
}
}
</script>
<style>
.content-wrap {
width: 300px;
height: 200px;
position: relative;
}
.content {
font-size: 14px;
color: black;
letter-spacing: 0;
line-height: 22px;
text-align: justify;
overflow: hidden;
/* display: -webkit-box; */
/* -webkit-line-clamp: 3;
-webkit-box-orient: vertical; */
/* text-overflow: ellipsis; */
}
.expande {
overflow: auto;
height: auto;
padding-bottom: 22px;
}
.close {
overflow: hidden;
height: 66px;
padding-bottom: 0;
}
.expande-button-wrap {
position: absolute;
bottom: 0;
right: 0;
height: 22px;
background: white;
}
.expande-button {
text-align: right;
vertical-align: middle;
color: #5995ef;
font-size: 14px;
line-height: 22px;
}
</style>