MobileLandPage.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <div class="mobile-land-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. <img class="icon" :src="currencyIconPath" />
  45. <span class="pre-amount-value" v-if="amountValue">{{ amountValue }}</span>
  46. <span class="prize-name">{{ prize }}</span>
  47. <span class="usd-amount treasure-usd-amount"> ${{ usValue }} for you two!</span>
  48. </div>
  49. </template>
  50. <!-- NFT -->
  51. <template v-else-if="isNFTCpd">
  52. <div class="mobile-land-page-prize-info-test">
  53. <span class="prize-name">{{ prize }}</span>
  54. is in your
  55. </div>
  56. <div class="mobile-land-page-prize-info-test">DeNet NFT wallet!</div>
  57. </template>
  58. <!-- 兜底显示 -->
  59. <template v-else>
  60. <div class="mobile-land-page-prize-info-test"></div>
  61. </template>
  62. </div>
  63. <FontZoom width="330">
  64. <div class="mobile-land-page-tip">{{ tipCpd }}</div>
  65. </FontZoom>
  66. <div class="mobile-land-page-login-twitter" @click="toLogin">{{ isLoginCpd || loginSuccessBack ? 'Claim Prize' : 'Login Twitter' }}</div>
  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. };
  149. },
  150. computed: {
  151. isCustomRewardCpd() {
  152. return this.rewardType === RewardType.custom;
  153. },
  154. isLottaryCpd() {
  155. return this.playType === PlayType.lottery;
  156. },
  157. isCommonCpd() {
  158. return this.playType === PlayType.common;
  159. },
  160. isTreasureCpd() {
  161. return this.playType === PlayType.Treasure;
  162. },
  163. isNFTCpd() {
  164. return this.playType === PlayType.NFT;
  165. },
  166. iconCpd() {
  167. if (!this.useFul) {
  168. return overTimePic;
  169. } else if (this.isCommonCpd) {
  170. return redpackPic;
  171. } else if (this.isLottaryCpd) {
  172. return giveawayPic;
  173. } else if (this.isTreasureCpd) {
  174. return treasurePic;
  175. } else if (this.isNFTCpd) {
  176. return this.prizePicPath;
  177. }
  178. {
  179. return overTimePic;
  180. }
  181. },
  182. tipCpd() {
  183. if (!this.useFul) {
  184. return 'login Twitter to install DeNet Chrome Extension';
  185. } else if (this.isCommonCpd) {
  186. return 'to claim, log in twitter to install Denet Chrome Extension';
  187. } else if (this.isLottaryCpd) {
  188. return 'To participate, login Twitter to install DeNet Chrome Extension';
  189. } else if (this.isTreasureCpd) {
  190. return 'To complete, log in twitter to install Denet Chrome Extension';
  191. } else {
  192. return 'login Twitter to install DeNet Chrome Extension';
  193. }
  194. },
  195. isLoginCpd() {
  196. return !!getStorage(storageKey.userInfo);
  197. },
  198. },
  199. methods: {
  200. toLogin() {
  201. let userInfo = getStorage(storageKey.userInfo);
  202. let logData = {
  203. baseInfo: {
  204. mid: getMid(),
  205. pageSource: Report.pageSource.mobileLandingPage,
  206. machineCode: getMid(),
  207. },
  208. params: {
  209. eventData: {
  210. businessType: Report.businessType.buttonClick,
  211. objectType: userInfo ? Report.objectType.cliamRewardButton : Report.objectType.loginTwitterButton,
  212. postId: this.postId,
  213. },
  214. },
  215. };
  216. if (this.isNFTCpd) {
  217. delete logData.params.eventData.postId;
  218. logData.params.eventData.nftProjectId = this.nftProjectId;
  219. }
  220. Report.reportLog(logData);
  221. if (userInfo) {
  222. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}&nftProjectId=${this.nftProjectId}&srcContentId=${this.srcContentId}`;
  223. } else {
  224. this.twitterAuth();
  225. }
  226. },
  227. cancelLogin() {
  228. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}&nftProjectId=${this.nftProjectId}&srcContentId=${this.srcContentId}`;
  229. },
  230. async twitterAuth() {
  231. let win = window.open();
  232. win.opener = null;
  233. postRequest(`/denet/user/twitterRequestToken`, {
  234. params: {
  235. oauthCallback: `${location.protocol}//${location.host}/authlogin`,
  236. },
  237. }).then(({ code, data }) => {
  238. if (code == 0) {
  239. let url = getOauthUrl(data.authToken);
  240. win.location.href = url;
  241. this.timer.value = setInterval(() => {
  242. if (win && win.closed) {
  243. clearInterval(this.timer.value);
  244. this.twitterLogin(data);
  245. if (getStorage(storageKey.backFromTwitterLogin)) {
  246. removeStorage(storageKey.backFromTwitterLogin);
  247. this.cancelLogin();
  248. }
  249. }
  250. }, 500);
  251. } else {
  252. Toast('login fail');
  253. win.close();
  254. this.cancelLogin();
  255. }
  256. });
  257. },
  258. async twitterLogin(authData) {
  259. let verifier = getStorage(storageKey.verifier);
  260. if (verifier) {
  261. postRequest(`/denet/user/twitterLogin`, {
  262. params: {
  263. consumerKey: authData.consumerKey,
  264. oauthToken: authData.authToken,
  265. oauthVerifier: verifier,
  266. },
  267. }).then(({ code, data }) => {
  268. if (code == 0) {
  269. setStorage(storageKey.userInfo, data);
  270. removeStorage(storageKey.verifier);
  271. this.loginSuccessBack = true;
  272. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}`;
  273. }
  274. });
  275. }
  276. },
  277. },
  278. unmounted() {
  279. removeStorage(storageKey.backFromTwitterLogin);
  280. },
  281. components: { FontZoom },
  282. };
  283. </script>
  284. <style lang="scss" scoped>
  285. .mobile-land-page {
  286. min-height: 100%;
  287. max-height: 100%;
  288. background: linear-gradient(180deg, #cceaff 0%, #ffffff 70.42%);
  289. display: flex;
  290. flex-direction: column;
  291. justify-content: space-between;
  292. align-items: center;
  293. padding: 0 16px;
  294. &-invited-info {
  295. width: 302px;
  296. height: 72px;
  297. margin-top: 28px;
  298. position: relative;
  299. padding-left: 81px;
  300. border-radius: 35px;
  301. display: flex;
  302. flex-direction: column;
  303. align-items: flex-start;
  304. justify-content: flex-start;
  305. background: #ffffff;
  306. border: 1px solid #c0daeb;
  307. .invited-photo {
  308. width: 70px;
  309. height: 70px;
  310. border-radius: 50%;
  311. position: absolute;
  312. left: 0;
  313. top: 0;
  314. }
  315. .invited-name {
  316. margin: 13px 0 5px;
  317. font-weight: 500;
  318. font-size: 13px;
  319. line-height: 16px;
  320. letter-spacing: 0.3px;
  321. color: #000000;
  322. max-width: 210px;
  323. text-overflow: ellipsis;
  324. white-space: nowrap;
  325. overflow: hidden;
  326. }
  327. .invited-text {
  328. font-weight: 700;
  329. font-size: 17px;
  330. line-height: 20px;
  331. letter-spacing: 0.3px;
  332. color: #f99d23;
  333. }
  334. }
  335. &-icon-wrap {
  336. display: flex;
  337. flex: 1;
  338. align-items: center;
  339. .mobile-land-page-icon {
  340. width: 100%;
  341. }
  342. }
  343. &-prize-info {
  344. font-style: normal;
  345. font-weight: 700;
  346. font-size: 18px;
  347. line-height: 21px;
  348. color: #000000;
  349. &-test {
  350. display: flex;
  351. align-items: center;
  352. justify-content: center;
  353. .pre-amount-value {
  354. margin-left: 3px;
  355. }
  356. .icon {
  357. width: 22px;
  358. height: 22px;
  359. margin-left: 3px;
  360. }
  361. .prize-name {
  362. margin: 0 3px;
  363. }
  364. .treasure-usd-amount {
  365. color: #f99d23;
  366. font-weight: 700;
  367. font-size: 18px;
  368. }
  369. }
  370. }
  371. &-tip {
  372. font-weight: 400;
  373. font-size: 13px;
  374. line-height: 16px;
  375. text-align: center;
  376. color: #7b7b7b;
  377. margin-top: 10px;
  378. }
  379. &-login-twitter {
  380. width: 100%;
  381. height: 54px;
  382. margin: 18px 16px 30px;
  383. border-radius: 54px;
  384. background: #1d9bf0;
  385. text-align: center;
  386. line-height: 54px;
  387. font-weight: 700;
  388. font-size: 18px;
  389. text-align: center;
  390. color: #fff;
  391. }
  392. }
  393. </style>