index.vue 9.8 KB

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