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

222 lines
4.7 KiB

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