index.vue 9.6 KB

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