invite.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <div class="nft-content">
  3. <template v-if="isLoading">
  4. <img class="loading" src="../../static/svg/icon-loading.svg" />
  5. </template>
  6. <template v-else>
  7. <template v-if="isMobile">
  8. <MobileLandPage :playType="PlayType.Treasure" :useFul="true" :userInfo="detail.inviteUserInfo" :usValue="detail.upGainAmountValue" :postId="detail.postId" :srcContentId="detail.srcContentId"></MobileLandPage>
  9. </template>
  10. <template v-else>
  11. <div class="logo">
  12. <img src="/img/icon-logo.png" alt />
  13. </div>
  14. <div class="show">
  15. <div class="center">
  16. <div class="content-wrapper">
  17. <img class="img img-left" :src="detail.inviteUserInfo.avatarUrl" alt="" />
  18. <div class="middle">
  19. <div class="invite-txt">@{{ detail.inviteUserInfo.nickName }} invite you to</div>
  20. <div class="title">Hunt the Treaure</div>
  21. <div class="up-gain-txt">
  22. Each can gain up to <span class="amount"> ${{ detail.upGainAmountValue }}</span>
  23. </div>
  24. </div>
  25. <img class="img" src="../../static/svg/icon-treasure.svg" alt="" />
  26. </div>
  27. <div class="btn-wrapper" @click="clickBtn()">
  28. <template v-if="isChrome"> Install Denet Chrome Extension </template>
  29. <template v-else>
  30. <img class="img" src="../../static/svg/icon-chrome-down.svg" />
  31. Open in Chrome to participate
  32. </template>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. </template>
  38. </div>
  39. </template>
  40. <script>
  41. import axios from 'axios';
  42. import Cookies from 'js-cookie';
  43. import { Toast } from 'vant';
  44. import { isBrowser, appVersionCode, appType } from '../../utils/help.js';
  45. import Report from '@/log-center/log';
  46. import MobileLandPage from '@/components/MobileLandPage.vue';
  47. import { PlayType } from '@/types';
  48. const api = {
  49. prod: 'https://api.denetme.net',
  50. pre: 'https://preapi.denetme.net',
  51. test: 'https://testapi.denetme.net',
  52. };
  53. const page = {
  54. prod: 'https://h5.denetme.net',
  55. pre: 'https://preh5.denetme.net',
  56. test: 'https://testh5.denetme.net',
  57. };
  58. const jumpUrl = page[process.env.NUXT_ENV.MODE] + '/';
  59. const baseURL = api[process.env.NUXT_ENV.MODE];
  60. const ClipboardJS = require('clipboard');
  61. export default {
  62. name: 'ntf',
  63. data() {
  64. return {
  65. PlayType,
  66. isLoading: true,
  67. appVersionCode: appVersionCode,
  68. jumpUrl: jumpUrl,
  69. detail: {
  70. inviteUserInfo: {
  71. avatarUrl: '',
  72. nickName: '',
  73. },
  74. amountValue: '',
  75. currencySymbol: '',
  76. amountUsdValue: '',
  77. totalCount: '',
  78. },
  79. config: {},
  80. title: 'Treasure Hunt',
  81. isMobile: false,
  82. isChrome: false,
  83. linkHref: '',
  84. };
  85. },
  86. components: {
  87. MobileLandPage,
  88. },
  89. head() {
  90. return {
  91. type: '',
  92. title: this.title,
  93. appVersionCode: appVersionCode,
  94. meta: [
  95. // facebook
  96. {
  97. name: 'og:title',
  98. content: `Treasure Chest: ${this.detail.amountValue} ${this.detail.currencySymbol} (worth $${this.detail.amountUsdValue}) for ${this.detail.totalCount} winners`,
  99. },
  100. {
  101. name: 'og:image',
  102. content: this.detail.imagePath || '',
  103. },
  104. // twitter
  105. {
  106. name: 'twitter:card',
  107. content: 'summary_large_image',
  108. },
  109. {
  110. name: 'twitter:title',
  111. content: `Treasure Chest: ${this.detail.amountValue} ${this.detail.currencySymbol} (worth $${this.detail.amountUsdValue}) for ${this.detail.totalCount} winners`,
  112. },
  113. {
  114. name: 'twitter:image',
  115. content: this.detail.imagePath || '',
  116. },
  117. ],
  118. };
  119. },
  120. async asyncData(params) {
  121. let { route } = params;
  122. let { data } = await axios.post(`${baseURL}/denet/post/treasure/invite/detail`, {
  123. baseInfo: {
  124. appVersionCode: appVersionCode,
  125. mid: (function () {
  126. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  127. var r = (Math.random() * 16) | 0,
  128. v = c == 'x' ? r : (r & 0x3) | 0x8;
  129. return v.toString(16);
  130. });
  131. })(),
  132. },
  133. params: {
  134. inviteCode: route.params.id || '',
  135. },
  136. });
  137. if (data.code == 0) {
  138. return {
  139. detail: data.data,
  140. };
  141. }
  142. },
  143. created() {
  144. this.setCookieMid();
  145. this.getConfig();
  146. },
  147. mounted() {
  148. Cookies.set(this.detail.postId, JSON.stringify({ inviteCode: this.$route.params.id }), { expires: 100 });
  149. this.setTreasureInfo();
  150. setTimeout(() => {
  151. this.checkInstall()
  152. .then(() => {
  153. console.log(this.detail);
  154. if (this.detail.repostSrcContentId && this.detail.inviteUserInfo && this.detail.inviteUserInfo.nickName) {
  155. let url = `https://twitter.com/${this.detail.inviteUserInfo.nickName}/status/${this.detail.repostSrcContentId}`;
  156. window.location.replace(url);
  157. }
  158. this.isLoading = false;
  159. })
  160. .catch(() => {
  161. this.isLoading = false;
  162. });
  163. }, 1000);
  164. this.checkBrowser();
  165. var clipboard = new ClipboardJS('.btn');
  166. let that = this;
  167. clipboard.on('success', function (e) {
  168. Toast('copy success');
  169. // 埋点
  170. that.trackingClick();
  171. e.clearSelection();
  172. });
  173. this.pageSource = Report.pageSource.newUserLandingPage;
  174. // 埋点
  175. if (this.isMobile) {
  176. this.pageSource = Report.pageSource.mobileLandingPage;
  177. Report.reportLog({
  178. baseInfo: {
  179. appVersionCode: this.appVersionCode,
  180. mid: this.mid,
  181. pageSource: this.pageSource,
  182. machineCode: this.mid,
  183. },
  184. params: {
  185. eventData: {
  186. businessType: Report.businessType.pageView,
  187. shareLinkId: this.$route.params.id,
  188. postId: this.detail.postId,
  189. },
  190. },
  191. });
  192. } else {
  193. Report.reportLog({
  194. baseInfo: {
  195. appVersionCode: appVersionCode,
  196. mid: this.mid,
  197. pageSource: this.pageSource,
  198. appType,
  199. machineCode: this.mid,
  200. },
  201. params: {
  202. eventData: {
  203. businessType: Report.businessType.pageView,
  204. postId: this.detail.postId,
  205. srcContentId: this.detail.srcContentId,
  206. redPacketType: 4,
  207. shareLinkId: this.$route.params.id,
  208. },
  209. },
  210. });
  211. }
  212. },
  213. methods: {
  214. clickBtn() {
  215. if (this.isChrome) {
  216. Report.reportLog({
  217. baseInfo: {
  218. appVersionCode: appVersionCode,
  219. mid: this.mid,
  220. pageSource: this.pageSource,
  221. appType,
  222. machineCode: this.mid,
  223. },
  224. params: {
  225. eventData: {
  226. businessType: Report.businessType.buttonClick,
  227. postId: this.detail.postId,
  228. srcContentId: this.detail.srcContentId,
  229. redPacketType: 4,
  230. shareLinkId: this.$route.params.id,
  231. },
  232. },
  233. });
  234. let { extensionsInstallUrl } = this.config;
  235. window.open(extensionsInstallUrl);
  236. } else {
  237. this.installChrome();
  238. }
  239. },
  240. checkInstall() {
  241. return new Promise((resolve, reject) => {
  242. let dom = document.querySelector('#denet_message');
  243. console.log('denet_message', dom);
  244. if (dom) {
  245. resolve(true);
  246. } else {
  247. reject(false);
  248. }
  249. });
  250. },
  251. trackingClick() {},
  252. guid() {
  253. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  254. var r = (Math.random() * 16) | 0,
  255. v = c == 'x' ? r : (r & 0x3) | 0x8;
  256. return v.toString(16);
  257. });
  258. },
  259. setCookieMid() {
  260. let _cookie_mid_arr = Cookies.get('mid') || [];
  261. if (_cookie_mid_arr.length > 0) {
  262. this.mid = JSON.parse(_cookie_mid_arr)[0].mid;
  263. } else {
  264. this.mid = this.guid();
  265. Cookies.set('mid', JSON.stringify([{ mid: this.mid }]), { expires: 1000 });
  266. }
  267. },
  268. installExtension() {
  269. // 埋点
  270. this.trackingClick();
  271. let { extensionsInstallUrl } = this.config;
  272. window.open(extensionsInstallUrl);
  273. },
  274. installChrome() {
  275. window.open('https://www.google.com/chrome');
  276. },
  277. async getConfig() {
  278. let { data } = await axios.post(`${baseURL}/denet/base/config/getFrontConfig`, {
  279. baseInfo: {
  280. appVersionCode: appVersionCode,
  281. mid: this.mid,
  282. },
  283. params: {},
  284. });
  285. if (data.code == 0) {
  286. this.config = data.data;
  287. }
  288. },
  289. checkBrowser() {
  290. this.linkHref = window.location.href;
  291. this.isChrome = isBrowser() == 'chrome';
  292. this.isMobile = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
  293. },
  294. setTreasureInfo() {
  295. let treasureInfo = {
  296. createTime: Date.now(),
  297. jump_type: 'treasure_info',
  298. srcContentId: this.detail.repostSrcContentId || '',
  299. postNickName: this.detail.inviteUserInfo.nickName,
  300. };
  301. Cookies.set('jump_info', JSON.stringify(treasureInfo), { expires: 100 });
  302. },
  303. },
  304. };
  305. </script>
  306. <style lang="scss">
  307. html,
  308. body,
  309. #__nuxt,
  310. #__layout {
  311. width: 100%;
  312. height: 100%;
  313. padding: 0;
  314. margin: 0;
  315. }
  316. .nft-content {
  317. overflow: hidden;
  318. width: 100%;
  319. height: 100%;
  320. background: linear-gradient(180deg, #d8efff 0%, #ffffff 44.3%);
  321. .loading {
  322. position: absolute;
  323. transform: translate(-50%, -50%);
  324. top: 50%;
  325. left: 50%;
  326. margin: auto;
  327. width: 40px;
  328. border-radius: 50%;
  329. }
  330. .logo {
  331. display: flex;
  332. align-items: center;
  333. height: 70px;
  334. margin-left: 25px;
  335. img {
  336. width: 99px;
  337. height: 32px;
  338. }
  339. }
  340. .show {
  341. display: flex;
  342. align-items: center;
  343. height: calc(100% - 70px);
  344. .center {
  345. margin: -50px auto 0;
  346. width: 480px;
  347. height: 260px;
  348. box-shadow: 0px 2px 18px rgba(0, 0, 0, 0.1);
  349. border-radius: 12px;
  350. display: flex;
  351. justify-content: space-between;
  352. flex-direction: column;
  353. padding: 26px;
  354. box-sizing: border-box;
  355. .content-wrapper {
  356. display: flex;
  357. justify-content: center;
  358. align-items: center;
  359. margin-top: 14px;
  360. .img {
  361. width: 70px;
  362. height: 70px;
  363. }
  364. .img-left {
  365. border-radius: 50%;
  366. }
  367. .middle {
  368. padding: 0 20px;
  369. box-sizing: border-box;
  370. .invite-txt {
  371. color: #727272;
  372. font-weight: 400;
  373. font-size: 13px;
  374. }
  375. .title {
  376. font-weight: 800;
  377. font-size: 20px;
  378. margin: 6px 3px 0;
  379. }
  380. .up-gain-txt {
  381. color: #f8bc2b;
  382. font-weight: 600;
  383. font-size: 13px;
  384. display: flex;
  385. align-items: center;
  386. .amount {
  387. font-weight: 700;
  388. font-size: 22px;
  389. }
  390. }
  391. }
  392. }
  393. .btn-wrapper {
  394. margin-top: 54px;
  395. padding: 16px;
  396. box-sizing: border-box;
  397. background: #1d9bf0;
  398. border-radius: 100px;
  399. color: #ffffff;
  400. font-weight: 700;
  401. font-size: 17px;
  402. display: flex;
  403. align-items: center;
  404. justify-content: center;
  405. cursor: pointer;
  406. .img {
  407. width: 28px;
  408. height: 28px;
  409. margin-right: 8px;
  410. }
  411. }
  412. }
  413. }
  414. }
  415. </style>