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

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