addHealthButler.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template> <view class="container">
  2. <view class="x-c" style="height: 50vh;" v-if="loading">
  3. <u-loading-icon :show="loading" text="加载中" vertical></u-loading-icon>
  4. </view> <template v-if="imgurl"> <image class="bg" id="bg" :src="imgurl" mode="widthFix" show-menu-by-longpress="true" @longpress="longpressImg"></image> </template> <u-empty mode="data" v-if="!imgurl && !loading" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无数据"></u-empty> </view> </template> <script> import { getAppContactWay } from "@/api/user.js" export default { data() { return {
  5. loading: false, userId: '', imgurl: "", } }, onLoad() {
  6. const user= JSON.parse(uni.getStorageSync('userInfo')) ;
  7. this.userId= user.userId; this.getQRCode() }, methods: { getQRCode() {
  8. this.loading = true getAppContactWay(this.userId).then(res=>{
  9. this.loading = false if(res.code==200){ this.imgurl = res.data || '' } else { uni.showToast({ title: res.msg, icon: '' }) } }).catch(()=>{
  10. this.loading = false
  11. }) },
  12. longpressImg() {
  13. // #ifndef MP-WEIXIN
  14. uni.showActionSheet({
  15. title: "保存图片,微信扫图片描二维码添加健康管家",
  16. itemList: ["保存图片"],
  17. success: (res)=> {
  18. console.log("保存图片")
  19. this.downImg()
  20. }
  21. });
  22. // #endif
  23. },
  24. downImg() {
  25. uni.showLoading({
  26. title: "图片保存中..."
  27. })
  28. uni.downloadFile({
  29. url: this.imgurl,
  30. fail: function(res) {
  31. uni.showModal({
  32. title: '提示',
  33. content: '保存失败',
  34. })
  35. uni.hideLoading();
  36. },
  37. success: function(res) {
  38. var tempFilePath = res.tempFilePath;
  39. uni.saveImageToPhotosAlbum({
  40. filePath: tempFilePath,
  41. success:()=> {
  42. uni.showToast({
  43. title: "保存成功",
  44. duration: 2000
  45. })
  46. },
  47. fail:()=>{
  48. console.log("图片失败");
  49. uni.showToast({
  50. title: "图片失败",
  51. duration: 2000,
  52. icon: "error"
  53. })
  54. uni.hideLoading();
  55. },
  56. complete: function() {
  57. uni.hideLoading();
  58. }
  59. })
  60. },
  61. })
  62. } } } </script> <style lang="scss" scoped>
  63. .container {
  64. position: relative;
  65. } .bg { width: 100%; }
  66. .qrcode {
  67. width: 186rpx;
  68. height: 186rpx;
  69. box-sizing: border-box;
  70. background: #FFFFFF;
  71. border-radius: 6rpx;
  72. border: 3px solid #FB601F;
  73. position: absolute;
  74. right: 39rpx;
  75. bottom: 32rpx;
  76. z-index: 9;
  77. } </style>