boxs.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <div class="area-boxs">
  3. <!-- 箱子 -->
  4. <div class="box-process">
  5. <div class="item" v-for="item, i in state.boxs"
  6. :key="i"
  7. :style="{ 'margin-left': item.icon_margin_left, 'z-index': 10 - i }">
  8. <!--悬浮 -->
  9. <!-- < hover - tip : txt=" item.txt" v-show="item.show || item.openStatus" :icon="item.hover_icon">
  10. </hover-tip> -->
  11. <!-- 金额 -->
  12. <span class="money" :style="{ 'color': item.money_color, 'top': item.money_top }">
  13. <img :src="require('@/assets/svg/icon-green-yes.svg')" alt="" v-if="item.openStatus == 1" />
  14. {{ item.txt }}
  15. </span>
  16. <!-- 宝箱 -->
  17. <img :src="item.icon" alt="" @mouseenter="mouseItem(i)" @mouseleave="mouseLeaveItem(i)"
  18. :style="{ 'width': item.icon_width, 'height': item.icon_width }" class="box"
  19. :class="{ 'active': i == 0 && item.openStatus == 0 ? true : item.openStatus == 0 && state.boxs[i-1]['openStatus'] == 1 }" @click="clickBox(item)" />
  20. <!-- 发光 -->
  21. <img :src="require('@/assets/img/icon-flash-active.png')" alt="" class="flash"
  22. v-if="i == 0 && item.openStatus == 0 ? true : item.openStatus == 0 && state.boxs[i-1]['openStatus'] == 1"
  23. :style="{ 'margin-left': item.flash_margin_top, 'margin-top': item.flash_margin_top, 'width': item.flash_width, 'height': item.flash_width }" />
  24. <!-- 进度条 -->
  25. <div class="line" :style="{ 'width': item.line_width, 'left': item.line_left }">
  26. <div class="full" :style="{ 'width': item.full_width }"></div>
  27. </div>
  28. </div>
  29. </div>
  30. <!-- 人数 -->
  31. <div class="people">
  32. <div class="item" v-for="item, i in state.boxs"
  33. :style="{ 'margin-left': item.icon_margin_left, 'width': item.icon_width }">
  34. <img :src="require('@/assets/svg/icon-user1.svg')" alt="" />
  35. <span>{{ item.inviteProgress }}</span>
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script setup>
  41. import { onMounted, inject, watch } from 'vue'
  42. import { checkIsLogin } from '@/uilts/chromeExtension'
  43. let state = inject('state')
  44. // ---- box 区域
  45. let silver_close_box = require('@/assets/img/icon-silver-close-box.png')
  46. let silver_open_box = require('@/assets/img/icon-silver-open-box.png')
  47. let gold_open_box = require('@/assets/img/icon-gold-open-box.png')
  48. let gold_close_box = require('@/assets/img/icon-gold-close-box.png')
  49. let purple_open_box = require('@/assets/img/icon-purple-open-box.png')
  50. let purple_close_box = require('@/assets/img/icon-purple-close-box.png')
  51. let global_refresh = inject('global_refresh')
  52. watch(global_refresh, () => {
  53. if (global_refresh.value) {
  54. init()
  55. }
  56. })
  57. onMounted(() => {
  58. init()
  59. })
  60. const init = () => {
  61. boxsStatus()
  62. btnStatus()
  63. }
  64. async function clickBox(item) {
  65. let _userInfo = await checkIsLogin()
  66. if (!_userInfo) {
  67. return
  68. }
  69. if (item.openStatus == 0 && item.taskFinishStatus == 1 && state.btn_loading == false) {
  70. state.btn_loading = true
  71. state.treasureOpen()
  72. }
  73. }
  74. state.boxs = [{
  75. icon: '',
  76. icon_open: silver_open_box,
  77. icon_close: silver_close_box,
  78. icon_margin_left: '17px',
  79. icon_width: '46px',
  80. show: false,
  81. flash_width: '70px',
  82. flash_margin_top: `-${70 / 2}px`,
  83. line_width: '25px',
  84. line_left: `-${25 - 10}px`,
  85. money_color: '#BFCCE4',
  86. money_top: '-20px'
  87. }, {
  88. icon: '',
  89. icon_open: gold_open_box,
  90. icon_close: gold_close_box,
  91. show: false,
  92. icon_width: '46px',
  93. flash_width: '70px',
  94. icon_margin_left: '33px',
  95. flash_margin_top: `-${70 / 2}px`,
  96. line_width: '55px',
  97. line_left: `-${55 - 10}px`,
  98. money_color: '#FCB936', money_top: '-20px'
  99. }, {
  100. icon: '',
  101. icon_open: gold_open_box,
  102. icon_close: gold_close_box,
  103. show: false,
  104. icon_width: '66px',
  105. flash_width: '90px',
  106. icon_margin_left: '31px',
  107. flash_margin_top: `-${90 / 2}px`,
  108. line_width: '60px',
  109. line_left: `-${60 - 15}px`,
  110. money_color: '#FCB936', money_top: '-15px'
  111. }, {
  112. icon: purple_close_box,
  113. icon_open: purple_open_box,
  114. icon_close: purple_close_box,
  115. show: false,
  116. icon_width: '84px',
  117. flash_width: '108px',
  118. icon_margin_left: '23px',
  119. flash_margin_top: `-${108 / 2}px`,
  120. line_width: '60px',
  121. line_left: `-${60 - 20}px`,
  122. money_color: '#FCB936', money_top: '-10px'
  123. }]
  124. const setLineFull = (box_num = 0, finishNeedInviteCount = 0, successInviteCount = 0) => {
  125. state.boxs[box_num].full_width = `${(successInviteCount / finishNeedInviteCount) * 100}%`
  126. }
  127. const btnStatus = () => {
  128. for (let i in state.boxs) {
  129. if (state.boxs[i].taskFinishStatus == 0) {
  130. let num = state.boxs[i].finishNeedInviteCount - state.boxs[i].successInviteCount
  131. if (num == 1) {
  132. state.open_btn.txt = 'Invite 1 Friend to Open'
  133. } else {
  134. state.open_btn.txt = `Invite ${num} Friends to Open`
  135. }
  136. state.open_btn.disabled = true
  137. break
  138. }
  139. }
  140. state.treasureId = ''
  141. let open_num = 0
  142. // 有打开的箱子 Open the chest
  143. state.boxs.forEach((item, index) => {
  144. if (item.taskFinishStatus == 1 && item.openStatus == 0) {
  145. state.open_btn.txt = 'Open the Treasure Chest'
  146. state.open_btn.disabled = false
  147. if (!state.treasureId) {
  148. state.treasureId = item.id
  149. }
  150. }
  151. setLineFull(index, item.finishNeedInviteCount, item.successInviteCount)
  152. // 箱子全部打开了
  153. if (item.openStatus == 1) {
  154. open_num++
  155. }
  156. if (open_num == state.boxs.length) {
  157. state.open_btn.txt = 'All Chests Have Been Opened'
  158. state.open_btn.disabled = true
  159. }
  160. })
  161. }
  162. const mouseItem = (i) => {
  163. state.boxs[i].show = true
  164. state.active_share_channel = true
  165. }
  166. const mouseLeaveItem = (i) => {
  167. state.boxs[i].show = false
  168. state.active_share_channel = false
  169. }
  170. const boxsStatus = () => {
  171. state.detail.treasureRecords.forEach((item, index) => {
  172. let box = state.boxs[index]
  173. if (item.openStatus == 0) {
  174. box.icon = box.icon_close
  175. } else {
  176. box.icon = box.icon_open
  177. }
  178. box.txt = `$${item.targetAmountUsdValue}`
  179. state.boxs[index] = Object.assign(box, item)
  180. })
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .area-boxs {
  185. position: relative;
  186. .people {
  187. display: flex;
  188. position: absolute;
  189. bottom: 0px;
  190. left: 10px;
  191. .item {
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. text-align: center;
  196. user-select: none;
  197. img {
  198. user-select: none;
  199. width: 16px;
  200. height: 16px;
  201. margin-right: 3px;
  202. cursor: pointer;
  203. }
  204. span {
  205. color: #FFFFFF;
  206. opacity: 0.4;
  207. font-weight: 500;
  208. font-size: 12px;
  209. }
  210. }
  211. }
  212. .box-process {
  213. width: 350px;
  214. height: 90px;
  215. margin: 0 auto;
  216. display: flex;
  217. align-items: center;
  218. img {
  219. width: 60px;
  220. height: 60px;
  221. z-index: 2;
  222. user-select: none;
  223. }
  224. .item {
  225. z-index: 2;
  226. display: flex;
  227. justify-content: center;
  228. position: relative;
  229. .box {
  230. cursor: pointer;
  231. }
  232. .active {
  233. animation: bounce-up 0.5s linear infinite;
  234. }
  235. .flash {
  236. position: absolute;
  237. left: 50%;
  238. top: 50%;
  239. z-index: 0;
  240. width: 100%;
  241. height: 100%;
  242. }
  243. .money {
  244. display: flex;
  245. align-items: center;
  246. white-space: nowrap;
  247. position: absolute;
  248. top: -20px;
  249. font-weight: 700;
  250. font-size: 16px;
  251. img {
  252. width: 13px;
  253. height: 13px;
  254. margin-right: 4px;
  255. }
  256. }
  257. .line {
  258. width: 40px;
  259. height: 4px;
  260. background: rgba(255, 210, 59, 0.2);
  261. position: absolute;
  262. border-radius: 100px;
  263. overflow: hidden;
  264. left: -40px;
  265. top: 50%;
  266. .full {
  267. position: absolute;
  268. left: 0;
  269. top: 0;
  270. height: 4px;
  271. width: 0px;
  272. background: #FFD23B;
  273. }
  274. }
  275. }
  276. }
  277. }
  278. @keyframes bounce-up {
  279. 25% {
  280. -webkit-transform: translateY(1px);
  281. }
  282. 50%,
  283. 100% {
  284. -webkit-transform: translateY(0);
  285. }
  286. 75% {
  287. -webkit-transform: translateY(-1px);
  288. }
  289. }
  290. </style>