index.vue 9.7 KB

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