esign-dialog.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div>
  3. <!-- 做使用el-dialog做签字的弹框 -->
  4. <el-dialog title="签字" v-if="dialogVisible" :visible.sync="dialogVisible" width="800px" append-to-body>
  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="dialogVisible = false">取消</el-button>
  29. </div>
  30. </span>
  31. </el-dialog>
  32. </div>
  33. </template>
  34. <script>
  35. import { submitElectiveModels, saveEsign, getStudentElectiveModels } from '@/api/webApi/elective/selected-subject'
  36. export default {
  37. data() {
  38. return {
  39. selectedList: [],
  40. dialogVisible: 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. open(selectedList) {
  57. this.selectedList = selectedList
  58. this.dialogVisible = true
  59. },
  60. // 清空画板
  61. handleReset() {
  62. this.$refs.esign.reset()
  63. },
  64. saveELective() {
  65. submitElectiveModels({
  66. models: this.selectedList
  67. // esign:this.base64Img
  68. }).then(res => {
  69. if (res.code == 200) {
  70. this.dialogVisible = false
  71. this.$message.success('报名成功')
  72. this.loadStudentSelected()
  73. this.getStudentElectiveModels()
  74. }
  75. console.log(res)
  76. })
  77. },
  78. // 生成签字图
  79. handleGenerate() {
  80. this.$refs.esign
  81. .generate() // 使用生成器调用把签字的图片转换成为base64图片格式
  82. .then((res) => {
  83. console.log(this.selectedList)
  84. this.base64Img = res
  85. this.saveELective()
  86. // 在这里向后端发请求把转换后的base64文件传给后端,后端接收以后再转换成图片做静态图片存储
  87. // 当然也可以把base64转成流文件blob格式的,类似上传给后端这样,具体哪种方式看后端要求
  88. console.log(this.resultImg)
  89. })
  90. .catch((err) => {
  91. // 画布没有签字时会执行这里提示一下
  92. this.$message({
  93. type: 'warning',
  94. message: '请先签名'
  95. })
  96. return
  97. })
  98. this.dialogVisible = true
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. #app {
  105. width: 100%;
  106. height: 100%;
  107. padding: 60px;
  108. .checkMan {
  109. width: 400px;
  110. height: 360px;
  111. text-align: center;
  112. border: 1px solid #e9e9e9;
  113. padding-top: 40px;
  114. h2 {
  115. margin-bottom: 20px;
  116. }
  117. .el-button {
  118. margin-bottom: 20px;
  119. }
  120. img {
  121. width: 100%;
  122. height: 200px;
  123. }
  124. }
  125. }
  126. ::v-deep .el-dialog__body {
  127. // 设置一下签字区域的虚线边框
  128. .mySign {
  129. border: 1px dashed #000;
  130. }
  131. }
  132. </style>