index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="one_1">
  5. <input type="text" v-model="name" @input="toInput" placeholder="搜索课程名称">
  6. </view>
  7. <view class="one_2">
  8. <button size="mini" class="button" type="primary" @click="toAdd">添加</button>
  9. </view>
  10. </view>
  11. <view class="two" v-if="total>0">
  12. <up-list @scrolltolower="scrolltolower">
  13. <up-list-item v-for="(item, index) in list" :key="index">
  14. <view class="list">
  15. 1111
  16. </view>
  17. </up-list-item>
  18. </up-list>
  19. </view>
  20. <up-empty v-else mode="list" icon="/static/list.png">
  21. </up-empty>
  22. <view class="is_bottom" v-if="is_bottom">
  23. <text>{{config.bottom_title||'没有更多了!'}}</text>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup lang="ts">
  28. import { inject, computed, ref } from 'vue';
  29. //该依赖已内置不需要单独安装
  30. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  31. // 请求接口
  32. const $api = inject('$api');
  33. // 基本信息
  34. const config = ref({ logo: [], file: [] });
  35. // 列表
  36. const list = ref([]);
  37. const total = ref(0);
  38. const skip = ref(0);
  39. const limit = ref(5);
  40. const page = ref(0);
  41. // 数据是否触底
  42. const is_bottom = ref(false);
  43. const name = ref('');
  44. // user
  45. const user = computed(() => {
  46. return uni.getStorageSync('user');
  47. })
  48. onShow(async () => {
  49. await searchConfig();
  50. await searchOther();
  51. await clearPage();
  52. await search();
  53. })
  54. onPullDownRefresh(async () => {
  55. await clearPage();
  56. await search();
  57. uni.stopPullDownRefresh();
  58. })
  59. // config信息
  60. const searchConfig = async () => {
  61. config.value = uni.getStorageSync('config');
  62. };
  63. // 其他查询信息
  64. const searchOther = async () => { };
  65. // 查询
  66. const search = async () => {
  67. const info : any = {
  68. skip: skip.value,
  69. limit: limit.value,
  70. teacher: user.value._id,
  71. is_show: '0'
  72. }
  73. if (name.value) info.name = name.value
  74. const res = await $api('course', 'GET', info);
  75. if (res.errcode === 0) {
  76. list.value = list.value.concat(res.data)
  77. total.value = res.total
  78. } else {
  79. uni.showToast({
  80. title: res.errmsg || '',
  81. icon: 'error',
  82. });
  83. }
  84. };
  85. // 搜索课程
  86. const toInput = async (e) => {
  87. await clearPage();
  88. await search();
  89. };
  90. // 新增课程
  91. const toAdd = async () => {
  92. uni.navigateTo({
  93. url: `/pagesMy/course/add`
  94. })
  95. };
  96. const scrolltolower = () => {
  97. if (total.value > list.value.length) {
  98. uni.showLoading({
  99. title: '加载中',
  100. mask: true
  101. })
  102. page.value = page.value + 1;
  103. skip.value = page.value * limit.value;
  104. search();
  105. uni.hideLoading();
  106. } else is_bottom.value = true
  107. };
  108. // 清空列表
  109. const clearPage = () => {
  110. list.value = []
  111. skip.value = 0
  112. limit.value = 6
  113. page.value = 0
  114. };
  115. </script>
  116. <style lang="scss" scoped>
  117. .content {
  118. display: flex;
  119. flex-direction: column;
  120. min-height: 100vh;
  121. background-color: var(--f1Color);
  122. .one {
  123. display: flex;
  124. justify-content: center;
  125. align-items: center;
  126. padding: 2vw;
  127. background-color: var(--mainColor);
  128. .one_1 {
  129. padding: 0 2vw;
  130. width: 75vw;
  131. input {
  132. padding: 2vw;
  133. background-color: var(--f1Color);
  134. font-size: var(--font14Size);
  135. border-radius: 5px;
  136. }
  137. }
  138. .button {
  139. background-color: var(--f3CColor);
  140. color: var(--mainColor);
  141. }
  142. }
  143. .one {
  144. display: flex;
  145. justify-content: center;
  146. align-items: center;
  147. padding: 2vw;
  148. .one_1 {
  149. padding: 0 2vw;
  150. width: 75vw;
  151. input {
  152. padding: 2vw;
  153. background-color: var(--f1Color);
  154. font-size: var(--font14Size);
  155. border-radius: 5px;
  156. }
  157. }
  158. .button {
  159. background-color: var(--3c9Color);
  160. color: var(--mainColor);
  161. }
  162. }
  163. }
  164. </style>