SchoolSelect.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <script setup lang="ts">
  2. import { SchoolList } from "@/api/school/types";
  3. import { getSchoolSelect } from "@/api/school";
  4. import { watch } from "vue";
  5. import { useUserStore } from "@/store/modules/user";
  6. const userStore = useUserStore();
  7. /**
  8. * 学校数据
  9. */
  10. const schoolData = ref<SchoolList[]>();
  11. const schoolId = ref(0);
  12. const schoolNum = ref("");
  13. async function getSchoolData() {
  14. getSchoolSelect()
  15. .then(({ data }) => {
  16. schoolData.value = data;
  17. if (schoolId.value == 0) {
  18. schoolId.value = data[0].school_id;
  19. schoolNum.value = data[0].num;
  20. userStore.changeSchool(schoolId.value, schoolNum.value);
  21. }
  22. })
  23. .catch((error) => {
  24. console.log(error);
  25. });
  26. }
  27. onMounted(() => {
  28. getSchoolData();
  29. });
  30. watch(
  31. () => schoolId.value,
  32. (newValue) => {
  33. let num: string = "";
  34. schoolData.value?.some((school) => {
  35. if (newValue == school.school_id) {
  36. num = school.num;
  37. return true;
  38. }
  39. });
  40. userStore.changeSchool(newValue, num);
  41. }
  42. );
  43. </script>
  44. <template>
  45. <!-- 学校选择下拉框 -->
  46. <div class="nav-select">
  47. <el-select v-model="schoolId" size="large" placeholder="请选择学校">
  48. <el-option
  49. v-for="item in schoolData"
  50. :key="item.school_id"
  51. :label="item.name"
  52. :value="item.school_id"
  53. />
  54. </el-select>
  55. <span class="school">学校编码:{{ userStore.schoolNum }}</span>
  56. </div>
  57. </template>
  58. <style scoped lang="scss">
  59. .nav-select {
  60. display: flex;
  61. align-items: center;
  62. justify-items: center;
  63. .school {
  64. padding-left: 15px;
  65. }
  66. }
  67. .svg-icon {
  68. margin-bottom: -2px;
  69. }
  70. .el-select {
  71. padding: 15px 0;
  72. width: 280px;
  73. margin-left: 12px;
  74. }
  75. //移动端兼容
  76. .mobile {
  77. .navbar {
  78. .nav-select {
  79. position: absolute;
  80. left: 0;
  81. top: 80px;
  82. z-index: 1;
  83. width: 100%;
  84. box-sizing: border-box;
  85. padding: 0 24px;
  86. .el-select {
  87. width: 100%;
  88. padding: 0;
  89. margin: 0;
  90. }
  91. :deep(.el-input__wrapper) {
  92. background: #ffffff;
  93. }
  94. }
  95. }
  96. }
  97. /* 自定义 el-select 样式 */
  98. :deep(.el-input__wrapper) {
  99. background: #efefef;
  100. border-radius: 12px;
  101. }
  102. /* el-select 各种边框线隐藏**/
  103. :deep(.el-select) {
  104. --el-select-input-focus-border-color: none !important;
  105. }
  106. :deep(.el-input__wrapper) {
  107. box-shadow: none !important;
  108. }
  109. :deep(.el-select .el-input.is-focus .el-input__wrapper) {
  110. box-shadow: none !important;
  111. }
  112. :deep(.el-select .el-input__wrapper.is-focus) {
  113. box-shadow: none !important;
  114. }
  115. :deep(.el-select:hover:not(.el-select--disabled) .el-input__wrapper) {
  116. box-shadow: none !important;
  117. }
  118. </style>