裂变星小程序-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.

191 lines
3.7 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. if (id) {
  55. uni.setStorageSync('id', id)
  56. }
  57. this.id = id
  58. if(uni.getStorageSync('token')){
  59. this.fetchDetails()
  60. }else{
  61. this.$refs.loginPopup.open()
  62. }
  63. },
  64. onShareAppMessage(res) {
  65. const {
  66. headTitle,
  67. indexImage,
  68. } = this.detail
  69. let o = {
  70. title : headTitle,
  71. imageUrl: indexImage,
  72. query: `id=${this.id}&state=0&shareId=${this.userInfo.id}`,
  73. }
  74. this.refreshLockStatus()
  75. return o
  76. },
  77. methods: {
  78. async fetchDetails() {
  79. try {
  80. this.detail = await this.$fetch('getShareInfo', { id: this.id })
  81. } catch (err) {
  82. }
  83. },
  84. async fetchCheckShare(id) {
  85. try {
  86. return await this.$fetch('checkShare', { id })
  87. } catch (err) {
  88. return {}
  89. }
  90. },
  91. async refreshLockStatus() {
  92. const result = await this.fetchCheckShare()
  93. const { title, open } = result
  94. if (open) {
  95. this.isLocked = false
  96. this.$refs.popupUnlock.close();
  97. return
  98. }
  99. title && uni.showToast({
  100. title,
  101. icon: 'none',
  102. duration: 3000
  103. })
  104. },
  105. openPopup() {
  106. this.$refs.popupUnlock.open();
  107. },
  108. async onAdd() {
  109. const result = await this.fetchCheckShare()
  110. const { open } = result
  111. // todo: check
  112. if (open) { // 转发已达标
  113. this.isLocked = false
  114. return
  115. }
  116. this.openPopup()
  117. }
  118. },
  119. }
  120. </script>
  121. <style scoped lang="scss">
  122. .page {
  123. position: relative;
  124. height: 100vh;
  125. }
  126. .content {
  127. display: flex;
  128. flex-direction: column;
  129. align-items: center;
  130. }
  131. .avatar {
  132. width: 180rpx;
  133. height: 180rpx;
  134. margin-top: 127rpx;
  135. }
  136. .nick-name {
  137. color: #1B1B1B;
  138. font-size: 32rpx;
  139. margin-top: 30rpx;
  140. }
  141. .btn, .qr {
  142. position: absolute;
  143. }
  144. .btn {
  145. width: calc(100% - 60rpx*2);
  146. height: auto;
  147. left: 60rpx;
  148. bottom: 292rpx;
  149. background-color: #07C160;
  150. border: none;
  151. color: #FFFFFF;
  152. font-size: 28rpx;
  153. line-height: 1;
  154. border-radius: 45rpx;
  155. padding: 25rpx 0;
  156. box-sizing: border-box;
  157. }
  158. .qr {
  159. width: 350rpx;
  160. height: 350rpx;
  161. bottom: 269rpx;
  162. }
  163. </style>