Files
JayuCloud/YumiNail-Frontend/src/components/TableEllipsisText.vue
T

75 lines
1.7 KiB
Vue
Raw Normal View History

<template>
<span v-if="!displayText" class="empty-text">{{ emptyText }}</span>
<a-tooltip v-else :title="displayText" placement="topLeft">
<div class="ellipsis-text" :class="lineClass">
{{ displayText }}
</div>
</a-tooltip>
</template>
<script setup lang="ts">
/**
* TableEllipsisText page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed } from 'vue'
2026-05-23 18:44:57 +08:00
/**
* Purpose: props supports TableEllipsisText.vue by holding or executing the props page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const props = withDefaults(defineProps<{
text?: string | number | null
lines?: 1 | 2 | 3
emptyText?: string
}>(), {
lines: 1,
emptyText: '--'
})
/** displayText is a reactive state variable used by the template and event handlers. */
const displayText = computed(() => {
if (props.text === undefined || props.text === null) {
return ''
}
const value = String(props.text).trim()
return value
})
/** lineClass is a reactive state variable used by the template and event handlers. */
const lineClass = computed(() => {
return props.lines > 1 ? `lines-${props.lines}` : ''
})
</script>
<style scoped>
.ellipsis-text {
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
word-break: break-all;
line-height: 1.5;
}
.lines-2,
.lines-3 {
display: -webkit-box;
-webkit-box-orient: vertical;
white-space: normal;
word-break: break-word;
}
.lines-2 {
-webkit-line-clamp: 2;
}
.lines-3 {
-webkit-line-clamp: 3;
}
.empty-text {
color: #bfbfbf;
}
</style>