裂变星小程序-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 }, false)
  84. } catch (err) {
  85. return {}
  86. }
  87. },
  88. async refreshLockStatus() {
  89. const res = await this.fetchCheckShare()
  90. const { result, message } = res
  91. if (result) {
  92. this.isLocked = false
  93. this.$refs.popupUnlock.close();
  94. this.$refs.popupQrCode.open()
  95. return
  96. }
  97. message && uni.showToast({
  98. title: message,
  99. icon: 'none'
  100. })
  101. },
  102. async onJoin() {
  103. if (!this.isLocked) {
  104. this.$refs.popupQrCode.open()
  105. return
  106. }
  107. const res = await this.fetchCheckShare()
  108. const { result, message } = res
  109. if (result) { // 转发已达标
  110. this.isLocked = false
  111. this.$refs.popupQrCode.open()
  112. } else {
  113. this.$refs.popupUnlock.open();
  114. }
  115. },
  116. }
  117. }
  118. </script>
  119. <style scoped lang="scss">
  120. .content {
  121. padding: 40rpx 20rpx;
  122. padding-top: calc(#{$navbar-height} + var(--status-bar-height) + 20rpx + 40rpx);
  123. }
  124. .title {
  125. color: #474747;
  126. font-size: 36rpx;
  127. font-weight: 700;
  128. }
  129. .desc {
  130. color: #A2A2A2;
  131. font-size: 24rpx;
  132. margin-top: 6rpx;
  133. }
  134. .editor {
  135. margin-top: 22rpx;
  136. height: 40vh;
  137. }
  138. .btn {
  139. position: absolute;
  140. width: calc(100% - 60rpx*2);
  141. height: auto;
  142. left: 60rpx;
  143. bottom: 292rpx;
  144. background-color: #07C160;
  145. border: none;
  146. color: #FFFFFF;
  147. font-size: 28rpx;
  148. line-height: 1;
  149. border-radius: 45rpx;
  150. padding: 25rpx 0;
  151. box-sizing: border-box;
  152. }
  153. </style>