|
|
@@ -0,0 +1,68 @@
|
|
|
+<template>
|
|
|
+ <span ref="textRef" class="ellipsis-container">
|
|
|
+ <span class="ellipsis-text" :style="{ lineClamp: lines }">{{ text }}</span>
|
|
|
+ <a-tooltip v-if="isEllipsis" :title="text">
|
|
|
+ <span class="ellipsis-trigger">{{ text }}</span>
|
|
|
+ </a-tooltip>
|
|
|
+ </span>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { ref, onMounted, nextTick, watch } from 'vue';
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ text: {
|
|
|
+ type: String,
|
|
|
+ required: true
|
|
|
+ },
|
|
|
+ lines: {
|
|
|
+ type: [Number, String],
|
|
|
+ default: 1
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+const textRef = ref(null);
|
|
|
+const isEllipsis = ref(false);
|
|
|
+
|
|
|
+const checkEllipsis = () => {
|
|
|
+ if (!textRef.value) return;
|
|
|
+
|
|
|
+ const textElement = textRef.value.querySelector('.ellipsis-text');
|
|
|
+
|
|
|
+ isEllipsis.value = textElement.scrollHeight > textElement.clientHeight;
|
|
|
+};
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ nextTick(checkEllipsis);
|
|
|
+});
|
|
|
+
|
|
|
+watch(() => props.text, () => {
|
|
|
+ nextTick(checkEllipsis);
|
|
|
+});
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.ellipsis-container {
|
|
|
+ position: relative;
|
|
|
+ display: inline-block;
|
|
|
+ max-width: 100%;
|
|
|
+}
|
|
|
+
|
|
|
+.ellipsis-text {
|
|
|
+ display: -webkit-box;
|
|
|
+ -webkit-box-orient: vertical;
|
|
|
+ overflow: hidden;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ max-width: 100%;
|
|
|
+}
|
|
|
+
|
|
|
+.ellipsis-trigger {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ opacity: 0;
|
|
|
+ cursor: pointer;
|
|
|
+}
|
|
|
+</style>
|