cover.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <!-- 封面页 -->
  3. <div class="cover" v-show-log="state.log_show">
  4. <v-head :left-data="state.detail.postUserInfo || null"></v-head>
  5. <div class="waring" v-if="state.cover_status == '奖励已被领光'">
  6. <div>All treasures</div>
  7. <div>are hunted</div>
  8. </div>
  9. <!-- 邀请人 -->
  10. <template v-else>
  11. <div class="invite"
  12. v-if="state.detail.inviteUserInfo && state.detail.inviteUserInfo.nickName != state.detail.postUserInfo.nickName">
  13. <img :src="state.detail.inviteUserInfo.avatarUrl" alt="" />
  14. <span>@{{ state.detail.inviteUserInfo.nickName }} invites you</span>
  15. </div>
  16. <div class="in-invite" v-else></div>
  17. <div class="treasure">
  18. <component-zoom width="335" fontSize="34" style="margin:0 auto;">
  19. <span>Treasure</span>
  20. <span>${{ toLast(state.detail.amountUsdValue, 2) }}</span>
  21. </component-zoom>
  22. </div>
  23. <div class="gain" v-if="Number(state.detail.upGainAmountValue) > 0">
  24. <component-zoom width="335" fontSize="34" style="margin:0 auto;">
  25. <span>Your Gain Up to</span>
  26. <span>$</span>
  27. <span>{{ toLast(state.detail.upGainAmountValue, 3) }}</span>
  28. </component-zoom>
  29. </div>
  30. <div class="coin" v-if="state.detail.currencySymbol != 'USD'">
  31. <img :src="state.detail.currencyIconPath" alt="" />
  32. <span> {{ state.detail.currencySymbol }} equivalent (Crypto)</span>
  33. </div>
  34. <div class="coin" v-else></div>
  35. </template>
  36. <div class="box">
  37. <img :src="require('@/assets/img/icon-gold-close-box.png')" alt="" v-if="state.cover_status == '奖励已被领光'" />
  38. <img :src="require('@/assets/img/icon-treasure-box.png')" alt="" v-else />
  39. </div>
  40. <div class="mark" :style="{ 'opacity': state.cover_status == '奖励已被领光' ? '0' : '1' }">
  41. <img :src="require('@/assets/svg/icon-three-line.svg')" alt="" />
  42. <span>to Hunt Treasure</span>
  43. </div>
  44. <v-btn :txt="state.open_btn.txt" :font-size="'17px'" :icon="true" :disabled="false" @onClick="clickBtn"
  45. :loading="state.btn_loading"></v-btn>
  46. </div>
  47. </template>
  48. <script setup>
  49. import { inject } from 'vue'
  50. import VBtn from '@/view/iframe/treasure-hunt/components/btn.vue'
  51. import VHead from '@/view/iframe/treasure-hunt/components/head.vue'
  52. import ComponentZoom from "@/view/components/component-zoom.vue";
  53. import { pageUrl } from "@/http/configAPI.js"
  54. import Report from "@/log-center/log"
  55. import { prepareStart, treasureStart } from '@/http/treasure.js'
  56. import { getChromeCookie, removeChromeCookie, getChromeStorage } from '@/uilts/chromeExtension.js'
  57. import { reSetBindRepost } from '@/http/help.js'
  58. let state = inject('state')
  59. state.log_show = {
  60. businessType: Report.businessType.pageView,
  61. pageSource: Report.pageSource.pending_page,
  62. redPacketType: Report.redPacketType.treasure,
  63. shareLinkId: state.invite_code,
  64. postId: state.postId
  65. }
  66. chrome.storage.onChanged.addListener(changes => {
  67. if (changes.userInfo) {
  68. // let item = JSON.parse(changes.userInfo.newValue)
  69. state.btn_loading = false
  70. state.init()
  71. }
  72. })
  73. const toStart = (req) => {
  74. treasureStart({
  75. params: {
  76. postId: state.postId || '',
  77. inviteCode: state.invite_code || ''
  78. }
  79. }).then((res) => {
  80. if (res.code == 0) {
  81. state.page = '开奖页'
  82. state.start_task = res.data
  83. state.btn_loading = false
  84. if (req.response) {
  85. let repost_tweetId = req.response.data.data.create_tweet.tweet_results.result.rest_id
  86. reSetBindRepost({
  87. inviteCode: res.data.inviteCode,
  88. tweetId: repost_tweetId
  89. })
  90. }
  91. } else {
  92. state.init()
  93. }
  94. }).catch((error) => {
  95. console.error(error)
  96. })
  97. }
  98. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  99. switch (req.actionType) {
  100. case 'DO_TASK':
  101. if (!req.task_type || state.tweetId != req.tweet_Id) {
  102. return
  103. }
  104. if (!req.task_done && req.task_type == 'createTweet') {
  105. state.toast.txt = 'Seems something went wrong, please try again'
  106. state.toast.show = true
  107. state.toast.has_icon = false
  108. setTimeout(() => {
  109. state.toast.show = false
  110. }, 2000)
  111. } else if (req.task_type == 'createTweet' && req.task_done) {
  112. toStart(req);
  113. getChromeStorage('userInfo', (_userInfo) => {
  114. if(_userInfo) {
  115. sendChromeTabMessage({
  116. actionType: "IFRAME_API_GET_TWEET_USER_INFO_REQ",
  117. data: {
  118. screen_name: _userInfo.nickName,
  119. tweetId: state.tweetId,
  120. }
  121. })
  122. }
  123. })
  124. }
  125. break
  126. case 'CONTENT_API_GET_TWEET_USER_INFO_RES':
  127. let twitterFans = 0;
  128. let { user } = req.data || {};
  129. if (user && user.result && user.result.legacy) {
  130. let legacy = user.result.legacy;
  131. twitterFans = legacy ? legacy.followers_count : 0;
  132. }
  133. if (state.tweetId != req.tweetId) return;
  134. Report.reportLog({
  135. objectType: Report.objectType.repostSuccess,
  136. twitterFans: twitterFans,
  137. redPacketType: Report.redPacketType.treasure,
  138. postId: state.postId
  139. });
  140. break;
  141. }
  142. })
  143. const toLast = (num, bit) => {
  144. let str = 1
  145. for (let i = 0; i < bit; i++) {
  146. str = str + '0'
  147. }
  148. let _num = Number(str)
  149. return Math.floor(Number(num) * _num) / _num
  150. }
  151. async function clickBtn() {
  152. let _userInfo = await state.checkIsLogin()
  153. if (!_userInfo) {
  154. return
  155. }
  156. if (state.cover_status == '奖励已被领光') {
  157. Report.reportLog({
  158. pageSource: Report.pageSource.pending_page,
  159. businessType: Report.businessType.buttonClick,
  160. objectType: Report.objectType.getMoreGiveaway,
  161. postId: state.postId
  162. });
  163. window.open('https://twitter.com/search?q=%23denet');
  164. return
  165. }
  166. Report.reportLog({
  167. businessType: Report.businessType.buttonClick,
  168. objectType: Report.objectType.open_button,
  169. pageSource: Report.pageSource.pending_page,
  170. redPacketType: Report.redPacketType.treasure,
  171. shareLinkId: state.invite_code,
  172. postId: state.postId
  173. });
  174. state.btn_loading = true
  175. setTimeout(() => {
  176. if (state.btn_loading == true) {
  177. state.btn_loading = false
  178. }
  179. }, 10000)
  180. // 获取邀请码
  181. getChromeCookie({
  182. name: state.postId,
  183. url: pageUrl,
  184. }, (res) => {
  185. if (res && res.inviteCode) {
  186. state.invite_code = res.inviteCode
  187. }
  188. startBtn()
  189. })
  190. }
  191. const startBtn = () => {
  192. // 获取文本
  193. prepareStart({
  194. params: {
  195. postId: state.postId || '',
  196. inviteCode: state.invite_code || ''
  197. }
  198. }).then((res) => {
  199. if (res.code == 0) {
  200. removeChromeCookie({
  201. name: state.postId,
  202. url: pageUrl,
  203. })
  204. let text = res.data.rePostTweetContent
  205. // 一键三连
  206. chrome.tabs.getCurrent((tab) => {
  207. chrome.tabs.sendMessage(tab.id, {
  208. actionType: "IFRAME_TWITTER_API_DO_TASK",
  209. task_data: {
  210. tweet_Id: state.tweetId,
  211. tweet_text: text
  212. },
  213. task_type: 'tasks',
  214. tasks: state.tasks,
  215. });
  216. })
  217. } else {
  218. state.init()
  219. }
  220. })
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .cover {
  225. width: 375px;
  226. height: 500px;
  227. background: linear-gradient(179.96deg, #25180D 38.82%, #5E4025 55.4%, #876635 61.6%, #24180C 71.59%);
  228. border-radius: 20px;
  229. .head {
  230. padding: 10px;
  231. display: flex;
  232. align-items: center;
  233. img {
  234. width: 16px;
  235. height: 16px;
  236. border-radius: 100px;
  237. }
  238. span {
  239. color: #B69882;
  240. font-weight: 400;
  241. margin-left: 5px;
  242. font-size: 11px;
  243. flex-grow: 0;
  244. }
  245. }
  246. .waring {
  247. margin-top: 54px;
  248. font-weight: 900;
  249. font-size: 34px;
  250. color: #FFFFFF;
  251. text-align: center;
  252. opacity: 0.7;
  253. margin-bottom: 35px;
  254. }
  255. .in {
  256. height: 58px;
  257. }
  258. .in-invite {
  259. height: 28px;
  260. margin-top: 20px;
  261. margin-bottom: 10px;
  262. }
  263. .invite {
  264. background: rgba(255, 255, 255, 0.1);
  265. height: 28px;
  266. display: flex;
  267. align-items: center;
  268. margin: 0 auto;
  269. margin-top: 20px;
  270. margin-bottom: 10px;
  271. border-radius: 100px;
  272. width: fit-content;
  273. padding-right: 11px;
  274. img {
  275. width: 18px;
  276. height: 18px;
  277. border-radius: 100px;
  278. margin-left: 11px;
  279. margin-right: 6px;
  280. }
  281. span {
  282. color: #BE9F89;
  283. }
  284. }
  285. .treasure {
  286. text-align: center;
  287. height: 37px;
  288. display: flex;
  289. align-items: center;
  290. span {
  291. font-size: 34px;
  292. font-weight: 900;
  293. line-height: 40px;
  294. }
  295. span:first-child {
  296. color: #FFC83A;
  297. margin-right: 10px;
  298. }
  299. span:last-child {
  300. color: #FFFFFF;
  301. }
  302. }
  303. .gain {
  304. width: 100%;
  305. background: #332319;
  306. height: 37px;
  307. margin-top: 10px;
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. span {
  312. color: #fff;
  313. font-weight: 500;
  314. font-size: 16px;
  315. line-height: 16px;
  316. }
  317. span:first-child {
  318. font-size: 15px;
  319. line-height: 15px;
  320. margin-right: 10px;
  321. }
  322. span:last-child {
  323. margin-left: 2px;
  324. font-weight: 800;
  325. font-size: 24px;
  326. line-height: 24px;
  327. }
  328. }
  329. .coin {
  330. height: 17px;
  331. display: flex;
  332. align-items: center;
  333. justify-content: center;
  334. margin-top: 10px;
  335. img {
  336. width: 17px;
  337. height: 17px;
  338. }
  339. span {
  340. margin-left: 4px;
  341. font-weight: 400;
  342. font-size: 11px;
  343. line-height: 15px;
  344. color: #FFFFFF;
  345. opacity: 0.7;
  346. }
  347. }
  348. .box {
  349. text-align: center;
  350. img {
  351. width: 160px;
  352. height: 160px;
  353. }
  354. }
  355. .mark {
  356. display: flex;
  357. align-items: center;
  358. justify-content: center;
  359. margin-top: 24px;
  360. margin-bottom: 15px;
  361. span {
  362. font-weight: 500;
  363. font-size: 12px;
  364. line-height: 17px;
  365. color: #65C1FF;
  366. }
  367. }
  368. }
  369. </style>