index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <div>
  3. <!-- 电子签名 -->
  4. <el-card class="qianming-container" body-style="padding:0px">
  5. <vue-esign ref="esign" :isCrop="isCrop" :width="600" :height="300" :lineWidth="lineWidth" :lineColor="lineColor" :bgColor.sync="bgColor" ></vue-esign>
  6. <div class="contro-container">
  7. <el-button type="danger" @click="handleReset">清空画板</el-button>
  8. <el-button type="primary" @click="handleGenerate">生成图片</el-button>
  9. </div>
  10. </el-card>
  11. </div>
  12. </template>
  13. <script>
  14. // import client from 'common/js/ossClient.js'
  15. export default {
  16. name:'Qianming',
  17. data(){
  18. return {
  19. lineWidth: 6,
  20. lineColor: '#000000',
  21. bgColor: '',
  22. resultImg: '',
  23. isCrop: false
  24. }
  25. },
  26. methods:{
  27. //清空画板..
  28. handleReset () {
  29. this.$refs.esign.reset();
  30. this.resultImg =''
  31. },
  32. //生成签名图片..
  33. handleGenerate () {
  34. this.$refs.esign.generate().then(res => {
  35. let randnum = Math.random() * 10000000000000
  36. randnum = Math.floor(randnum)
  37. let fileName = "dianziqianming/" + randnum + '.png'
  38. let file = this.dataURLtoFile(res,fileName)
  39. client.put(fileName, file).then(res=>{
  40. if(res.url){
  41. this.resultImg = res.url
  42. }else{
  43. this.$message.error('文件上传失败')
  44. }
  45. }).catch(err=>{})
  46. }).catch(err => {
  47. this.$message.error('请签名之后提交!')
  48. })
  49. },
  50. //将base64转换为文件..
  51. dataURLtoFile(dataurl, filename) {
  52. var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
  53. bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
  54. while(n--){
  55. u8arr[n] = bstr.charCodeAt(n);
  56. }
  57. return new File([u8arr], filename, {type:mime});
  58. }
  59. }
  60. }
  61. </script>
  62. <style scoped>
  63. button{
  64. height:40px;
  65. }
  66. .show-img{
  67. width:400px;
  68. height:200px;
  69. border:1px solid #123456;
  70. }
  71. .show-info{
  72. width:400px;
  73. height:200px;
  74. font-size:24px;
  75. display:flex;
  76. align-items:center;
  77. justify-content:center;
  78. }
  79. .contro-container{
  80. width:600px;
  81. height:50px;
  82. display:flex;
  83. flex-direction:row;
  84. align-items:center;
  85. justify-content:space-around;
  86. background-color:#D3D3D3;
  87. position:absolute;
  88. bottom:0px;
  89. }
  90. .qianming-container{
  91. width:600px;
  92. height:350px;
  93. margin:20px auto;
  94. position:relative;
  95. }
  96. .text {
  97. font-size: 14px;
  98. }
  99. .item {
  100. margin-bottom: 18px;
  101. }
  102. .clearfix:before,
  103. .clearfix:after {
  104. display: table;
  105. content: "";
  106. }
  107. .clearfix:after {
  108. clear: both
  109. }
  110. .box-card {
  111. width: 95%;
  112. margin-left:2.5%;
  113. margin-top:20px;
  114. }
  115. </style>