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

223 lines
4.6 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 { 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. this.refreshLockStatus()
  82. this.closePopup()
  83. return o
  84. },
  85. methods: {
  86. onEditorReady() {
  87. uni.createSelectorQuery().select('#editor').context((res) => {
  88. this.editorCtx = res.context
  89. }).exec()
  90. },
  91. initEditor(html) {
  92. if (!this.editorCtx) {
  93. setTimeout(() => {
  94. this.initEditor(html)
  95. }, 200)
  96. return
  97. }
  98. this.editorCtx.setContents({ html })
  99. },
  100. async fetchDetails(id) {
  101. try {
  102. this.detail = await this.$fetch('getArticleShareInfo', { id })
  103. } catch (err) {
  104. }
  105. },
  106. async initData() {
  107. await this.fetchDetails(this.id)
  108. this.initEditor(this.detail.textDetails)
  109. },
  110. async fetchCheckShare() {
  111. try {
  112. return await this.$fetch('checkArticleShare', { id: this.id })
  113. } catch (err) {
  114. return {}
  115. }
  116. },
  117. async refreshLockStatus() {
  118. const result = await this.fetchCheckShare()
  119. const { title, open } = result
  120. console.log('--open', open)
  121. this.$refs.popupUnlock.close();
  122. if (open) {
  123. this.isLocked = false
  124. this.$refs.popupQrCode.open()
  125. return
  126. }
  127. title && uni.showToast({
  128. title,
  129. icon: 'none',
  130. duration: 3000
  131. })
  132. },
  133. async onJoin() {
  134. if (!this.isLocked) {
  135. this.$refs.popupQrCode.open()
  136. return
  137. }
  138. const result = await this.fetchCheckShare()
  139. const { open, need_num, num } = result
  140. console.log('--open', open)
  141. if (open) { // 转发已达标
  142. this.isLocked = false
  143. this.$refs.popupQrCode.open()
  144. } else {
  145. uni.showToast({
  146. title: `还需转发${need_num - num}`,
  147. icon: 'none',
  148. })
  149. this.$refs.popupUnlock.open();
  150. }
  151. },
  152. }
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .content {
  157. padding: 40rpx 20rpx;
  158. padding-top: calc(#{$navbar-height} + var(--status-bar-height) + 20rpx + 40rpx);
  159. }
  160. .title {
  161. color: #474747;
  162. font-size: 36rpx;
  163. font-weight: 700;
  164. }
  165. .desc {
  166. color: #A2A2A2;
  167. font-size: 24rpx;
  168. margin-top: 6rpx;
  169. }
  170. .editor {
  171. margin-top: 22rpx;
  172. height: 40vh;
  173. }
  174. .btn {
  175. position: absolute;
  176. width: calc(100% - 60rpx*2);
  177. height: auto;
  178. left: 60rpx;
  179. bottom: 292rpx;
  180. background-color: #07C160;
  181. border: none;
  182. color: #FFFFFF;
  183. font-size: 28rpx;
  184. line-height: 1;
  185. border-radius: 45rpx;
  186. padding: 25rpx 0;
  187. box-sizing: border-box;
  188. }
  189. </style>