Commit df3d9c04599d3238a71838303623984e39b9228e

Authored by zhiyangdu
1 parent 66c5a80e

长按页面保存证书到相册

Showing 1 changed file with 40 additions and 17 deletions
src/pages/test.vue
1 -// cdn图片有问题 需要换成本地的图片  
2 <template> 1 <template>
3 <div class="index"> 2 <div class="index">
4 - <div class="canvas" ref="canvas">  
5 - <div class="avatar">  
6 - <img :src="imgUrl" alt="">  
7 - </div>  
8 - <div>  
9 - {{textInfo}}  
10 - </div> 3 + <div id="captureId" class="capture" v-show="firstFlag">
  4 + <div class="back"></div>
  5 + <h2>{{this.textInfo}}</h2>
11 </div> 6 </div>
12 - <div class="save_btn" @click="savecanvas">  
13 - 保存图片 7 + <img :src="dataURL" alt="" v-show="!firstFlag">
  8 + <div v-show="this.isCNLive.value" class="save_btn" @click="savecanvas">
  9 + 点击按钮保存图片
  10 + </div>
  11 + <div v-show="!this.isCNLive.value" class="tip_text" >
  12 + 长按页面保存证书到手机相册
14 </div> 13 </div>
15 </div> 14 </div>
16 </template> 15 </template>
@@ -19,11 +18,19 @@ @@ -19,11 +18,19 @@
19 export default { 18 export default {
20 data () { 19 data () {
21 return { 20 return {
  21 + dataURL:'',
  22 + firstFlag:true,
22 imgUrl:"https://wjjtest.ys2.cnliveimg.com/shop/img/2019/12/31/5e0b06db22be5.jpg", 23 imgUrl:"https://wjjtest.ys2.cnliveimg.com/shop/img/2019/12/31/5e0b06db22be5.jpg",
23 - textInfo:'哈哈哈' 24 + textInfo:'杜致阳签名'
24 }; 25 };
25 }, 26 },
  27 +
26 mounted(){ 28 mounted(){
  29 + html2canvas(document.querySelector('#captureId')).then(canvas => {
  30 + let imgUrl = canvas.toDataURL('image/png');
  31 + this.dataURL = imgUrl;
  32 + this.firstFlag = false;
  33 + })
27 }, 34 },
28 methods: { 35 methods: {
29 // 直接获取图片url传给原生 36 // 直接获取图片url传给原生
@@ -50,15 +57,11 @@ @@ -50,15 +57,11 @@
50 let r = type.match(/png|jpeg|bmp|gif/)[0]; 57 let r = type.match(/png|jpeg|bmp|gif/)[0];
51 return 'image/' + r; 58 return 'image/' + r;
52 }; 59 };
53 - imgData = imgData.replace(_fixType(type),''); 60 +// imgData = imgData.replace(_fixType(type),'');
54 let filename = "证书" + '.' + type; 61 let filename = "证书" + '.' + type;
55 if(that.isCNLive.value){ 62 if(that.isCNLive.value){
56 that.getimgUrl(imgData) 63 that.getimgUrl(imgData)
57 }else { 64 }else {
58 - // 判断在ios内  
59 -// if(that.isiPhone.value){  
60 -// imgData = imgData.replace("data:;base64,","");  
61 -// }  
62 that.saveFile(imgData,filename); 65 that.saveFile(imgData,filename);
63 } 66 }
64 67
@@ -81,9 +84,9 @@ @@ -81,9 +84,9 @@
81 .index{ 84 .index{
82 height: 100%; 85 height: 100%;
83 width: 100%; 86 width: 100%;
  87 + position: relative;
84 .canvas{ 88 .canvas{
85 height: 100%; 89 height: 100%;
86 - height: 100%;  
87 background: #d5574a; 90 background: #d5574a;
88 padding: 0.5067rem 0.6rem 0; 91 padding: 0.5067rem 0.6rem 0;
89 box-sizing: border-box; 92 box-sizing: border-box;
@@ -99,5 +102,25 @@ @@ -99,5 +102,25 @@
99 color: #ffffff; 102 color: #ffffff;
100 font-size: 36px; 103 font-size: 36px;
101 } 104 }
  105 + img{
  106 + width: 100%;
  107 + }
  108 + h2{
  109 + position: absolute;
  110 + top:20px;
  111 + right: 50px;
  112 + }
  113 + .back{
  114 + height: 860px;
  115 + background: url("../../static/img/index/1.jpg") no-repeat center top;
  116 + background-size: 100%;
  117 + }
  118 + .tip_text{
  119 + height: 100px;
  120 + line-height: 100px;
  121 + text-align: center;
  122 + color: #000;
  123 + font-size: 36px;
  124 + }
102 } 125 }
103 </style> 126 </style>