MobileLandPage.vue 9.8 KB

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