index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="wh-full bg-white">
  3. <div class="search-box">
  4. <n-gradient-text
  5. :gradient="{
  6. from: '#1890ff',
  7. to: '#bc3c1a'
  8. }"
  9. >
  10. <h1>请搜索学员后查看学员档案</h1>
  11. </n-gradient-text>
  12. <n-select
  13. v-model:value="studentNumber"
  14. size="large"
  15. filterable
  16. placeholder="搜索学员"
  17. :options="options"
  18. :loading="loading"
  19. clearable
  20. remote
  21. @update:value="goToList"
  22. @search="handleSearch"
  23. />
  24. </div>
  25. <div class="list-archives">
  26. <ArchivesList :student-number="studentNumber" />
  27. </div>
  28. </div>
  29. </template>
  30. <script setup lang="ts">
  31. import { ref } from 'vue';
  32. import type { SelectOption } from 'naive-ui';
  33. import { getStudentByKeyword } from './api';
  34. import ArchivesList from './component/index.vue';
  35. const options = ref<SelectOption[]>([]);
  36. const loading = ref(false);
  37. const studentNumber = ref<string>('');
  38. function handleSearch(query: string) {
  39. if (!query.length) {
  40. options.value = [];
  41. return;
  42. }
  43. loading.value = true;
  44. getStudentByKeyword(query).then(result => {
  45. const optionData = result.data?.map(res => {
  46. return {
  47. label: res.studentName,
  48. value: res.studentNumber
  49. };
  50. });
  51. options.value = optionData as SelectOption[];
  52. loading.value = false;
  53. });
  54. }
  55. function goToList(value: string) {
  56. studentNumber.value = value;
  57. }
  58. </script>
  59. <style scoped>
  60. .search-box {
  61. width: 26%;
  62. margin: 0 auto;
  63. }
  64. .list-archives {
  65. height: calc(100% - 94px);
  66. }
  67. h1 {
  68. font-size: 36px;
  69. }
  70. </style>