index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <u-swiper :radius="0" :list="config.file" height="240px" indicator indicatorMode="dot" circular></u-swiper>
  5. </view>
  6. <view class="two" v-if="config.notice">
  7. <up-notice-bar :text="config.notice" duration="3000"></up-notice-bar>
  8. </view>
  9. <view class="thr">
  10. <view class="list" v-for="(item, index) in typeList" :key="index">
  11. <text class="t-icon" :class="[item.icon]"></text>
  12. <view class="text">{{item.name}}</view>
  13. </view>
  14. </view>
  15. <view class="four">
  16. <up-tabs :list="subjectList" keyName="label" @click="toTab"></up-tabs>
  17. </view>
  18. <view class="five">
  19. <up-list @scrolltolower="scrolltolower">
  20. <up-list-item v-for="(item, index) in list" :key="index">
  21. {{item.nick_name}}
  22. </up-list-item>
  23. </up-list>
  24. </view>
  25. <up-overlay :show="show">
  26. <login @showChange='showChange'></login>
  27. </up-overlay>
  28. </view>
  29. </template>
  30. <script setup lang="ts">
  31. import login from "@/components/login.vue"
  32. import { inject, computed, ref } from 'vue';
  33. //该依赖已内置不需要单独安装
  34. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  35. // 请求接口
  36. const $api = inject('$api');
  37. const $apifile = inject('$apifile');
  38. // 基本信息
  39. const typeList = ref([
  40. { name: '兴趣', icon: 't-icon-xingqu', type: '0' },
  41. { name: '小学', icon: 't-icon-xiaoxue', type: '1' },
  42. { name: '中学', icon: 't-icon-zhongxue', type: '2' },
  43. { name: '高中', icon: 't-icon-gaozhong', type: '3' },
  44. ]);
  45. const config = ref({ icon: [], logo: [], file: [] });
  46. // 列表
  47. const list = ref([]);
  48. const total = ref(0);
  49. const skip = ref(0);
  50. const limit = ref(5);
  51. const page = ref(0);
  52. // 数据是否触底
  53. const is_bottom = ref(false);
  54. // 字典表
  55. const subjectList = ref([]);
  56. // 遮罩层
  57. const show = ref(false);
  58. // user
  59. const user = computed(() => {
  60. return uni.getStorageSync('user');
  61. })
  62. onShow(async () => {
  63. await searchConfig();
  64. await searchOther();
  65. await clearPage();
  66. await search();
  67. if (!user.value) show.value = true
  68. })
  69. onPullDownRefresh(async () => {
  70. await clearPage();
  71. await search();
  72. uni.stopPullDownRefresh();
  73. })
  74. // config信息
  75. const searchConfig = async () => {
  76. config.value = uni.getStorageSync('config');
  77. };
  78. // 其他查询信息
  79. const searchOther = async () => {
  80. let res;
  81. // 学科
  82. res = await $api(`dictData`, 'GET', { code: 'subject', is_use: '0' });
  83. if (res.errcode === 0) subjectList.value = res.data;
  84. subjectList.value.unshift({ label: '全部', value: '-1', is_show: true })
  85. };
  86. // 查询
  87. const search = async () => {
  88. const info : any = {
  89. skip: skip.value,
  90. limit: limit.value,
  91. status: '1',
  92. is_show: '0'
  93. }
  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. background-color: var(--f1Color);
  137. .two {
  138. margin: 2vw 2vw 0 2vw;
  139. border-radius: 5px;
  140. }
  141. .thr {
  142. display: flex;
  143. justify-content: space-between;
  144. align-items: center;
  145. background-color: var(--mainColor);
  146. margin: 2vw;
  147. border-radius: 5px;
  148. padding: 4vw;
  149. .list {
  150. display: flex;
  151. flex-direction: column;
  152. align-items: center;
  153. .text {
  154. margin: 2vw 0 0 0;
  155. font-size: var(--font14Size);
  156. }
  157. }
  158. }
  159. .four {
  160. margin: 2vw;
  161. border-radius: 5px;
  162. background-color: var(--mainColor);
  163. }
  164. .five {
  165. margin: 2vw;
  166. border-radius: 5px;
  167. background-color: var(--mainColor);
  168. }
  169. }
  170. </style>