testResultImg.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="content">
  3. <view class="banenr">
  4. <image class="slide-image" :src="url" mode="widthFix" show-menu-by-longpress />
  5. </view>
  6. <view class="btn-box">
  7. <view class="btn" @click="shareImg()">分享好友</view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import {getTestReportImg} from '@/api/test.js'
  13. export default {
  14. name: 'Poster',
  15. components: {
  16. },
  17. props: {},
  18. data: function() {
  19. return {
  20. url:null,
  21. }
  22. },
  23. mounted: function() {
  24. this.getTestReportImg()
  25. },
  26. methods: {
  27. shareImg:function(){
  28. wx.downloadFile({
  29. url: this.url,
  30. success: (res) => {
  31. wx.showShareImageMenu({
  32. path: res.tempFilePath
  33. })
  34. }
  35. })
  36. },
  37. getTestReportImg: function() {
  38. let that = this
  39. var data={
  40. reportId:this.reportId
  41. }
  42. getTestReportImg(data).then(
  43. res => {
  44. that.url =res.url
  45. },
  46. err => {
  47. uni.showToast({
  48. title: err.msg,
  49. icon: 'none',
  50. duration: 2000,
  51. })
  52. }
  53. )
  54. },
  55. downloadIamge(imgsrc, name) {
  56. var that = this
  57. this.isDown = true
  58. var downloadUrl = imgsrc
  59. // if (!wx.saveImageToPhotosAlbum) {
  60. // uni.showModal({
  61. // title: '提示',
  62. // content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
  63. // })
  64. // that.openDialogVisible = true
  65. // return
  66. // }
  67. that.downloadFile(downloadUrl)
  68. //可以通过 uni.getSetting 先查询一下用户是否授权了 "scope.writePhotosAlbum" 这个 scope
  69. // uni.getSetting({
  70. // success(res) {
  71. // if (!res.authSetting["scope.writePhotosAlbum"]) {
  72. // that.openDialogVisible = true;
  73. // // 接口调用询问
  74. // uni.authorize({
  75. // scope: "scope.writePhotosAlbum",
  76. // success() {
  77. // that.downloadFile(downloadUrl);
  78. // },
  79. // fail() {
  80. // // 用户拒绝了授权
  81. // // 打开设置页面
  82. // uni.openSetting({
  83. // success: function (data) {},
  84. // fail: function (data) {}
  85. // });
  86. // }
  87. // });
  88. // } else {
  89. // that.downloadFile(downloadUrl);
  90. // }
  91. // },
  92. // fail(res) {
  93. // that.openDialogVisible = true;
  94. // }
  95. // });
  96. },
  97. saveImg: function() {
  98. this.downloadIamge(this.url, 'poster')
  99. },
  100. downloadFile(url) {
  101. console.log(url);
  102. uni.showLoading({
  103. title: "图片保存中..."
  104. })
  105. uni.downloadFile({
  106. url,
  107. fail: function(res) {
  108. uni.showModal({
  109. title: '提示',
  110. content: '保存失败',
  111. })
  112. },
  113. success: function(res) {
  114. console.log(res)
  115. var tempFilePath = res.tempFilePath;
  116. uni.saveImageToPhotosAlbum({
  117. filePath: tempFilePath,
  118. success:()=> {
  119. // 5 提示保存成功
  120. uni.showToast({
  121. title: "保存成功",
  122. duration: 2000
  123. })
  124. },
  125. fail:()=>{
  126. // 6 失败关闭提示信息!!!
  127. console.log("saveImageToPhotosAlbum 失败");
  128. uni.hideLoading();
  129. },
  130. complete: function() {
  131. // 7 隐藏提示
  132. uni.hideLoading();
  133. }
  134. })
  135. },
  136. })
  137. },
  138. },
  139. }
  140. </script>
  141. <style lang="less">
  142. page {
  143. height: 100%;
  144. }
  145. .content {
  146. height: 100%;
  147. }
  148. .banenr {
  149. display: flex;
  150. align-items: center;
  151. justify-content: center;
  152. padding-bottom:140upx ;
  153. height: 100%;
  154. }
  155. .banner .slide-image {
  156. width: 100%;
  157. height: auto;
  158. }
  159. .btn-box{
  160. height: 140upx;
  161. z-index: 9999;
  162. width: 100%;
  163. padding: 0rpx 30upx;
  164. position: fixed;
  165. bottom: 0;
  166. left: 0;
  167. box-sizing: border-box;
  168. background-color: #ffffff;
  169. display: flex;
  170. align-items: center;
  171. justify-content: center;
  172. .btn{
  173. width: 100%;
  174. height: 88upx;
  175. line-height: 88upx;
  176. text-align: center;
  177. font-size: 34upx;
  178. font-family: PingFang SC;
  179. font-weight: 400;
  180. color: #ffffff;
  181. background:#018C39 !important;
  182. border-radius: 44upx;
  183. }
  184. }
  185. </style>