cover.vue 16 KB

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