ImageModify.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="flex direction-column full">
  3. <mark-header :exclude-operations="['delete', 'bookmark']" @click="onOperationClick"> </mark-header>
  4. <div class="flex-1 overflow-hidden p-base mark-container">
  5. <div
  6. class="p-base radius-base full fill-blank scroll-auto mark-content"
  7. :class="{ 'text-center': center }"
  8. :style="{ 'background-color': backgroundColor }"
  9. >
  10. <span class="preview" @click="onPreview">
  11. <svg-icon name="preview"></svg-icon>
  12. </span>
  13. <img :src="dataUrl" alt="" class="paper-img" :style="{ 'background-color': frontColor }" />
  14. </div>
  15. </div>
  16. </div>
  17. <image-preview v-model="previewModalVisible" :url="MockImg"></image-preview>
  18. </template>
  19. <script setup lang="ts" name="ImageModify">
  20. import { computed, ref } from 'vue'
  21. import { useSetImgBg } from '@/hooks/useSetImgBg'
  22. import useMarkHeader from '@/hooks/useMarkHeader'
  23. import MarkHeader from '@/components/shared/MarkHeader.vue'
  24. import ImagePreview from '@/components/shared/ImagePreview.vue'
  25. import SvgIcon from '@/components/common/SvgIcon.vue'
  26. import MockImg from '@/assets/mock/SAMPA-1.jpg'
  27. import type { SetImgBgOption } from '@/hooks/useSetImgBg'
  28. import type { MarkHeaderInstance } from 'global-type'
  29. /** 图片预览 */
  30. const previewModalVisible = ref<boolean>(false)
  31. const {
  32. rotate,
  33. scale,
  34. center,
  35. frontColor,
  36. backgroundColor,
  37. onBack,
  38. onScaleChange,
  39. onCenter,
  40. onRotate,
  41. setBackgroundColor,
  42. setFrontColor,
  43. onViewSample,
  44. onViewStandard,
  45. } = useMarkHeader()
  46. /** 预览试卷 */
  47. const onPreview = () => {
  48. previewModalVisible.value = true
  49. }
  50. type OperationClick = MarkHeaderInstance['onClick']
  51. type OperationType = Parameters<Exclude<OperationClick, undefined>>[0]['type']
  52. const operationHandles: Partial<Record<OperationType, (...args: any) => void>> = {
  53. back: onBack,
  54. 'scale-change': onScaleChange,
  55. center: onCenter,
  56. rotate: onRotate,
  57. 'front-color': setFrontColor,
  58. 'background-color': setBackgroundColor,
  59. example: onViewSample,
  60. standard: onViewStandard,
  61. }
  62. const onOperationClick: OperationClick = ({ type, value }) => {
  63. operationHandles[type]?.(value)
  64. }
  65. const imgOption = computed<SetImgBgOption>(() => {
  66. return {
  67. image: MockImg,
  68. rotate: rotate.value,
  69. scale: scale.value,
  70. }
  71. })
  72. const { drawing, dataUrl } = useSetImgBg(imgOption)
  73. </script>
  74. <style scoped lang="scss">
  75. .canvas {
  76. // width: 400px;
  77. // height: 400px;
  78. }
  79. .image {
  80. width: 400px;
  81. // height: 400px;
  82. img {
  83. max-width: 100%;
  84. max-height: 100%;
  85. object-fit: contain;
  86. }
  87. }
  88. </style>