ActionSheet.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="actionSheet">
  3. <img :src="url" alt="" @click="md" class="qr" />
  4. </div>
  5. </template>
  6. <script>
  7. // @ is an alias to /src
  8. // let sT = 0;
  9. export default {
  10. name: "Applyreal",
  11. data() {
  12. return {
  13. // url: "http://192.168.31.196:8080/qr.png",
  14. url: "http://djweb.smcic.net/img/qr.png",
  15. load: {},
  16. };
  17. },
  18. mounted() {
  19. document.title = "车险";
  20. },
  21. computed: {},
  22. methods: {
  23. md() {
  24. console.log("---");
  25. // this.download({
  26. // savePath: this.url,
  27. // });
  28. this.downimg(this.url);
  29. },
  30. downimg(url) {
  31. let img = new Image();
  32. img.src = url;
  33. img.onload = function (ev) {
  34. console.log(ev)
  35. // 组装a标签
  36. // let elink = document.createElement("a");
  37. // // 设置下载文件名
  38. // elink.download = Date.now() + ".png";
  39. // elink.style.display = "none";
  40. // elink.href = URL.createObjectURL(this.response);
  41. // document.body.appendChild(elink);
  42. // elink.click();
  43. // document.body.removeChild(elink);
  44. };
  45. },
  46. download(row) {
  47. // download
  48. this.load[row.savePath] = true;
  49. let xhttp,
  50. that = this;
  51. if (window.XMLHttpRequest) xhttp = new XMLHttpRequest();
  52. else xhttp = new window.ActiveXObject("Microsoft.XMLHTTP");
  53. xhttp.responseType = "blob";
  54. xhttp.open("GET", row.savePath, true);
  55. console.log(xhttp);
  56. xhttp.send();
  57. xhttp.addEventListener(
  58. "progress",
  59. res => {
  60. console.log(res, (res.loaded / res.total) * 100);
  61. that.load[row.savePath] =
  62. ((res.loaded / res.total) * 100).toFixed(0) - 0;
  63. },
  64. false
  65. );
  66. xhttp.onreadystatechange = function () {
  67. if (this.readyState != 4 || this.status != 200) return;
  68. // 组装a标签
  69. let elink = document.createElement("a");
  70. // 设置下载文件名
  71. elink.download = Date.now() + ".png";
  72. elink.style.display = "none";
  73. elink.href = URL.createObjectURL(this.response);
  74. document.body.appendChild(elink);
  75. elink.click();
  76. document.body.removeChild(elink);
  77. delete that.load[row.savePath];
  78. };
  79. },
  80. },
  81. beforeUnmount: function () {},
  82. components: {},
  83. };
  84. </script>
  85. <style>
  86. .actionSheet {
  87. background-image: url("http://djweb.smcic.net/img/cx.png");
  88. background-size: 100% 100%;
  89. width: 100vw;
  90. height: 100vh;
  91. position: relative;
  92. }
  93. .actionSheet .qr {
  94. position: absolute;
  95. top: 50%;
  96. width: 100%;
  97. transform: translateY(-60%);
  98. }
  99. </style>