game.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="main">
  3. <view class="first">
  4. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索赛事名称">
  5. </view>
  6. <view class="second">
  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" @tap="toInfo(item)">
  10. <view class="list_1">
  11. <view class="left">
  12. <image class="image" mode="aspectFill" :src="item.logo||config.logoUrl"></image>
  13. </view>
  14. <view class="right">
  15. <view class="name">
  16. {{item.name||'暂无名称'}}
  17. </view>
  18. <view class="other">
  19. {{item.address||'暂无地点'}} | {{item.date||'暂无日期'}}
  20. </view>
  21. <view class="other">
  22. {{item.format||'暂无赛制'}}
  23. </view>
  24. </view>
  25. </view>
  26. <view class="list_2">{{item.ranking||'暂无排名'}}</view>
  27. </view>
  28. <view class="is_bottom" v-if="is_bottom">
  29. <text>{{config.bottomTitle||'到底了!'}}</text>
  30. </view>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. </view>
  35. </template>
  36. <script setup lang="ts">
  37. import { ref, toRefs, getCurrentInstance } from 'vue';
  38. //该依赖已内置不需要单独安装
  39. import { onShow } from "@dcloudio/uni-app";
  40. // 请求接口
  41. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  42. interface PropsItem {
  43. id ?: number,
  44. name ?: string,
  45. address ?: string,
  46. type ?: string,
  47. logo ?: string,
  48. date ?: string,
  49. format ?: string,
  50. ranking ?: string,
  51. };
  52. // 用户信息
  53. const user = ref({});
  54. // 查询
  55. const searchInfo = ref({});
  56. // 列表
  57. const list = ref<PropsItem[]>([{ id: 1, name: '肝帝33联赛' }]);
  58. // 分页
  59. const pageNum = ref(1);
  60. const pageSize = ref(10);
  61. const total = ref(0);
  62. // 数据是否触底
  63. const scrollTop = ref(0);
  64. const is_bottom = ref(false);
  65. const props = defineProps({
  66. config: { type: Object, default: () => { } },
  67. });
  68. const { config } = toRefs(props);
  69. onShow(async () => {
  70. await searchUser();
  71. await search();
  72. })
  73. // 用户信息
  74. const searchUser = async () => {
  75. user.value = uni.getStorageSync('user');
  76. };
  77. // 查询列表
  78. const search = async () => {
  79. // const info = {
  80. // pageNum: pageNum.value,
  81. // pageSize: pageSize.value,
  82. // userId: user.value.id
  83. // }
  84. // const res = await $api('game/list', 'GET', {
  85. // ...info,
  86. // ...searchInfo.value
  87. // });
  88. // if (res.code === 200) {
  89. // list.value = res.rows
  90. // total.value = res.total
  91. // } else {
  92. // uni.showToast({
  93. // title: res.msg || '',
  94. // icon: 'error',
  95. // });
  96. // }
  97. };
  98. //查询
  99. const toInput = (e : any) => {
  100. if (searchInfo.value.name) searchInfo.value.name = e.detail.value
  101. searchInfo.value = { }
  102. clearPage();
  103. search();
  104. };
  105. // 赛事详情
  106. const toInfo = (item : any) => {
  107. uni.navigateTo({
  108. url: `/pagesHome/match/info?id=${item._id || item.id}&name=${item.name}`,
  109. })
  110. };
  111. // 分页
  112. const toPage = () => {
  113. if (total.value > list.value.length) {
  114. uni.showLoading({
  115. title: '加载中',
  116. mask: true
  117. })
  118. pageNum.value = pageNum.value + 1
  119. pageSize.value = pageNum.value * 10;
  120. search();
  121. uni.hideLoading();
  122. } else is_bottom.value = true
  123. };
  124. const toScroll = (e : any) => {
  125. let up = scrollTop.value;
  126. scrollTop.value = e.detail.scrollTop
  127. let num = Math.sign(up - e.detail.scrollTop);
  128. if (num == 1) is_bottom.value = false
  129. };
  130. // 清空数据
  131. const clearPage = () => {
  132. list.value = []
  133. pageNum.value = 1
  134. pageSize.value = 10
  135. };
  136. </script>
  137. <style lang="scss" scoped>
  138. .main {
  139. display: flex;
  140. flex-direction: column;
  141. width: 100vw;
  142. height: 66vh;
  143. .first {
  144. display: flex;
  145. justify-content: center;
  146. align-items: center;
  147. padding: 2vw;
  148. border-bottom: 1px solid var(--f5Color);
  149. input {
  150. width: 100%;
  151. padding: 2vw;
  152. background-color: var(--f1Color);
  153. font-size: var(--font14Size);
  154. border-radius: 5px;
  155. }
  156. }
  157. .second {
  158. position: relative;
  159. flex-grow: 1;
  160. .list {
  161. border-bottom: 1px solid var(--f5Color);
  162. padding: 3vw;
  163. .list_1 {
  164. display: flex;
  165. align-items: center;
  166. .left {
  167. width: 15vw;
  168. .image {
  169. width: 15vw;
  170. height: 15vw;
  171. border-radius: 20vw;
  172. }
  173. }
  174. .right {
  175. width: 75vw;
  176. margin: 0 0 0 2vw;
  177. .name {
  178. font-size: var(--font16Size);
  179. }
  180. .other {
  181. margin: 1vw 0 0 0;
  182. font-size: var(--font14Size);
  183. color: var(--f85Color);
  184. }
  185. }
  186. }
  187. .list_2 {
  188. text-align: right;
  189. font-size: var(--font14Size);
  190. color: var(--fFFColor);
  191. }
  192. }
  193. }
  194. }
  195. .scroll-view {
  196. position: absolute;
  197. top: 0;
  198. left: 0;
  199. right: 0;
  200. bottom: 0;
  201. .list-scroll-view {
  202. display: flex;
  203. flex-direction: column;
  204. }
  205. }
  206. .is_bottom {
  207. width: 100%;
  208. text-align: center;
  209. text {
  210. padding: 2vw 0;
  211. display: inline-block;
  212. color: var(--f85Color);
  213. font-size: var(--font14Size);
  214. }
  215. }
  216. </style>