goCode.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="goCode" :class="[AppTheme]">
  3. <view class="code">
  4. <image :src="code1" alt="" class="img" mode="widthFix"/>
  5. </view>
  6. <view class=" bcfxhb" @click="saveImg(code1)" :style="{'background-color': primary}">
  7. 保存分享海报
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. import mineApi from '@/api/mine/index.js'
  13. export default {
  14. data() {
  15. return {
  16. primary:this.$theme.primary,
  17. settingFile:getApp().globalData.siteinfo,
  18. code1: ''
  19. };
  20. },
  21. onShow() {
  22. var that = this;
  23. mineApi.myqrcode({
  24. // #ifdef MP-WEIXIN
  25. apptype: 'weixin'
  26. // #endif
  27. // #ifdef H5
  28. apptype: 'h5'
  29. // #endif
  30. }).then(ret=>{
  31. if(ret.status == 200){
  32. that.code1 = ret.data.img
  33. }else{
  34. this.$u.toast(ret.msg)
  35. }
  36. })
  37. },
  38. methods: {
  39. saveImg(url) {
  40. const that = this;
  41. console.log('url',url)
  42. uni.downloadFile({
  43. url: url,
  44. success: res => {
  45. if (res.statusCode === 200) {
  46. uni.saveImageToPhotosAlbum({
  47. filePath: res.tempFilePath,
  48. success: function() {
  49. uni.showToast({
  50. title: '保存下载成功',
  51. icon: 'none',
  52. position: 'top'
  53. })
  54. },
  55. fail: function() {
  56. uni.showToast({
  57. title: '保存失败,请稍后重试',
  58. icon: 'none',
  59. position: 'top'
  60. })
  61. }
  62. });
  63. } else {
  64. uni.showToast({
  65. title: '下载失败',
  66. icon: 'none',
  67. position: 'top'
  68. })
  69. }
  70. }
  71. });
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss">
  77. page{
  78. width:100%;
  79. height: 100%;
  80. }
  81. .code {
  82. width: 100%;
  83. height: 100%;
  84. }
  85. .code .img {
  86. // position: fixed;
  87. // width: 100%;
  88. // height: 100%;
  89. width: 690rpx;
  90. display: block;
  91. margin: auto;
  92. border-radius: 20rpx;
  93. }
  94. .bcfxhb {
  95. width: 550rpx;
  96. height: 100rpx;
  97. color: #fff;
  98. border-radius: 50rpx;
  99. text-align: center;
  100. line-height: 100rpx;
  101. margin:20rpx auto;
  102. }
  103. </style>