index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <up-search v-model="nick_name" @custom="searchInfo"></up-search>
  5. </view>
  6. <view class="two">
  7. <up-tabs :list="subjectList" keyName="label" @click="toTab"></up-tabs>
  8. </view>
  9. <view class="thr" v-if="total>0">
  10. <up-list @scrolltolower="scrolltolower">
  11. <up-list-item v-for="(item, index) in list" :key="index">
  12. <view class="list">
  13. {{item.nick_name}}
  14. </view>
  15. </up-list-item>
  16. </up-list>
  17. </view>
  18. <up-empty v-else mode="list" icon="/static/list.png">
  19. </up-empty>
  20. <view class="is_bottom" v-if="is_bottom">
  21. <text>{{config.bottom_title||'没有更多了!'}}</text>
  22. </view>
  23. <up-overlay :show="show">
  24. <login @showChange='showChange'></login>
  25. </up-overlay>
  26. </view>
  27. </template>
  28. <script setup lang="ts">
  29. import login from "@/components/login.vue"
  30. import { inject, computed, ref } from 'vue';
  31. //该依赖已内置不需要单独安装
  32. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  33. // 请求接口
  34. const $api = inject('$api');
  35. // 基本信息
  36. const config = ref({ logo: [], file: [] });
  37. // 列表
  38. const list = ref([]);
  39. const total = ref(0);
  40. const skip = ref(0);
  41. const limit = ref(5);
  42. const page = ref(0);
  43. // 数据是否触底
  44. const is_bottom = ref(false);
  45. // 遮罩层
  46. const show = ref(false);
  47. // 字典表
  48. const subjectList = ref([]);
  49. const nick_name = ref('');
  50. // user
  51. const user = computed(() => {
  52. return uni.getStorageSync('user');
  53. })
  54. onShow(async () => {
  55. await searchConfig();
  56. await searchOther();
  57. await clearPage();
  58. await search();
  59. if (!user.value) show.value = true
  60. })
  61. onPullDownRefresh(async () => {
  62. await clearPage();
  63. await search();
  64. uni.stopPullDownRefresh();
  65. })
  66. // config信息
  67. const searchConfig = async () => {
  68. config.value = uni.getStorageSync('config');
  69. };
  70. // 其他查询信息
  71. const searchOther = async () => {
  72. let res;
  73. // 学科
  74. res = await $api(`dictData`, 'GET', { code: 'subject', is_use: '0' });
  75. if (res.errcode === 0) subjectList.value = res.data;
  76. subjectList.value.unshift({ label: '全部', value: '-1', is_show: true })
  77. };
  78. // 名称搜索
  79. const searchInfo = async () => {
  80. if (nick_name.value) {
  81. await clearPage();
  82. await search();
  83. }
  84. };
  85. // 查询
  86. const search = async () => {
  87. const info : any = {
  88. skip: skip.value,
  89. limit: limit.value,
  90. status: '1',
  91. is_show: '0'
  92. }
  93. if (nick_name.value) info.nick_name = nick_name.value
  94. const res = await $api('teacher', 'GET', info);
  95. if (res.errcode === 0) {
  96. list.value = list.value.concat(res.data)
  97. total.value = res.total
  98. } else {
  99. uni.showToast({
  100. title: res.errmsg || '',
  101. icon: 'error',
  102. });
  103. }
  104. };
  105. // 改变标签
  106. const toTab = async (data) => {
  107. console.log(data);
  108. };
  109. const showChange = () => {
  110. show.value = false
  111. }
  112. const scrolltolower = () => {
  113. if (total.value > list.value.length) {
  114. uni.showLoading({
  115. title: '加载中',
  116. mask: true
  117. })
  118. page.value = page.value + 1;
  119. skip.value = page.value * limit.value;
  120. search();
  121. uni.hideLoading();
  122. } else is_bottom.value = true
  123. };
  124. // 清空列表
  125. const clearPage = () => {
  126. list.value = []
  127. skip.value = 0
  128. limit.value = 6
  129. page.value = 0
  130. };
  131. </script>
  132. <style lang="scss" scoped>
  133. .content {
  134. display: flex;
  135. flex-direction: column;
  136. min-height: 100vh;
  137. background-color: var(--f1Color);
  138. .one {
  139. padding: 2vw;
  140. background-color: var(--mainColor);
  141. }
  142. .two {
  143. margin: 2vw;
  144. border-radius: 5px;
  145. background-color: var(--mainColor);
  146. }
  147. }
  148. </style>