MobileLandPage.vue 9.9 KB

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