WxCode.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view style="display: flex;justify-content: center;">
  3. <view class="wx_code">
  4. <view class="wx_code_name">
  5. <view class="ellipsis">{{ enterpriseInfo.enterpriseName }}</view>
  6. <view class="user-name">{{ userInfo.name }}</view>
  7. </view>
  8. <view class="wx_code_scan"><image :src="QrSrc" mode="aspectFit" /></view>
  9. <view class="wx_code_tips"><text>扫一扫,立即使用小程序商城</text></view>
  10. </view>
  11. <view class="save-btn" @click="downloadFile">保存小程序码</view>
  12. </view>
  13. </template>
  14. <script>
  15. import webUrl from '../../common/config.js';
  16. export default {
  17. data() {
  18. return {
  19. QrSrc: ''
  20. };
  21. },
  22. computed: {
  23. userInfo() {
  24. return this.$store.state.userInfo;
  25. },
  26. enterpriseInfo() {
  27. return this.$store.state.enterprise;
  28. }
  29. },
  30. onLoad() {
  31. this.createwxaqrcode();
  32. },
  33. methods: {
  34. async createwxaqrcode() {
  35. let pathS = 'pages/index/index';
  36. this.$u.api
  37. .createwxaqrcode({
  38. path: pathS,
  39. params: this.userInfo.staffId + '_'
  40. })
  41. .then(res => {
  42. this.QrSrc = res.data.indexOf('https') > -1 ? res.data : webUrl.QRC_SRC + res.data;
  43. });
  44. },
  45. downloadFile() {
  46. uni.showLoading({
  47. title: '正在保存'
  48. });
  49. uni.downloadFile({
  50. url: this.QrSrc,
  51. success: res => {
  52. if (res.statusCode === 200) {
  53. uni.saveImageToPhotosAlbum({
  54. filePath: res.tempFilePath,
  55. success: function() {
  56. uni.showToast({
  57. title: '保存成功',
  58. icon: 'none'
  59. });
  60. },
  61. fail: function() {
  62. uni.showToast({
  63. title: '保存失败,请稍后重试',
  64. icon: 'none'
  65. });
  66. }
  67. });
  68. }
  69. },
  70. fail: err => {
  71. uni.showToast({
  72. title: '保存失败,请稍后重试',
  73. icon: 'none'
  74. });
  75. }
  76. });
  77. }
  78. }
  79. };
  80. </script>
  81. <style scoped lang="scss">
  82. .save-btn {
  83. width: 680upx;
  84. position: fixed;
  85. bottom: 30upx;
  86. left: 50%;
  87. transform: translateX(-50%);
  88. line-height: 80upx;
  89. text-align: center;
  90. color: #ffffff;
  91. background: $uni-color-primary;
  92. height: 80upx;
  93. border-radius: 8upx;
  94. }
  95. .wx_code {
  96. width: 660upx;
  97. background-color: #fff;
  98. margin-top: 160upx;
  99. border-radius: 10upx;
  100. .wx_code_name {
  101. margin: 50upx 0 40upx 50upx;
  102. font-size: 32upx;
  103. .user-name {
  104. font-size: 28upx;
  105. color: #666666;
  106. padding-top: 6upx;
  107. }
  108. }
  109. .wx_code_scan {
  110. width: 540upx;
  111. height: 540upx;
  112. margin: 0 auto;
  113. }
  114. .wx_code_scan image {
  115. width: 540upx;
  116. height: 540upx;
  117. }
  118. .wx_code_tips {
  119. margin: 50upx 0;
  120. font-size: 24upx;
  121. color: #999999;
  122. text-align: center;
  123. }
  124. }
  125. </style>