index.vue 7.7 KB

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