CToolButton.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div
  3. class="button custom-button"
  4. :class="{
  5. active: isActive,
  6. [type]: type,
  7. [className]: className,
  8. 'with-text': forms.includes(toolName)
  9. }"
  10. @click="onClick()"
  11. :title="title"
  12. >
  13. <Highlight v-if="toolName === 'highlight'" />
  14. <Underline v-if="toolName === 'underline'" />
  15. <Strikeout v-if="toolName === 'strikeout'" />
  16. <Squiggle v-if="toolName === 'squiggly'" />
  17. <Ink v-if="toolName === 'ink'" />
  18. <EllipseTool v-if="toolName === 'circle'" />
  19. <RectangleTool v-if="toolName === 'square'" />
  20. <ArrowTool v-if="toolName === 'arrow'" />
  21. <LineTool v-if="toolName === 'line'" />
  22. <Text v-if="toolName === 'freetext'" />
  23. <Stamp v-if="toolName === 'stamp'" />
  24. <Image v-if="toolName === 'image'" />
  25. <Link v-if="toolName === 'link'" />
  26. <template v-if="toolName === 'textfield'">
  27. <TextFieldIcon />
  28. <span>{{ $t('header.textField') }}</span>
  29. </template>
  30. <template v-if="toolName === 'checkbox'">
  31. <CheckBoxIcon />
  32. <span>{{ $t('header.checkbox') }}</span>
  33. </template>
  34. <template v-if="toolName === 'radiobutton'">
  35. <RadioButtonIcon />
  36. <span>{{ $t('header.radioButton') }}</span>
  37. </template>
  38. <template v-if="toolName === 'listbox'">
  39. <ListBoxIcon />
  40. <span>{{ $t('header.listBox') }}</span>
  41. </template>
  42. <template v-if="toolName === 'combobox'">
  43. <ComboBoxIcon />
  44. <span>{{ $t('header.comboButton') }}</span>
  45. </template>
  46. <template v-if="toolName === 'pushbutton'">
  47. <PushButtonIcon />
  48. <span>{{ $t('header.button') }}</span>
  49. </template>
  50. </div>
  51. </template>
  52. <script setup>
  53. import { ref, onMounted, onUnmounted } from 'vue';
  54. import { useViewerStore } from '@/stores/modules/viewer'
  55. import { useDocumentStore } from '@/stores/modules/document'
  56. import { computed } from 'vue'
  57. import core from '@/core'
  58. const useViewer = useViewerStore()
  59. const useDocument = useDocumentStore()
  60. const { item } = defineProps(['item'])
  61. const {
  62. type,
  63. title,
  64. disabled,
  65. className,
  66. toolName
  67. } = item
  68. const markups = ['highlight', 'underline', 'squiggly', 'strikeout']
  69. const shapes = ['square', 'circle', 'arrow', 'line']
  70. const annotations = ['ink', 'freetext', 'stamp', 'image', 'link']
  71. const forms = ['textfield', 'checkbox', 'radiobutton', 'listbox', 'combobox', 'pushbutton']
  72. const toolType = computed(() => {
  73. if (markups.includes(toolName)) return 'markup'
  74. if (shapes.includes(toolName)) return 'shape'
  75. if (annotations.includes(toolName)) return 'annotation'
  76. if (forms.includes(toolName)) return 'form'
  77. })
  78. const activeTool = computed(() => useDocument.getActiveTool)
  79. const isActive = computed(() => {
  80. return toolName === activeTool.value
  81. })
  82. const changeActiveTool = (tool) => {
  83. useDocument.setToolState(tool)
  84. useViewer.toggleActiveHand(false)
  85. core.switchTool(0)
  86. core.switchAnnotationEditorMode(0)
  87. if (tool === 'stamp') {
  88. useViewer.toggleElement('stampPanel')
  89. } else {
  90. useViewer.closeElement('stampPanel')
  91. }
  92. if (activeTool.value === 'image') {
  93. document.getElementById('signImageInput').click()
  94. }
  95. }
  96. const changeMarkupTool = (tool) => {
  97. useDocument.setMarkupToolState(tool)
  98. changeActiveTool(tool)
  99. }
  100. const changeShapeTool = (tool) => {
  101. useDocument.setShapeToolState(tool)
  102. changeActiveTool(tool)
  103. }
  104. const onClick = (() => {
  105. if (markups.includes(toolName)) changeMarkupTool(toolName)
  106. if (shapes.includes(toolName)) changeShapeTool(toolName)
  107. if (annotations.includes(toolName)) changeActiveTool(toolName)
  108. if (forms.includes(toolName)) changeActiveTool(toolName)
  109. })
  110. </script>
  111. <style lang="scss" scoped>
  112. .custom-button {
  113. width: auto;
  114. }
  115. </style>