123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- <template>
- <!-- 富文本详情弹窗 -->
- <el-dialog
- v-model="dialogVisible"
- title="数据详情"
- width="80%"
- class="rich-content-dialog"
- :before-close="handleClose"
- @opened="onOpened"
- >
- <!-- 弹窗内容区 -->
- <div class="content-wrapper" ref="contentWrapper">
- <div
- v-loading="loading"
- element-loading-text="加载中..."
- class="content-container"
- >
- <!-- 富文本内容展示区 -->
- <div
- v-if="content"
- class="rich-content-display"
- v-html="content"
- ></div>
-
- <!-- 空状态 -->
- <el-empty v-else description="暂无内容" />
- </div>
- </div>
-
- <!-- 底部信息栏 -->
- <template #footer>
- <div class="dialog-footer-info">
- <span v-if="createTime" class="create-time">
- 创建时间: {{ formatTime(createTime) }}
- </span>
- <span v-if="updateTime" class="update-time">
- 更新时间: {{ formatTime(updateTime) }}
- </span>
- </div>
- </template>
- </el-dialog>
- </template>
- <script lang="ts" setup>
- import { ref } from 'vue'
- // 弹窗可见性
- const dialogVisible = ref(false)
- // 加载状态
- const loading = ref(false)
- // 富文本内容
- const content = ref('')
- // 创建时间
- const createTime = ref<string | Date | null>(null)
- // 更新时间
- const updateTime = ref<string | Date | null>(null)
- // 内容容器引用
- const contentWrapper = ref<HTMLElement | null>(null)
- // 打开弹窗方法
- const openDialog = (
- richContent: string,
- options?: {
- createTime?: string | Date,
- updateTime?: string | Date
- }
- ) => {
- dialogVisible.value = true
- loading.value = true
-
- // 设置内容和时间信息
- content.value = richContent
- createTime.value = options?.createTime || null
- updateTime.value = options?.updateTime || null
-
- // 模拟加载延迟
- setTimeout(() => {
- loading.value = false
- }, 300)
- }
- // 弹窗打开后的回调
- const onOpened = () => {
- // 可以在这里处理弹窗打开后的逻辑,如聚焦等
- if (contentWrapper.value) {
- // 滚动到顶部
- contentWrapper.value.scrollTop = 0
- }
- }
- // 格式化时间
- const formatTime = (time: string | Date | null) => {
- if (!time) return '--'
- const date = new Date(time)
- return date.toLocaleString('zh-CN')
- }
- // 关闭前的处理
- const handleClose = () => {
- dialogVisible.value = false
- }
- // 暴露方法给父组件
- defineExpose({
- openDialog
- })
- </script>
- <style scoped lang="scss">
- .rich-content-dialog {
- height: 80vh;
-
- :deep(.el-dialog__body) {
- padding: 0;
- height: calc(80vh - 120px);
- }
-
- :deep(.el-dialog__header) {
- padding: 20px 20px 10px;
- border-bottom: 1px solid #eee;
- }
- }
- .content-wrapper {
- height: 100%;
- overflow: hidden;
- position: relative;
- }
- .content-container {
- height: 100%;
- overflow-y: auto;
- padding: 20px;
-
- // 自定义滚动条样式
- &::-webkit-scrollbar {
- width: 6px;
- }
-
- &::-webkit-scrollbar-thumb {
- background-color: #c1c1c1;
- border-radius: 3px;
- }
-
- &::-webkit-scrollbar-track {
- background-color: #f1f1f1;
- }
- }
- .rich-content-display {
- min-height: 100%;
-
- // 通用富文本样式
- :deep(img) {
- max-width: 100%;
- height: auto;
- border-radius: 4px;
- }
-
- :deep(h1),
- :deep(h2),
- :deep(h3),
- :deep(h4),
- :deep(h5),
- :deep(h6) {
- margin: 20px 0 10px 0;
- color: #333;
- font-weight: 600;
- }
-
- :deep(h1) {
- font-size: 24px;
- border-bottom: 1px solid #eee;
- padding-bottom: 10px;
- }
-
- :deep(h2) {
- font-size: 22px;
- }
-
- :deep(h3) {
- font-size: 20px;
- }
-
- :deep(h4) {
- font-size: 18px;
- }
-
- :deep(p) {
- margin: 10px 0;
- line-height: 1.8;
- color: #555;
- font-size: 14px;
- }
-
- :deep(ul),
- :deep(ol) {
- padding-left: 20px;
- margin: 10px 0;
- }
-
- :deep(li) {
- margin: 5px 0;
- line-height: 1.6;
- }
-
- :deep(strong) {
- font-weight: 600;
- }
-
- :deep(em) {
- font-style: italic;
- }
-
- :deep(a) {
- color: #409eff;
- text-decoration: none;
-
- &:hover {
- text-decoration: underline;
- }
- }
-
- :deep(blockquote) {
- margin: 15px 0;
- padding: 10px 15px;
- border-left: 4px solid #409eff;
- background-color: #f5f8ff;
- color: #666;
- }
-
- :deep(code) {
- background-color: #f5f5f5;
- padding: 2px 5px;
- border-radius: 3px;
- font-family: monospace;
- font-size: 13px;
- }
-
- :deep(pre) {
- background-color: #2d2d2d;
- color: #f8f8f2;
- padding: 15px;
- border-radius: 5px;
- overflow-x: auto;
- margin: 15px 0;
- font-size: 13px;
- line-height: 1.5;
- }
-
- :deep(table) {
- width: 100%;
- border-collapse: collapse;
- margin: 15px 0;
- }
-
- :deep(th),
- :deep(td) {
- border: 1px solid #ddd;
- padding: 8px 12px;
- text-align: left;
- }
-
- :deep(th) {
- background-color: #f8f9fa;
- font-weight: 600;
- }
-
- :deep(tr:nth-child(even)) {
- background-color: #f9f9f9;
- }
- }
- .dialog-footer-info {
- display: flex;
- justify-content: space-between;
- padding: 10px 0;
- border-top: 1px solid #eee;
- font-size: 12px;
- color: #999;
-
- .create-time,
- .update-time {
- display: inline-block;
- }
- }
- // 响应式设计
- @media (max-width: 768px) {
- .rich-content-dialog {
- width: 95%;
- height: 90vh;
-
- :deep(.el-dialog__body) {
- height: calc(90vh - 120px);
- }
- }
-
- .dialog-footer-info {
- flex-direction: column;
- gap: 5px;
- align-items: flex-start;
- }
- }
- </style>
|