MobileLandPage.vue 10 KB

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