调整学生选择逻辑,避免重复弹窗选择
This commit is contained in:
parent
55c62cc033
commit
e392903194
@ -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 (getUser.xsList.length > 1 ) {
|
||||
// 检查是否已经初始化过
|
||||
if (getXsPickerInitialized) {
|
||||
// 已经初始化过,直接使用当前选中的学生,不显示选择器
|
||||
if (getUser.xsList.length > 0) {
|
||||
setCurrentStudent(getCurXs);
|
||||
}
|
||||
} else {
|
||||
// 首次初始化
|
||||
if (getUser.xsList.length > 1) {
|
||||
showPicker();
|
||||
} else {
|
||||
// 只有一个学生时,直接设置但不显示提示
|
||||
setCurrentStudent(getUser.xsList[0]);
|
||||
}
|
||||
// 标记为已初始化
|
||||
setXsPickerInitialized(true);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user