list.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <div class="bg101010">
  3. <div v-for="item in list" :key="item.id" class="m15">
  4. <div style="display: flex;align-items: center;">
  5. <div class="wh60">
  6. <img class="wh56" :src="iconURL(item.giftBagFileKey)" alt="" />
  7. </div>
  8. <div class="ml12">
  9. <div class="txt1">{{ item.giftBagName.length > 8 ? item.giftBagName.slice(0, 8) + '...' : item.giftBagName }}</div>
  10. <div class="txt2">{{ item.giftBagDetailed }}</div>
  11. </div>
  12. </div>
  13. <div :class="item.availableStatus === 1 ? 'gift-btn disabled' : 'gift-btn'" @click="receive(item)">{{ ['领取', '已领完', '查看'][item.availableStatus] }}</div>
  14. </div>
  15. <img class="w80h67" src="~/assets/image/activity/welfare-community/return.png" alt="" @click="returnUp">
  16. <van-popup v-model="showVideoSuccess" style="background: transparent;color: #999;" :close-on-click-overlay="false">
  17. <div class="w290h215 dialog-view">
  18. <div class="txt3">恭喜您获得礼包</div>
  19. <pre class="txt7">{{ giftBagDetailed }}</pre>
  20. <van-icon name="cross" color="#999999" size="15" class="icon-close" @click="showVideoSuccess = false" />
  21. <div class="txt4">请在游戏中兑换<br />激活码为:{{ gameActivationCode | activationCodeMask }}。<span class="c3B86FF" @click="copyCode()">复制</span></div>
  22. <div class="buy-btn" @click="order('showVideoSuccess')">购买云机</div>
  23. </div>
  24. </van-popup>
  25. <van-popup v-model="showAd" style="background: transparent;color: #999;" :close-on-click-overlay="false" @close="closeShowAd">
  26. <div v-for="(item, index) in adlist" :key="item.id">
  27. <div v-if="index === 0" class="fwc">
  28. <div v-if="time" class="countdown">{{ time }}s后关闭广告</div>
  29. <video v-if="showAd" ref="videoPlayer" class="w290h330" :src="item.adVideoBase.videoUrl" x5-video-orientation="landscape" x5-video-player-type="h5" :x5-video-player-fullscreen="false" :controls="false" :webkit-playsinline="true" :playsinline="true" :autoplay="true" play-btn-position="center" :show-fullscreen-btn="false" :muted="true" @ended="ended" />
  30. <van-icon name="close" color="#999999" size="34" style="margin:15px auto 0;" @click="closeAd" />
  31. </div>
  32. </div>
  33. </van-popup>
  34. <van-popup v-model="showBuy" style="background: transparent;color: #999;" :close-on-click-overlay="false">
  35. <div class="w290h276 dialog-view">
  36. <div class="txt3" style="margin-top: 47px;">平台内下1单,立得惊喜礼包</div>
  37. <van-icon name="cross" color="#999999" size="15" class="icon-close" @click="showBuy = false" />
  38. <img class="w100h107" src="~/assets/image/activity/welfare-community/gift.png" alt="">
  39. <div class="buy-btn" style="margin:15px auto 0;" @click="order('showBuy')">下单得惊喜礼包</div>
  40. </div>
  41. </van-popup>
  42. <van-popup v-model="showBuySuccess" style="background: transparent;color: #999;" :close-on-click-overlay="false">
  43. <div class="w290h233 dialog-view">
  44. <div class="txt3">恭喜您获得礼包</div>
  45. <pre class="txt7">{{ giftBagDetailed }}</pre>
  46. <van-icon name="cross" color="#999999" size="15" class="icon-close" @click="showBuySuccess = false" />
  47. <div class="txt4">请在游戏中兑换<br />激活码为:{{ gameActivationCode | activationCodeMask }}。<span class="c3B86FF" @click="copyCode()">复制</span></div>
  48. <div class="fsc mt20">
  49. <div class="fcc">
  50. <img class="wh40" src="~/assets/image/activity/welfare-community/icon_iphone@2x.png" alt="" />
  51. <span class="txt5">进入云机</span>
  52. </div>
  53. <img class="w12h10 ml10 mt15" src="~/assets/image/activity/welfare-community/arrow@2x.png" alt="">
  54. <div class="fcc">
  55. <img class="wh40" src="~/assets/image/activity/welfare-community/icon_yingyongshichang@2x.png" alt="">
  56. <span class="txt5">打开应用市场</span>
  57. </div>
  58. <img class="w12h10 mt15" src="~/assets/image/activity/welfare-community/arrow@2x.png" alt="">
  59. <div class="fcc">
  60. <img class="wh40" src="~/assets/image/activity/welfare-community/icon_xiazai@2x.png" alt="">
  61. <span class="txt5">下载游戏</span>
  62. </div>
  63. </div>
  64. </div>
  65. </van-popup>
  66. <van-popup v-model="showLogin" style="background: transparent;color: #999;" :close-on-click-overlay="false" @click-close-icon="returnUp">
  67. <div class="w580h582">
  68. <img class="w412h238" src="~/assets/image/activity/welfare-community/tip.png" />
  69. <van-icon name="cross" color="#999999" size="15" class="icon-close" @click="returnUp" />
  70. <div class="txt6">领取礼包,请先绑定手机号</div>
  71. <img class="buy-btn-2" src="~/assets/image/activity/welfare-community/btn.png" @click="login" />
  72. </div>
  73. </van-popup>
  74. </div>
  75. </template>
  76. <script>
  77. import { Toast } from 'vant';
  78. import { fileKeyToUrl } from '@/plugins/file-center.js';
  79. export default {
  80. auth: false,
  81. filters: {
  82. activationCodeMask(value) {
  83. // 微信环境不支持零宽断言
  84. // return value.replace(/(?<=^.{4})(.*)(?=.{4}$)/, '***');
  85. return value.replace(/(.{4})(.*)(.{4}$)/, '$1***$3');
  86. },
  87. },
  88. data() {
  89. return {
  90. showVideoSuccess: false,
  91. showAd: false,
  92. showBuy: false,
  93. showBuySuccess: false,
  94. showLogin: false,
  95. list: [],
  96. id: '',
  97. token: '',
  98. giftBagId: '',
  99. gameActivationCode: '',
  100. adlist: [],
  101. time: 30,
  102. timer: null,
  103. giftBagDetailed: ''
  104. }
  105. },
  106. head: {
  107. title: '福利社区',
  108. },
  109. computed: {
  110. iconURL() {
  111. return (key) => {
  112. return fileKeyToUrl(key)
  113. }
  114. }
  115. },
  116. created() {
  117. this.token = this.$route.query.token;
  118. this.id = this.$route.query.id;
  119. this.user = this.$route.query.user;
  120. this.gameName = this.$route.query.gameName;
  121. this.getAppGameGiftActivityDetailsList();
  122. },
  123. mounted() {
  124. document.addEventListener('visibilitychange', this.handleVisiable)
  125. },
  126. destroyed() {
  127. document.removeEventListener('visibilitychange', this.handleVisiable)
  128. },
  129. methods: {
  130. handleVisiable(e) {
  131. if (e.target.visibilityState === 'visible') {
  132. this.getAppGameGiftActivityDetailsList();
  133. }
  134. },
  135. closeShowAd() {
  136. this.showAd = false;
  137. clearInterval(this.timer);
  138. },
  139. closeAd() {
  140. this.showAd = false;
  141. clearInterval(this.timer);
  142. if (this.time === 0) {
  143. this.videoSuccess()
  144. }
  145. },
  146. async copyCode() {
  147. await this.$native.clipboard.writeText(this.gameActivationCode);
  148. this.$toast.success('复制成功');
  149. },
  150. order(key) {
  151. if (key === 'showBuy') {
  152. this.showBuy = false
  153. }
  154. if (key === 'showVideoSuccess') {
  155. this.showVideoSuccess = false
  156. }
  157. if (this.$userAgent.isSzx && this.$userAgent.isIos) {
  158. window.webkit.messageHandlers.order.postMessage({});
  159. }
  160. if (this.$userAgent.isSzx && this.$userAgent.isAndroid) {
  161. window.native.startPurchase();
  162. }
  163. },
  164. login() {
  165. this.showLogin = false
  166. if (this.$userAgent.isSzx && this.$userAgent.isIos) {
  167. window.webkit.messageHandlers.showLogin.postMessage({});
  168. }
  169. if (this.$userAgent.isSzx && this.$userAgent.isAndroid) {
  170. window.native.startBindPhone();
  171. }
  172. },
  173. ended() {
  174. this.showAd = false;
  175. clearInterval(this.timer);
  176. this.videoSuccess();
  177. },
  178. returnUp() {
  179. this.$router.push({ path: '/welfare-community', query: { token: this.$route.query.token, user: this.user } })
  180. },
  181. async receive(item) {
  182. this.giftBagDetailed = item.giftBagDetailed.replace(/ /g, "\n");
  183. if (item.availableStatus === 2) {
  184. this.gameActivationCode = item.gameActivationCode
  185. if (item.buy === 1) {
  186. this.showBuySuccess = true;
  187. }
  188. if (item.buy === 0) {
  189. this.showVideoSuccess = true;
  190. }
  191. return
  192. }
  193. if (item.availableStatus === 1) {
  194. return
  195. }
  196. this.giftBagId = item.id;
  197. if (this.$route.query.user === '2') {
  198. if (item.taskType === 2) {
  199. this.buySuccess(item);
  200. }
  201. if (item.taskType === 1) {
  202. const res = await this.$axios.$post('/public/v5/advertising/getAdInfoByAdPlace', { id: 1, adPlace: 24, os: this.$userAgent.isAndroid ? 1 : 2 }, { headers: { Authorization: this.token } });
  203. this.adlist = res.data
  204. if (!this.adlist.length) {
  205. return
  206. }
  207. this.adlist = this.adlist.length > 1 ? this.randomSort(this.adlist) : this.adlist;
  208. this.showAd = true
  209. setTimeout(() => {
  210. this.time = this.$refs.videoPlayer[0].duration > 30 ? 30 : parseInt(this.$refs.videoPlayer[0].duration);
  211. this.timer = setInterval(
  212. () => --this.time <= 0 && clearInterval(this.timer),
  213. 1000);
  214. }, 800)
  215. }
  216. } else {
  217. if (this.$userAgent.isSzx && this.$userAgent.isAndroid) {
  218. this.showLogin = true
  219. }
  220. if (this.$userAgent.isSzx && this.$userAgent.isIos) {
  221. window.webkit.messageHandlers.showLogin.postMessage({});
  222. }
  223. }
  224. },
  225. randomSort(array) {
  226. const length = array.length;
  227. if (!Array.isArray(array) || length <= 1) return;
  228. for (let index = 0; index < length - 1; index++) {
  229. const randomIndex = Math.floor(Math.random() * (length - index)) + index;
  230. [array[index], array[randomIndex]] = [array[randomIndex], array[index]];
  231. }
  232. return array;
  233. },
  234. async getAppGameGiftActivityDetailsList() {
  235. try {
  236. const res = await this.$axios.$get('/activity/game/giftActivity/getAppGameGiftActivityDetailsList?giftActivityId=' + this.id, { headers: { Authorization: this.token } });
  237. this.list = res.data;
  238. } catch (err) {
  239. Toast({
  240. message: err.message,
  241. duration: 3000
  242. });
  243. }
  244. },
  245. async buySuccess(item) {
  246. try {
  247. const res = await this.$axios.$get('/activity/game/giftActivity/receiveGameGift?giftBagId=' + item.id, { headers: { Authorization: this.token } });
  248. this.gameActivationCode = res.data.gameActivationCode;
  249. if (res.data.buy === 1) {
  250. this.showBuySuccess = true;
  251. }
  252. if (res.data.buy === 0) {
  253. this.showVideoSuccess = true;
  254. }
  255. } catch (err) {
  256. if (err.response.data.status === 8500) {
  257. this.showBuy = true;
  258. } else {
  259. Toast({
  260. message: err.message,
  261. duration: 3000
  262. });
  263. }
  264. }
  265. },
  266. async videoSuccess() {
  267. try {
  268. const res = await this.$axios.$get('/activity/game/giftActivity/receiveGameGift?giftBagId=' + this.giftBagId, { headers: { Authorization: this.token } });
  269. this.gameActivationCode = res.data.gameActivationCode;
  270. this.getAppGameGiftActivityDetailsList();
  271. if (res.data.buy === 1) {
  272. this.showBuySuccess = true;
  273. }
  274. if (res.data.buy === 0) {
  275. this.showVideoSuccess = true;
  276. }
  277. } catch (err) {
  278. Toast({
  279. message: err.message,
  280. duration: 3000
  281. });
  282. }
  283. }
  284. }
  285. }
  286. </script>
  287. <style scoped>
  288. .txt7 {
  289. font-size: 14px;
  290. font-weight: 500;
  291. color: #3B7FFF;
  292. line-height: 20px;
  293. text-align: center;
  294. margin: 20px auto;
  295. }
  296. .w80h67 {
  297. width: 80px;
  298. height: 67px;
  299. position: fixed;
  300. left: 0;
  301. bottom: 35px;
  302. }
  303. .buy-btn-2 {
  304. width: 207px;
  305. height: 40px;
  306. display: block;
  307. margin: 27px auto 0;
  308. }
  309. .w580h582 {
  310. width: 290px;
  311. height: 291px;
  312. background-color: #ffffff;
  313. border-radius: 8px;
  314. overflow: hidden;
  315. position: relative;
  316. }
  317. .w412h238 {
  318. width: 206px;
  319. height: 119px;
  320. display: block;
  321. margin: 40px auto 17px;
  322. }
  323. .disabled {
  324. background: #2b3c5c !important;
  325. color: #999999 !important;
  326. }
  327. .txt6 {
  328. height: 22px;
  329. font-size: 16px;
  330. font-weight: 500;
  331. color: #363636;
  332. line-height: 22px;
  333. text-align: center;
  334. }
  335. .wh40 {
  336. width: 40px;
  337. height: 40px;
  338. }
  339. .mt20 {
  340. margin-top: 20px;
  341. }
  342. .fsc {
  343. display: flex;
  344. align-items: flex-start;
  345. justify-content: center;
  346. }
  347. .ml10 {
  348. margin-left: 10px;
  349. }
  350. .w12h10 {
  351. width: 12px;
  352. height: 10px;
  353. }
  354. .txt5 {
  355. font-size: 12px;
  356. color: #666666;
  357. margin-top: 3px;
  358. }
  359. .fcc {
  360. display: flex;
  361. flex-direction: column;
  362. justify-content: center;
  363. align-items: center;
  364. min-width: 72px;
  365. }
  366. .w100h107 {
  367. width: 100px;
  368. height: 107px;
  369. display: block;
  370. margin: 17px auto 0;
  371. }
  372. .w290h233 {
  373. width: 290px;
  374. padding: 39px 0 26px;
  375. }
  376. .w290h276 {
  377. width: 290px;
  378. height: 276px;
  379. }
  380. .dialog-view {
  381. background: linear-gradient(360deg, #ffffff 0%, #dfefff 100%);
  382. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.5);
  383. border-radius: 8px;
  384. position: relative;
  385. overflow: hidden;
  386. }
  387. .countdown {
  388. width: 92px;
  389. height: 25px;
  390. background: rgba(6, 6, 6, 0.5);
  391. border-radius: 13px;
  392. position: absolute;
  393. top: 10px;
  394. right: 10px;
  395. font-size: 11px;
  396. text-align: center;
  397. line-height: 25px;
  398. color: #cccccc;
  399. }
  400. .mt15 {
  401. margin-top: 15px;
  402. }
  403. .fwc {
  404. display: flex;
  405. flex-direction: column;
  406. justify-content: center;
  407. position: relative;
  408. }
  409. .w290h330 {
  410. width: 290px;
  411. height: 330px;
  412. background: #000000;
  413. }
  414. .buy-btn {
  415. width: 207px;
  416. height: 40px;
  417. background: linear-gradient(90deg, #38aefc 0%, #3b7fff 100%);
  418. border-radius: 20px;
  419. line-height: 40px;
  420. text-align: center;
  421. font-weight: 500;
  422. color: #ffffff;
  423. font-size: 16px;
  424. margin: 20px auto 0;
  425. }
  426. .c3B86FF {
  427. color: #3b86ff;
  428. }
  429. .txt4 {
  430. width: 290px;
  431. font-size: 14px;
  432. color: #666666;
  433. line-height: 20px;
  434. margin-top: 12px;
  435. text-align: center;
  436. }
  437. .txt3 {
  438. width: 290px;
  439. font-size: 18px;
  440. font-weight: 500;
  441. color: #363636;
  442. line-height: 25px;
  443. text-align: center;
  444. }
  445. .w290h215 {
  446. width: 290px;
  447. padding: 40px 0 30px;
  448. position: relative;
  449. }
  450. .icon-close {
  451. position: absolute;
  452. top: 20px;
  453. right: 20px;
  454. }
  455. .gift-btn {
  456. width: 78px;
  457. height: 28px;
  458. background: #3b7fff;
  459. border-radius: 4px;
  460. font-size: 14px;
  461. color: #ffffff;
  462. line-height: 28px;
  463. text-align: center;
  464. justify-self: end;
  465. }
  466. .ml12 {
  467. margin-left: 12px;
  468. }
  469. .txt2 {
  470. font-size: 14px;
  471. color: #cfd1d4;
  472. line-height: 20px;
  473. margin-top: 5px;
  474. }
  475. .txt1 {
  476. font-size: 18px;
  477. font-weight: 500;
  478. color: #cfd1d4;
  479. line-height: 25px;
  480. }
  481. .wh60 {
  482. width: 60px;
  483. height: 60px;
  484. border: 1px solid #eaeaea;
  485. border-radius: 50%;
  486. padding: 2px;
  487. box-sizing: border-box;
  488. }
  489. .wh56 {
  490. width: 56px;
  491. height: 56px;
  492. border-radius: 50%;
  493. }
  494. .bg101010 {
  495. background: #101010;
  496. min-height: 100vh;
  497. overflow: hidden;
  498. }
  499. .m15 {
  500. margin: 15px;
  501. height: 83px;
  502. background: #1e2022;
  503. box-shadow: 0px 3px 7px 0px #1e2022;
  504. border-radius: 8px;
  505. display: flex;
  506. align-items: center;
  507. justify-content: space-between;
  508. padding: 12px 15px 12px;
  509. box-sizing: border-box;
  510. }
  511. </style>