test.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="video">
  3. <view class="header">
  4. {{$t('tips.title')}}
  5. </view>
  6. <helang-waterfall-list :status="waterfall.status" :list="waterfall.list" :reset="waterfall.reset"
  7. @click="onClick" @done="onDone"></helang-waterfall-list>
  8. <image src="/static/image/videos/add.png" mode="" @click="toUrl('./publish')" class="add"></image>
  9. </view>
  10. </template>
  11. <script>
  12. import helangWaterfallList from "@/uni_modules/helang-waterfall/components/waterfall/waterfall-list"
  13. // 列表接口模拟数据
  14. import mockData from '@/uni_modules/helang-waterfall/mock-data/waterfall-list.js'
  15. export default {
  16. components: {
  17. "helang-waterfall-list": helangWaterfallList
  18. },
  19. data() {
  20. return {
  21. // 异步请求相关
  22. ajax: {
  23. // 是否可以加载
  24. load: true,
  25. // 每页的请求条件
  26. rows: 10,
  27. // 页码
  28. page: 1,
  29. // 数据列表
  30. dataList: []
  31. },
  32. // 瀑布流组件相关
  33. waterfall: {
  34. status: "success",
  35. reset: false,
  36. list: []
  37. }
  38. }
  39. },
  40. onReady() {
  41. this.getList();
  42. },
  43. // 触底触发
  44. onReachBottom() {
  45. this.getList();
  46. },
  47. computed: {
  48. isLogin() {
  49. return this.$store.state.isLogin
  50. },
  51. info() {
  52. return this.$store.state.info
  53. }
  54. },
  55. // 下拉刷新
  56. onPullDownRefresh() {
  57. // 正常情况下接口返回应该很会很快。故意延迟调用,让用户有在刷新的体验感
  58. this.ajax.page = 1;
  59. this.ajax.load = true;
  60. this.getList();
  61. },
  62. methods: {
  63. toUrl() {
  64. // 判断是否登录
  65. if (this.isLogin == 2){
  66. this.$toUrl('/pages/login/login')
  67. return
  68. }
  69. if (this.info.is_writer != 1) return this.$toast('Please apply for')
  70. this.$toUrl('./publish')
  71. },
  72. // 瀑布流组件点击事件
  73. onClick(data, index, tag) {
  74. let direction = {
  75. "left": '左',
  76. "right": '右'
  77. }
  78. // this.globalData.info1 = ''
  79. // this.
  80. this.$common.set('videoInfo', data)
  81. this.$toUrl('./live?id=' + data.id + '&i=' + index)
  82. },
  83. // 瀑布流组件渲染完成
  84. onDone() {
  85. // 设置组件为 非重置,这行代码保留不删即可
  86. this.waterfall.reset = false;
  87. // 恢复 getList 方法的调用
  88. this.ajax.load = true;
  89. this.ajax.page++;
  90. // 设置组件状态为 等待加载
  91. this.waterfall.status = 'await';
  92. /**
  93. * 如果你是一个追求完美的开发者,可以通过判断当前数据的长度和请求的数据长度来优化前端请求,减少不必要请求
  94. * 不需要则删除
  95. * */
  96. /**
  97. if(this.ajax.dataCount >= this.ajax.rows){
  98. this.ajax.load = true;
  99. this.ajax.page++;
  100. }
  101. */
  102. },
  103. async getImage(res) {
  104. for (var i = 0; i < res.data.length; i++) {
  105. let {
  106. img
  107. } = res.data[i].video[0];
  108. let errMsg = await uni.getImageInfo({
  109. src: img,
  110. });
  111. if (errMsg[errMsg.length - 1].errMsg == 'getImageInfo:ok') {
  112. res.data[i].imgs = img
  113. } else {
  114. res.data[i].imgs = 'https://cdn.uviewui.com/uview/album/1.jpg'
  115. }
  116. }
  117. // 数据无效时处理
  118. if (!res.data || res.data.length < 1) {
  119. // 设置组件为 加载结束 状态
  120. this.waterfall.status = 'finish';
  121. return;
  122. }
  123. // 将数据赋值给瀑布流 list 属性
  124. this.waterfall.list = res.data;
  125. // 设置组件为 加载成功 状态
  126. this.waterfall.status = 'success';
  127. /**
  128. * 下方的代码为扩展其他功能的示例代码 可做参考,不需要可删除
  129. * */
  130. // 缓存当前数据给其他需要该数据的功能使用
  131. if (this.ajax.page == 1) {
  132. this.ajax.dataList = res.data;
  133. } else {
  134. this.ajax.dataList = [...this.ajax.dataList, ...res.data];
  135. }
  136. // 记录本次数据长度,意义请看 done 事件的回调
  137. this.ajax.dataCount = res.data.length || 0;
  138. },
  139. // 获取数据
  140. async getList() {
  141. if (!this.ajax.load) {
  142. return;
  143. }
  144. this.ajax.load = false;
  145. // 设置状态为加载中
  146. this.waterfall.status = 'loading';
  147. uni.$u.http.get('/api/Video/getList', {
  148. params: {
  149. page: this.ajax.page,
  150. type: 1
  151. }
  152. }).then(res => {
  153. // 获取到的数据,请注意数据结构
  154. // 第一页数据执行以下代码
  155. if (this.ajax.page == 1) {
  156. // 关闭下拉
  157. uni.stopPullDownRefresh();
  158. // 设置组件状态为 重置,可供下拉刷新这类需要重置列表功能时使用
  159. this.waterfall.reset = true;
  160. }
  161. this.getImage(res)
  162. // 。。。下面不需要写代码了,等待组件渲染完成
  163. }).catch(res => {})
  164. // 请求数据, mockData.getList 示例一个 ajax 请求
  165. // mockData.getList({
  166. // pageNum:this.ajax.page,
  167. // pageSize:this.ajax.rows
  168. // }).then(res=>{})
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss">
  174. page {
  175. background-color: #f3f3f3;
  176. }
  177. .video {
  178. padding-bottom: 100rpx;
  179. }
  180. .add {
  181. position: fixed;
  182. right: 32rpx;
  183. bottom: 172rpx;
  184. width: 94rpx;
  185. height: 94rpx;
  186. z-index: 99;
  187. }
  188. .header {
  189. position: sticky;
  190. top: 0;
  191. color: #fff;
  192. z-index: 999;
  193. font-weight: bold;
  194. font-size: 44rpx;
  195. padding: 26rpx 24rpx;
  196. background-color: #1D2550;
  197. }
  198. </style>