list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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" position="top" 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" position="top" style="background: transparent;color: #999;" :close-on-click-overlay="false" @close="closeShowAd">
  25. <div v-for="(item, index) in adlist" :key="item.id" class="m114">
  26. <div v-if="index === 0" class="fwc">
  27. <div v-if="time" class="countdown">{{ time }}s后关闭广告</div>
  28. <video 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;" position="top" :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;" position="top" :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;" position="top" :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. data() {
  80. return {
  81. showVideoSuccess: false,
  82. showAd: false,
  83. showBuy: false,
  84. showBuySuccess: false,
  85. showLogin: false,
  86. list: [],
  87. id: '',
  88. token: '',
  89. giftBagId: '',
  90. gameActivationCode: '',
  91. adlist: [],
  92. time: 30,
  93. timer: null
  94. }
  95. },
  96. head: {
  97. title: '福利社区',
  98. },
  99. filters: {
  100. activationCodeMask(value) {
  101. // 微信环境不支持零宽断言
  102. // return value.replace(/(?<=^.{4})(.*)(?=.{4}$)/, '***');
  103. return value.replace(/(.{4})(.*)(.{4}$)/, '$1***$3');
  104. },
  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: 70px;
  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. margin: 0 auto;
  304. position: relative;
  305. }
  306. .w412h238 {
  307. width: 206px;
  308. height: 119px;
  309. display: block;
  310. margin: 40px auto 17px;
  311. }
  312. .disabled {
  313. background: #2b3c5c !important;
  314. color: #999999 !important;
  315. }
  316. .txt6 {
  317. height: 22px;
  318. font-size: 16px;
  319. font-weight: 500;
  320. color: #363636;
  321. line-height: 22px;
  322. text-align: center;
  323. }
  324. .wh40 {
  325. width: 40px;
  326. height: 40px;
  327. }
  328. .mt20 {
  329. margin-top: 20px;
  330. }
  331. .fsc {
  332. display: flex;
  333. align-items: flex-start;
  334. justify-content: center;
  335. }
  336. .ml10 {
  337. margin-left: 10px;
  338. }
  339. .w12h10 {
  340. width: 12px;
  341. height: 10px;
  342. }
  343. .txt5 {
  344. font-size: 12px;
  345. color: #666666;
  346. margin-top: 3px;
  347. }
  348. .fcc {
  349. display: flex;
  350. flex-direction: column;
  351. justify-content: center;
  352. align-items: center;
  353. min-width: 72px;
  354. }
  355. .w100h107 {
  356. width: 100px;
  357. height: 107px;
  358. display: block;
  359. margin: 17px auto 0;
  360. }
  361. .w290h233 {
  362. width: 290px;
  363. height: 233px;
  364. margin: 0 auto;
  365. }
  366. .w290h276 {
  367. width: 290px;
  368. height: 276px;
  369. margin: 0 auto;
  370. }
  371. .dialog-view {
  372. background: linear-gradient(360deg, #ffffff 0%, #dfefff 100%);
  373. box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.5);
  374. border-radius: 8px;
  375. position: relative;
  376. overflow: hidden;
  377. }
  378. .countdown {
  379. width: 92px;
  380. height: 25px;
  381. background: rgba(6, 6, 6, 0.5);
  382. border-radius: 13px;
  383. position: absolute;
  384. top: 10px;
  385. right: 10px;
  386. font-size: 11px;
  387. text-align: center;
  388. line-height: 25px;
  389. color: #cccccc;
  390. }
  391. .mt15 {
  392. margin-top: 15px;
  393. }
  394. .fwc {
  395. display: flex;
  396. flex-direction: column;
  397. justify-content: center;
  398. position: relative;
  399. }
  400. .w290h330 {
  401. width: 290px;
  402. height: 330px;
  403. background: #000000;
  404. }
  405. .buy-btn {
  406. width: 207px;
  407. height: 40px;
  408. background: linear-gradient(90deg, #38aefc 0%, #3b7fff 100%);
  409. border-radius: 20px;
  410. line-height: 40px;
  411. text-align: center;
  412. font-weight: 500;
  413. color: #ffffff;
  414. font-size: 16px;
  415. margin: 20px auto 0;
  416. }
  417. .c3B86FF {
  418. color: #3b86ff;
  419. }
  420. .txt4 {
  421. width: 290px;
  422. font-size: 14px;
  423. color: #666666;
  424. line-height: 20px;
  425. margin-top: 12px;
  426. text-align: center;
  427. }
  428. .txt3 {
  429. width: 290px;
  430. font-size: 18px;
  431. font-weight: 500;
  432. color: #363636;
  433. line-height: 25px;
  434. text-align: center;
  435. margin-top: 47px;
  436. }
  437. .w290h215 {
  438. width: 290px;
  439. height: 215px;
  440. margin: 0 auto;
  441. position: relative;
  442. }
  443. .m114 {
  444. margin: 0 auto;
  445. width: 290px;
  446. }
  447. .icon-close {
  448. position: absolute;
  449. top: 20px;
  450. right: 20px;
  451. }
  452. .gift-btn {
  453. width: 78px;
  454. height: 28px;
  455. background: #3b7fff;
  456. border-radius: 4px;
  457. font-size: 14px;
  458. color: #ffffff;
  459. line-height: 28px;
  460. text-align: center;
  461. justify-self: end;
  462. }
  463. .ml12 {
  464. margin-left: 12px;
  465. }
  466. .txt2 {
  467. font-size: 14px;
  468. color: #cfd1d4;
  469. line-height: 20px;
  470. margin-top: 5px;
  471. }
  472. .txt1 {
  473. font-size: 18px;
  474. font-weight: 500;
  475. color: #cfd1d4;
  476. line-height: 25px;
  477. }
  478. .wh60 {
  479. width: 60px;
  480. height: 60px;
  481. border: 1px solid #eaeaea;
  482. border-radius: 50%;
  483. padding: 2px;
  484. box-sizing: border-box;
  485. }
  486. .wh56 {
  487. width: 56px;
  488. height: 56px;
  489. border-radius: 50%;
  490. }
  491. .bg101010 {
  492. background: #101010;
  493. min-height: 100vh;
  494. overflow: hidden;
  495. }
  496. .m15 {
  497. margin: 15px;
  498. height: 83px;
  499. background: #1e2022;
  500. box-shadow: 0px 3px 7px 0px #1e2022;
  501. border-radius: 8px;
  502. display: flex;
  503. align-items: center;
  504. justify-content: space-between;
  505. padding: 12px 15px 12px;
  506. box-sizing: border-box;
  507. }
  508. </style>