testResultImg.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. // #ifdef APP-PLUS
  103. if(plus.runtime.isAgreePrivacy()) {
  104. uni.showToast({title: "请同意隐私政策",icon: "none"});
  105. return;
  106. }
  107. // #endif
  108. uni.showLoading({
  109. title: "图片保存中..."
  110. })
  111. uni.downloadFile({
  112. url,
  113. fail: function(res) {
  114. uni.showModal({
  115. title: '提示',
  116. content: '保存失败',
  117. })
  118. },
  119. success: function(res) {
  120. console.log(res)
  121. var tempFilePath = res.tempFilePath;
  122. uni.saveImageToPhotosAlbum({
  123. filePath: tempFilePath,
  124. success:()=> {
  125. // 5 提示保存成功
  126. uni.showToast({
  127. title: "保存成功",
  128. duration: 2000
  129. })
  130. },
  131. fail:()=>{
  132. // 6 失败关闭提示信息!!!
  133. console.log("saveImageToPhotosAlbum 失败");
  134. uni.hideLoading();
  135. },
  136. complete: function() {
  137. // 7 隐藏提示
  138. uni.hideLoading();
  139. }
  140. })
  141. },
  142. })
  143. },
  144. },
  145. }
  146. </script>
  147. <style lang="less">
  148. page {
  149. height: 100%;
  150. }
  151. .content {
  152. height: 100%;
  153. }
  154. .banenr {
  155. display: flex;
  156. align-items: center;
  157. justify-content: center;
  158. padding-bottom:140upx ;
  159. height: 100%;
  160. }
  161. .banner .slide-image {
  162. width: 100%;
  163. height: auto;
  164. }
  165. .btn-box{
  166. height: 140upx;
  167. z-index: 9999;
  168. width: 100%;
  169. padding: 0rpx 30upx;
  170. position: fixed;
  171. bottom: 0;
  172. left: 0;
  173. box-sizing: border-box;
  174. background-color: #ffffff;
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. .btn{
  179. width: 100%;
  180. height: 88upx;
  181. line-height: 88upx;
  182. text-align: center;
  183. font-size: 34upx;
  184. font-family: PingFang SC;
  185. font-weight: 400;
  186. color: #ffffff;
  187. background:#C39A58 !important;
  188. border-radius: 44upx;
  189. }
  190. }
  191. </style>