invite.vue 10 KB

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