index.bk.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <view class="container">
  3. <image class="headImg" mode="aspectFill" :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/homeHead.jpeg'" />
  4. <view class="headBarrage">
  5. <view class="barrage-container">
  6. <view v-for="(item, index) in barrageData" :key="index" class="barrage-item" :style="item.style">
  7. {{ item.text }}
  8. </view>
  9. </view>
  10. </view>
  11. <view class="tabs">
  12. <!-- <view class="tab">
  13. <image :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/Frame3.png'" alt="" />
  14. <span>全部</span>
  15. </view> -->
  16. <view class="tab" @click="$navigateTo('/pages/excellentValue/excellentValue')">
  17. <image :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/Frame4.png'" alt="" />
  18. <span>超值挑战</span>
  19. </view>
  20. <view class="tab" @click="$navigateTo('/pages/task/index')">
  21. <image :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/Frame2.png'" alt="" />
  22. <span>任务大厅</span>
  23. </view>
  24. <view class="tab" @click="$navigateTo('/pages/index2/index')">
  25. <image :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/Frame1.png'" alt="" />
  26. <span>VIP福利</span>
  27. </view>
  28. </view>
  29. <view class="buttons">
  30. <view class="left">
  31. <image :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/button3.png'" @click="toInvite" />
  32. </view>
  33. <view class="right">
  34. <image :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/button1.png'" @click="showQRcode" />
  35. <image
  36. :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/button2.png'"
  37. @click="$navigateTo('/pages/raffle/raffle')"
  38. />
  39. </view>
  40. </view>
  41. <view class="list-title">- 热门推荐 -</view>
  42. <view class="list">
  43. <view class="ka" v-for="(item, index) in kaList" @click="drawCard(item)">
  44. <view class="top">
  45. <image mode="aspectFit" :src="item.icon" />
  46. </view>
  47. <view class="ka-info">
  48. <view class="ka-name">{{ item.name }}</view>
  49. <view class="row">
  50. <uni-tag :text="item.tags" inverted type="default"></uni-tag>
  51. <view class="money">¥{{ item.price }}</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <uni-popup class="popup" ref="popup" type="center">
  57. <image
  58. class="qrcodeImg"
  59. :show-menu-by-longpress="true"
  60. :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/QRcode.png'"
  61. mode="widthFix"
  62. />
  63. </uni-popup>
  64. </view>
  65. </template>
  66. <script>
  67. import { messageListApi } from '@/api/common.js'
  68. import { raffleListApi } from '@/api/drawCard.js'
  69. export default {
  70. data() {
  71. return {
  72. timer: null,
  73. kaList: [],
  74. messageList: [],
  75. barrageData: [],
  76. barrageIndex: 0,
  77. timeOut: null,
  78. interval: null,
  79. params: {
  80. limit: 20,
  81. page: 1,
  82. },
  83. total: null,
  84. containerWidth: 0,
  85. usedTops: [],
  86. }
  87. },
  88. onLoad(query) {
  89. if (query.inviteId) {
  90. getApp().globalData.inviteId = query.inviteId
  91. } else {
  92. const scene = decodeURIComponent(query.scene)
  93. let inviteId = scene.split('=')[1]
  94. console.log(inviteId, 'inviteId')
  95. getApp().globalData.inviteId = inviteId
  96. }
  97. console.log(this.$refs)
  98. },
  99. onShow() {
  100. this.getMessage()
  101. this.getHot()
  102. this.interval = setInterval(() => {
  103. console.log('重复获取消息')
  104. this.barrageIndex = 0
  105. this.getMessage()
  106. // let num = this.params.page * this.params.limit
  107. // if (this.total == null || this.total > num) {
  108. // console.log('获取消息接口')
  109. // // this.params.page += 1
  110. // this.barrageIndex = 0
  111. // this.getMessage()
  112. // }
  113. }, 60000)
  114. setTimeout(() => {
  115. this.launchBarrage()
  116. }, 2000)
  117. },
  118. onHide() {
  119. clearInterval(this.interval)
  120. clearInterval(this.timer)
  121. },
  122. methods: {
  123. showQRcode() {
  124. this.$refs.popup.open()
  125. },
  126. drawCard(value) {
  127. let url = ''
  128. if (value.type == 1) {
  129. url = '/pages/drawCard_infinite/drawCard_infinite'
  130. } else if (value.type == 2) {
  131. url = '/pages/drawCard_last/drawCard_last'
  132. } else if (value.type == 3) {
  133. url = '/pages/drawCard_fullSet/drawCard_fullSet'
  134. } else if (value.type == 4) {
  135. url = '/pages/drawCard_box/drawCard_box'
  136. } else if (value.type == 5) {
  137. url = '/pages/drawCard_first/drawCard_first'
  138. }
  139. this.$navigateTo(url, {
  140. id: value.id,
  141. })
  142. },
  143. getHot() {
  144. let params = {
  145. limit: 999,
  146. page: 1,
  147. isHot: true,
  148. }
  149. raffleListApi(params).then(res => {
  150. this.kaList = res.data.list
  151. })
  152. },
  153. getMessage() {
  154. messageListApi(this.params).then(res => {
  155. this.messageList = res.data.list
  156. this.total = res.data.total
  157. this.initBarrage()
  158. })
  159. },
  160. launchBarrage() {
  161. if (this.timer) {
  162. clearInterval(this.timer)
  163. }
  164. this.timer = setInterval(() => {
  165. this.barrageData.forEach((barrage, index) => {
  166. if (!barrage.tag) {
  167. barrage.tag = true
  168. barrage.right = -400
  169. barrage.top = this.randomTop()
  170. barrage.style = `display: block; top: ${barrage.top}px; right: ${barrage.right}px;`
  171. } else {
  172. barrage.right = parseInt(barrage.right) + 2
  173. barrage.style = `display: block; top: ${barrage.top}px; right: ${barrage.right}px;`
  174. }
  175. })
  176. }, 20)
  177. },
  178. // 初始化弹幕
  179. initBarrage() {
  180. // console.log(this.barrageIndex, 'this.barrageIndex')
  181. if (this.messageList.length > 0) {
  182. this.timeOut = setTimeout(() => {
  183. let barrage = {
  184. text: this.messageList[this.barrageIndex].content,
  185. }
  186. this.$set(barrage, 'right', -400)
  187. this.$set(barrage, 'top', this.randomTop())
  188. this.$set(barrage, 'tag', false)
  189. this.barrageData.push(barrage)
  190. this.barrageIndex += 1
  191. clearTimeout(this.timeOut)
  192. if (this.barrageIndex > this.messageList.length - 1) {
  193. this.barrageIndex = 0
  194. } else {
  195. this.initBarrage()
  196. }
  197. }, 1000)
  198. }
  199. },
  200. // 发送弹幕
  201. sendingBarrage() {
  202. let messageList = this.messageList
  203. },
  204. randomTop() {
  205. // return Math.floor(Math.random() * 150)
  206. // 往前5个不重复top值
  207. let top = 0
  208. this.usedTops.push(top)
  209. do {
  210. top = Math.floor(Math.random() * 6) * 30 // 生成0, 30, 60, 90, 120的随机值
  211. } while (this.usedTops.slice(-4).includes(top))
  212. this.usedTops.push(top)
  213. return top
  214. },
  215. toInvite() {
  216. wx.navigateTo({
  217. url: '/pages/invite/invite',
  218. })
  219. },
  220. },
  221. }
  222. </script>
  223. <style scoped lang="scss">
  224. .barrage-container {
  225. width: 100%;
  226. height: 180px;
  227. position: relative;
  228. overflow: hidden;
  229. background-color: rgba(0, 0, 0, 0.2);
  230. /* 背景色,可根据需要调整 */
  231. }
  232. .barrage-item {
  233. color: #fff;
  234. padding: 5px 10px;
  235. font-size: 14px;
  236. line-height: 30px;
  237. position: absolute;
  238. white-space: nowrap;
  239. display: none;
  240. border-radius: 15px;
  241. background-color: rgba(0, 0, 0, 0.3);
  242. }
  243. .container {
  244. /* padding: 20px; */
  245. font-size: 14px;
  246. line-height: 24px;
  247. }
  248. .headImg {
  249. height: 180px;
  250. width: 100%;
  251. }
  252. .headBarrage {
  253. height: 180px;
  254. width: 100%;
  255. position: absolute;
  256. top: 0;
  257. }
  258. .tabs {
  259. display: flex;
  260. justify-content: space-around;
  261. margin-top: 10px;
  262. > .tab {
  263. width: 20%;
  264. display: flex;
  265. flex-direction: column;
  266. justify-content: center;
  267. align-items: center;
  268. > image {
  269. width: 40px;
  270. height: 40px;
  271. }
  272. }
  273. }
  274. .buttons {
  275. margin-top: 5px;
  276. padding: 10px;
  277. display: flex;
  278. justify-content: space-between;
  279. > .left {
  280. width: calc(50vw - 15px);
  281. height: 40vw;
  282. image {
  283. width: 100%;
  284. height: 100%;
  285. }
  286. }
  287. > .right {
  288. width: calc(50vw - 15px);
  289. height: 40vw;
  290. display: flex;
  291. flex-direction: column;
  292. justify-content: space-between;
  293. align-items: center;
  294. image {
  295. width: 100%;
  296. height: calc(50% - 5px);
  297. }
  298. }
  299. }
  300. .list-title {
  301. font-size: 16px;
  302. font-weight: 600;
  303. text-align: center;
  304. padding: 10px;
  305. }
  306. .list {
  307. display: grid;
  308. grid-template-columns: 1fr 1fr;
  309. grid-gap: 10px;
  310. padding: 10px;
  311. .ka {
  312. width: calc(50vw - 15px);
  313. box-shadow: 0px 2px 8px 2px rgba(0, 0, 0, 0.1);
  314. border-radius: 10px;
  315. // height: 60vw;
  316. .top {
  317. // height: 60vw;
  318. background: linear-gradient(180deg, #faf1a7 0%, #ffe456 100%);
  319. text-align: center;
  320. display: flex;
  321. justify-content: center;
  322. image {
  323. width: 35vw;
  324. height: 50vw;
  325. }
  326. }
  327. .ka-info {
  328. padding: 10px;
  329. .ka-name {
  330. font-size: 15px;
  331. font-weight: 600;
  332. }
  333. .row {
  334. margin-top: 5px;
  335. display: flex;
  336. justify-content: space-between;
  337. .money {
  338. font-size: 16px;
  339. font-weight: 600;
  340. color: #ff2c43;
  341. }
  342. }
  343. }
  344. }
  345. }
  346. .bullet {
  347. height: 30px;
  348. line-height: 30px;
  349. padding: 0 10px;
  350. border-radius: 15px;
  351. background-color: rgba(0, 0, 0, 0.3);
  352. color: #fff;
  353. }
  354. .qrcodeImg {
  355. width: 70vw;
  356. border-radius: 5px;
  357. }
  358. </style>