MobileLandPage.vue 12 KB

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