index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div class="live" style="padding-top: 44px">
  3. <div class="live-title">
  4. <van-nav-bar
  5. title="我的稻田"
  6. class="van-nav-bar-my-fixed"
  7. left-arrow
  8. @click-left="onClickLeft"
  9. />
  10. </div>
  11. <van-list
  12. v-if="list && list.length > 0"
  13. class="videoList"
  14. v-model="loading"
  15. :finished="finished"
  16. finished-text="没有更多了"
  17. @load="onLoad()"
  18. >
  19. <div
  20. v-for="item in list"
  21. :key="item.id"
  22. class="videoItem"
  23. @click="goto(item.id)"
  24. >
  25. <div class="img">
  26. <img :src="item.video_img" :border="0" alt="" />
  27. </div>
  28. <div class="videoName">{{ item.video_name }}</div>
  29. <div class="videoDesc">{{ item.video_sn }}</div>
  30. </div>
  31. </van-list>
  32. <van-empty v-else description="暂无视频!" />
  33. </div>
  34. </template>
  35. <script>
  36. import { List, cell } from "vant";
  37. import asyncRequest from "@/apis/live/index";
  38. import resToken from "@/mixins/resToken";
  39. export default {
  40. mixins: [resToken],
  41. components: {
  42. "van-cell": cell,
  43. "van-list": List,
  44. },
  45. async created() {
  46. //在组件被创建的时候就加载
  47. await this.onLoad(1);
  48. },
  49. data() {
  50. return {
  51. list: [], //用来放接口获得的数据,来渲染页面
  52. loading: false, //是否在加载
  53. finished: false, //是否加载完成
  54. total: 0, //页码数
  55. parmValue: {
  56. //使用preview接口的入参
  57. page: 1, // 页码
  58. size: 10, // 每页显示条数
  59. },
  60. };
  61. },
  62. methods: {
  63. //判断当时传递的页码是不是1,
  64. async onLoad(e) {
  65. if (e) {
  66. this.parmValue.page = 1; //重置页码数
  67. } else {
  68. this.parmValue.page++; //如果页码数不是1,页码++
  69. console.log(this.parmValue);
  70. }
  71. if (!this.loading) {
  72. //加载结束
  73. if (this.parmValue.page === 1) {
  74. //判断当前页码是不是1
  75. this.list = []; //当前页码是1且未加载,那么代表初始化数据
  76. }
  77. }
  78. let res = await asyncRequest.list(this.parmValue); //视频预览接口
  79. // this.loading = false;//加载状态结束
  80. if (res && res.code == 0 && res.data) {
  81. //
  82. let arr = res.data.list; //缓存接口返回是数据
  83. this.list.push(...arr); //
  84. this.total = res.data.count;
  85. if (
  86. this.list.length > 0 &&
  87. this.total > 0 &&
  88. this.total === this.list.length
  89. ) {
  90. this.finished = true;
  91. }
  92. if (this.total === 0) {
  93. this.finished = true;
  94. }
  95. } else if (res && res.code >= 100 && res.code <= 104) {
  96. await this.logout();
  97. } else {
  98. this.show_title(res.msg);
  99. if (this.parmValue.page !== 1) {
  100. this.parmValue.page--;
  101. }
  102. }
  103. this.loading = false;
  104. },
  105. onClickLeft() {
  106. window.history.back(-1);
  107. },
  108. goto(id) {
  109. window.vm.$router.push({
  110. path: "/liveD",
  111. query: {
  112. id: id,
  113. },
  114. });
  115. },
  116. },
  117. };
  118. </script>
  119. <style lang="scss" scoped>
  120. .live {
  121. position: relative;
  122. width: 100%;
  123. height: 100%;
  124. padding: 44px 0 0 0;
  125. box-sizing: border-box;
  126. overflow-y: scroll;
  127. background: transparent;
  128. .live-title {
  129. position: fixed;
  130. padding: 0;
  131. width: 100%;
  132. margin: 0;
  133. top: 0;
  134. left: 0;
  135. z-index: 3;
  136. border: 0;
  137. height: 44px;
  138. }
  139. .videoList {
  140. padding: 0 16px 60px 16px;
  141. box-sizing: border-box;
  142. background: transparent;
  143. position: relative;
  144. height: auto;
  145. width: 100%;
  146. .videoItem {
  147. position: relative;
  148. width: 100%;
  149. font-size: 14px;
  150. line-height: 30px;
  151. padding: 0;
  152. margin: 0;
  153. cursor: pointer;
  154. box-sizing: border-box;
  155. .img {
  156. width: 100%;
  157. display: block;
  158. height: 180px;
  159. padding: 0;
  160. border: 0;
  161. border-radius: 20px;
  162. overflow: hidden;
  163. border: 0;
  164. img {
  165. width: 100%;
  166. display: inline-block;
  167. height: 100%;
  168. border: 0;
  169. }
  170. }
  171. .videoName {
  172. display: block;
  173. box-sizing: border-box;
  174. font-size: 16px;
  175. font-weight: bolder;
  176. padding: 0 5px;
  177. margin: 10px 0 5px 0;
  178. width: 100%;
  179. line-height: 20px;
  180. color: #1a1a1a;
  181. }
  182. .videoDesc {
  183. display: block;
  184. font-size: 12px;
  185. color: #999;
  186. box-sizing: border-box;
  187. margin: 0 0 10px 0;
  188. line-height: 25px;
  189. padding: 0 5px;
  190. }
  191. }
  192. }
  193. // &:last-child {
  194. // margin: 0 0 2px 0;
  195. // }
  196. }
  197. </style>