index - 副本.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <view class="content">
  3. <!-- 头部 -->
  4. <Header />
  5. <!-- 搜索框 -->
  6. <Search class="searchBox" />
  7. <!-- 头部导航 -- tab标签 -->
  8. <MenuTab :typeList="typeList" @changeTab="handleSelectTab" />
  9. <!-- 内容列表 -->
  10. <scroll-view style="height:calc(100% - 100rpx - (88rpx + 40rpx) - 80rpx)" :scroll-y="true"
  11. :refresher-enabled="true" :refresher-triggered="triggered" @scrolltolower="scrolltolower"
  12. @refresherrefresh="onRefresh" refresher-default-style="black">
  13. <!-- 需要滚动的区域 -->
  14. <view class="videoBox" v-for="item in videoList" :key="item.id">
  15. <view class="title">
  16. {{item.title}}
  17. </view>
  18. <view class="videoInfo" @click="goDetail(item)">
  19. <image class="bgImg" :src="getUrl(item.picPath)" alt=""></image>
  20. <view class="time">
  21. 04:30
  22. </view>
  23. <view class="func">
  24. <view class="collectCount">
  25. <i class="custom-icon custom-icon-collected"></i>
  26. 2145
  27. </view>
  28. <view class="share" @click.stop="handleShare(item)">
  29. <i class="custom-icon custom-icon-share"></i>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. <!-- 底部导航 -->
  36. <Tabbar :current-page="1" />
  37. <!-- 分享弹出组件 -->
  38. <Share :show="shareShow" @close="closeShare" />
  39. </view>
  40. </template>
  41. <script>
  42. import Header from "@/components/Header/index.vue";
  43. import Search from "@/components/Search/index.vue";
  44. import MenuTab from "@/components/MenuTab/index.vue";
  45. import Tabbar from "@/components/Tabbar/index.vue";
  46. import Share from '@/components/Share/index.vue'
  47. import {
  48. getVideoList,
  49. getVideoType
  50. } from '@/api/video.js'
  51. import {
  52. baseUrl
  53. } from "@/utils/apiconfig.js";
  54. export default {
  55. components: {
  56. Header,
  57. Search,
  58. MenuTab,
  59. Tabbar,
  60. Share
  61. },
  62. data() {
  63. return {
  64. baseUrl,
  65. typeList: [], // 分类
  66. triggered: false, // 下拉是否激活
  67. videoList: [],
  68. videoParams: {
  69. pageNum: 1,
  70. pageSize: 10,
  71. // checkStatus: '5', // 已发布的数据
  72. categoryId: '', // 分类
  73. },
  74. total: 0,
  75. pageNum: 1,
  76. pageSize: 10,
  77. isRequesting: false, // 是否正在请求,如果是则返回,用于节流
  78. shareShow: false,
  79. }
  80. },
  81. onLoad() {
  82. this.getType();
  83. this.getList();
  84. },
  85. methods: {
  86. // 获取图片完整地址
  87. getUrl(url) {
  88. return baseUrl + url
  89. },
  90. // 获取视频分类
  91. getType() {
  92. let params = {
  93. status: '0',
  94. pageNum: 1,
  95. pageSize: 9999,
  96. }
  97. getVideoType(params).then(res => {
  98. console.log(res)
  99. let obj = {
  100. id: -1,
  101. name: '全部'
  102. }
  103. this.typeList = [obj, ...res.rows]
  104. })
  105. },
  106. // 切换tab
  107. handleSelectTab(val) {
  108. // 切换tab时页面要回到顶部
  109. uni.pageScrollTo({
  110. scrollTop: 0,
  111. duration: 0, // 直接跳转到顶部,不需要动画
  112. })
  113. this.videoParams = {
  114. ...this.videoParams,
  115. pageNum: 1,
  116. categoryId: val.id === -1 ? '' : val.id,
  117. }
  118. this.getList()
  119. },
  120. // 上拉加载
  121. scrolltolower() {
  122. if (this.videoList.length < this.total) {
  123. this.pageNum += 1;
  124. // 继续请求下一页,记得保留原先数组
  125. this.getList();
  126. } else {
  127. uni.showToast({
  128. title: "没有更多了",
  129. icon: "none",
  130. duration: 2000,
  131. });
  132. return;
  133. }
  134. },
  135. // 自定义下拉刷新被触发
  136. onRefresh() {
  137. // 开启下拉自定义样式
  138. this.triggered = true;
  139. // 重新调用
  140. this.getList();
  141. // 1秒之后复位
  142. setTimeout(() => {
  143. this.triggered = false;
  144. }, 1000);
  145. },
  146. scrolltolower() {
  147. this.getList();
  148. },
  149. getList() {
  150. this.isRequesting = true
  151. getVideoList(this.videoParams).then(res => {
  152. // console.log("res:", res)
  153. this.videoList = [...this.videoList, ...res.rows]
  154. // console.log('videoList', this.videoList)
  155. this.total = res.total
  156. // this.loadingStatus = this.videoList.length >= this.total ? 'nomore' : 'loading'
  157. }).finally(() => this.isRequesting = false)
  158. },
  159. // 点击资讯跳转详情
  160. goDetail(val) {
  161. console.log('跳转')
  162. uni.navigateTo({
  163. url: '/pages/video/detail'
  164. });
  165. },
  166. // 点击弹出分享框
  167. handleShare(val) {
  168. console.log(111)
  169. this.shareShow = true
  170. },
  171. // 关闭分享弹出窗
  172. closeShare() {
  173. this.shareShow = false
  174. },
  175. }
  176. }
  177. </script>
  178. <style lang="scss">
  179. page {
  180. background-color: #f9f9f9;
  181. font-size: 28rpx;
  182. height: 100%;
  183. // background-color: yellow;
  184. }
  185. .content {
  186. height: 100%;
  187. padding-top: 20rpx;
  188. .Search {
  189. margin: 20rpx 0;
  190. }
  191. .videoBox {
  192. margin: 20rpx auto;
  193. width: 100%;
  194. // display: flex;
  195. // justify-content: space-between;
  196. padding: 0 40rpx;
  197. .title {
  198. // font-size: 32rpx;
  199. margin-bottom: 20rpx;
  200. font-weight: 600;
  201. color: #666;
  202. }
  203. .videoInfo {
  204. border-radius: 30rpx;
  205. height: 360rpx;
  206. position: relative;
  207. .bgImg{
  208. position: absolute;
  209. z-index: -1;
  210. width: 100%;
  211. height: 100%;
  212. }
  213. .time {
  214. color: #fff;
  215. position: absolute;
  216. top: 20rpx;
  217. right: 20rpx;
  218. width: 100rpx;
  219. height: 50rpx;
  220. text-align: center;
  221. line-height: 50rpx;
  222. border-radius: 50rpx;
  223. background-color: rgba(255, 255, 255, 0.5);
  224. }
  225. .func {
  226. width: 100%;
  227. position: absolute;
  228. bottom: 0;
  229. left: 0;
  230. display: flex;
  231. justify-content: space-between;
  232. padding: 28rpx 40rpx;
  233. .collectCount,
  234. .share {
  235. height: 100rpx;
  236. background-color: #fff;
  237. text-align: center;
  238. line-height: 100rpx;
  239. border-radius: 20rpx;
  240. .custom-icon {
  241. &::before {
  242. background: -webkit-linear-gradient(left, #f84a1a, #f79234);
  243. -webkit-background-clip: text;
  244. -webkit-text-fill-color: transparent;
  245. font-weight: bold;
  246. }
  247. }
  248. }
  249. .collectCount {
  250. padding: 0 20rpx;
  251. display: flex;
  252. align-items: center;
  253. .custom-icon {
  254. margin-right: 10rpx;
  255. }
  256. }
  257. .share {
  258. padding: 0 40rpx;
  259. .custom-icon {
  260. font-size: 24rpx;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. </style>