invite.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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. <span class="amount"> ${{ detail.amountUsdValue }} Giveaway</span>
  30. </div>
  31. </div>
  32. <img class="img" src="../../static/img/icon-treasure.png" 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, getDetailSSR } 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(context) {
  133. const { route, error } = context;
  134. let result = await getDetailSSR({
  135. context,
  136. params: {
  137. inviteCode: route.params.id || '',
  138. pageName: 'landPage',
  139. },
  140. url: `${baseURL}/denet/post/treasure/invite/detail`,
  141. });
  142. if (result.code == 0) {
  143. let pageLink = `${jumpUrl}treasure/invite/${route.params.id}`;
  144. if (route.params.channel) {
  145. pageLink = `${pageLink}/${route.params.channel}`;
  146. }
  147. return {
  148. detail: result.data,
  149. pageLink,
  150. };
  151. } else {
  152. return error({
  153. message: result.msg,
  154. statusCode: 500,
  155. });
  156. }
  157. },
  158. created() {
  159. this.getConfig();
  160. },
  161. mounted() {
  162. console.log('detail', this.detail);
  163. this.setCookieMid();
  164. Cookies.set(this.detail.postId, JSON.stringify({ inviteCode: this.$route.params.id, channel: this.$route.params.channel }), { expires: 100 });
  165. this.setTreasureInfo();
  166. detectExtension(denetExtensionId, (isInstall) => {
  167. if (isInstall) {
  168. if (this.detail.repostSrcContentId && this.detail.inviteUserInfo && this.detail.inviteUserInfo.nickName) {
  169. let url = `https://twitter.com/${this.detail.inviteUserInfo.nickName}/status/${this.detail.repostSrcContentId}`;
  170. window.location.replace(url);
  171. }
  172. this.isLoading = false;
  173. } else {
  174. this.isLoading = false;
  175. }
  176. });
  177. this.checkBrowser();
  178. var clipboard = new ClipboardJS('.btn');
  179. let that = this;
  180. clipboard.on('success', function (e) {
  181. Toast('copy success');
  182. // 埋点
  183. that.trackingClick();
  184. e.clearSelection();
  185. });
  186. this.pageSource = Report.pageSource.newUserLandingPage;
  187. // 埋点
  188. if (this.isMobile) {
  189. this.pageSource = Report.pageSource.mobileLandingPage;
  190. Report.reportLog({
  191. baseInfo: {
  192. appVersionCode: this.appVersionCode,
  193. mid: this.mid,
  194. pageSource: this.pageSource,
  195. machineCode: this.mid,
  196. },
  197. params: {
  198. eventData: {
  199. businessType: Report.businessType.pageView,
  200. shareLinkId: this.$route.params.id,
  201. postId: this.detail.postId,
  202. redPacketType: 4,
  203. },
  204. },
  205. });
  206. } else {
  207. Report.reportLog({
  208. baseInfo: {
  209. appVersionCode: appVersionCode,
  210. mid: this.mid,
  211. pageSource: this.pageSource,
  212. appType,
  213. machineCode: this.mid,
  214. },
  215. params: {
  216. eventData: {
  217. businessType: Report.businessType.pageView,
  218. postId: this.detail.postId,
  219. srcContentId: this.detail.srcContentId,
  220. redPacketType: 4,
  221. shareLinkId: this.$route.params.id,
  222. },
  223. },
  224. });
  225. }
  226. },
  227. methods: {
  228. clickBtn() {
  229. if (this.isChrome) {
  230. Report.reportLog({
  231. baseInfo: {
  232. appVersionCode: appVersionCode,
  233. mid: this.mid,
  234. pageSource: this.pageSource,
  235. appType,
  236. machineCode: this.mid,
  237. },
  238. params: {
  239. eventData: {
  240. businessType: Report.businessType.buttonClick,
  241. postId: this.detail.postId,
  242. srcContentId: this.detail.srcContentId,
  243. redPacketType: 4,
  244. shareLinkId: this.$route.params.id,
  245. },
  246. },
  247. });
  248. let { extensionsInstallUrl } = this.config;
  249. window.open(extensionsInstallUrl);
  250. } else {
  251. this.installChrome();
  252. }
  253. },
  254. checkInstall() {
  255. return new Promise((resolve, reject) => {
  256. let dom = document.querySelector('#denet_message');
  257. console.log('denet_message', dom);
  258. if (dom) {
  259. resolve(true);
  260. } else {
  261. reject(false);
  262. }
  263. });
  264. },
  265. trackingClick() {},
  266. guid() {
  267. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  268. var r = (Math.random() * 16) | 0,
  269. v = c == 'x' ? r : (r & 0x3) | 0x8;
  270. return v.toString(16);
  271. });
  272. },
  273. setCookieMid() {
  274. let _cookie_mid_arr = Cookies.get('mid') || [];
  275. if (_cookie_mid_arr.length > 0) {
  276. this.mid = JSON.parse(_cookie_mid_arr)[0].mid;
  277. } else {
  278. this.mid = this.guid();
  279. Cookies.set('mid', JSON.stringify([{ mid: this.mid }]), { expires: 1000 });
  280. }
  281. },
  282. installExtension() {
  283. // 埋点
  284. this.trackingClick();
  285. let { extensionsInstallUrl } = this.config;
  286. window.open(extensionsInstallUrl);
  287. },
  288. installChrome() {
  289. window.open('https://www.google.com/chrome');
  290. },
  291. async getConfig() {
  292. let { data } = await axios.post(`${baseURL}/denet/base/config/getFrontConfig`, {
  293. baseInfo: {
  294. appVersionCode: appVersionCode,
  295. mid: this.mid,
  296. },
  297. params: {},
  298. });
  299. if (data.code == 0) {
  300. this.config = data.data;
  301. }
  302. },
  303. checkBrowser() {
  304. this.linkHref = window.location.href;
  305. this.isChrome = isBrowser() == 'chrome';
  306. 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);
  307. },
  308. setTreasureInfo() {
  309. let treasureInfo = {
  310. createTime: Date.now(),
  311. jump_type: 'treasure_info',
  312. srcContentId: this.detail.repostSrcContentId || '',
  313. postNickName: this.detail.inviteUserInfo.nickName,
  314. postId: this.detail.postId || '',
  315. shareLinkId: this.$route.params.id || '',
  316. channelName: this.$route.params.channel ? window.atob(this.$route.params.channel) : '',
  317. };
  318. Cookies.set('jump_info', JSON.stringify(treasureInfo), { expires: 100 });
  319. },
  320. },
  321. };
  322. </script>
  323. <style lang="scss">
  324. html,
  325. body,
  326. #__nuxt,
  327. #__layout {
  328. width: 100%;
  329. height: 100%;
  330. padding: 0;
  331. margin: 0;
  332. }
  333. .nft-content {
  334. width: 100%;
  335. height: 100%;
  336. background: linear-gradient(180deg, #d8efff 0%, #ffffff 44.3%);
  337. .loading {
  338. position: absolute;
  339. transform: translate(-50%, -50%);
  340. top: 50%;
  341. left: 50%;
  342. margin: auto;
  343. width: 40px;
  344. border-radius: 50%;
  345. }
  346. .logo {
  347. display: flex;
  348. align-items: center;
  349. height: 70px;
  350. margin-left: 25px;
  351. img {
  352. width: 99px;
  353. height: 32px;
  354. }
  355. }
  356. .show {
  357. display: flex;
  358. align-items: center;
  359. height: calc(100% - 70px);
  360. .center {
  361. margin: -50px auto 0;
  362. width: 480px;
  363. box-shadow: 0px 2px 18px rgba(0, 0, 0, 0.1);
  364. border-radius: 12px;
  365. display: flex;
  366. justify-content: space-between;
  367. flex-direction: column;
  368. padding: 26px;
  369. box-sizing: border-box;
  370. .content-wrapper {
  371. display: flex;
  372. justify-content: center;
  373. align-items: center;
  374. margin-top: 14px;
  375. .img {
  376. width: 70px;
  377. height: 70px;
  378. }
  379. .img-left {
  380. border-radius: 50%;
  381. }
  382. .middle {
  383. padding: 0 20px;
  384. box-sizing: border-box;
  385. .invite-txt {
  386. text-align: center;
  387. color: #727272;
  388. font-weight: 400;
  389. font-size: 13px;
  390. }
  391. .title {
  392. font-weight: 800;
  393. font-size: 20px;
  394. margin: 3px 0;
  395. line-height: 20px;
  396. }
  397. .up-gain-txt {
  398. color: #f8bc2b;
  399. font-weight: 600;
  400. font-size: 13px;
  401. display: flex;
  402. align-items: center;
  403. justify-content: center;
  404. .amount {
  405. font-weight: 700;
  406. font-size: 22px;
  407. line-height: 22px;
  408. }
  409. }
  410. }
  411. }
  412. .btn-wrapper {
  413. margin-top: 50px;
  414. padding: 16px;
  415. box-sizing: border-box;
  416. background: #1d9bf0;
  417. border-radius: 100px;
  418. color: #ffffff;
  419. font-weight: 700;
  420. font-size: 17px;
  421. display: flex;
  422. align-items: center;
  423. justify-content: center;
  424. cursor: pointer;
  425. .img {
  426. width: 28px;
  427. height: 28px;
  428. margin-right: 8px;
  429. }
  430. }
  431. }
  432. }
  433. }
  434. </style>