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