game.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. page.value = 0
  136. };
  137. </script>
  138. <style lang="scss" scoped>
  139. .main {
  140. display: flex;
  141. flex-direction: column;
  142. width: 100vw;
  143. height: 66vh;
  144. .first {
  145. display: flex;
  146. justify-content: center;
  147. align-items: center;
  148. padding: 2vw;
  149. border-bottom: 1px solid var(--f5Color);
  150. input {
  151. width: 100%;
  152. padding: 2vw;
  153. background-color: var(--f1Color);
  154. font-size: var(--font14Size);
  155. border-radius: 5px;
  156. }
  157. }
  158. .second {
  159. position: relative;
  160. flex-grow: 1;
  161. .list {
  162. border-bottom: 1px solid var(--f5Color);
  163. padding: 3vw;
  164. .list_1 {
  165. display: flex;
  166. align-items: center;
  167. .left {
  168. width: 15vw;
  169. .image {
  170. width: 15vw;
  171. height: 15vw;
  172. border-radius: 20vw;
  173. }
  174. }
  175. .right {
  176. width: 75vw;
  177. margin: 0 0 0 2vw;
  178. .name {
  179. font-size: var(--font16Size);
  180. }
  181. .other {
  182. margin: 1vw 0 0 0;
  183. font-size: var(--font14Size);
  184. color: var(--f85Color);
  185. }
  186. }
  187. }
  188. .list_2 {
  189. text-align: right;
  190. font-size: var(--font14Size);
  191. color: var(--fFFColor);
  192. }
  193. }
  194. }
  195. }
  196. .scroll-view {
  197. position: absolute;
  198. top: 0;
  199. left: 0;
  200. right: 0;
  201. bottom: 0;
  202. .list-scroll-view {
  203. display: flex;
  204. flex-direction: column;
  205. }
  206. }
  207. .is_bottom {
  208. width: 100%;
  209. text-align: center;
  210. text {
  211. padding: 2vw 0;
  212. display: inline-block;
  213. color: var(--f85Color);
  214. font-size: var(--font14Size);
  215. }
  216. }
  217. </style>