signatureTest.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="signature-container">
  3. <h3>电子签名测试</h3>
  4. <div class="demo-section">
  5. <h4>基础用法</h4>
  6. <SignaturePad
  7. v-model:value="signatureImage"
  8. height="250px"
  9. @save="handleSave"
  10. @clear="handleClear"
  11. />
  12. </div>
  13. <div class="demo-section">
  14. <h4>自定义样式</h4>
  15. <SignaturePad
  16. v-model:value="customSignature"
  17. height="200px"
  18. :line-width="3"
  19. line-color="#2196F3"
  20. background-color="#f5f5f5"
  21. clear-btn-text="重置"
  22. save-btn-text="确认"
  23. />
  24. </div>
  25. <div class="demo-section">
  26. <h4>无控制按钮</h4>
  27. <SignaturePad
  28. ref="noControlsPad"
  29. v-model:value="noControlsSignature"
  30. height="150px"
  31. :show-controls="false"
  32. />
  33. <div class="custom-controls">
  34. <button class="action-btn clear-btn" @click="clearNoControls">清除</button>
  35. <button class="action-btn save-btn" @click="saveNoControls">保存</button>
  36. </div>
  37. </div>
  38. <div v-if="signatureImage" class="result-section">
  39. <h4>签名结果</h4>
  40. <p>签名已保存为Base64格式,长度为: {{ signatureImage.length }}</p>
  41. <div class="preview">
  42. <img :src="signatureImage" alt="签名预览" />
  43. </div>
  44. </div>
  45. </div>
  46. </template>
  47. <script setup lang="ts">
  48. import { ref, onMounted } from 'vue';
  49. import SignaturePad from '@/components/SignaturePad.vue';
  50. defineOptions({
  51. name: 'SignatureTest',
  52. });
  53. // 签名数据
  54. const signatureImage = ref<string>('');
  55. const customSignature = ref<string>('');
  56. const noControlsSignature = ref<string>('');
  57. // 无控制按钮的签名板引用
  58. const noControlsPad = ref<InstanceType<typeof SignaturePad> | null>(null);
  59. // 处理保存事件
  60. const handleSave = (dataUrl: string) => {
  61. console.log('签名已保存,长度为:', dataUrl.length);
  62. };
  63. // 处理清除事件
  64. const handleClear = () => {
  65. console.log('签名已清除');
  66. };
  67. // 清除无控制按钮的签名
  68. const clearNoControls = () => {
  69. noControlsPad.value?.clear();
  70. };
  71. // 保存无控制按钮的签名
  72. const saveNoControls = () => {
  73. noControlsPad.value?.save();
  74. };
  75. onMounted(() => {
  76. console.log('SignatureTest mounted');
  77. });
  78. </script>
  79. <style scoped>
  80. .signature-container {
  81. max-width: 800px;
  82. margin: 0 auto;
  83. padding: 20px;
  84. }
  85. .demo-section {
  86. margin-bottom: 30px;
  87. }
  88. h4 {
  89. margin-bottom: 10px;
  90. color: #333;
  91. }
  92. .custom-controls {
  93. display: flex;
  94. gap: 10px;
  95. margin-top: 10px;
  96. }
  97. .action-btn {
  98. padding: 8px 16px;
  99. border: none;
  100. border-radius: 4px;
  101. cursor: pointer;
  102. font-size: 14px;
  103. color: white;
  104. }
  105. .clear-btn {
  106. background-color: #f44336;
  107. }
  108. .clear-btn:hover {
  109. background-color: #d32f2f;
  110. }
  111. .save-btn {
  112. background-color: #4CAF50;
  113. }
  114. .save-btn:hover {
  115. background-color: #45a049;
  116. }
  117. .result-section {
  118. margin-top: 30px;
  119. border-top: 1px solid #eee;
  120. padding-top: 20px;
  121. }
  122. .preview {
  123. margin-top: 10px;
  124. max-width: 300px;
  125. max-height: 300px;
  126. overflow: hidden;
  127. border: 1px solid #ddd;
  128. border-radius: 4px;
  129. }
  130. .preview img {
  131. width: 100%;
  132. height: auto;
  133. }
  134. </style>