教师选择调整
This commit is contained in:
parent
5a84fb483b
commit
b7038ea1c8
@ -13,7 +13,7 @@ export const bjFindByNjId = async (params: any) => {
|
|||||||
|
|
||||||
// 所有教师
|
// 所有教师
|
||||||
export const jsFindAll = async () => {
|
export const jsFindAll = async () => {
|
||||||
return await get("/api/js/findAll");
|
return await get("/api/js/findAllBasicInfo");
|
||||||
};
|
};
|
||||||
|
|
||||||
// 所有职务
|
// 所有职务
|
||||||
|
|||||||
@ -248,11 +248,15 @@ const onSelectTypeChange = async (e: any) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectType.value === 1 || selectType.value === 3 || selectType.value === 5) {
|
// 根据选择类型加载对应的基础数据
|
||||||
|
if (selectType.value === 3 || selectType.value === 5) {
|
||||||
|
// 按班主任、按年级:需要加载年级数据
|
||||||
await loadNjData();
|
await loadNjData();
|
||||||
} else if (selectType.value === 2) {
|
} else if (selectType.value === 2) {
|
||||||
|
// 按科目:需要加载科目数据
|
||||||
await loadKmData();
|
await loadKmData();
|
||||||
} else if (selectType.value === 4) {
|
} else if (selectType.value === 4) {
|
||||||
|
// 按职务:需要加载职务数据
|
||||||
await loadZwData();
|
await loadZwData();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -696,46 +700,60 @@ const loadKmData = async () => {
|
|||||||
// 加载职务数据
|
// 加载职务数据
|
||||||
const loadZwData = async () => {
|
const loadZwData = async () => {
|
||||||
try {
|
try {
|
||||||
console.log('=== 开始从localStorage加载职务数据 ===');
|
console.log('=== 开始加载职务数据 ===');
|
||||||
|
|
||||||
// 从localStorage获取职务数据
|
// 首先尝试从localStorage获取职务数据
|
||||||
const storageData = uni.getStorageSync('app-common');
|
const storageData = uni.getStorageSync('app-common');
|
||||||
console.log('localStorage原始数据:', storageData);
|
let zwData = null;
|
||||||
|
|
||||||
if (!storageData) {
|
if (storageData) {
|
||||||
console.warn('localStorage中没有找到app-common数据');
|
|
||||||
uni.showToast({ title: '未找到app-common数据', icon: 'none' });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果storageData是字符串,需要先解析成对象
|
|
||||||
let parsedData;
|
let parsedData;
|
||||||
if (typeof storageData === 'string') {
|
if (typeof storageData === 'string') {
|
||||||
try {
|
try {
|
||||||
parsedData = JSON.parse(storageData);
|
parsedData = JSON.parse(storageData);
|
||||||
console.log('解析后的数据:', parsedData);
|
|
||||||
} catch (parseError) {
|
} catch (parseError) {
|
||||||
console.error('解析localStorage数据失败:', parseError);
|
console.error('解析localStorage数据失败:', parseError);
|
||||||
uni.showToast({ title: '数据格式错误', icon: 'none' });
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parsedData = storageData;
|
parsedData = storageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('parsedData的data属性:', parsedData?.data);
|
// 检查是否有职务数据缓存
|
||||||
console.log('parsedData.data.zw:', parsedData?.data?.zw);
|
if (parsedData?.data?.zw) {
|
||||||
|
zwData = parsedData.data.zw;
|
||||||
// 检查数据结构,从parsedData.data.zw获取职务数据
|
console.log('从localStorage找到职务数据缓存');
|
||||||
if (!parsedData.data || !parsedData.data.zw) {
|
}
|
||||||
console.warn('localStorage中没有找到职务数据');
|
|
||||||
console.warn('可用的属性:', Object.keys(parsedData || {}));
|
|
||||||
uni.showToast({ title: '未找到职务数据', icon: 'none' });
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const zwData = parsedData.data.zw;
|
// 如果没有缓存数据,则调用getZwListByLx方法获取并缓存
|
||||||
console.log('职务数据结构:', zwData);
|
if (!zwData) {
|
||||||
|
console.log('localStorage中没有职务数据,开始调用getZwListByLx获取并缓存');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 导入并调用getZwListByLx方法
|
||||||
|
const { useCommonStore } = await import('@/store/modules/common');
|
||||||
|
const commonStore = useCommonStore();
|
||||||
|
|
||||||
|
// 分别获取党政职务和其他职务数据
|
||||||
|
const dzZwResult = await commonStore.getZwListByLx({ zwlx: '党政职务' });
|
||||||
|
const qtZwResult = await commonStore.getZwListByLx({ zwlx: '其他职务' });
|
||||||
|
|
||||||
|
console.log('党政职务API返回结果:', dzZwResult);
|
||||||
|
console.log('其他职务API返回结果:', qtZwResult);
|
||||||
|
|
||||||
|
// 构建职务数据结构
|
||||||
|
zwData = {
|
||||||
|
'党政职务': { result: dzZwResult.result || [] },
|
||||||
|
'其他职务': { result: qtZwResult.result || [] }
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('getZwListByLx获取的职务数据已按类型分组:', zwData);
|
||||||
|
} catch (apiError) {
|
||||||
|
console.error('调用getZwListByLx失败:', apiError);
|
||||||
|
uni.showToast({ title: '获取职务数据失败', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 根据职务类型过滤数据
|
// 根据职务类型过滤数据
|
||||||
let filteredData = [];
|
let filteredData = [];
|
||||||
@ -775,8 +793,9 @@ const loadZwData = async () => {
|
|||||||
value: item.id || item.value
|
value: item.id || item.value
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('=== 从localStorage加载职务数据完成 ===');
|
console.log('=== 职务数据加载完成 ===');
|
||||||
console.log('处理后的职务数据:', datas.value);
|
console.log('处理后的职务数据:', datas.value);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载职务数据失败:', error);
|
console.error('加载职务数据失败:', error);
|
||||||
uni.showToast({ title: '加载职务数据失败', icon: 'none' });
|
uni.showToast({ title: '加载职务数据失败', icon: 'none' });
|
||||||
@ -924,9 +943,87 @@ const handleConfirm = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 页面加载时初始化
|
// 页面加载时初始化
|
||||||
onMounted(() => {
|
onMounted(async () => {
|
||||||
// 可以在这里加载默认数据或进行其他初始化
|
// 进入页面时,确保教师数据已缓存
|
||||||
|
await ensureTeacherDataCached();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 确保教师数据已缓存的函数
|
||||||
|
const ensureTeacherDataCached = async () => {
|
||||||
|
try {
|
||||||
|
console.log('=== 开始确保教师数据已缓存 ===');
|
||||||
|
|
||||||
|
// 从localStorage检查是否已有教师数据
|
||||||
|
const storageData = uni.getStorageSync('app-common');
|
||||||
|
let hasTeacherData = false;
|
||||||
|
let hasZwData = false;
|
||||||
|
|
||||||
|
if (storageData) {
|
||||||
|
let parsedData;
|
||||||
|
if (typeof storageData === 'string') {
|
||||||
|
try {
|
||||||
|
parsedData = JSON.parse(storageData);
|
||||||
|
} catch (parseError) {
|
||||||
|
console.error('解析localStorage数据失败:', parseError);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
parsedData = storageData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否已有教师数据
|
||||||
|
if (parsedData?.data?.allJs?.result && parsedData.data.allJs.result.length > 0) {
|
||||||
|
hasTeacherData = true;
|
||||||
|
console.log('localStorage中已有教师数据,数量:', parsedData.data.allJs.result.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否已有职务数据
|
||||||
|
if (parsedData?.data?.zw) {
|
||||||
|
hasZwData = true;
|
||||||
|
console.log('localStorage中已有职务数据');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有教师数据,则调用API获取并缓存
|
||||||
|
if (!hasTeacherData) {
|
||||||
|
console.log('localStorage中没有教师数据,开始获取并缓存');
|
||||||
|
|
||||||
|
// 导入并调用getAllJs方法
|
||||||
|
const { useCommonStore } = await import('@/store/modules/common');
|
||||||
|
const commonStore = useCommonStore();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await commonStore.getAllJs();
|
||||||
|
console.log('成功获取教师数据并写入缓存:', result);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取教师数据失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有职务数据,则调用getZwListByLx获取并缓存
|
||||||
|
if (!hasZwData) {
|
||||||
|
console.log('localStorage中没有职务数据,开始获取并缓存');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 导入并调用getZwListByLx方法
|
||||||
|
const { useCommonStore } = await import('@/store/modules/common');
|
||||||
|
const commonStore = useCommonStore();
|
||||||
|
|
||||||
|
// 分别获取党政职务和其他职务数据
|
||||||
|
await commonStore.getZwListByLx({ zwlx: '党政职务' });
|
||||||
|
await commonStore.getZwListByLx({ zwlx: '其他职务' });
|
||||||
|
|
||||||
|
console.log('成功获取职务数据并写入缓存');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取职务数据失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('=== 确保教师数据已缓存完成 ===');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('确保教师数据缓存过程中出错:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user