ElectiveSign.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div>
  3. <!-- 做使用el-dialog做签字的弹框 -->
  4. <el-dialog title="签字" :visible.sync="show" width="800px" destroy-on-close >
  5. <!-- 使用这个签名组件 -->
  6. <vue-esign
  7. ref="esign"
  8. class="mySign"
  9. :width="800"
  10. :height="300"
  11. :isCrop="isCrop"
  12. :lineWidth="lineWidth"
  13. :lineColor="lineColor"
  14. :bgColor.sync="bgColor"
  15. />
  16. <span slot="footer" class="dialog-footer fx-row jc-end">
  17. <!-- <el-popover-->
  18. <!-- placement="top-start"-->
  19. <!-- title="协议"-->
  20. <!-- width="200"-->
  21. <!-- trigger="click"-->
  22. <!-- content="协议内容">-->
  23. <!-- <el-button slot="reference">协议</el-button>-->
  24. <!-- </el-popover>-->
  25. <div>
  26. <el-button @click="handleGenerate" type="primary">保存</el-button>
  27. <el-button @click="handleReset">清空画板</el-button>
  28. <el-button @click="show = false">取消</el-button>
  29. </div>
  30. </span>
  31. </el-dialog>
  32. </div>
  33. </template>
  34. <script>
  35. import { saveEsign } from '@/api/webApi/elective/selected-subject'
  36. export default {
  37. // props: ['generation'],
  38. data() {
  39. return {
  40. show: false, // 弹框是否开启
  41. lineWidth: 3, // 画笔的线条粗细
  42. lineColor: '#000000', // 画笔的颜色
  43. bgColor: '', // 画布的背景颜色
  44. base64Img: '', // 最终画布生成的base64图片
  45. isCrop: false // 是否裁剪,在画布设定尺寸基础上裁掉四周空白部分
  46. }
  47. },
  48. inject: {
  49. 'refreshData': {
  50. default: function() {
  51. // do nothing
  52. }
  53. }
  54. },
  55. methods: {
  56. // 清空画板
  57. handleReset() {
  58. this.$refs.esign.reset()
  59. },
  60. saveElective() {
  61. saveEsign({
  62. id: this.flowId,
  63. esignPath:this.base64Img
  64. }).then(res => {
  65. if (res.code == 200) {
  66. this.show = false
  67. this.success()
  68. }
  69. })
  70. },
  71. // 生成签字图
  72. handleGenerate() {
  73. this.$refs.esign
  74. .generate() // 使用生成器调用把签字的图片转换成为base64图片格式
  75. .then((res) => {
  76. this.base64Img = res
  77. this.saveElective()
  78. // 在这里向后端发请求把转换后的base64文件传给后端,后端接收以后再转换成图片做静态图片存储
  79. // 当然也可以把base64转成流文件blob格式的,类似上传给后端这样,具体哪种方式看后端要求
  80. })
  81. .catch((err) => {
  82. console.log(err)
  83. // 画布没有签字时会执行这里提示一下
  84. this.$message({
  85. type: 'warning',
  86. message: '请先签名'
  87. })
  88. return
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. #app {
  96. width: 100%;
  97. height: 100%;
  98. padding: 60px;
  99. .checkMan {
  100. width: 400px;
  101. height: 360px;
  102. text-align: center;
  103. border: 1px solid #e9e9e9;
  104. padding-top: 40px;
  105. h2 {
  106. margin-bottom: 20px;
  107. }
  108. .el-button {
  109. margin-bottom: 20px;
  110. }
  111. img {
  112. width: 100%;
  113. height: 200px;
  114. }
  115. }
  116. }
  117. ::v-deep .el-dialog__body {
  118. // 设置一下签字区域的虚线边框
  119. .mySign {
  120. border: 1px dashed #000;
  121. }
  122. }
  123. </style>