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

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