index.vue 9.4 KB

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