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

243 lines
4.1 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. <view v-else class="flex flex-column qr-popup">
  11. <text class="tips">长按识别二维码了解更多内容</text>
  12. <image class="qr" :src="detail.wxCodeImage" :show-menu-by-longpress="true"></image>
  13. </view>
  14. </view>
  15. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-user.png"></popupUnlock>
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. mapState
  21. } from 'vuex'
  22. import shareLog from '@/utils/shareLog'
  23. import popupUnlock from '../components/popupUnlock.vue'
  24. export default {
  25. components: {
  26. popupUnlock,
  27. },
  28. data() {
  29. return {
  30. id: null,
  31. detail: {
  32. id: null,
  33. userId: null,
  34. headImage: null,
  35. headTitle: null,
  36. indexImage: null,
  37. num: 0,
  38. wxCodeImage: null,
  39. textDetails: null,
  40. },
  41. isLocked: true,
  42. }
  43. },
  44. computed: {
  45. ...mapState(['userInfo']),
  46. },
  47. onShow() {
  48. // if (this.id && uni.getStorageSync('token')) {
  49. // this.detail.id ? this.refreshLockStatus() : this.fetchDetails()
  50. // }
  51. if (this.detail.id) { // 转发后返回页面的场景
  52. this.refreshLockStatus()
  53. }
  54. },
  55. onLoad(option) {
  56. const {
  57. id,
  58. state,
  59. shareId
  60. } = option
  61. if (shareId) {
  62. uni.setStorageSync('shareId', shareId)
  63. }
  64. if (state) {
  65. uni.setStorageSync('state', state)
  66. }
  67. if (id) {
  68. uni.setStorageSync('id', id)
  69. }
  70. this.id = id
  71. // if (uni.getStorageSync('token')) {
  72. // this.fetchDetails()
  73. // } else {
  74. // uni.navigateTo({
  75. // url: '/pages_order/auth/wxLogin'
  76. // })
  77. // }
  78. this.fetchDetails()
  79. },
  80. onShareAppMessage(res) {
  81. const {
  82. textDetails,
  83. indexImage,
  84. } = this.detail
  85. let o = {
  86. title: textDetails,
  87. imageUrl: indexImage,
  88. query: `id=${this.id}&state=0&shareId=${this.userInfo.id}`,
  89. }
  90. //调用增加分享次数的方法
  91. const params = {
  92. id: this.id,
  93. state: "0",
  94. }
  95. // this.$fetch('addLogShareInfo', params)
  96. shareLog.insert(this.id)
  97. return o
  98. },
  99. methods: {
  100. async fetchDetails() {
  101. try {
  102. this.detail = await this.$fetch('getShareInfo', {
  103. id: this.id
  104. })
  105. } catch (err) {
  106. }
  107. },
  108. async fetchCheckShare() {
  109. try {
  110. return await shareLog.check(this.id, this.detail.num)
  111. } catch (err) {
  112. return {}
  113. }
  114. },
  115. async refreshLockStatus() {
  116. const result = await this.fetchCheckShare()
  117. const {
  118. title,
  119. open
  120. } = result
  121. console.log('--open', open)
  122. this.$refs.popupUnlock.close();
  123. if (open) {
  124. this.isLocked = false
  125. return
  126. }
  127. title && uni.showToast({
  128. title,
  129. icon: 'none',
  130. duration: 3000
  131. })
  132. },
  133. openPopup() {
  134. this.$refs.popupUnlock.open();
  135. },
  136. async onAdd() {
  137. const result = await this.fetchCheckShare()
  138. const {
  139. open,
  140. need_num,
  141. num
  142. } = result
  143. console.log('--open', open)
  144. if (open) { // 转发已达标
  145. this.isLocked = false
  146. return
  147. }
  148. uni.showToast({
  149. title: `还需转发${need_num - num}`,
  150. icon: 'none',
  151. })
  152. this.openPopup()
  153. }
  154. },
  155. }
  156. </script>
  157. <style scoped lang="scss">
  158. .page {
  159. position: relative;
  160. height: 100vh;
  161. }
  162. .content {
  163. display: flex;
  164. flex-direction: column;
  165. align-items: center;
  166. }
  167. .avatar {
  168. width: 180rpx;
  169. height: 180rpx;
  170. margin-top: 127rpx;
  171. }
  172. .nick-name {
  173. color: #1B1B1B;
  174. font-size: 32rpx;
  175. margin-top: 30rpx;
  176. }
  177. .btn,
  178. .qr-popup {
  179. position: absolute;
  180. }
  181. .btn {
  182. width: calc(100% - 60rpx*2);
  183. height: auto;
  184. left: 60rpx;
  185. bottom: 292rpx;
  186. background-color: #07C160;
  187. border: none;
  188. color: #FFFFFF;
  189. font-size: 28rpx;
  190. line-height: 1;
  191. border-radius: 45rpx;
  192. padding: 25rpx 0;
  193. box-sizing: border-box;
  194. }
  195. .qr-popup {
  196. width: 100vw;
  197. bottom: 269rpx;
  198. .tips {
  199. color: #1B1B1B;
  200. font-size: 32rpx;
  201. }
  202. }
  203. .qr {
  204. margin-top: 40rpx;
  205. width: 350rpx;
  206. height: 350rpx;
  207. }
  208. </style>