cover.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. <div class="footer">
  45. <v-btn :txt="state.open_btn.txt" :font-size="'17px'" :icon="true" :disabled="false" @onClick="clickBtn"
  46. :loading="state.btn_loading"></v-btn>
  47. </div>
  48. </div>
  49. </template>
  50. <script setup>
  51. import { inject } from 'vue'
  52. import VBtn from '@/view/iframe/treasure-hunt/components/btn.vue'
  53. import VHead from '@/view/iframe/treasure-hunt/components/head.vue'
  54. import ComponentZoom from "@/view/components/component-zoom.vue";
  55. import { pageUrl } from "@/http/configAPI.js"
  56. import Report from "@/log-center/log"
  57. import { prepareStart, treasureStart } from '@/http/treasure.js'
  58. import { getChromeCookie, removeChromeCookie, getChromeStorage, sendChromeTabMessage } from '@/uilts/chromeExtension.js'
  59. import { reSetBindRepost } from '@/http/help.js'
  60. import { guid } from '@/uilts/help.js'
  61. let state = inject('state')
  62. let global_userInfo
  63. state.log_show = {
  64. businessType: Report.businessType.pageView,
  65. pageSource: Report.pageSource.pending_page,
  66. redPacketType: Report.redPacketType.treasure,
  67. shareLinkId: state.invite_code,
  68. postId: state.postId
  69. }
  70. chrome.storage.onChanged.addListener(changes => {
  71. if (changes.userInfo && changes.userInfo.newValue) {
  72. // let item = JSON.parse(changes.userInfo.newValue)
  73. state.btn_loading = false
  74. state.init()
  75. }
  76. })
  77. let to_start_time = new Date().getTime()
  78. let now_time
  79. const toStart = (req) => {
  80. now_time = new Date().getTime()
  81. if (now_time - to_start_time <= 1000) {
  82. return
  83. }
  84. to_start_time = now_time
  85. console.log('to_start_time', to_start_time)
  86. treasureStart({
  87. params: {
  88. postId: state.postId || '',
  89. inviteCode: state.invite_code || '',
  90. frontFollowRelJSON: JSON.stringify(state.usersFollowStatusList),
  91. time: new Date().getTime(),
  92. guid: guid(),
  93. channelCode: state.invite_channel
  94. }
  95. }).then((res) => {
  96. state.usersFollowStatusList = [];
  97. if (res.code == 0) {
  98. // state.page = '开奖页'
  99. state.init(() => {
  100. state.page = '邀请页'
  101. state.page_status = '显示开奖'
  102. state.btn_loading = false
  103. })
  104. state.start_task = res.data
  105. if (req.response) {
  106. let repost_tweetId = req.response.data.data.create_tweet.tweet_results.result.rest_id
  107. reSetBindRepost({
  108. inviteCode: res.data.inviteCode,
  109. tweetId: repost_tweetId
  110. })
  111. }
  112. } else {
  113. state.init()
  114. }
  115. }).catch((error) => {
  116. console.error(error)
  117. })
  118. }
  119. chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
  120. switch (req.actionType) {
  121. case 'DO_TASK':
  122. if (!req.task_type || state.tweetId != req.tweet_Id || state.iframeId != req.iframeId) {
  123. return
  124. }
  125. console.log('DO_TASK', req)
  126. if (req.task_type == 'createTweet1' && req.task_done == '否') {
  127. console.log('createTweet1', req)
  128. state.toast.txt = 'Seems something went wrong, please try again'
  129. state.toast.show = true
  130. state.toast.has_icon = false
  131. setTimeout(() => {
  132. state.toast.show = false
  133. }, 2000)
  134. } else if (req.task_type == 'createTweet1' && req.task_done == '是') {
  135. console.log('createTweet2', req)
  136. toStart(req);
  137. getChromeStorage('userInfo', (_userInfo) => {
  138. if (_userInfo) {
  139. sendChromeTabMessage({
  140. actionType: "IFRAME_API_GET_TWEET_USER_INFO_REQ",
  141. data: {
  142. screen_name: _userInfo.nickName,
  143. tweetId: state.tweetId,
  144. objectType: Report.objectType.repostSuccess
  145. }
  146. })
  147. }
  148. })
  149. }
  150. break
  151. case 'CONTENT_API_GET_TWEET_USER_INFO_RES':
  152. let twitterFans = 0;
  153. let { user } = req.data || {};
  154. if (user && user.result && user.result.legacy) {
  155. let legacy = user.result.legacy;
  156. twitterFans = legacy ? legacy.followers_count : 0;
  157. }
  158. if (state.tweetId == req.tweetId && req.objectType == Report.objectType.repostSuccess) {
  159. Report.reportLog({
  160. objectType: Report.objectType.repostSuccess,
  161. twitterFans: twitterFans,
  162. redPacketType: Report.redPacketType.treasure,
  163. postId: state.postId,
  164. shareLinkId: state.invite_code,
  165. });
  166. };
  167. break;
  168. case 'CONTENT_GET_TWEET_USER_FOLLOW_STATUS_RES':
  169. if (state.tweetId == req.tweetId && state.iframeId == req.iframeId) {
  170. if (req.type == 'pre_repost') {
  171. // 发送埋点
  172. let list = getFollowStatus(req.data)
  173. log_pre_repost.names.forEach(item => {
  174. list.forEach((item2) => {
  175. if (item.name == item2.name) {
  176. if (item.type == 'invite') {
  177. log_pre_repost.params.isFatherTwitterFans = item2.followed
  178. }
  179. if (item.type == 'post') {
  180. log_pre_repost.params.isRootTwitterFans = item2.followed
  181. }
  182. }
  183. })
  184. })
  185. // 上报埋点
  186. Report.reportLog(Object.assign({
  187. objectType: Report.objectType.preRepost,
  188. }, log_pre_repost.params))
  189. } else {
  190. state.usersFollowStatusList = getFollowStatus(req.data);
  191. // 上报埋点
  192. logPreRepost()
  193. // 做任务
  194. chrome.tabs.getCurrent((tab) => {
  195. // // 一键三连
  196. chrome.tabs.sendMessage(tab.id, {
  197. actionType: "IFRAME_TWITTER_API_DO_TASK",
  198. task_data: {
  199. tweet_Id: state.tweetId,
  200. tweet_text: state.rePostTweetContent
  201. },
  202. task_type: 'tasks',
  203. tasks: state.tasks,
  204. iframeId: state.iframeId
  205. })
  206. // double like
  207. chrome.tabs.sendMessage(tab.id, {
  208. actionType: "IFRAME_TWITTER_API_DO_TASK", task_data: {
  209. tweet_Id: state.detail.srcContentId
  210. }, task_type: 'like',
  211. iframeId: state.iframeId
  212. })
  213. })
  214. }
  215. }
  216. break;
  217. }
  218. })
  219. const getFollowStatus = (arr = []) => {
  220. let list = [];
  221. let userInfoList = arr;
  222. for (let i = 0; i < userInfoList.length; i++) {
  223. let item = userInfoList[i];
  224. if (item.user && item.user.result && item.user.result.legacy) {
  225. let legacy = item.user.result.legacy;
  226. list.push({
  227. name: legacy.screen_name,
  228. followed: legacy.following
  229. })
  230. }
  231. }
  232. return list
  233. }
  234. let log_pre_repost = {
  235. params: {},
  236. names: []
  237. }
  238. const logPreRepost = () => {
  239. log_pre_repost.params = {}
  240. log_pre_repost.names = []
  241. // rootTwitterName 上报原始发布者的name
  242. // fatherTwitterName 上报分享者的name or 原始发布者的name
  243. // isFatherTwitterFans 在原始链接或分享链接 邀请者非自己
  244. // isRootTwitterFans 在原始链接或分享链接 发布者非自己
  245. let params = {}
  246. params.postId = state.postId
  247. if (state.page_type == '邀请链接') {
  248. params.shareLinkId = state.invite_code
  249. params.fatherTwitterName = state.detail.inviteUserInfo.nickName
  250. } else if (state.page_type == '原始链接') {
  251. params.fatherTwitterName = state.detail.postUserInfo.nickName
  252. }
  253. params.rootTwitterName = state.detail.postUserInfo.nickName
  254. let names = []
  255. if (state.detail.inviteUserInfo) {
  256. if (state.detail.inviteUserInfo.uid != global_userInfo.uid) {
  257. // isFatherTwitterFans = inviteUserInfo.nickName 的关注关系
  258. // 发送事件校验关注关系
  259. names.push({
  260. type: 'invite',
  261. name: state.detail.inviteUserInfo.nickName
  262. })
  263. }
  264. } else {
  265. if (state.detail.postUserInfo.uid != global_userInfo.uid) {
  266. names.push({
  267. type: 'invite',
  268. name: state.detail.postUserInfo.nickName
  269. })
  270. }
  271. }
  272. if (state.detail.postUserInfo && (state.detail.postUserInfo.uid != global_userInfo.uid)) {
  273. // isRootTwitterFans = postUserInfo.nickName 的关注关系
  274. // 发送事件校验关注关系
  275. names.push({
  276. type: 'post',
  277. name: state.detail.postUserInfo.nickName
  278. })
  279. }
  280. sendChromeTabMessage({
  281. actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
  282. data: {
  283. userList: names,
  284. tweetId: state.tweetId
  285. },
  286. type: 'pre_repost',
  287. iframeId: state.iframeId
  288. })
  289. log_pre_repost.params = params
  290. log_pre_repost.names = names
  291. }
  292. const toLast = (num, bit) => {
  293. let str = 1
  294. for (let i = 0; i < bit; i++) {
  295. str = str + '0'
  296. }
  297. let _num = Number(str)
  298. return Math.floor(Number(num) * _num) / _num
  299. }
  300. async function clickBtn() {
  301. global_userInfo = await state.checkIsLogin()
  302. if (!global_userInfo || !global_userInfo.uid) {
  303. return
  304. }
  305. if (state.cover_status == '奖励已被领光') {
  306. Report.reportLog({
  307. pageSource: Report.pageSource.pending_page,
  308. businessType: Report.businessType.buttonClick,
  309. objectType: Report.objectType.getMoreGiveaway,
  310. postId: state.postId
  311. });
  312. window.open('https://twitter.com/search?q=%23denet');
  313. return
  314. }
  315. state.btn_loading = true
  316. Report.reportLog({
  317. businessType: Report.businessType.buttonClick,
  318. objectType: Report.objectType.open_button,
  319. pageSource: Report.pageSource.pending_page,
  320. redPacketType: Report.redPacketType.treasure,
  321. shareLinkId: state.invite_code,
  322. postId: state.postId
  323. });
  324. setTimeout(() => {
  325. if (state.btn_loading == true) {
  326. state.btn_loading = false
  327. }
  328. }, 10000)
  329. // 获取邀请码
  330. getChromeCookie({
  331. name: state.postId,
  332. url: pageUrl,
  333. }, (res) => {
  334. if (res && res.inviteCode) {
  335. state.invite_code = res.inviteCode
  336. state.invite_channel = res.channel ? window.atob(res.channel) : '';
  337. }
  338. startBtn()
  339. })
  340. }
  341. const startBtn = () => {
  342. // 获取文本
  343. prepareStart({
  344. params: {
  345. postId: state.postId || '',
  346. inviteCode: state.invite_code || ''
  347. }
  348. }).then((res) => {
  349. if (res.code == 0) {
  350. removeChromeCookie({
  351. name: state.postId,
  352. url: pageUrl,
  353. })
  354. state.rePostTweetContent = res.data.rePostTweetContent;
  355. getUsersFollowStatus();
  356. } else {
  357. state.init()
  358. }
  359. })
  360. }
  361. const getUsersFollowStatus = () => {
  362. let userList = state.follows;
  363. if (userList && userList.length) {
  364. sendChromeTabMessage({
  365. actionType: "IFRAME_API_GET_TWEET_USER_FOLLOW_STATUS",
  366. data: {
  367. userList: userList,
  368. tweetId: state.tweetId,
  369. },
  370. iframeId: state.iframeId
  371. })
  372. }
  373. }
  374. </script>
  375. <style lang="scss" scoped>
  376. .cover {
  377. position: relative;
  378. width: 375px;
  379. height: 580px;
  380. background: linear-gradient(179.96deg, #25180D 38.82%, #5E4025 55.4%, #876635 61.6%, #24180C 71.59%);
  381. border-radius: 20px;
  382. .head {
  383. padding: 10px;
  384. display: flex;
  385. align-items: center;
  386. img {
  387. width: 16px;
  388. height: 16px;
  389. border-radius: 100px;
  390. }
  391. span {
  392. color: #B69882;
  393. font-weight: 400;
  394. margin-left: 5px;
  395. font-size: 11px;
  396. flex-grow: 0;
  397. }
  398. }
  399. .waring {
  400. margin-top: 94px;
  401. font-weight: 900;
  402. font-size: 34px;
  403. color: #FFFFFF;
  404. text-align: center;
  405. opacity: 0.7;
  406. margin-bottom: 35px;
  407. }
  408. .in {
  409. height: 58px;
  410. }
  411. .in-invite {
  412. height: 28px;
  413. margin-top: 30px;
  414. margin-bottom: 10px;
  415. }
  416. .invite {
  417. background: rgba(255, 255, 255, 0.1);
  418. height: 28px;
  419. display: flex;
  420. align-items: center;
  421. margin: 0 auto;
  422. margin-top: 20px;
  423. margin-bottom: 10px;
  424. border-radius: 100px;
  425. width: fit-content;
  426. padding-right: 11px;
  427. img {
  428. width: 18px;
  429. height: 18px;
  430. border-radius: 100px;
  431. margin-left: 11px;
  432. margin-right: 6px;
  433. }
  434. span {
  435. color: #BE9F89;
  436. }
  437. }
  438. .treasure {
  439. text-align: center;
  440. height: 37px;
  441. display: flex;
  442. align-items: center;
  443. span {
  444. font-size: 34px;
  445. font-weight: 900;
  446. line-height: 40px;
  447. }
  448. span:first-child {
  449. color: #FFC83A;
  450. margin-right: 10px;
  451. }
  452. span:last-child {
  453. color: #FFFFFF;
  454. }
  455. }
  456. .gain {
  457. width: 100%;
  458. background: #332319;
  459. height: 37px;
  460. margin-top: 10px;
  461. display: flex;
  462. align-items: center;
  463. justify-content: center;
  464. span {
  465. color: #fff;
  466. font-weight: 500;
  467. font-size: 16px;
  468. line-height: 16px;
  469. }
  470. span:first-child {
  471. font-size: 15px;
  472. line-height: 15px;
  473. margin-right: 10px;
  474. }
  475. span:last-child {
  476. margin-left: 2px;
  477. font-weight: 800;
  478. font-size: 24px;
  479. line-height: 24px;
  480. }
  481. }
  482. .coin {
  483. height: 17px;
  484. display: flex;
  485. align-items: center;
  486. justify-content: center;
  487. margin-top: 10px;
  488. img {
  489. width: 17px;
  490. height: 17px;
  491. }
  492. span {
  493. margin-left: 4px;
  494. font-weight: 400;
  495. font-size: 11px;
  496. line-height: 15px;
  497. color: #FFFFFF;
  498. opacity: 0.7;
  499. }
  500. }
  501. .box {
  502. text-align: center;
  503. position: absolute;
  504. width: 100%;
  505. bottom: 155px;
  506. img {
  507. width: 160px;
  508. height: 160px;
  509. }
  510. }
  511. .mark {
  512. position: absolute;
  513. bottom: 84px;
  514. display: flex;
  515. align-items: center;
  516. justify-content: center;
  517. width: 100%;
  518. img {
  519. margin-right: 9px;
  520. }
  521. span {
  522. font-weight: 500;
  523. font-size: 12px;
  524. line-height: 17px;
  525. color: #65C1FF;
  526. }
  527. }
  528. .footer {
  529. width: 100%;
  530. position: absolute;
  531. bottom: 16px;
  532. }
  533. }
  534. </style>