index.vue
2.03 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
<template>
<div class="full-container">
<el-tooltip placement="top" v-if="hoverStatus">
<div slot="content">
<template v-if="$slots.default && content">{{ content }}</template>
<template v-else-if="$slots.default && !content"><slot></slot></template>
<template v-else>
{{ content ? content : label }}
</template>
</div>
<div :class="[line ? 'full-text-line' : 'full-text']" :style="{ width: labelWidth + 'px', '-webkit-line-clamp': line }">
<template v-if="$slots.default"><slot></slot></template>
<template v-else>
{{ label }}
</template>
</div>
</el-tooltip>
<div :class="[line ? 'full-text-line' : 'full-text', identification]" v-else @mouseenter="hoverFun" :style="{ width: labelWidth + 'px', '-webkit-line-clamp': line }">
<template v-if="$slots.default"><slot></slot></template>
<template v-else>
{{ label }}
</template>
</div>
</div>
</template>
<script>
export default {
name: 'GLFull',
data() {
return {
hoverStatus: false
}
},
props: {
identification: {
type: String,
default: ''
},
label: {
type: String,
default: ''
},
content: {
type: String,
default: ''
},
labelWidth: {
type: Number,
default: 100
},
line: {
type: Number,
default: 0
}
},
methods: {
hoverFun() {
console.log(document.querySelector(`.full-text`).scrollWidth)
this.hoverStatus = this.identification ? document.querySelector(`.${this.identification}`).scrollWidth > this.labelWidth : document.querySelector(`.full-text`).scrollWidth > this.labelWidth
}
}
}
</script>
<style scoped lang="scss">
.full-container {
display: inline-block;
}
.full-text {
display: inline-block;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.full-text-line {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
word-break: break-all;
}
</style>