WriteBasePreview.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="write-base-preview" :style="getAreaStyle()">
  4. <SerialNumberPosition v-if="isEnable(data.property.sn_display_mode)" :property="data.property" />
  5. <div v-if="width" class="main">
  6. <h2>书写区</h2>
  7. <div class="esign-box">
  8. <vue-esign
  9. ref="esign"
  10. class="esign-canvas"
  11. :width="width"
  12. :height="150"
  13. :is-crop="isCrop"
  14. :line-width="lineWidth"
  15. :line-color="lineColor"
  16. :bg-color.sync="bgColor"
  17. />
  18. <div class="btn-box">
  19. <SvgIcon icon-class="clear" size="24" title="清除" @click="handleReset" />
  20. <SvgIcon icon-class="camera" size="24" title="保存" @click="handleGenerate" />
  21. </div>
  22. </div>
  23. <template v-if="data.write_base64[0]">
  24. <h2>展示区</h2>
  25. <img style="background-color: #f7f8fa" :src="data.write_base64[0]" alt="write-show" />
  26. </template>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import { getWriteBaseData } from '@/views/book/courseware/data/writeBase';
  32. import PreviewMixin from '../common/PreviewMixin';
  33. import vueEsign from 'vue-esign';
  34. export default {
  35. name: 'WriteBasePreview',
  36. components: { vueEsign },
  37. mixins: [PreviewMixin],
  38. data() {
  39. return {
  40. data: getWriteBaseData(),
  41. lineWidth: 2,
  42. lineColor: '#000000',
  43. bgColor: '#f7f8fa',
  44. isCrop: false,
  45. width: 0,
  46. };
  47. },
  48. computed: {},
  49. watch: {},
  50. mounted() {
  51. this.width = document.getElementsByClassName('write-base-preview')[0].clientWidth - 16;
  52. },
  53. methods: {
  54. handleReset() {
  55. this.$refs.esign.reset();
  56. this.$nextTick(() => {
  57. this.bgColor = '#f7f8fa';
  58. });
  59. },
  60. handleGenerate() {
  61. this.$refs.esign
  62. .generate({ format: 'png', quality: 0.8 })
  63. .then((res) => {
  64. this.data.write_base64[0] = res;
  65. this.$forceUpdate();
  66. })
  67. .catch((err) => {
  68. console.error(err);
  69. // alert('生成图片失败:' + err.message);
  70. });
  71. },
  72. },
  73. };
  74. </script>
  75. <style lang="scss" scoped>
  76. @use '@/styles/mixin.scss' as *;
  77. .write-base-preview {
  78. @include preview-base;
  79. display: block;
  80. .main {
  81. h2 {
  82. margin: 5px 0;
  83. font-size: 14px;
  84. }
  85. .esign-box {
  86. position: relative;
  87. background-color: #f7f8fa;
  88. .btn-box {
  89. position: absolute;
  90. right: 10px;
  91. bottom: 10px;
  92. display: flex;
  93. gap: 5px;
  94. cursor: pointer;
  95. }
  96. }
  97. }
  98. }
  99. </style>