MobileLandPage.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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, getOauthUrl } from '../utils/help';
  72. import { postRequest } from '../http';
  73. import FontZoom from './FontZoom';
  74. import { Toast } from 'vant';
  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. if (userInfo) {
  192. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}`;
  193. } else {
  194. this.twitterAuth();
  195. }
  196. },
  197. cancelLogin() {
  198. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}`;
  199. },
  200. async twitterAuth() {
  201. let win = window.open();
  202. win.opener = null;
  203. postRequest(`/denet/user/twitterRequestToken`, {
  204. params: {
  205. oauthCallback: `${location.protocol}//${location.host}/authlogin`,
  206. },
  207. }).then(({ code, data }) => {
  208. if (code == 0) {
  209. let url = getOauthUrl(data.authToken);
  210. win.location.href = url;
  211. this.timer.value = setInterval(() => {
  212. if (win && win.closed) {
  213. clearInterval(this.timer.value);
  214. this.twitterLogin(data);
  215. if (getStorage(storageKey.backFromTwitterLogin)) {
  216. removeStorage(storageKey.backFromTwitterLogin);
  217. this.cancelLogin();
  218. }
  219. }
  220. }, 500);
  221. } else {
  222. Toast('login fail');
  223. win.close();
  224. this.cancelLogin();
  225. }
  226. });
  227. },
  228. async twitterLogin(authData) {
  229. let verifier = getStorage(storageKey.verifier);
  230. if (verifier) {
  231. postRequest(`/denet/user/twitterLogin`, {
  232. params: {
  233. consumerKey: authData.consumerKey,
  234. oauthToken: authData.authToken,
  235. oauthVerifier: verifier,
  236. },
  237. }).then(({ code, data }) => {
  238. if (code == 0) {
  239. setStorage(storageKey.userInfo, data);
  240. removeStorage(storageKey.verifier);
  241. this.loginSuccessBack = true;
  242. location.href = `/course?useful=${this.useFul ? '1' : '0'}&playType=${this.playType}&rewardType=${this.rewardType}&postId=${this.postId}`;
  243. }
  244. });
  245. }
  246. },
  247. },
  248. unmounted() {
  249. removeStorage(storageKey.backFromTwitterLogin);
  250. },
  251. components: { FontZoom },
  252. };
  253. </script>
  254. <style lang="scss" scoped>
  255. .mobile-land-page {
  256. min-height: 100%;
  257. max-height: 100%;
  258. background: linear-gradient(180deg, #cceaff 0%, #ffffff 70.42%);
  259. display: flex;
  260. flex-direction: column;
  261. justify-content: space-between;
  262. align-items: center;
  263. padding: 0 16px;
  264. &-invited-info {
  265. width: 302px;
  266. height: 72px;
  267. margin-top: 28px;
  268. position: relative;
  269. padding-left: 81px;
  270. border-radius: 35px;
  271. display: flex;
  272. flex-direction: column;
  273. align-items: flex-start;
  274. justify-content: flex-start;
  275. background: #ffffff;
  276. border: 1px solid #c0daeb;
  277. .invited-photo {
  278. width: 70px;
  279. height: 70px;
  280. border-radius: 50%;
  281. position: absolute;
  282. left: 0;
  283. top: 0;
  284. }
  285. .invited-name {
  286. margin: 13px 0 5px;
  287. font-weight: 500;
  288. font-size: 13px;
  289. line-height: 16px;
  290. letter-spacing: 0.3px;
  291. color: #000000;
  292. max-width: 210px;
  293. text-overflow: ellipsis;
  294. white-space: nowrap;
  295. overflow: hidden;
  296. }
  297. .invited-text {
  298. font-weight: 700;
  299. font-size: 17px;
  300. line-height: 20px;
  301. letter-spacing: 0.3px;
  302. color: #f99d23;
  303. }
  304. }
  305. &-icon-wrap {
  306. display: flex;
  307. flex: 1;
  308. align-items: center;
  309. .mobile-land-page-icon {
  310. width: 100%;
  311. }
  312. }
  313. &-prize-info {
  314. font-style: normal;
  315. font-weight: 700;
  316. font-size: 18px;
  317. line-height: 21px;
  318. color: #000000;
  319. &-test {
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. .pre-amount-value {
  324. margin-left: 3px;
  325. }
  326. .icon {
  327. width: 22px;
  328. height: 22px;
  329. margin-left: 3px;
  330. }
  331. .prize-name {
  332. margin: 0 3px;
  333. }
  334. .treasure-usd-amount {
  335. color: #f99d23;
  336. font-weight: 700;
  337. font-size: 18px;
  338. }
  339. }
  340. }
  341. &-tip {
  342. font-weight: 400;
  343. font-size: 13px;
  344. line-height: 16px;
  345. text-align: center;
  346. color: #7b7b7b;
  347. margin-top: 10px;
  348. }
  349. &-login-twitter {
  350. width: 100%;
  351. height: 54px;
  352. margin: 18px 16px 30px;
  353. border-radius: 54px;
  354. background: #1d9bf0;
  355. text-align: center;
  356. line-height: 54px;
  357. font-weight: 700;
  358. font-size: 18px;
  359. text-align: center;
  360. color: #fff;
  361. }
  362. }
  363. </style>