裂变星小程序-25.03.04
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
3.6 KiB

  1. <template>
  2. <view class="page">
  3. <navbar leftClick @leftClick="$utils.navigateBack" />
  4. <view class="content">
  5. <image class="avatar" :src="detail.headImage"></image>
  6. <text class="nick-name">{{ detail.headTitle || '' }}</text>
  7. <template v-if="isLocked">
  8. <button class="btn" type="success" @click="onAdd">添加</button>
  9. </template>
  10. <template v-else>
  11. <image class="qr" :src="detail.wxCodeImage" :show-menu-by-longpress="true"></image>
  12. </template>
  13. </view>
  14. <loginPopup ref="loginPopup" @login="fetchDetails"/>
  15. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-user.png"></popupUnlock>
  16. </view>
  17. </template>
  18. <script>
  19. import { mapState } from 'vuex'
  20. import loginPopup from '@/components/config/loginPopup.vue'
  21. import popupUnlock from '../components/popupUnlock.vue'
  22. export default {
  23. components: {
  24. loginPopup,
  25. popupUnlock,
  26. },
  27. data() {
  28. return {
  29. id: null,
  30. detail: {
  31. id: null,
  32. userId: null,
  33. headImage: null,
  34. headTitle: null,
  35. indexImage: null,
  36. num: 10,
  37. wxCodeImage: null,
  38. textDetails: null,
  39. },
  40. isLocked: true,
  41. }
  42. },
  43. computed: {
  44. ...mapState(['userInfo']),
  45. },
  46. onLoad(option) {
  47. const { id, state, shareId } = option
  48. if (shareId) {
  49. uni.setStorageSync('shareId', shareId)
  50. }
  51. if (state) {
  52. uni.setStorageSync('state', state)
  53. }
  54. this.id = id
  55. if(uni.getStorageSync('token')){
  56. this.fetchDetails()
  57. }else{
  58. this.$refs.loginPopup.open()
  59. }
  60. },
  61. onShareAppMessage(res) {
  62. const {
  63. headTitle,
  64. indexImage,
  65. } = this.detail
  66. let o = {
  67. title : headTitle,
  68. imageUrl: indexImage,
  69. query: `id=${this.id}&state=0&shareId=${this.userInfo.id}`,
  70. }
  71. this.refreshLockStatus()
  72. return o
  73. },
  74. methods: {
  75. async fetchDetails() {
  76. try {
  77. this.detail = await this.$fetch('getShareInfo', { id: this.id })
  78. } catch (err) {
  79. }
  80. },
  81. async fetchCheckShare(id) {
  82. try {
  83. return await this.$fetch('checkShare', { id })
  84. } catch (err) {
  85. return {}
  86. }
  87. },
  88. async refreshLockStatus() {
  89. const result = await this.fetchCheckShare()
  90. const { title, open } = result
  91. if (open) {
  92. this.isLocked = false
  93. this.$refs.popupUnlock.close();
  94. return
  95. }
  96. title && uni.showToast({
  97. title,
  98. icon: 'none',
  99. duration: 3000
  100. })
  101. },
  102. openPopup() {
  103. this.$refs.popupUnlock.open();
  104. },
  105. async onAdd() {
  106. const result = await this.fetchCheckShare()
  107. const { open } = result
  108. // todo: check
  109. if (open) { // 转发已达标
  110. this.isLocked = false
  111. return
  112. }
  113. this.openPopup()
  114. }
  115. },
  116. }
  117. </script>
  118. <style scoped lang="scss">
  119. .page {
  120. position: relative;
  121. height: 100vh;
  122. }
  123. .content {
  124. display: flex;
  125. flex-direction: column;
  126. align-items: center;
  127. }
  128. .avatar {
  129. width: 180rpx;
  130. height: 180rpx;
  131. margin-top: 127rpx;
  132. }
  133. .nick-name {
  134. color: #1B1B1B;
  135. font-size: 32rpx;
  136. margin-top: 30rpx;
  137. }
  138. .btn, .qr {
  139. position: absolute;
  140. }
  141. .btn {
  142. width: calc(100% - 60rpx*2);
  143. height: auto;
  144. left: 60rpx;
  145. bottom: 292rpx;
  146. background-color: #07C160;
  147. border: none;
  148. color: #FFFFFF;
  149. font-size: 28rpx;
  150. line-height: 1;
  151. border-radius: 45rpx;
  152. padding: 25rpx 0;
  153. box-sizing: border-box;
  154. }
  155. .qr {
  156. width: 350rpx;
  157. height: 350rpx;
  158. bottom: 269rpx;
  159. }
  160. </style>