favorites.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="container">
  3. <image @longtap="bc_code" class="backImg" :src="backImg"></image>
  4. <view class="tki-qrcode"><canvas @longtap="bc_code" canvas-id="qrcode" /></view>
  5. </view>
  6. </template>
  7. <script>
  8. import { spreadBanner } from '@/api/user.js';
  9. export default {
  10. // components: { tkiQrcode },
  11. data() {
  12. return {
  13. url: '',
  14. backImg: '',
  15. userInfo: ''
  16. };
  17. },
  18. onLoad() {
  19. this.spread();
  20. uni.setNavigationBarTitle({
  21. title: this.$t("tab.b2"),
  22. });
  23. },
  24. computed: {
  25. cpSize() {
  26. if (this.unit == 'upx') {
  27. return uni.upx2px(this.size);
  28. } else {
  29. return this.size;
  30. }
  31. }
  32. },
  33. methods: {
  34. spread() {
  35. uni.showLoading({
  36. title: '加载中'
  37. });
  38. let obj = this;
  39. spreadBanner({
  40. //#ifdef H5
  41. type: 2,
  42. //#endif
  43. //#ifdef MP
  44. type:1,
  45. //#endif
  46. //#ifdef APP-PLUS
  47. type:2,
  48. //#endif
  49. }).then(({ data }) => {
  50. console.log(data);
  51. //#ifdef MP
  52. obj.backImg = data[0].poster;
  53. //#endif
  54. //#ifdef H5
  55. obj.backImg = data[0].wap_poster;
  56. //#endif
  57. //#ifdef APP-PLUS
  58. obj.backImg = data[0].wap_poster;
  59. //#endif
  60. uni.hideLoading();
  61. });
  62. },
  63. bc_code() {
  64. let that = this;
  65. console.log('保存二维码', this.backImg);
  66. uni.downloadFile({
  67. //获得二维码的临时地址
  68. url: this.backImg,
  69. success: res => {
  70. //console.log('获取url',res)
  71. if (res.statusCode == 200) {
  72. uni.saveImageToPhotosAlbum({
  73. filePath: res.tempFilePath, //传入临时地址
  74. success() {
  75. that.$api.msg('保存成功'); //封装的提示
  76. },
  77. fail() {
  78. that.$api.msg('保存失败');
  79. }
  80. });
  81. }
  82. }
  83. });
  84. }
  85. }
  86. };
  87. </script>
  88. <style lang="scss">
  89. page {
  90. width: 100%;
  91. min-height: 100%;
  92. .container {
  93. width: 100%;
  94. height: 100%;
  95. }
  96. }
  97. .backImg {
  98. position: absolute;
  99. width: 100%;
  100. height: 100%;
  101. }
  102. .portrait {
  103. width: 100%;
  104. text-align: center;
  105. padding-top: 80rpx;
  106. padding-bottom: 30rpx;
  107. image {
  108. width: 250rpx;
  109. height: 250rpx;
  110. }
  111. }
  112. .text {
  113. text-align: center;
  114. width: 100%;
  115. color: #ffffff;
  116. font-size: 55rpx;
  117. letter-spacing: 15rpx;
  118. }
  119. .uid-name {
  120. padding: 50rpx 0rpx;
  121. text-align: center;
  122. width: 100%;
  123. color: #ffffff;
  124. }
  125. .copy-btn {
  126. color: #ffffff;
  127. background-color: #4ba6ed;
  128. border-radius: 50rpx;
  129. width: 170rpx;
  130. line-height: 70rpx;
  131. margin: 0rpx auto;
  132. text-align: center;
  133. }
  134. .tki-qrcode {
  135. position: fixed;
  136. bottom: 10%;
  137. left: 30%;
  138. }
  139. canvas {
  140. width: 150px;
  141. height: 150px;
  142. margin: auto;
  143. }
  144. </style>