index.vue 8.7 KB

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