list.vue 14 KB

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