MobileLandPage.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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</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" v-if="usValue"> (${{ usValue }})</span>
  48. for you two!
  49. </div>
  50. </template>
  51. <!-- NFT -->
  52. <template v-else-if="isNFTCpd">
  53. <div class="mobile-land-page-prize-info-test">
  54. <span class="prize-name">{{ prize }}</span>
  55. is in your
  56. </div>
  57. <div class="mobile-land-page-prize-info-test">DeNet NFT wallet!</div>
  58. </template>
  59. <!-- 兜底显示 -->
  60. <template v-else>
  61. <div class="mobile-land-page-prize-info-test"></div>
  62. </template>
  63. </div>
  64. <FontZoom width="330">
  65. <div class="mobile-land-page-tip">{{ tipCpd }}</div>
  66. </FontZoom>
  67. <div class="mobile-land-page-login-twitter" @click="toLogin">{{ isLoginCpd || loginSuccessBack ? 'Claim Prize' : 'Login Twitter' }}</div>
  68. </div>
  69. </template>
  70. <script>
  71. import { RewardType, PlayType } from '../types';
  72. import { getStorage, setStorage, removeStorage, storageKey, getMid, getOauthUrl } from '../utils/help';
  73. import { postRequest } from '../http';
  74. import FontZoom from './FontZoom';
  75. import { Toast } from 'vant';
  76. import Report from './../log-center/log';
  77. const overTimePic = require('../static/img/icon-h5-denet.svg');
  78. const giveawayPic = require('../static/img/icon-h5-giveaway.svg');
  79. const redpackPic = require('../static/img/icon-h5-redpack.svg');
  80. const treasurePic = require('../static/img/icon-h5-treasure.svg');
  81. export default {
  82. name: 'mobileLandPage',
  83. props: {
  84. playType: {
  85. // 玩法类型, 红包 / 抽奖 / 夺宝 / NFT
  86. type: Number,
  87. },
  88. rewardType: {
  89. // 奖品类型 货币/ 自定义奖品
  90. type: Number,
  91. default: 1,
  92. },
  93. useFul: {
  94. // 红包仍在有效期,可领取
  95. type: Boolean,
  96. default: true,
  97. },
  98. userInfo: {
  99. type: Object,
  100. default: () => {
  101. return {};
  102. },
  103. },
  104. currencyIconPath: {
  105. // 货币头像
  106. type: String,
  107. default: '',
  108. },
  109. amountValue: {
  110. // 奖品数量
  111. type: [String, Number],
  112. default: '1',
  113. },
  114. usValue: {
  115. // 转换为美金 的价值
  116. type: [String, Number],
  117. default: '',
  118. },
  119. prize: {
  120. // 奖品 描述
  121. type: String,
  122. default: '',
  123. },
  124. srcContentId: {
  125. // 推文ID
  126. type: String,
  127. default: '',
  128. },
  129. postId: {
  130. // 推文ID,用于retweer
  131. type: String,
  132. default: '',
  133. },
  134. nftProjectId: {
  135. // NFT ID
  136. type: String,
  137. default: '',
  138. },
  139. prizePicPath: {
  140. // NFT图片
  141. type: String,
  142. default: '',
  143. },
  144. },
  145. data() {
  146. return {
  147. timer: {},
  148. loginSuccessBack: 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. Report.reportLog(logData);
  222. if (userInfo) {
  223. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}&nftProjectId=${this.nftProjectId}&srcContentId=${this.srcContentId}`;
  224. } else {
  225. this.twitterAuth();
  226. }
  227. },
  228. cancelLogin() {
  229. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}&nftProjectId=${this.nftProjectId}&srcContentId=${this.srcContentId}`;
  230. },
  231. async twitterAuth() {
  232. let win = window.open();
  233. win.opener = null;
  234. postRequest(`/denet/user/twitterRequestToken`, {
  235. params: {
  236. oauthCallback: `${location.protocol}//${location.host}/authlogin`,
  237. },
  238. }).then(({ code, data }) => {
  239. if (code == 0) {
  240. let url = getOauthUrl(data.authToken);
  241. win.location.href = url;
  242. this.timer.value = setInterval(() => {
  243. if (win && win.closed) {
  244. clearInterval(this.timer.value);
  245. this.twitterLogin(data);
  246. if (getStorage(storageKey.backFromTwitterLogin)) {
  247. removeStorage(storageKey.backFromTwitterLogin);
  248. this.cancelLogin();
  249. }
  250. }
  251. }, 500);
  252. } else {
  253. Toast('login fail');
  254. win.close();
  255. this.cancelLogin();
  256. }
  257. });
  258. },
  259. async twitterLogin(authData) {
  260. let verifier = getStorage(storageKey.verifier);
  261. if (verifier) {
  262. postRequest(`/denet/user/twitterLogin`, {
  263. params: {
  264. consumerKey: authData.consumerKey,
  265. oauthToken: authData.authToken,
  266. oauthVerifier: verifier,
  267. },
  268. }).then(({ code, data }) => {
  269. if (code == 0) {
  270. setStorage(storageKey.userInfo, data);
  271. removeStorage(storageKey.verifier);
  272. this.loginSuccessBack = true;
  273. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}`;
  274. }
  275. });
  276. }
  277. },
  278. },
  279. unmounted() {
  280. removeStorage(storageKey.backFromTwitterLogin);
  281. },
  282. components: { FontZoom },
  283. };
  284. </script>
  285. <style lang="scss" scoped>
  286. .mobile-land-page {
  287. min-height: 100%;
  288. max-height: 100%;
  289. background: linear-gradient(180deg, #cceaff 0%, #ffffff 70.42%);
  290. display: flex;
  291. flex-direction: column;
  292. justify-content: space-between;
  293. align-items: center;
  294. padding: 0 16px;
  295. &-invited-info {
  296. width: 302px;
  297. height: 72px;
  298. margin-top: 28px;
  299. position: relative;
  300. padding-left: 81px;
  301. border-radius: 35px;
  302. display: flex;
  303. flex-direction: column;
  304. align-items: flex-start;
  305. justify-content: flex-start;
  306. background: #ffffff;
  307. border: 1px solid #c0daeb;
  308. .invited-photo {
  309. width: 70px;
  310. height: 70px;
  311. border-radius: 50%;
  312. position: absolute;
  313. left: 0;
  314. top: 0;
  315. }
  316. .invited-name {
  317. margin: 13px 0 5px;
  318. font-weight: 500;
  319. font-size: 13px;
  320. line-height: 16px;
  321. letter-spacing: 0.3px;
  322. color: #000000;
  323. max-width: 210px;
  324. text-overflow: ellipsis;
  325. white-space: nowrap;
  326. overflow: hidden;
  327. }
  328. .invited-text {
  329. font-weight: 700;
  330. font-size: 17px;
  331. line-height: 20px;
  332. letter-spacing: 0.3px;
  333. color: #f99d23;
  334. }
  335. }
  336. &-icon-wrap {
  337. display: flex;
  338. flex: 1;
  339. align-items: center;
  340. .mobile-land-page-icon {
  341. width: 100%;
  342. }
  343. }
  344. &-prize-info {
  345. font-style: normal;
  346. font-weight: 700;
  347. font-size: 18px;
  348. line-height: 21px;
  349. color: #000000;
  350. &-test {
  351. display: flex;
  352. align-items: center;
  353. justify-content: center;
  354. .pre-amount-value {
  355. margin-left: 3px;
  356. }
  357. .icon {
  358. width: 22px;
  359. height: 22px;
  360. margin-left: 3px;
  361. }
  362. .prize-name {
  363. margin: 0 3px;
  364. }
  365. }
  366. }
  367. &-tip {
  368. font-weight: 400;
  369. font-size: 13px;
  370. line-height: 16px;
  371. text-align: center;
  372. color: #7b7b7b;
  373. margin-top: 10px;
  374. }
  375. &-login-twitter {
  376. width: 100%;
  377. height: 54px;
  378. margin: 18px 16px 30px;
  379. border-radius: 54px;
  380. background: #1d9bf0;
  381. text-align: center;
  382. line-height: 54px;
  383. font-weight: 700;
  384. font-size: 18px;
  385. text-align: center;
  386. color: #fff;
  387. }
  388. }
  389. </style>