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

236 lines
5.0 KiB

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