MobileLandPage.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <div class="mobile-land-page" :class="isLoading ? 'loading-page' : ''">
  3. <div class="mobile-land-page-invited-info" v-if="useFul && !isNFTCpd">
  4. <img :src="userInfo.avatarUrl" class="invited-photo" />
  5. <div class="invited-name">{{ userInfo.nickName }}</div>
  6. <div class="invited-text">{{ isTreasureCpd ? 'Invite You to Hunt the Treasure' : 'Send You Giveaway!' }}</div>
  7. </div>
  8. <div class="mobile-land-page-icon-wrap">
  9. <img class="mobile-land-page-icon" :src="iconCpd" />
  10. </div>
  11. <div class="mobile-land-page-prize-info">
  12. <template v-if="!useFul">
  13. <div class="mobile-land-page-prize-info-test">
  14. <!-- time-expired -->
  15. </div>
  16. </template>
  17. <!-- 红包 -->
  18. <template v-else-if="isLottaryCpd">
  19. <div class="mobile-land-page-prize-info-test">You are gifted an entries to earn</div>
  20. <div class="mobile-land-page-prize-info-test">
  21. <img v-if="!isCustomRewardCpd" class="icon" :src="currencyIconPath" />
  22. <span class="pre-amount-value">{{ isCustomRewardCpd ? 1 : amountValue }}</span>
  23. <span class="prize-name">{{ prize }}</span>
  24. <span class="usd-amount" v-if="!isCustomRewardCpd && usValue"> (${{ usValue }})</span>
  25. </div>
  26. </template>
  27. <!-- 抽奖 -->
  28. <template v-else-if="isCommonCpd">
  29. <div class="mobile-land-page-prize-info-test">
  30. You Won
  31. <img v-if="!isCustomRewardCpd" class="icon" :src="currencyIconPath" />
  32. <span class="pre-amount-value">{{ isCustomRewardCpd ? 1 : amountValue }}</span>
  33. <FontZoom width="240" style="color: #000">
  34. <span class="prize-name">{{ prize }}</span>
  35. </FontZoom>
  36. <span class="usd-amount" v-if="!isCustomRewardCpd && usValue"> (${{ usValue }})</span>
  37. </div>
  38. <div class="mobile-land-page-prize-info-test">in the Giveaway!</div>
  39. </template>
  40. <!-- 夺宝 -->
  41. <template v-else-if="isTreasureCpd">
  42. <div class="mobile-land-page-prize-info-test">Complete the quest to win up to</div>
  43. <div class="mobile-land-page-prize-info-test">
  44. <span class="usd-amount treasure-usd-amount"> ${{ usValue }} for you two!</span>
  45. </div>
  46. </template>
  47. <!-- NFT -->
  48. <template v-else-if="isNFTCpd">
  49. <div class="mobile-land-page-prize-info-test">
  50. <span class="prize-name">{{ prize }}</span>
  51. is in your
  52. </div>
  53. <div class="mobile-land-page-prize-info-test">DeNet NFT wallet!</div>
  54. </template>
  55. <!-- 兜底显示 -->
  56. <template v-else>
  57. <div class="mobile-land-page-prize-info-test"></div>
  58. </template>
  59. </div>
  60. <FontZoom width="330">
  61. <div class="mobile-land-page-tip">{{ tipCpd }}</div>
  62. </FontZoom>
  63. <div class="mobile-land-page-login-twitter" @click="toLogin">{{ isLoginCpd || loginSuccessBack ? (!useFul || isNFTCpd ? 'Install' : 'Claim Prize') : 'Login Twitter' }}</div>
  64. <template v-if="isLoading">
  65. <img class="loading" src="../static/svg/icon-loading.svg" />
  66. </template>
  67. </div>
  68. </template>
  69. <script>
  70. import { RewardType, PlayType } from '../types';
  71. import { getStorage, setStorage, removeStorage, storageKey, getMid, getOauthUrl } from '../utils/help';
  72. import { postRequest } from '../http';
  73. import FontZoom from './FontZoom';
  74. import { Toast } from 'vant';
  75. import Report from './../log-center/log';
  76. const overTimePic = require('../static/img/icon-h5-denet.svg');
  77. const giveawayPic = require('../static/img/icon-h5-giveaway.svg');
  78. const redpackPic = require('../static/img/icon-h5-redpack.svg');
  79. const treasurePic = require('../static/img/icon-h5-treasure.svg');
  80. export default {
  81. name: 'mobileLandPage',
  82. props: {
  83. playType: {
  84. // 玩法类型, 红包 / 抽奖 / 夺宝 / NFT
  85. type: Number,
  86. },
  87. rewardType: {
  88. // 奖品类型 货币/ 自定义奖品
  89. type: Number,
  90. default: 1,
  91. },
  92. useFul: {
  93. // 红包仍在有效期,可领取
  94. type: Boolean,
  95. default: true,
  96. },
  97. userInfo: {
  98. type: Object,
  99. default: () => {
  100. return {};
  101. },
  102. },
  103. currencyIconPath: {
  104. // 货币头像
  105. type: String,
  106. default: '',
  107. },
  108. amountValue: {
  109. // 奖品数量
  110. type: [String, Number],
  111. default: '1',
  112. },
  113. usValue: {
  114. // 转换为美金 的价值
  115. type: [String, Number],
  116. default: '',
  117. },
  118. prize: {
  119. // 奖品 描述
  120. type: String,
  121. default: '',
  122. },
  123. srcContentId: {
  124. // 推文ID
  125. type: String,
  126. default: '',
  127. },
  128. postId: {
  129. // 推文ID,用于retweer
  130. type: String,
  131. default: '',
  132. },
  133. nftProjectId: {
  134. // NFT ID
  135. type: String,
  136. default: '',
  137. },
  138. prizePicPath: {
  139. // NFT图片
  140. type: String,
  141. default: '',
  142. },
  143. },
  144. data() {
  145. return {
  146. timer: {},
  147. loginSuccessBack: false,
  148. isLoading: false,
  149. };
  150. },
  151. computed: {
  152. isCustomRewardCpd() {
  153. return this.rewardType === RewardType.custom;
  154. },
  155. isLottaryCpd() {
  156. return this.playType === PlayType.lottery;
  157. },
  158. isCommonCpd() {
  159. return this.playType === PlayType.common;
  160. },
  161. isTreasureCpd() {
  162. return this.playType === PlayType.Treasure;
  163. },
  164. isNFTCpd() {
  165. return this.playType === PlayType.NFT;
  166. },
  167. iconCpd() {
  168. if (!this.useFul) {
  169. return overTimePic;
  170. } else if (this.isCommonCpd) {
  171. return redpackPic;
  172. } else if (this.isLottaryCpd) {
  173. return giveawayPic;
  174. } else if (this.isTreasureCpd) {
  175. return treasurePic;
  176. } else if (this.isNFTCpd) {
  177. return this.prizePicPath;
  178. }
  179. {
  180. return overTimePic;
  181. }
  182. },
  183. tipCpd() {
  184. if (!this.useFul) {
  185. return 'login Twitter to install DeNet Chrome Extension';
  186. } else if (this.isCommonCpd) {
  187. return 'to claim, log in twitter to install Denet Chrome Extension';
  188. } else if (this.isLottaryCpd) {
  189. return 'To participate, login Twitter to install DeNet Chrome Extension';
  190. } else if (this.isTreasureCpd) {
  191. return 'To complete, log in twitter to install Denet Chrome Extension';
  192. } else {
  193. return 'login Twitter to install DeNet Chrome Extension';
  194. }
  195. },
  196. isLoginCpd() {
  197. return !!getStorage(storageKey.userInfo);
  198. },
  199. },
  200. methods: {
  201. toLogin() {
  202. let userInfo = getStorage(storageKey.userInfo);
  203. let logData = {
  204. baseInfo: {
  205. mid: getMid(),
  206. pageSource: Report.pageSource.mobileLandingPage,
  207. machineCode: getMid(),
  208. },
  209. params: {
  210. eventData: {
  211. businessType: Report.businessType.buttonClick,
  212. objectType: userInfo ? Report.objectType.cliamRewardButton : Report.objectType.loginTwitterButton,
  213. postId: this.postId,
  214. },
  215. },
  216. };
  217. if (this.isNFTCpd) {
  218. delete logData.params.eventData.postId;
  219. logData.params.eventData.nftProjectId = this.nftProjectId;
  220. }
  221. if (userInfo) {
  222. // ios手机跳转时丢失log,缓存至下个页面进行上报
  223. setStorage('land-page-log', JSON.stringify(logData));
  224. this.goCoursePage();
  225. } else {
  226. Report.reportLog(logData);
  227. this.twitterAuth();
  228. }
  229. },
  230. goCoursePage() {
  231. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}&nftProjectId=${this.nftProjectId}&srcContentId=${this.srcContentId}`;
  232. },
  233. async twitterAuth() {
  234. let win = window.open();
  235. win.opener = null;
  236. postRequest(`/denet/user/twitterRequestToken`, {
  237. params: {
  238. oauthCallback: `${location.protocol}//${location.host}/authlogin`,
  239. },
  240. }).then(({ code, data }) => {
  241. if (code == 0) {
  242. let url = getOauthUrl(data.authToken);
  243. this.isLoading = true;
  244. setStorage('goto-twitter-login-page', 1);
  245. win.location.href = url;
  246. this.timer.value = setInterval(() => {
  247. if (win && win.closed) {
  248. clearInterval(this.timer.value);
  249. this.twitterLogin(data);
  250. if (getStorage(storageKey.backFromTwitterLogin)) {
  251. // 从twitter授权取消页面回来
  252. this.isLoading = false;
  253. removeStorage(storageKey.backFromTwitterLogin);
  254. this.goCoursePage();
  255. }
  256. }
  257. }, 500);
  258. } else {
  259. Toast('login fail');
  260. win.close();
  261. this.goCoursePage();
  262. }
  263. });
  264. },
  265. async twitterLogin(authData) {
  266. let verifier = getStorage(storageKey.verifier);
  267. removeStorage('goto-twitter-login-page');
  268. if (verifier) {
  269. postRequest(`/denet/user/twitterLogin`, {
  270. params: {
  271. consumerKey: authData.consumerKey,
  272. oauthToken: authData.authToken,
  273. oauthVerifier: verifier,
  274. },
  275. }).then(({ code, data }) => {
  276. if (code == 0) {
  277. setStorage(storageKey.userInfo, data);
  278. removeStorage(storageKey.verifier);
  279. this.loginSuccessBack = true;
  280. this.isLoading = false;
  281. this.goCoursePage();
  282. } else {
  283. this.isLoading = false;
  284. Toast('login fail');
  285. }
  286. });
  287. } else {
  288. this.isLoading = false;
  289. }
  290. },
  291. visibilityHandle() {
  292. console.log('visibilitychange', document.hidden);
  293. var isHidden = document.hidden;
  294. if (!isHidden) {
  295. // 此处解决 点击login按钮后 主动返回的情况
  296. let verifier = getStorage(storageKey.verifier);
  297. const isFromTwitterLoginPage = getStorage('goto-twitter-login-page');
  298. if (isFromTwitterLoginPage && !verifier) {
  299. removeStorage('goto-twitter-login-page');
  300. this.isLoading = false;
  301. this.goCoursePage();
  302. }
  303. }
  304. },
  305. },
  306. mounted() {
  307. document.addEventListener('visibilitychange', this.visibilityHandle);
  308. },
  309. unmounted() {
  310. removeStorage('goto-twitter-login-page');
  311. removeStorage(storageKey.backFromTwitterLogin);
  312. document.removeEventListener('visibilitychange', this.visibilityHandle);
  313. },
  314. components: { FontZoom },
  315. };
  316. </script>
  317. <style lang="scss" scoped>
  318. .mobile-land-page {
  319. min-height: 100%;
  320. max-height: 100%;
  321. background: linear-gradient(180deg, #cceaff 0%, #ffffff 70.42%);
  322. display: flex;
  323. flex-direction: column;
  324. justify-content: space-between;
  325. align-items: center;
  326. padding: 0 16px;
  327. &-invited-info {
  328. min-width: 302px;
  329. max-width: 98%;
  330. height: 72px;
  331. margin-top: 28px;
  332. position: relative;
  333. padding-left: 81px;
  334. border-radius: 35px;
  335. display: flex;
  336. flex-direction: column;
  337. align-items: flex-start;
  338. justify-content: flex-start;
  339. background: #ffffff;
  340. border: 1px solid #c0daeb;
  341. padding-right: 12px;
  342. box-sizing: border-box;
  343. .invited-photo {
  344. width: 70px;
  345. height: 70px;
  346. border-radius: 50%;
  347. position: absolute;
  348. left: 0;
  349. top: 0;
  350. }
  351. .invited-name {
  352. margin: 13px 0 5px;
  353. font-weight: 500;
  354. font-size: 13px;
  355. line-height: 16px;
  356. letter-spacing: 0.3px;
  357. color: #000000;
  358. max-width: 210px;
  359. text-overflow: ellipsis;
  360. white-space: nowrap;
  361. overflow: hidden;
  362. }
  363. .invited-text {
  364. font-weight: 700;
  365. font-size: 17px;
  366. line-height: 20px;
  367. letter-spacing: 0.3px;
  368. color: #f99d23;
  369. height: 28px;
  370. display: flex;
  371. align-items: center;
  372. }
  373. }
  374. &-icon-wrap {
  375. display: flex;
  376. flex: 1;
  377. align-items: center;
  378. .mobile-land-page-icon {
  379. width: 100%;
  380. }
  381. }
  382. &-prize-info {
  383. font-style: normal;
  384. font-weight: 700;
  385. font-size: 18px;
  386. line-height: 21px;
  387. color: #000000;
  388. &-test {
  389. display: flex;
  390. align-items: center;
  391. justify-content: center;
  392. .pre-amount-value {
  393. margin-left: 3px;
  394. }
  395. .icon {
  396. width: 22px;
  397. height: 22px;
  398. margin-left: 3px;
  399. }
  400. .prize-name {
  401. margin: 0 3px;
  402. }
  403. .treasure-usd-amount {
  404. color: #f99d23;
  405. font-weight: 700;
  406. font-size: 18px;
  407. }
  408. }
  409. }
  410. &-tip {
  411. font-weight: 400;
  412. font-size: 13px;
  413. line-height: 16px;
  414. text-align: center;
  415. color: #7b7b7b;
  416. margin-top: 10px;
  417. }
  418. &-login-twitter {
  419. width: 100%;
  420. height: 54px;
  421. margin: 18px 16px 30px;
  422. border-radius: 54px;
  423. background: #1d9bf0;
  424. text-align: center;
  425. line-height: 54px;
  426. font-weight: 700;
  427. font-size: 18px;
  428. text-align: center;
  429. color: #fff;
  430. }
  431. .loading {
  432. position: absolute;
  433. transform: translate(-50%, -50%);
  434. top: 50%;
  435. left: 50%;
  436. margin: auto;
  437. width: 40px;
  438. border-radius: 50%;
  439. z-index: 1;
  440. }
  441. }
  442. .loading-page {
  443. position: relative;
  444. }
  445. .loading-page::after {
  446. content: '';
  447. position: absolute;
  448. width: 100%;
  449. height: 100%;
  450. background-color: #fff;
  451. left: 0;
  452. top: 0;
  453. }
  454. </style>