MobileLandPage.vue 9.3 KB

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