index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.title" @blur="toInput" placeholder="请输入视频名称">
  5. </view>
  6. <view class="two">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  8. <view class="list-scroll-view">
  9. <view class="two_1">
  10. <view class="list" v-for="(item,index) in list" :key="index" @tap="videoView(item)">
  11. <image class="image" :src="item.img_url&&item.img_url.length>0?item.img_url[0].url:''"
  12. mode="">
  13. </image>
  14. <view class="name textOver">
  15. {{item.title}}
  16. </view>
  17. <view class="other">
  18. <view class="other_1">
  19. <uni-icons type="eye" color="var(--rgbfff)" size="12"></uni-icons>
  20. {{item.view_num}}
  21. </view>
  22. <view class="other_2">
  23. {{item.time_num}}
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. // 用户信息
  38. user: {},
  39. searchInfo: {},
  40. list: [],
  41. total: 0,
  42. page: 0,
  43. skip: 0,
  44. limit: 10,
  45. // 数据是否触底
  46. is_bottom: false,
  47. scrollTop: 0
  48. }
  49. },
  50. onLoad() {
  51. const that = this;
  52. that.searchUser()
  53. },
  54. onHide() {
  55. const that = this;
  56. // that.clearPage()
  57. },
  58. onPullDownRefresh: async function() {
  59. const that = this;
  60. that.clearPage();
  61. await that.search();
  62. uni.stopPullDownRefresh();
  63. },
  64. methods: {
  65. searchUser() {
  66. const that = this;
  67. uni.getStorage({
  68. key: 'token',
  69. success: (res) => {
  70. let user = that.$jwt(res.data);
  71. if (user) that.$set(that, `user`, user);
  72. that.search();
  73. },
  74. fail: (err) => {
  75. uni.showToast({
  76. title: '暂无用户信息,无法查询',
  77. icon: 'none'
  78. })
  79. }
  80. })
  81. },
  82. async search() {
  83. const that = this;
  84. let user = that.user;
  85. let info = {
  86. skip: that.skip,
  87. limit: that.limit,
  88. user_id: user._id
  89. }
  90. let res = await that.$api('collects', 'GET', {
  91. ...info,
  92. ...that.searchInfo,
  93. })
  94. if (res.errcode == '0') {
  95. let list = [...that.list, ...res.data]
  96. that.$set(that, `list`, list);
  97. that.$set(that, `total`, res.total);
  98. }
  99. },
  100. toInput(e) {
  101. const that = this;
  102. let title = e.detail.value;
  103. if (title) that.$set(that.searchInfo, `title`, title);
  104. else delete that.searchInfo.title;
  105. that.clearPage();
  106. that.search()
  107. },
  108. toPage() {
  109. const that = this;
  110. let list = that.list;
  111. let limit = that.limit;
  112. if (that.total > list.length) {
  113. uni.showLoading({
  114. title: '加载中',
  115. mask: true
  116. })
  117. let page = that.page + 1;
  118. that.$set(that, `page`, page)
  119. let skip = page * limit;
  120. that.$set(that, `skip`, skip)
  121. that.search();
  122. uni.hideLoading();
  123. } else that.$set(that, `is_bottom`, true)
  124. },
  125. toScroll(e) {
  126. const that = this;
  127. let up = that.scrollTop;
  128. that.$set(that, `scrollTop`, e.detail.scrollTop);
  129. let num = Math.sign(up - e.detail.scrollTop);
  130. if (num == 1) that.$set(that, `is_bottom`, false);
  131. },
  132. // 视频查看
  133. videoView(e) {
  134. uni.navigateTo({
  135. url: `/pagesVideo/video/index?id=${e._id}`
  136. })
  137. },
  138. // 清空列表
  139. clearPage() {
  140. const that = this;
  141. that.$set(that, `list`, [])
  142. that.$set(that, `skip`, 0)
  143. that.$set(that, `limit`, 10)
  144. that.$set(that, `page`, 0)
  145. if (!that.searchInfo.title) delete that.searchInfo.title;
  146. },
  147. },
  148. }
  149. </script>
  150. <style lang="scss">
  151. .content {
  152. background-color: var(--rgb111);
  153. .one {
  154. padding: 2vw;
  155. input {
  156. border: 1px solid var(--rgbf1f);
  157. border-radius: 5px;
  158. padding: 5px;
  159. font-size: 14px;
  160. color: var(--rgbfff);
  161. }
  162. }
  163. .two {
  164. flex-grow: 1;
  165. position: relative;
  166. .two_1 {
  167. display: flex;
  168. flex-wrap: wrap;
  169. .list {
  170. width: 48%;
  171. margin: 0 10px 10px 0;
  172. .image {
  173. width: 100%;
  174. height: 100px;
  175. overflow: hidden;
  176. border-radius: 5px;
  177. box-shadow: 0 0 5px var(--rgbf1f);
  178. margin: 0 0 5px 0;
  179. }
  180. .name {
  181. font-size: 14px;
  182. color: var(--rgbfff);
  183. margin: 0 0 5px 0;
  184. }
  185. .other {
  186. display: flex;
  187. color: var(--rgbfff);
  188. font-size: 12px;
  189. justify-content: space-between;
  190. }
  191. }
  192. .list:nth-child(2n) {
  193. margin: 0 0 10px 0;
  194. }
  195. }
  196. }
  197. }
  198. .scroll-view {
  199. position: absolute;
  200. top: 0;
  201. left: 0;
  202. right: 0;
  203. bottom: 0;
  204. .list-scroll-view {
  205. display: flex;
  206. flex-direction: column;
  207. padding: 0 2vw;
  208. }
  209. }
  210. .is_bottom {
  211. text-align: center;
  212. text {
  213. padding: 2vw 0;
  214. display: inline-block;
  215. color: #858585;
  216. font-size: 14px;
  217. }
  218. }
  219. </style>