index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.name" @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="list" v-for="(item, index) in list" :key="index">
  10. <view class="name">
  11. <text>{{ index + 1 }}.</text>
  12. <text>{{ item.name }}</text>
  13. </view>
  14. <view class="other">
  15. <view class="other_1">
  16. <text>视频流:</text>
  17. <text>{{ item.path||'暂无视频流' }}</text>
  18. </view>
  19. </view>
  20. <view class="btn">
  21. <button type="primary" size="mini" @tap="toPlay(item)">
  22. 播放视频
  23. </button>
  24. </view>
  25. </view>
  26. </view>
  27. </scroll-view>
  28. </view>
  29. <view class="is_bottom" v-if="is_bottom">
  30. <text>到底了,嘻嘻!</text>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. data() {
  37. return {
  38. // 查询
  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.search();
  53. },
  54. onPullDownRefresh: async function() {
  55. const that = this;
  56. that.clearPage();
  57. await that.search();
  58. uni.stopPullDownRefresh();
  59. },
  60. methods: {
  61. async search() {
  62. const that = this;
  63. let info = {
  64. skip: that.skip,
  65. limit: that.limit,
  66. is_use: "0"
  67. };
  68. let res = await that.$api("test", "GET", {
  69. ...info,
  70. ...that.searchInfo
  71. });
  72. if (res.errcode == '0') {
  73. let list = [...that.list, ...res.data]
  74. that.$set(that, `list`, list)
  75. that.$set(that, `total`, res.total)
  76. } else {
  77. uni.showToast({
  78. title: res.errmsg,
  79. icon: 'icon'
  80. });
  81. }
  82. },
  83. // 分页
  84. toPage() {
  85. const that = this;
  86. let list = that.list;
  87. let limit = that.limit;
  88. if (that.total > list.length) {
  89. uni.showLoading({
  90. title: '加载中',
  91. mask: true
  92. })
  93. let page = that.page + 1;
  94. that.$set(that, `page`, page)
  95. let skip = page * limit;
  96. that.$set(that, `skip`, skip)
  97. that.search();
  98. uni.hideLoading();
  99. } else that.$set(that, `is_bottom`, true)
  100. },
  101. toScroll(e) {
  102. const that = this;
  103. let up = that.scrollTop;
  104. that.$set(that, `scrollTop`, e.detail.scrollTop);
  105. let num = Math.sign(up - e.detail.scrollTop);
  106. if (num == 1) that.$set(that, `is_bottom`, false);
  107. },
  108. // 输入框
  109. toInput(e) {
  110. const that = this;
  111. if (e.detail.value) that.$set(that.searchInfo, `name`, e.detail.value);
  112. else that.$set(that, `searchInfo`, {});
  113. that.clearPage();
  114. that.search();
  115. },
  116. toPlay(e) {
  117. if (e.path) {
  118. uni.navigateTo({
  119. url: `/pagesHome/home/video?path=${e.path}&&name=${e.name}`,
  120. });
  121. } else {
  122. uni.showToast({
  123. title: '暂无视频流,无法播放',
  124. icon: 'none'
  125. });
  126. }
  127. },
  128. // 清空列表
  129. clearPage() {
  130. const that = this;
  131. that.$set(that, `list`, [])
  132. that.$set(that, `skip`, 0)
  133. that.$set(that, `limit`, 10)
  134. that.$set(that, `page`, 0)
  135. }
  136. },
  137. };
  138. </script>
  139. <style lang="scss">
  140. .content {
  141. .one {
  142. border-bottom: 1px solid #000000;
  143. input {
  144. padding: 2vw;
  145. background-color: #f1f1f1;
  146. font-size: 14px;
  147. border-radius: 5px;
  148. }
  149. }
  150. .two {
  151. position: relative;
  152. flex-grow: 1;
  153. padding: 0 10px;
  154. .list {
  155. // width: 90%;
  156. margin: 10px 0 0 0;
  157. padding: 10px;
  158. border-radius: 5px;
  159. box-shadow: 0 0 5px #cccccc;
  160. .name {
  161. font-size: 16px;
  162. font-weight: bold;
  163. margin: 0 0 5px 0;
  164. }
  165. .other {
  166. margin: 0 0 10px 0;
  167. .other_1 {
  168. margin: 0 0 5px 0;
  169. text {
  170. font-size: 14px;
  171. color: #858585;
  172. }
  173. text:last-child {
  174. color: #000000;
  175. word-break: break-all;
  176. }
  177. }
  178. }
  179. .btn {
  180. text-align: center;
  181. }
  182. }
  183. .list:last-child {
  184. margin: 10px 0;
  185. }
  186. }
  187. }
  188. .scroll-view {
  189. position: absolute;
  190. top: 0;
  191. left: 0;
  192. right: 0;
  193. bottom: 0;
  194. .list-scroll-view {
  195. display: flex;
  196. flex-direction: column;
  197. padding: 0 10px;
  198. }
  199. }
  200. .is_bottom {
  201. text-align: center;
  202. text {
  203. padding: 2vw 0;
  204. display: inline-block;
  205. color: #858585;
  206. font-size: 14px;
  207. }
  208. }
  209. </style>