wechatcode.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="column centerV">
  3. <view class="codeimg">
  4. <view v-if="wechatImg!=null" class="centerV">
  5. <image :src="wechatImg" style="width: 100%;" mode="aspectFit" :show-menu-by-longpress="true" ></image>
  6. <view class="centerV">点击保存图片至本地!</view>
  7. </view>
  8. <view v-else>
  9. <image src="https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/no_data.png" style="width: 100%;"
  10. mode="aspectFill"></image>
  11. <view class="centerV">暂无二维码,请点击生成二维码</view>
  12. </view>
  13. </view>
  14. <view class="centerV generate" @click="generatecode" v-if="wechatImg==null">点击生成</view>
  15. <view class="centerV generate" @click="saveImage" v-else>保存图片</view>
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. getcomapycode,
  21. generateComapycode
  22. } from '@/api/companyUser'
  23. export default {
  24. data() {
  25. return {
  26. wechatImg: null,
  27. companyId: '',
  28. companyUserId:null
  29. }
  30. },
  31. onLoad(option) {
  32. this.companyId = option.companyId
  33. this.companyUserId=option.companyUserId
  34. this.getcomapycodes()
  35. },
  36. methods: {
  37. saveImage() {
  38. wx.downloadFile({
  39. url: this.wechatImg, //仅为示例,并非真实的资源
  40. success (res) {
  41. console.log(res)
  42. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  43. if (res.statusCode === 200) {
  44. wx.saveImageToPhotosAlbum({
  45. filePath: res.tempFilePath,
  46. success: function(res) {
  47. wx.showToast({
  48. title: '已保存至相册',
  49. icon: 'none',
  50. duration: 1000
  51. })
  52. },
  53. fail: function(err) {
  54. console.log(err);
  55. wx.showToast({
  56. title: '保存失败',
  57. icon: 'none',
  58. duration: 1000
  59. })
  60. }
  61. })
  62. wx.playVoice({
  63. filePath: res.tempFilePath
  64. })
  65. }
  66. }
  67. })
  68. },
  69. generatecode() {
  70. const data = {
  71. companyId: this.companyId,
  72. appId: wx.getAccountInfoSync().miniProgram.appId,
  73. companyUserId:this.companyUserId
  74. }
  75. generateComapycode(data).then(res => {
  76. if (res.code == 200) {
  77. this.getcomapycodes()
  78. console.log(res)
  79. } else {
  80. uni.showToast({
  81. icon: 'none',
  82. title: res.msg,
  83. });
  84. }
  85. })
  86. },
  87. getcomapycodes() {
  88. const data = {
  89. companyId: this.companyId,
  90. companyUserId:this.companyUserId,
  91. appId:wx.getAccountInfoSync().miniProgram.appId,
  92. }
  93. getcomapycode(data).then(res => {
  94. if (res.code == 200) {
  95. // 核心js代码:
  96. this.wechatImg = res.data
  97. } else {
  98. uni.showToast({
  99. icon: 'none',
  100. title: res.msg,
  101. });
  102. }
  103. })
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .codeimg {
  110. width: 80%;
  111. margin: 40rpx 0;
  112. }
  113. .generate {
  114. background-color: #2BC7B9;
  115. width: 70%;
  116. margin: 0 auto;
  117. border-radius: 40rpx;
  118. padding: 20rpx 0;
  119. color: #fff;
  120. margin-top: 30rpx;
  121. }
  122. </style>