boxs.vue 9.2 KB

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