my_share.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="share-container">
  3. <view class="requires2">
  4. <uni-row >
  5. <text>分享后,有用户登录,即可查看分享规则!</text>
  6. </uni-row>
  7. </view>
  8. <form >
  9. <view>
  10. <button class="alias-submit" type="primary" @click="queryResult" >分享结果</button>
  11. </view>
  12. <view class="share-begin">
  13. <button open-type="share" form-type="submit" class="alias-submit" type="primary">链接分享</button>
  14. </view>
  15. <view v-if="isShowShareQR">
  16. <button class="alias-submit" type="primary" @click="showOwnQRCode" >二维码分享</button>
  17. </view>
  18. <view v-if="isShowGetQR">
  19. <button class="alias-submit" type="primary" @click="generateOwnQRCode" >生成二维码</button>
  20. </view>
  21. </form>
  22. </view>
  23. </template>
  24. <script>
  25. import { mapMutations, mapState } from 'vuex'
  26. export default {
  27. computed: {
  28. ...mapState('m_user', ['userinfo'])
  29. },
  30. data() {
  31. return {
  32. isShowGetQR: true,
  33. isShowShareQR: false
  34. };
  35. },
  36. created() {
  37. this.getOwnQRCodeUrl();
  38. },
  39. methods: {
  40. /**
  41. * 分享处理函数,可以响应2类事件,1是button,2是右上角的menu中的Send to Chat
  42. * button用法:<button class="forshare" open-type="share">share</button>
  43. * menu用法:不用引入变量,当页面有这个函数时, Send to Chat会启用,否则灰色
  44. * path中的uid=txj123,txj123应该换为真实的用户号,当这个分享的卡片被打开时,小程序可以取到这个号
  45. */
  46. onShareAppMessage: function () {
  47. //console.log(this.userinfo)
  48. return {
  49. title:'来自 ' + this.userinfo.alias + ' 的分享',
  50. path: '/pages/home/home?uid=' + this.userinfo.uid,
  51. imageUrl: '/static/share.jpg', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
  52. }
  53. },
  54. queryResult(){
  55. uni.navigateTo({
  56. url: '/subpkg/my/share/my_share_result'
  57. })
  58. },
  59. showOwnQRCode(){
  60. uni.navigateTo({
  61. url: '/subpkg/my/share/my_share_qrcode'
  62. })
  63. },
  64. async generateOwnQRCode() {
  65. const {
  66. data: result
  67. } = await uni.$http.get('/file/generateQRcodeUrl?uid='+ this.userinfo.uid)
  68. //console.log(result.data.QRurl)
  69. if (result.data.QRurl != undefined) {
  70. if (result.data.QRurl != "") {
  71. this.setQRCodeUrl(this.userinfo.uid,result.data.QRurl)
  72. uni.$showMsg('二维码申请成功' , 2000)
  73. this.isShowGetQR = false
  74. this.isShowShareQR = true
  75. }
  76. }
  77. },
  78. async getOwnQRCodeUrl() {
  79. const {
  80. data: result
  81. } = await uni.$http.get('/ucenter/mini-program-openid-uid/getOwnQRcodeUrl?uid='+ this.userinfo.uid)
  82. //console.log(result.data.QRurl)
  83. if (result.data.QRurl != undefined) {
  84. if (result.data.QRurl != "0") {
  85. this.isShowGetQR = false
  86. this.isShowShareQR = true
  87. }
  88. }
  89. },
  90. async setQRCodeUrl(uid,qrurl) {
  91. // 准备参数对象
  92. const query = {
  93. uid: uid,
  94. qrurl: qrurl
  95. }
  96. const {
  97. data: result
  98. } = await uni.$http.get('/ucenter/mini-program-openid-uid/setOwnQRcodeUrl',query)
  99. //console.log(result.data)
  100. if (result.data.OK != "qrurl设置成功") {
  101. uni.$showMsg('二维码申请失败' , 2000)
  102. }
  103. },
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .share-container{
  109. height: 100%;
  110. padding: 0 40rpx;
  111. // background-color: #fff;
  112. }
  113. .share-begin{
  114. padding-top: 50rpx;
  115. margin-top: -50rpx;
  116. }
  117. .alias-submit {
  118. margin-top: 50rpx;
  119. border-radius: 50rpx;
  120. background-color: #35b882;
  121. font-size: 35rpx;
  122. //font-weight: bold;
  123. padding: 10rpx;
  124. }
  125. .requires2 {
  126. background-color: #FFF;
  127. margin: 20rpx 20rpx;
  128. border-radius: 50rpx;
  129. font-size: 30rpx;
  130. padding: 20rpx 20rpx;
  131. //font-weight: bold;
  132. color: gray;
  133. display: flex;
  134. align-items: center;
  135. justify-content: center;
  136. }
  137. </style>