diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index c4feed7..01449b6 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -90,16 +90,17 @@ const teacherName = computed(() => {
return userInfo.nickname || '教师'
})
-const teacherSubject = computed(() => {
- const userInfo = userStore.info
- // 从角色信息中获取学科,假设角色名包含学科信息
- const roleName = userInfo.roles?.[0]?.name
- if (roleName) {
- // 提取学科信息,例如"语文教师"中的"语文"
- const subjectMatch = roleName.match(/^(.+?)教师$/)
- return subjectMatch ? subjectMatch[1] : '学科'
- }
- return '学科'
+const currentRoleText = computed(() => {
+ const role = userStore.selectedRole
+ if (!role)
+ return '暂无角色'
+ const parts = [
+ role.grade,
+ role.class,
+ role.subject,
+ role.role,
+ ].filter(Boolean)
+ return parts.join(' ') || '教师'
})
// 计算当前选中的班级名称
@@ -245,13 +246,6 @@ const showClassPicker = ref(false)
// 班级选择处理
function handleClassChange() {
- if (homeStore.classOptions.length === 0) {
- uni.showToast({
- title: '暂无班级数据',
- icon: 'none',
- })
- return
- }
showClassPicker.value = true
}
@@ -259,8 +253,6 @@ function handleClassChange() {
watch(() => homeStore.selectedClassKey, () => {
// 选择班级后重新获取统计数据
fetchExamStats()
- // 关闭弹窗
- showClassPicker.value = false
})
// 设置按钮处理
@@ -400,7 +392,7 @@ onMounted(async () => {
{{ teacherName }}
- {{ teacherSubject }}教师
+ {{ currentRoleText }}
@@ -625,26 +617,54 @@ onMounted(async () => {
-
- 切换班级
-
-
-
-
- {{ classItem.label }}
+
+
+ 切换班级
+
+
+ v-for="classItem in homeStore.classOptions"
+ :key="classItem.value"
+ class="flex items-center justify-between rounded-lg px-3 py-2 transition-colors"
+ :class="homeStore.selectedClassId === classItem.value ? 'bg-blue-50 text-blue-600' : 'hover:bg-slate-50 text-slate-600'"
+ @tap="homeStore.selectedClassId = classItem.value;showClassPicker = false"
+ >
+ {{ classItem.label }}
+
+
-
-
+
+ 当前角色无可选班级
+
+
+
+
+
+
+ 切换角色
+
+
+
+
+ {{ roleItem.grade }}{{ roleItem.class }}
+ {{ roleItem.subject }}
+ {{ roleItem.role }}
+
+
+
+
+
+
+
关闭
diff --git a/src/store/home.ts b/src/store/home.ts
index 1d703bc..208eb03 100644
--- a/src/store/home.ts
+++ b/src/store/home.ts
@@ -1,9 +1,10 @@
-import type { ModelTeacherAnalysisClassInfo, ModelTeacherAnalysisExamInfo } from '@/api/data-contracts'
+import type { ModelTeacherAnalysisExamInfo } from '@/api/data-contracts'
import { whenever } from '@vueuse/core'
import { defineStore } from 'pinia'
-import { computed, ref } from 'vue'
+import { computed, onMounted, ref } from 'vue'
import { teacherScoreAnalysisApi } from '@/api'
import { useUserStorage } from '@/composables/useUserStorage'
+import { useUserStore } from '@/store/user'
export interface SelectOption {
label: string
@@ -14,23 +15,18 @@ export interface SelectOption {
gradeKey?: number
}
-// 班级信息类型
-export interface ClassItem {
- label: string
- value: number
- gradeKey: number
-}
-
/**
* 首页状态管理
*/
export const useHomeStore = defineStore(
'homeStore',
() => {
+ // 获取 userStore
+ const userStore = useUserStore()
+
// 数据存储
const loading = ref(false)
const examDataMap = ref