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

250 lines
4.5 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" :read-only="true" @ready="onEditorReady"></editor>
  7. </view>
  8. <uv-overlay :show="true" :opacity="0" zIndex="998">
  9. <navbar leftClick @leftClick="$utils.navigateBack" />
  10. <button class="btn" type="success" @click="onJoin">查看更多</button>
  11. <popupUnlock ref="popupUnlock" src="../static/sharing/unlock-article.png"></popupUnlock>
  12. <popupQrCode ref="popupQrCode" :src="detail.wxCodeImage"></popupQrCode>
  13. </uv-overlay>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. mapState
  19. } from 'vuex'
  20. import shareLog from '@/utils/shareLog'
  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. if (this.detail.id) { // 转发后返回页面的场景
  51. this.refreshLockStatus()
  52. }
  53. },
  54. async onLoad(option) {
  55. const {
  56. id,
  57. state,
  58. shareId
  59. } = option
  60. if (shareId) {
  61. uni.setStorageSync('shareId', shareId)
  62. }
  63. if (state) {
  64. uni.setStorageSync('state', state)
  65. }
  66. if (id) {
  67. uni.setStorageSync('id', id)
  68. }
  69. this.id = id
  70. // if (uni.getStorageSync('token')) {
  71. // this.initData()
  72. // } else {
  73. // uni.navigateTo({
  74. // url: '/pages_order/auth/wxLogin'
  75. // })
  76. // }
  77. this.initData()
  78. },
  79. onShareAppMessage(res) {
  80. const {
  81. headTitle,
  82. headImage,
  83. } = this.detail
  84. let o = {
  85. title: headTitle,
  86. imageUrl: headImage,
  87. query: `id=${this.id}&state=3&shareId=${this.userInfo.id}`,
  88. }
  89. //调用增加分享次数的方法
  90. const params = {
  91. id: this.id,
  92. state: "3",
  93. }
  94. this.$fetch('addLogShareInfo', params)
  95. shareLog.insert(this.id)
  96. return o
  97. },
  98. methods: {
  99. onEditorReady() {
  100. uni.createSelectorQuery().select('#editor').context((res) => {
  101. this.editorCtx = res.context
  102. }).exec()
  103. },
  104. initEditor(html) {
  105. if (!this.editorCtx) {
  106. setTimeout(() => {
  107. this.initEditor(html)
  108. }, 200)
  109. return
  110. }
  111. this.editorCtx.setContents({
  112. html
  113. })
  114. },
  115. async fetchDetails(id) {
  116. try {
  117. this.detail = await this.$fetch('getArticleShareInfo', {
  118. id
  119. })
  120. } catch (err) {
  121. }
  122. },
  123. async initData() {
  124. await this.fetchDetails(this.id)
  125. this.initEditor(this.detail.textDetails)
  126. },
  127. async fetchCheckShare() {
  128. try {
  129. return shareLog.check(this.id, this.detail.num)
  130. } catch (err) {
  131. return {}
  132. }
  133. },
  134. async refreshLockStatus() {
  135. const result = await this.fetchCheckShare()
  136. const {
  137. title,
  138. open
  139. } = result
  140. console.log('--open', open)
  141. this.$refs.popupUnlock.close();
  142. if (open) {
  143. this.isLocked = false
  144. this.$refs.popupQrCode.open()
  145. return
  146. }
  147. title && uni.showToast({
  148. title,
  149. icon: 'none',
  150. duration: 3000
  151. })
  152. },
  153. async onJoin() {
  154. if (!this.isLocked) {
  155. this.$refs.popupQrCode.open()
  156. return
  157. }
  158. const result = await this.fetchCheckShare()
  159. const {
  160. open,
  161. need_num,
  162. num
  163. } = result
  164. console.log('--open', open)
  165. if (open) { // 转发已达标
  166. this.isLocked = false
  167. this.$refs.popupQrCode.open()
  168. } else {
  169. uni.showToast({
  170. title: `还需转发${need_num - num}`,
  171. icon: 'none',
  172. })
  173. this.$refs.popupUnlock.open();
  174. }
  175. },
  176. }
  177. }
  178. </script>
  179. <style scoped lang="scss">
  180. .content {
  181. padding: 40rpx 20rpx;
  182. padding-top: calc(#{$navbar-height} + var(--status-bar-height) + 20rpx + 40rpx);
  183. }
  184. .title {
  185. color: #474747;
  186. font-size: 36rpx;
  187. font-weight: 700;
  188. }
  189. .desc {
  190. color: #A2A2A2;
  191. font-size: 24rpx;
  192. margin-top: 6rpx;
  193. }
  194. .editor {
  195. margin-top: 22rpx;
  196. height: 40vh;
  197. }
  198. .btn {
  199. position: absolute;
  200. width: calc(100% - 60rpx*2);
  201. height: auto;
  202. left: 60rpx;
  203. bottom: 292rpx;
  204. background-color: #07C160;
  205. border: none;
  206. color: #FFFFFF;
  207. font-size: 28rpx;
  208. line-height: 1;
  209. border-radius: 45rpx;
  210. padding: 25rpx 0;
  211. box-sizing: border-box;
  212. }
  213. </style>