index.vue 7.7 KB

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