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

229 lines
4.8 KiB

1 week ago
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="title">{{ detail.headTitle || '' }}</view>
  5. <view class="desc">{{ detail.createTime ? `发布于${detail.createTime}` : '' }}</view>
  6. <editor id="editor" class="editor"
  7. :read-only="true"
  8. @ready="onEditorReady"
  9. ></editor>
  10. </view>
  11. <uv-overlay :show="true" :opacity="0" zIndex="998">
  12. <navbar leftClick @leftClick="$utils.navigateBack" />
  13. <button class="btn" type="success" @click="onJoin">查看更多</button>
  14. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-article.png"></popupUnlock>
  15. <popupQrCode ref="popupQrCode" :src="detail.wxCodeImage"></popupQrCode>
  16. </uv-overlay>
  17. </view>
  18. </template>
  19. <script>
  20. import { mapState } from 'vuex'
  21. import popupUnlock from '../components/popupUnlock.vue'
  22. import popupQrCode from '../components/popupQrCode.vue'
  23. export default {
  24. components: {
  25. popupUnlock,
  26. popupQrCode,
  27. },
  28. data() {
  29. return {
  30. id: null,
  31. detail: {
  32. id: null,
  33. userId: null,
  34. headImage: null,
  35. headTitle: null,
  36. num: 0,
  37. wxCodeImage: null,
  38. textDetails: null,
  39. },
  40. isLocked: true,
  41. }
  42. },
  43. computed: {
  44. ...mapState(['userInfo']),
  45. },
  46. onShow() {
  47. if (this.id && uni.getStorageSync('token')) {
  48. this.initData()
  49. }
  50. },
  51. async onLoad(option) {
  52. const { id, state, shareId } = option
  53. if (shareId) {
  54. uni.setStorageSync('shareId', shareId)
  55. }
  56. if (state) {
  57. uni.setStorageSync('state', state)
  58. }
  59. if (id) {
  60. uni.setStorageSync('id', id)
  61. }
  62. this.id = id
  63. if (uni.getStorageSync('token')) {
  64. this.initData()
  65. } else {
  66. uni.navigateTo({
  67. url: '/pages_order/auth/wxLogin'
  68. })
  69. }
  70. },
  71. onShareAppMessage(res) {
  72. const {
  73. headTitle,
  74. headImage,
  75. } = this.detail
  76. let o = {
  77. title : headTitle,
  78. imageUrl: headImage,
  79. query: `id=${this.id}&state=3&shareId=${this.userInfo.id}`,
  80. }
  81. //调用增加分享次数的方法
  82. const params = {
  83. id:this.id,
  84. state:"3",
  85. }
  86. this.$fetch('addLogShareInfo', params)
  87. this.refreshLockStatus()
  88. this.closePopup()
  89. return o
  90. },
  91. methods: {
  92. onEditorReady() {
  93. uni.createSelectorQuery().select('#editor').context((res) => {
  94. this.editorCtx = res.context
  95. }).exec()
  96. },
  97. initEditor(html) {
  98. if (!this.editorCtx) {
  99. setTimeout(() => {
  100. this.initEditor(html)
  101. }, 200)
  102. return
  103. }
  104. this.editorCtx.setContents({ html })
  105. },
  106. async fetchDetails(id) {
  107. try {
  108. this.detail = await this.$fetch('getArticleShareInfo', { id })
  109. } catch (err) {
  110. }
  111. },
  112. async initData() {
  113. await this.fetchDetails(this.id)
  114. this.initEditor(this.detail.textDetails)
  115. },
  116. async fetchCheckShare() {
  117. try {
  118. return await this.$fetch('checkArticleShare', { id: this.id })
  119. } catch (err) {
  120. return {}
  121. }
  122. },
  123. async refreshLockStatus() {
  124. const result = await this.fetchCheckShare()
  125. const { title, open } = result
  126. console.log('--open', open)
  127. this.$refs.popupUnlock.close();
  128. if (open) {
  129. this.isLocked = false
  130. this.$refs.popupQrCode.open()
  131. return
  132. }
  133. title && uni.showToast({
  134. title,
  135. icon: 'none',
  136. duration: 3000
  137. })
  138. },
  139. async onJoin() {
  140. if (!this.isLocked) {
  141. this.$refs.popupQrCode.open()
  142. return
  143. }
  144. const result = await this.fetchCheckShare()
  145. const { open, need_num, num } = result
  146. console.log('--open', open)
  147. if (open) { // 转发已达标
  148. this.isLocked = false
  149. this.$refs.popupQrCode.open()
  150. } else {
  151. uni.showToast({
  152. title: `还需转发${need_num - num}`,
  153. icon: 'none',
  154. })
  155. this.$refs.popupUnlock.open();
  156. }
  157. },
  158. }
  159. }
  160. </script>
  161. <style scoped lang="scss">
  162. .content {
  163. padding: 40rpx 20rpx;
  164. padding-top: calc(#{$navbar-height} + var(--status-bar-height) + 20rpx + 40rpx);
  165. }
  166. .title {
  167. color: #474747;
  168. font-size: 36rpx;
  169. font-weight: 700;
  170. }
  171. .desc {
  172. color: #A2A2A2;
  173. font-size: 24rpx;
  174. margin-top: 6rpx;
  175. }
  176. .editor {
  177. margin-top: 22rpx;
  178. height: 40vh;
  179. }
  180. .btn {
  181. position: absolute;
  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. </style>