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

227 lines
4.8 KiB

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