addHealthButlerOld.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="container">
  3. <view class="qrcode-box x-c" v-if="imgurl">
  4. <!-- <view class="qrcode-title">{{info.name}}</view> -->
  5. <image class="qrcode" :src="imgurl" mode="aspectFill" show-menu-by-longpress="true"></image>
  6. <!-- #ifdef MP-WEIXIN -->
  7. <view class="qrcode-tip">长按识别二维码,添加健康管家</view>
  8. <!-- #endif -->
  9. <!-- #ifndef MP-WEIXIN -->
  10. <view class="qrcode-tip">保存二维码,微信扫描添加健康管家</view>
  11. <!-- #endif -->
  12. <!-- #ifndef H5 -->
  13. <button class="downbtn x-c" @click="downImg">保存</button>
  14. <!-- #endif -->
  15. </view>
  16. <u-empty mode="data" v-else="imgurl" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无数据"></u-empty>
  17. </view>
  18. </template>
  19. <script>
  20. import { getAppContactWay } from "@/api/user.js"
  21. export default {
  22. data() {
  23. return {
  24. userId: '',
  25. imgurl: ''
  26. }
  27. },
  28. onLoad() {
  29. const user= JSON.parse(uni.getStorageSync('userInfo')) ;
  30. this.userId= user.userId;
  31. this.getQRCode()
  32. },
  33. methods: {
  34. getQRCode(this.userId) {
  35. getAppContactWay().then(res=>{
  36. if(res.code==200){
  37. this.imgurl = res.data || ''
  38. } else {
  39. uni.showToast({
  40. title: res.msg,
  41. icon: ''
  42. })
  43. }
  44. })
  45. },
  46. downImg() {
  47. uni.showLoading({
  48. title: "图片保存中..."
  49. })
  50. uni.downloadFile({
  51. url: this.imgurl,
  52. fail: function(res) {
  53. uni.showModal({
  54. title: '提示',
  55. content: '保存失败',
  56. })
  57. uni.hideLoading();
  58. },
  59. success: function(res) {
  60. var tempFilePath = res.tempFilePath;
  61. uni.saveImageToPhotosAlbum({
  62. filePath: tempFilePath,
  63. success:()=> {
  64. uni.showToast({
  65. title: "保存成功",
  66. duration: 2000
  67. })
  68. },
  69. fail:()=>{
  70. console.log("图片失败");
  71. uni.showToast({
  72. title: "图片失败",
  73. duration: 2000,
  74. icon: "error"
  75. })
  76. uni.hideLoading();
  77. },
  78. complete: function() {
  79. uni.hideLoading();
  80. }
  81. })
  82. },
  83. })
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .container {
  90. padding: 40rpx 0;
  91. padding-top: 10vh;
  92. }
  93. .qrcode-box {
  94. width: 660rpx;
  95. padding: 32rpx;
  96. margin: 0 auto;
  97. box-sizing: border-box;
  98. overflow: hidden;
  99. flex-direction: column !important;
  100. border-radius: 16rpx;
  101. background-color: #fff;
  102. font-family: PingFang SC, PingFang SC;
  103. font-weight: 400;
  104. font-size: 28rpx;
  105. color: #222;
  106. .qrcode {
  107. width: 450rpx;
  108. height: 450rpx;
  109. }
  110. .qrcode-title {
  111. font-weight: bold;
  112. font-size: 32rpx;
  113. color: #222;
  114. margin-bottom: 32rpx;
  115. }
  116. .qrcode-tip {
  117. margin: 32rpx;
  118. color: #999;
  119. text-align: center;
  120. }
  121. }
  122. .downbtn {
  123. width: 160rpx;
  124. min-height: 68rpx;
  125. border: 1px solid #FF5C03 !important;
  126. color: #FF5C03 !important;
  127. background-color: #fff !important;
  128. border-radius: 168rpx;
  129. font-family: PingFang SC, PingFang SC;
  130. font-weight: 400;
  131. font-size: 28rpx;
  132. &::after {
  133. border: none;
  134. }
  135. }
  136. </style>