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

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