ImagePreview.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <!-- <base-dialog
  3. v-if="showDialog"
  4. v-model="visible"
  5. less
  6. title="试卷预览"
  7. :can-resize="resizeKey ? resizeKey : 'can-resize2'"
  8. :modal="false"
  9. class="preview-dialog"
  10. modal-class="no-mask preview-clear-mask"
  11. >
  12. <div class="preview-content" :class="{ 'is-big': isBig }">
  13. <img v-show="!!url" class="small-img" :src="url" alt="" />
  14. </div>
  15. </base-dialog> -->
  16. <div
  17. v-if="visible"
  18. v-customDialogResizeImg="resizeKey ? resizeKey : 'can-resize2'"
  19. class="preview-custom-dialog"
  20. :class="[resizeKey ? resizeKey : 'can-resize2']"
  21. >
  22. <div class="preview-head">
  23. <span>试卷预览</span>
  24. <div class="head-btn-box flex justify-center items-center" @click="closeDialog">
  25. <el-icon><close /></el-icon>
  26. </div>
  27. </div>
  28. <div class="preview-body">
  29. <img v-show="!!url" class="small-img" :src="url" alt="" />
  30. </div>
  31. <!-- <div class="preview-foot"></div> -->
  32. </div>
  33. </template>
  34. <script setup lang="ts" name="ImagePreview">
  35. // import BaseDialog from '../element/BaseDialog.vue'
  36. import useVModel from '@/hooks/useVModel'
  37. import { ref, watch } from 'vue'
  38. import { Close } from '@element-plus/icons-vue'
  39. import { ElIcon } from 'element-plus'
  40. const showDialog = ref(true)
  41. const props = defineProps<{
  42. modelValue: boolean
  43. url?: string
  44. isBig?: boolean
  45. resizeKey?: string
  46. }>()
  47. const visible = useVModel(props)
  48. const closeDialog = () => {
  49. visible.value = false
  50. }
  51. watch(
  52. () => props.url,
  53. () => {
  54. showDialog.value = false
  55. setTimeout(() => {
  56. showDialog.value = true
  57. }, 1)
  58. }
  59. )
  60. </script>
  61. <style scoped lang="scss">
  62. .preview-custom-dialog {
  63. display: flex;
  64. flex-direction: column;
  65. position: fixed;
  66. z-index: 500;
  67. border-radius: 6px;
  68. box-shadow: 0px 12px 32px 4px rgba(0, 0, 0, 0.04), 0px 8px 20px rgba(0, 0, 0, 0.08);
  69. .preview-head {
  70. background-color: #f8f8f8;
  71. border-radius: 6px 6px 0 0;
  72. color: #333;
  73. font-size: 14px;
  74. height: 44px;
  75. line-height: 44px;
  76. padding: 0 10px;
  77. position: relative;
  78. .head-btn-box {
  79. position: absolute;
  80. right: 0;
  81. top: 0;
  82. width: 44px;
  83. height: 44px;
  84. z-index: 1;
  85. cursor: pointer;
  86. &:hover {
  87. :deep(i) {
  88. color: $color--primary;
  89. }
  90. }
  91. }
  92. }
  93. .preview-body {
  94. flex: 1;
  95. padding: 2px;
  96. overflow: auto;
  97. img {
  98. width: 100%;
  99. height: auto;
  100. }
  101. }
  102. }
  103. </style>