index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <v-cover v-if="state.page == '封面页'"></v-cover>
  3. <v-invite v-if="state.page == '邀请页'"></v-invite>
  4. <v-result v-if="state.page == '开奖页'"></v-result>
  5. <open-box v-show="state.open_box.show"></open-box>
  6. <v-toast :show="state.toast.show" :txt="state.toast.txt"></v-toast>
  7. </template>
  8. <script setup>
  9. import { reactive, provide, onMounted } from 'vue'
  10. import VCover from '@/view/iframe/treasure-hunt/cover.vue'
  11. import VInvite from '@/view/iframe/treasure-hunt/invite.vue'
  12. import VResult from '@/view/iframe/treasure-hunt/result.vue'
  13. import { inviteDetail, treasureDetail, treasureOpen } from '@/http/treasure.js'
  14. import { reSetBindTwtterId } from '@/http/help.js'
  15. import { getQueryString } from '@/uilts/help'
  16. import VToast from '@/view/iframe/treasure-hunt/components/toast.vue'
  17. import OpenBox from '@/view/iframe/treasure-hunt/components/open-box.vue'
  18. let state = reactive({
  19. page: '',
  20. detail: {},
  21. open_box: {
  22. show: false,
  23. data: {}
  24. },
  25. open_btn: {
  26. txt: '',
  27. disabled: false
  28. },
  29. dialog: {
  30. show: false,
  31. },
  32. start_task: {},
  33. toast: {}
  34. })
  35. provide('state', state)
  36. let params = {}
  37. onMounted(() => {
  38. params = JSON.parse(getQueryString('params') || '{}')
  39. state.postId = params.post_Id || ''
  40. state.tweetId = params.tweet_Id || ''
  41. state.invite_code = params.invite_code || ''
  42. state.init()
  43. })
  44. state.init = (callback) => {
  45. if (params.page_type == '邀请链接') {
  46. // 邀请链接
  47. inviteDetail({
  48. params: {
  49. inviteCode: params.invite_code
  50. }
  51. }).then((res) => {
  52. if (res.code == 0) {
  53. handleCommon(res, callback)
  54. }
  55. })
  56. } else if (params.page_type == '原始链接') {
  57. // 原始链接
  58. treasureDetail({
  59. params: {
  60. postId: params.post_Id
  61. }
  62. }).then((res) => {
  63. if (res.code == 0) {
  64. handleCommon(res, callback)
  65. }
  66. })
  67. }
  68. }
  69. const handleCommon = (res, callback) => {
  70. state.detail = res.data
  71. state.postId = state.detail.postId
  72. try {
  73. state.tasks = JSON.parse(state.detail.startCondition)
  74. let follows = state.tasks.filter((item) => { return item.type == 1 })
  75. if (follows.length) {
  76. state.follows = follows[0].relatedUsers
  77. }
  78. }
  79. catch (error) {
  80. console.error('catch', error)
  81. }
  82. handleStatus()
  83. if (!res.data.srcContentId) {
  84. reSetBindTwtterId({
  85. postId: state.postId || '',
  86. tweetId: state.tweetId || ''
  87. })
  88. }
  89. callback && callback()
  90. }
  91. let silver_open_box_big = require('@/assets/img/icon-silver-open-box-big.png')
  92. let gold_open_box_big = require('@/assets/img/icon-gold-open-box-big.png')
  93. state.treasureOpen = () => {
  94. treasureOpen({
  95. params: {
  96. postId: state.postId,
  97. treasureId: state.treasureId,
  98. }
  99. }).then((res) => {
  100. if (res.code == 0) {
  101. for (let i in state.open_box) {
  102. if (state.boxs[i].id == state.treasureId) {
  103. if (i > 0) {
  104. state.open_box.icon = gold_open_box_big
  105. } else {
  106. state.open_box.icon = silver_open_box_big
  107. }
  108. break
  109. }
  110. }
  111. state.open_box.show = true
  112. state.open_box.data = res.data
  113. // icon
  114. state.init(() => {
  115. state.inviteInit()
  116. })
  117. } else {
  118. switch (String(res.code)) {
  119. case '2037':
  120. state.dialog.show = true
  121. break;
  122. case '2203':
  123. state.toast.txt = 'You have already opened the treasure chest'
  124. state.toast.show = true
  125. break
  126. case '2208':
  127. state.toast.txt = 'No treasure chests to open'
  128. state.toast.show = true
  129. break
  130. default:
  131. state.toast.txt = 'System Error'
  132. state.toast.show = true
  133. break
  134. }
  135. state.toast.has_icon = false
  136. setTimeout(() => {
  137. state.toast.show = false
  138. }, 2000)
  139. state.init(() => {
  140. state.inviteInit()
  141. })
  142. }
  143. })
  144. }
  145. const handleStatus = () => {
  146. // 如果 夺宝状态 = 未开始
  147. // 显示未开始页面
  148. // 如果 夺宝状态 = 进行中
  149. // 如果 夺宝参与状态 = 未参与夺宝
  150. // 显示封面页
  151. // 如果 夺宝参与状态 = 已参与夺宝
  152. // 显示邀请页
  153. // 如果 夺宝状态 = 已结束
  154. // 显示结束页面
  155. let { status, joinStatus } = state.detail || {}
  156. state.open_btn.txt = 'Start'
  157. // 如果 夺宝状态 = 未开始
  158. if (status == 0) {
  159. state.page = '封面页'
  160. }
  161. // 如果 夺宝状态 = 进行中
  162. else if (status == 1) {
  163. // 如果 夺宝参与状态 = 未参与夺宝
  164. if (joinStatus == 0) {
  165. // 显示封面页
  166. state.page = '封面页'
  167. state.cover_status = '有邀请人'
  168. state.open_btn.txt = 'Start'
  169. // state.cover_status = '无邀请人'
  170. // state.cover_status = '奖励已被领光'
  171. }
  172. // 如果 夺宝参与状态 = 已参与夺宝
  173. else if (joinStatus == 1) {
  174. state.page = '邀请页'
  175. }
  176. }
  177. // 如果 夺宝状态 = 已结束
  178. else {
  179. state.page = '封面页'
  180. state.cover_status = '奖励已被领光'
  181. state.open_btn.txt = 'Look for more treasures'
  182. }
  183. }
  184. </script>
  185. <style lang="scss" >
  186. html,
  187. body {
  188. margin: 0;
  189. padding: 0;
  190. }
  191. </style>