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

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

View File

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

View File

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