dataInfoModal.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <!-- 富文本详情弹窗 -->
  3. <el-dialog
  4. v-model="dialogVisible"
  5. title="数据详情"
  6. width="80%"
  7. class="rich-content-dialog"
  8. :before-close="handleClose"
  9. @opened="onOpened"
  10. >
  11. <!-- 弹窗内容区 -->
  12. <div class="content-wrapper" ref="contentWrapper">
  13. <div
  14. v-loading="loading"
  15. element-loading-text="加载中..."
  16. class="content-container"
  17. >
  18. <!-- 富文本内容展示区 -->
  19. <div
  20. v-if="content"
  21. class="rich-content-display"
  22. v-html="content"
  23. ></div>
  24. <!-- 空状态 -->
  25. <el-empty v-else description="暂无内容" />
  26. </div>
  27. </div>
  28. <!-- 底部信息栏 -->
  29. <template #footer>
  30. <div class="dialog-footer-info">
  31. <span v-if="createTime" class="create-time">
  32. 创建时间: {{ formatTime(createTime) }}
  33. </span>
  34. <span v-if="updateTime" class="update-time">
  35. 更新时间: {{ formatTime(updateTime) }}
  36. </span>
  37. </div>
  38. </template>
  39. </el-dialog>
  40. </template>
  41. <script lang="ts" setup>
  42. import { ref } from 'vue'
  43. // 弹窗可见性
  44. const dialogVisible = ref(false)
  45. // 加载状态
  46. const loading = ref(false)
  47. // 富文本内容
  48. const content = ref('')
  49. // 创建时间
  50. const createTime = ref<string | Date | null>(null)
  51. // 更新时间
  52. const updateTime = ref<string | Date | null>(null)
  53. // 内容容器引用
  54. const contentWrapper = ref<HTMLElement | null>(null)
  55. // 打开弹窗方法
  56. const openDialog = (
  57. richContent: string,
  58. options?: {
  59. createTime?: string | Date,
  60. updateTime?: string | Date
  61. }
  62. ) => {
  63. dialogVisible.value = true
  64. loading.value = true
  65. // 设置内容和时间信息
  66. content.value = richContent
  67. createTime.value = options?.createTime || null
  68. updateTime.value = options?.updateTime || null
  69. // 模拟加载延迟
  70. setTimeout(() => {
  71. loading.value = false
  72. }, 300)
  73. }
  74. // 弹窗打开后的回调
  75. const onOpened = () => {
  76. // 可以在这里处理弹窗打开后的逻辑,如聚焦等
  77. if (contentWrapper.value) {
  78. // 滚动到顶部
  79. contentWrapper.value.scrollTop = 0
  80. }
  81. }
  82. // 格式化时间
  83. const formatTime = (time: string | Date | null) => {
  84. if (!time) return '--'
  85. const date = new Date(time)
  86. return date.toLocaleString('zh-CN')
  87. }
  88. // 关闭前的处理
  89. const handleClose = () => {
  90. dialogVisible.value = false
  91. }
  92. // 暴露方法给父组件
  93. defineExpose({
  94. openDialog
  95. })
  96. </script>
  97. <style scoped lang="scss">
  98. .rich-content-dialog {
  99. height: 80vh;
  100. :deep(.el-dialog__body) {
  101. padding: 0;
  102. height: calc(80vh - 120px);
  103. }
  104. :deep(.el-dialog__header) {
  105. padding: 20px 20px 10px;
  106. border-bottom: 1px solid #eee;
  107. }
  108. }
  109. .content-wrapper {
  110. height: 100%;
  111. overflow: hidden;
  112. position: relative;
  113. }
  114. .content-container {
  115. height: 100%;
  116. overflow-y: auto;
  117. padding: 20px;
  118. // 自定义滚动条样式
  119. &::-webkit-scrollbar {
  120. width: 6px;
  121. }
  122. &::-webkit-scrollbar-thumb {
  123. background-color: #c1c1c1;
  124. border-radius: 3px;
  125. }
  126. &::-webkit-scrollbar-track {
  127. background-color: #f1f1f1;
  128. }
  129. }
  130. .rich-content-display {
  131. min-height: 100%;
  132. // 通用富文本样式
  133. :deep(img) {
  134. max-width: 100%;
  135. height: auto;
  136. border-radius: 4px;
  137. }
  138. :deep(h1),
  139. :deep(h2),
  140. :deep(h3),
  141. :deep(h4),
  142. :deep(h5),
  143. :deep(h6) {
  144. margin: 20px 0 10px 0;
  145. color: #333;
  146. font-weight: 600;
  147. }
  148. :deep(h1) {
  149. font-size: 24px;
  150. border-bottom: 1px solid #eee;
  151. padding-bottom: 10px;
  152. }
  153. :deep(h2) {
  154. font-size: 22px;
  155. }
  156. :deep(h3) {
  157. font-size: 20px;
  158. }
  159. :deep(h4) {
  160. font-size: 18px;
  161. }
  162. :deep(p) {
  163. margin: 10px 0;
  164. line-height: 1.8;
  165. color: #555;
  166. font-size: 14px;
  167. }
  168. :deep(ul),
  169. :deep(ol) {
  170. padding-left: 20px;
  171. margin: 10px 0;
  172. }
  173. :deep(li) {
  174. margin: 5px 0;
  175. line-height: 1.6;
  176. }
  177. :deep(strong) {
  178. font-weight: 600;
  179. }
  180. :deep(em) {
  181. font-style: italic;
  182. }
  183. :deep(a) {
  184. color: #409eff;
  185. text-decoration: none;
  186. &:hover {
  187. text-decoration: underline;
  188. }
  189. }
  190. :deep(blockquote) {
  191. margin: 15px 0;
  192. padding: 10px 15px;
  193. border-left: 4px solid #409eff;
  194. background-color: #f5f8ff;
  195. color: #666;
  196. }
  197. :deep(code) {
  198. background-color: #f5f5f5;
  199. padding: 2px 5px;
  200. border-radius: 3px;
  201. font-family: monospace;
  202. font-size: 13px;
  203. }
  204. :deep(pre) {
  205. background-color: #2d2d2d;
  206. color: #f8f8f2;
  207. padding: 15px;
  208. border-radius: 5px;
  209. overflow-x: auto;
  210. margin: 15px 0;
  211. font-size: 13px;
  212. line-height: 1.5;
  213. }
  214. :deep(table) {
  215. width: 100%;
  216. border-collapse: collapse;
  217. margin: 15px 0;
  218. }
  219. :deep(th),
  220. :deep(td) {
  221. border: 1px solid #ddd;
  222. padding: 8px 12px;
  223. text-align: left;
  224. }
  225. :deep(th) {
  226. background-color: #f8f9fa;
  227. font-weight: 600;
  228. }
  229. :deep(tr:nth-child(even)) {
  230. background-color: #f9f9f9;
  231. }
  232. }
  233. .dialog-footer-info {
  234. display: flex;
  235. justify-content: space-between;
  236. padding: 10px 0;
  237. border-top: 1px solid #eee;
  238. font-size: 12px;
  239. color: #999;
  240. .create-time,
  241. .update-time {
  242. display: inline-block;
  243. }
  244. }
  245. // 响应式设计
  246. @media (max-width: 768px) {
  247. .rich-content-dialog {
  248. width: 95%;
  249. height: 90vh;
  250. :deep(.el-dialog__body) {
  251. height: calc(90vh - 120px);
  252. }
  253. }
  254. .dialog-footer-info {
  255. flex-direction: column;
  256. gap: 5px;
  257. align-items: flex-start;
  258. }
  259. }
  260. </style>