MobileLandPage.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. cancelLogin() {
  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. win.location.href = url;
  247. this.timer.value = setInterval(() => {
  248. if (win && win.closed) {
  249. clearInterval(this.timer.value);
  250. this.twitterLogin(data);
  251. if (getStorage(storageKey.backFromTwitterLogin)) {
  252. this.isLoading = false;
  253. removeStorage(storageKey.backFromTwitterLogin);
  254. this.cancelLogin();
  255. }
  256. }
  257. }, 500);
  258. } else {
  259. Toast('login fail');
  260. win.close();
  261. this.cancelLogin();
  262. }
  263. });
  264. },
  265. async twitterLogin(authData) {
  266. let verifier = getStorage(storageKey.verifier);
  267. if (verifier) {
  268. postRequest(`/denet/user/twitterLogin`, {
  269. params: {
  270. consumerKey: authData.consumerKey,
  271. oauthToken: authData.authToken,
  272. oauthVerifier: verifier,
  273. },
  274. }).then(({ code, data }) => {
  275. this.isLoading = false;
  276. if (code == 0) {
  277. setStorage(storageKey.userInfo, data);
  278. removeStorage(storageKey.verifier);
  279. this.loginSuccessBack = true;
  280. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}`;
  281. }
  282. });
  283. }
  284. },
  285. },
  286. unmounted() {
  287. removeStorage(storageKey.backFromTwitterLogin);
  288. },
  289. components: { FontZoom },
  290. };
  291. </script>
  292. <style lang="scss" scoped>
  293. .mobile-land-page {
  294. min-height: 100%;
  295. max-height: 100%;
  296. background: linear-gradient(180deg, #cceaff 0%, #ffffff 70.42%);
  297. display: flex;
  298. flex-direction: column;
  299. justify-content: space-between;
  300. align-items: center;
  301. padding: 0 16px;
  302. &-invited-info {
  303. min-width: 302px;
  304. height: 72px;
  305. margin-top: 28px;
  306. position: relative;
  307. padding-left: 81px;
  308. border-radius: 35px;
  309. display: flex;
  310. flex-direction: column;
  311. align-items: flex-start;
  312. justify-content: flex-start;
  313. background: #ffffff;
  314. border: 1px solid #c0daeb;
  315. padding-right: 12px;
  316. box-sizing: border-box;
  317. white-space: nowrap;
  318. .invited-photo {
  319. width: 70px;
  320. height: 70px;
  321. border-radius: 50%;
  322. position: absolute;
  323. left: 0;
  324. top: 0;
  325. }
  326. .invited-name {
  327. margin: 13px 0 5px;
  328. font-weight: 500;
  329. font-size: 13px;
  330. line-height: 16px;
  331. letter-spacing: 0.3px;
  332. color: #000000;
  333. max-width: 210px;
  334. text-overflow: ellipsis;
  335. white-space: nowrap;
  336. overflow: hidden;
  337. }
  338. .invited-text {
  339. font-weight: 700;
  340. font-size: 17px;
  341. line-height: 20px;
  342. letter-spacing: 0.3px;
  343. color: #f99d23;
  344. }
  345. }
  346. &-icon-wrap {
  347. display: flex;
  348. flex: 1;
  349. align-items: center;
  350. .mobile-land-page-icon {
  351. width: 100%;
  352. }
  353. }
  354. &-prize-info {
  355. font-style: normal;
  356. font-weight: 700;
  357. font-size: 18px;
  358. line-height: 21px;
  359. color: #000000;
  360. &-test {
  361. display: flex;
  362. align-items: center;
  363. justify-content: center;
  364. .pre-amount-value {
  365. margin-left: 3px;
  366. }
  367. .icon {
  368. width: 22px;
  369. height: 22px;
  370. margin-left: 3px;
  371. }
  372. .prize-name {
  373. margin: 0 3px;
  374. }
  375. .treasure-usd-amount {
  376. color: #f99d23;
  377. font-weight: 700;
  378. font-size: 18px;
  379. }
  380. }
  381. }
  382. &-tip {
  383. font-weight: 400;
  384. font-size: 13px;
  385. line-height: 16px;
  386. text-align: center;
  387. color: #7b7b7b;
  388. margin-top: 10px;
  389. }
  390. &-login-twitter {
  391. width: 100%;
  392. height: 54px;
  393. margin: 18px 16px 30px;
  394. border-radius: 54px;
  395. background: #1d9bf0;
  396. text-align: center;
  397. line-height: 54px;
  398. font-weight: 700;
  399. font-size: 18px;
  400. text-align: center;
  401. color: #fff;
  402. }
  403. .loading {
  404. position: absolute;
  405. transform: translate(-50%, -50%);
  406. top: 50%;
  407. left: 50%;
  408. margin: auto;
  409. width: 40px;
  410. border-radius: 50%;
  411. z-index: 1;
  412. }
  413. }
  414. .loading-page {
  415. position: relative;
  416. }
  417. .loading-page::after {
  418. content: '';
  419. position: absolute;
  420. width: 100%;
  421. height: 100%;
  422. background-color: #fff;
  423. left: 0;
  424. top: 0;
  425. }
  426. </style>