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

207 lines
4.4 KiB

  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. <loginPopup ref="loginPopup" @login="initData"/>
  17. </uv-overlay>
  18. </view>
  19. </template>
  20. <script>
  21. import { mapState } from 'vuex'
  22. import loginPopup from '@/components/config/loginPopup.vue'
  23. import popupUnlock from '../components/popupUnlock.vue'
  24. import popupQrCode from '../components/popupQrCode.vue'
  25. export default {
  26. components: {
  27. popupUnlock,
  28. popupQrCode,
  29. loginPopup,
  30. },
  31. data() {
  32. return {
  33. id: null,
  34. detail: {
  35. id: null,
  36. userId: null,
  37. headImage: null,
  38. headTitle: null,
  39. num: 10,
  40. wxCodeImage: null,
  41. textDetails: null,
  42. },
  43. isLocked: true,
  44. }
  45. },
  46. computed: {
  47. ...mapState(['userInfo']),
  48. },
  49. async onLoad(option) {
  50. const { id, state, shareId } = option
  51. if (shareId) {
  52. uni.setStorageSync('shareId', shareId)
  53. }
  54. if (state) {
  55. uni.setStorageSync('state', state)
  56. }
  57. this.id = id
  58. if(uni.getStorageSync('token')){
  59. this.initData()
  60. }else{
  61. this.$refs.loginPopup.open()
  62. }
  63. },
  64. onShareAppMessage(res) {
  65. const {
  66. headTitle,
  67. headImage,
  68. } = this.detail
  69. let o = {
  70. title : headTitle,
  71. imageUrl: headImage,
  72. query: `id=${this.id}&state=3&shareId=${this.userInfo.id}`,
  73. }
  74. // todo: get times and check is unlocked
  75. this.refreshLockStatus()
  76. return o
  77. },
  78. methods: {
  79. onEditorReady() {
  80. uni.createSelectorQuery().select('#editor').context((res) => {
  81. this.editorCtx = res.context
  82. }).exec()
  83. },
  84. initEditor(html) {
  85. if (!this.editorCtx) {
  86. setTimeout(() => {
  87. this.initEditor(html)
  88. }, 200)
  89. return
  90. }
  91. this.editorCtx.setContents({ html })
  92. },
  93. async fetchDetails(id) {
  94. try {
  95. this.detail = await this.$fetch('getArticleShareInfo', { id })
  96. } catch (err) {
  97. }
  98. },
  99. async initData() {
  100. await this.fetchDetails(this.id)
  101. this.initEditor(this.detail.textDetails)
  102. },
  103. async fetchCheckShare(id) {
  104. try {
  105. return await this.$fetch('checkArticleShare', { id })
  106. } catch (err) {
  107. return {}
  108. }
  109. },
  110. async refreshLockStatus() {
  111. const result = await this.fetchCheckShare()
  112. const { title, open } = result
  113. if (open) {
  114. this.isLocked = false
  115. this.$refs.popupUnlock.close();
  116. this.$refs.popupQrCode.open()
  117. return
  118. }
  119. title && uni.showToast({
  120. title,
  121. icon: 'none',
  122. duration: 3000
  123. })
  124. },
  125. async onJoin() {
  126. if (!this.isLocked) {
  127. this.$refs.popupQrCode.open()
  128. return
  129. }
  130. const result = await this.fetchCheckShare()
  131. const { open } = result
  132. if (open) { // 转发已达标
  133. this.isLocked = false
  134. this.$refs.popupQrCode.open()
  135. } else {
  136. this.$refs.popupUnlock.open();
  137. }
  138. },
  139. }
  140. }
  141. </script>
  142. <style scoped lang="scss">
  143. .content {
  144. padding: 40rpx 20rpx;
  145. padding-top: calc(#{$navbar-height} + var(--status-bar-height) + 20rpx + 40rpx);
  146. }
  147. .title {
  148. color: #474747;
  149. font-size: 36rpx;
  150. font-weight: 700;
  151. }
  152. .desc {
  153. color: #A2A2A2;
  154. font-size: 24rpx;
  155. margin-top: 6rpx;
  156. }
  157. .editor {
  158. margin-top: 22rpx;
  159. height: 40vh;
  160. }
  161. .btn {
  162. position: absolute;
  163. width: calc(100% - 60rpx*2);
  164. height: auto;
  165. left: 60rpx;
  166. bottom: 292rpx;
  167. background-color: #07C160;
  168. border: none;
  169. color: #FFFFFF;
  170. font-size: 28rpx;
  171. line-height: 1;
  172. border-radius: 45rpx;
  173. padding: 25rpx 0;
  174. box-sizing: border-box;
  175. }
  176. </style>