DigitalSignCreatePanel.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <Dialog class="digital-signature-dialog trackpad" :show="true" :dialogName="dialogName">
  3. <template #header>
  4. <CloseB class="close" @click="close" />
  5. </template>
  6. <div class="paint-container" ref="paintContainer">
  7. <canvas id="digitalTrackpadCanvas" :width="canvasWidth" :height="canvasHeight"></canvas>
  8. </div>
  9. <template #footer>
  10. <div class="rect-button white" @click="clear">{{ $t('signatures.clear') }}</div>
  11. <div class="rect-button white" @click="close">{{ $t('cancel') }}</div>
  12. <div class="rect-button blue" @click="save">{{ $t('ok') }}</div>
  13. </template>
  14. </Dialog>
  15. </template>
  16. <script setup>
  17. import { computed, watch, ref, nextTick } from 'vue'
  18. import { useViewerStore } from '@/stores/modules/viewer'
  19. import { useDocumentStore } from '@/stores/modules/document'
  20. import core from '@/core'
  21. import { isMobile } from '@/helpers/device'
  22. const emits = defineEmits(['modifyImage'])
  23. const dialogName = 'digitalSignCreatePanel'
  24. const useViewer = useViewerStore()
  25. const useDocument = useDocumentStore()
  26. const show = computed(() => useViewer.isElementOpen(dialogName))
  27. const canvasWidth = ref(578)
  28. const canvasHeight = ref(isMobile ? 0 : 270)
  29. const paintContainer = ref()
  30. watch(() => show.value, (newValue, oldValue) => {
  31. if (newValue) {
  32. if (isMobile) {
  33. nextTick(() => {
  34. const { clientWidth, clientHeight } = paintContainer.value
  35. clientWidth && canvasWidth.value !== clientWidth && (canvasWidth.value = clientWidth)
  36. clientHeight && canvasHeight.value !== clientHeight && (canvasHeight.value = clientHeight)
  37. })
  38. }
  39. }
  40. })
  41. const close = () => {
  42. useViewer.closeElement(dialogName)
  43. clear()
  44. }
  45. const clear = () => {
  46. core.handleSign({
  47. flag: 'clear'
  48. })
  49. }
  50. const save = () => {
  51. const imageBase64 = core.handleSign({
  52. type: 1,
  53. flag: 'image',
  54. })
  55. emits('modifyImage', imageBase64)
  56. close()
  57. }
  58. </script>
  59. <style lang="scss">
  60. .digital-signature-dialog {
  61. .dialog-container {
  62. padding: 16px 24px;
  63. main {
  64. margin-top: 40px;
  65. margin-bottom: 12px;
  66. }
  67. footer {
  68. .rect-button.white {
  69. border-radius: 2px;
  70. }
  71. .rect-button:first-child {
  72. margin-right: auto;
  73. }
  74. }
  75. }
  76. .paint-container {
  77. position: relative;
  78. display: flex;
  79. justify-content: center;
  80. align-items: center;
  81. height: 270px;
  82. background-color: #F2F3F5;
  83. canvas {
  84. z-index: 1;
  85. }
  86. p {
  87. position: absolute;
  88. font-size: 14px;
  89. line-height: 16px;
  90. color: #757780;
  91. pointer-events: none;
  92. }
  93. }
  94. }
  95. @media screen and (max-width: 640px) {
  96. .digital-signature-dialog.trackpad {
  97. .dialog-container {
  98. display: flex;
  99. flex-direction: column;
  100. width: 90vh;
  101. height: 90vw;
  102. transform: rotate(90deg);
  103. -ms-transform: rotate(90deg);
  104. -moz-transform: rotate(90deg);
  105. -webkit-transform: rotate(90deg);
  106. -o-transform: rotate(90deg);
  107. main {
  108. flex: 1;
  109. .paint-container {
  110. width: 100%;
  111. height: 100%;
  112. }
  113. }
  114. }
  115. }
  116. }
  117. </style>