addHealthButler.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="container">
  3. <view class="img-box">
  4. <view class="img">
  5. <image class="qrcode" :src="imgurl" mode="widthFix" lazy-load :show-menu-by-longpress="true"></image>
  6. </view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. import { getAppContactWay } from "@/api/user.js"
  12. export default {
  13. data() {
  14. return {
  15. baseUrl:uni.getStorageSync('requestPath'),
  16. userId:null,
  17. imgurl: ''
  18. }
  19. },
  20. onLoad(options) {
  21. this.userId=options.userId;
  22. console.log(options.userId)
  23. this.getQRCode()
  24. },
  25. methods: {
  26. getQRCode() {
  27. getAppContactWay(this.userId).then(res=>{
  28. if(res.code==200){
  29. this.imgurl = res.data || ''
  30. } else {
  31. uni.showToast({
  32. title: res.msg,
  33. icon: ''
  34. })
  35. }
  36. })
  37. },
  38. downImg() {
  39. uni.showLoading({
  40. title: "图片保存中..."
  41. })
  42. uni.downloadFile({
  43. url: this.imgurl,
  44. fail: function(res) {
  45. uni.showModal({
  46. title: '提示',
  47. content: '保存失败',
  48. })
  49. uni.hideLoading();
  50. },
  51. success: function(res) {
  52. var tempFilePath = res.tempFilePath;
  53. uni.saveImageToPhotosAlbum({
  54. filePath: tempFilePath,
  55. success:()=> {
  56. uni.showToast({
  57. title: "保存成功",
  58. duration: 2000
  59. })
  60. },
  61. fail:()=>{
  62. console.log("图片失败");
  63. uni.showToast({
  64. title: "图片失败",
  65. duration: 2000,
  66. icon: "error"
  67. })
  68. uni.hideLoading();
  69. },
  70. complete: function() {
  71. uni.hideLoading();
  72. }
  73. })
  74. },
  75. })
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss">
  81. .container {
  82. padding: 15rpx;
  83. .img-box{
  84. display: flex;
  85. align-items: center;
  86. justify-content: center;
  87. width: 100%;
  88. height:100%;
  89. .img{
  90. width: 100%;
  91. height:100%;
  92. position: relative;
  93. .qrcode{
  94. width: 100%;
  95. height:100%;
  96. image{
  97. width: 100%;
  98. height:100%;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. </style>