调整学生选择逻辑,避免重复弹窗选择

This commit is contained in:
ywyonui 2025-08-06 21:41:58 +08:00
parent 55c62cc033
commit e392903194
3 changed files with 32 additions and 7 deletions

View File

@ -60,7 +60,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useUserStore } from "@/store/modules/user"; import { useUserStore } from "@/store/modules/user";
const { getUser, setCurXs, getCurXs } = useUserStore(); const { getUser, setCurXs, getCurXs, getXsPickerInitialized, setXsPickerInitialized } = useUserStore();
// //
const props = defineProps<{ const props = defineProps<{
@ -96,12 +96,23 @@ const setCurrentStudent = (xs: any) => {
// bar // bar
if (props.isBar) { if (props.isBar) {
//
if (getXsPickerInitialized) {
// 使
if (getUser.xsList.length > 0) {
setCurrentStudent(getCurXs);
}
} else {
//
if (getUser.xsList.length > 1) { if (getUser.xsList.length > 1) {
showPicker(); showPicker();
} else { } else {
// //
setCurrentStudent(getUser.xsList[0]); setCurrentStudent(getUser.xsList[0]);
} }
//
setXsPickerInitialized(true);
}
} }
</script> </script>

View File

@ -16,9 +16,12 @@ import XsPicker from "@/pages/base/components/XsPicker/index.vue"
import { useDataStore } from "@/store/modules/data"; import { useDataStore } from "@/store/modules/data";
import { useUserStore } from "@/store/modules/user"; import { useUserStore } from "@/store/modules/user";
const { getGlobal } = useDataStore(); const { getGlobal } = useDataStore();
const { checkXqk, checkJlb } = useUserStore(); const { checkXqk, checkJlb, setXsPickerInitialized } = useUserStore();
const switchXs = (xs: any) => { const switchXs = (xs: any) => {
//
setXsPickerInitialized(true);
if (getGlobal.type == 1) { if (getGlobal.type == 1) {
checkXqk(); checkXqk();
} else if (getGlobal.type == 2) { } else if (getGlobal.type == 2) {

View File

@ -19,6 +19,7 @@ interface UserState {
changeTime: string; // 权限变更时间 changeTime: string; // 权限变更时间
ws: any; ws: any;
wsCallback: any; wsCallback: any;
xsPickerInitialized: boolean; // 学生选择器是否已初始化
} }
export const useUserStore = defineStore({ export const useUserStore = defineStore({
@ -36,7 +37,8 @@ export const useUserStore = defineStore({
refreshInterval: 7 * 24 * 60 * 60 * 1000, // 刷新间隔(毫秒) refreshInterval: 7 * 24 * 60 * 60 * 1000, // 刷新间隔(毫秒)
changeTime: '', // 权限变更时间 changeTime: '', // 权限变更时间
ws: null, ws: null,
wsCallback: defWsCallback wsCallback: defWsCallback,
xsPickerInitialized: false // 学生选择器是否已初始化
}), }),
getters: { getters: {
getToken(): string { getToken(): string {
@ -59,6 +61,9 @@ export const useUserStore = defineStore({
}, },
getChangeTime(): string { getChangeTime(): string {
return this.changeTime; return this.changeTime;
},
getXsPickerInitialized(): boolean {
return this.xsPickerInitialized;
} }
}, },
actions: { actions: {
@ -83,6 +88,9 @@ export const useUserStore = defineStore({
setChangeTime(changeTime: string) { setChangeTime(changeTime: string) {
this.changeTime = changeTime; this.changeTime = changeTime;
}, },
setXsPickerInitialized(initialized: boolean) {
this.xsPickerInitialized = initialized;
},
// 更新学生信息 // 更新学生信息
updateStudentInfo(studentInfo: any) { updateStudentInfo(studentInfo: any) {
this.setCurXs(studentInfo); this.setCurXs(studentInfo);
@ -186,6 +194,8 @@ export const useUserStore = defineStore({
} else { } else {
this.setCurXs({}) this.setCurXs({})
} }
// 重置学生选择器初始化标记
this.setXsPickerInitialized(false);
if (value[AUTH_KEY]) { if (value[AUTH_KEY]) {
this.setToken(value[AUTH_KEY]) this.setToken(value[AUTH_KEY])
} }
@ -389,6 +399,7 @@ export const useUserStore = defineStore({
this.setUser('') this.setUser('')
this.setCurXs({}) this.setCurXs({})
this.setAuth([]) this.setAuth([])
this.setXsPickerInitialized(false); // 注销时重置学生选择器状态
if (this.ws) { if (this.ws) {
this.ws.closeConnect(); this.ws.closeConnect();
this.ws = null; this.ws = null;