perf: 所有基础数据下拉统一使用 Store 缓存
修改以下组件使用 baseDataStore: - business/school/components/GradeDialog.vue (年级) - business/school/components/ClassDialog.vue (班级) - school/index.vue (区域树) - school/components/GradeDialog.vue (年级) - school/components/ClassDialog.vue (年级+班级) - member/components/MemberDialog.vue (区域树) 登录后预加载数据,后续全部命中缓存
This commit is contained in:
parent
e8489536d6
commit
d0d0f0ee6d
|
|
@ -39,7 +39,10 @@
|
||||||
*/
|
*/
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { addGradeClass, getClassOptions } from '@/api/pangu/school'
|
import { addGradeClass } from '@/api/pangu/school'
|
||||||
|
import useBaseDataStore from '@/store/modules/baseData'
|
||||||
|
|
||||||
|
const baseDataStore = useBaseDataStore()
|
||||||
|
|
||||||
const emit = defineEmits(['success'])
|
const emit = defineEmits(['success'])
|
||||||
|
|
||||||
|
|
@ -59,18 +62,16 @@ const form = ref({
|
||||||
// 已有班级ID列表
|
// 已有班级ID列表
|
||||||
const existingClassIds = ref([])
|
const existingClassIds = ref([])
|
||||||
|
|
||||||
// 获取班级选项
|
// 获取班级选项(使用 Store 缓存)
|
||||||
const fetchClassOptions = async () => {
|
const fetchClassOptions = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getClassOptions()
|
const data = await baseDataStore.fetchClasses()
|
||||||
if (res.code === 200) {
|
// 转换为选项格式 { value: classId, label: className }
|
||||||
// 转换为选项格式 { value: classId, label: className }
|
classOptions.value = (data || []).map(item => ({
|
||||||
classOptions.value = (res.data || []).map(item => ({
|
value: item.classId,
|
||||||
value: item.classId,
|
label: item.className,
|
||||||
label: item.className,
|
disabled: existingClassIds.value.includes(item.classId)
|
||||||
disabled: existingClassIds.value.includes(item.classId)
|
}))
|
||||||
}))
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取班级选项失败:', error)
|
console.error('获取班级选项失败:', error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,10 @@
|
||||||
*/
|
*/
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { addSchoolGrade, getGradeOptions } from '@/api/pangu/school'
|
import { addSchoolGrade } from '@/api/pangu/school'
|
||||||
|
import useBaseDataStore from '@/store/modules/baseData'
|
||||||
|
|
||||||
|
const baseDataStore = useBaseDataStore()
|
||||||
|
|
||||||
const emit = defineEmits(['success'])
|
const emit = defineEmits(['success'])
|
||||||
|
|
||||||
|
|
@ -58,18 +61,16 @@ const form = ref({
|
||||||
// 已有年级ID列表
|
// 已有年级ID列表
|
||||||
const existingGradeIds = ref([])
|
const existingGradeIds = ref([])
|
||||||
|
|
||||||
// 获取年级选项
|
// 获取年级选项(使用 Store 缓存)
|
||||||
const fetchGradeOptions = async () => {
|
const fetchGradeOptions = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getGradeOptions()
|
const data = await baseDataStore.fetchGrades()
|
||||||
if (res.code === 200) {
|
// 转换为选项格式 { value: gradeId, label: gradeName }
|
||||||
// 转换为选项格式 { value: gradeId, label: gradeName }
|
gradeOptions.value = (data || []).map(item => ({
|
||||||
gradeOptions.value = (res.data || []).map(item => ({
|
value: item.gradeId,
|
||||||
value: item.gradeId,
|
label: item.gradeName,
|
||||||
label: item.gradeName,
|
disabled: existingGradeIds.value.includes(item.gradeId)
|
||||||
disabled: existingGradeIds.value.includes(item.gradeId)
|
}))
|
||||||
}))
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取年级选项失败:', error)
|
console.error('获取年级选项失败:', error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,10 +147,13 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { addMember, getClassList, getGradeList, getMember, getRegionTree, getSchoolList, updateMember } from '@/api/pangu/member'
|
import { addMember, getClassList, getGradeList, getMember, getSchoolList, updateMember } from '@/api/pangu/member'
|
||||||
import { Plus } from '@element-plus/icons-vue'
|
import { Plus } from '@element-plus/icons-vue'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { computed, reactive, ref, watch } from 'vue'
|
import { computed, reactive, ref, watch } from 'vue'
|
||||||
|
import useBaseDataStore from '@/store/modules/baseData'
|
||||||
|
|
||||||
|
const baseDataStore = useBaseDataStore()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
|
@ -207,10 +210,9 @@ const classList = ref([])
|
||||||
* 弹窗打开时加载数据
|
* 弹窗打开时加载数据
|
||||||
*/
|
*/
|
||||||
const handleOpen = async () => {
|
const handleOpen = async () => {
|
||||||
// 加载区域树
|
// 加载区域树(使用 Store 缓存)
|
||||||
try {
|
try {
|
||||||
const res = await getRegionTree()
|
regionTree.value = await baseDataStore.fetchRegionTree()
|
||||||
regionTree.value = res.data || []
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// 忽略错误
|
// 忽略错误
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,10 @@
|
||||||
*/
|
*/
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { addGradeClass, getClassOptions, getGradeOptions } from '@/api/pangu/school'
|
import { addGradeClass } from '@/api/pangu/school'
|
||||||
|
import useBaseDataStore from '@/store/modules/baseData'
|
||||||
|
|
||||||
|
const baseDataStore = useBaseDataStore()
|
||||||
|
|
||||||
const emit = defineEmits(['success'])
|
const emit = defineEmits(['success'])
|
||||||
|
|
||||||
|
|
@ -68,25 +71,19 @@ const form = ref({
|
||||||
classIds: []
|
classIds: []
|
||||||
})
|
})
|
||||||
|
|
||||||
// 获取年级选项
|
// 获取年级选项(使用 Store 缓存)
|
||||||
const fetchGradeOptions = async () => {
|
const fetchGradeOptions = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getGradeOptions()
|
gradeOptions.value = await baseDataStore.fetchGrades()
|
||||||
if (res.code === 200) {
|
|
||||||
gradeOptions.value = res.data
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取年级选项失败:', error)
|
console.error('获取年级选项失败:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取班级选项
|
// 获取班级选项(使用 Store 缓存)
|
||||||
const fetchClassOptions = async () => {
|
const fetchClassOptions = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getClassOptions()
|
classOptions.value = await baseDataStore.fetchClasses()
|
||||||
if (res.code === 200) {
|
|
||||||
classOptions.value = res.data
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取班级选项失败:', error)
|
console.error('获取班级选项失败:', error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,10 @@
|
||||||
*/
|
*/
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import { addSchoolGrade, getGradeOptions } from '@/api/pangu/school'
|
import { addSchoolGrade } from '@/api/pangu/school'
|
||||||
|
import useBaseDataStore from '@/store/modules/baseData'
|
||||||
|
|
||||||
|
const baseDataStore = useBaseDataStore()
|
||||||
|
|
||||||
const emit = defineEmits(['success'])
|
const emit = defineEmits(['success'])
|
||||||
|
|
||||||
|
|
@ -55,13 +58,10 @@ const form = ref({
|
||||||
gradeIds: []
|
gradeIds: []
|
||||||
})
|
})
|
||||||
|
|
||||||
// 获取年级选项
|
// 获取年级选项(使用 Store 缓存)
|
||||||
const fetchGradeOptions = async () => {
|
const fetchGradeOptions = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getGradeOptions()
|
gradeOptions.value = await baseDataStore.fetchGrades()
|
||||||
if (res.code === 200) {
|
|
||||||
gradeOptions.value = res.data
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取年级选项失败:', error)
|
console.error('获取年级选项失败:', error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,9 @@ import request from '@/utils/request'
|
||||||
import ClassDialog from './components/ClassDialog.vue'
|
import ClassDialog from './components/ClassDialog.vue'
|
||||||
import GradeDialog from './components/GradeDialog.vue'
|
import GradeDialog from './components/GradeDialog.vue'
|
||||||
import SchoolDialog from './components/SchoolDialog.vue'
|
import SchoolDialog from './components/SchoolDialog.vue'
|
||||||
|
import useBaseDataStore from '@/store/modules/baseData'
|
||||||
|
|
||||||
|
const baseDataStore = useBaseDataStore()
|
||||||
|
|
||||||
// 区域树相关
|
// 区域树相关
|
||||||
const treeRef = ref()
|
const treeRef = ref()
|
||||||
|
|
@ -149,12 +152,9 @@ const filterNode = (value, data) => {
|
||||||
return data.regionName.includes(value)
|
return data.regionName.includes(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取区域树
|
// 获取区域树(使用 Store 缓存)
|
||||||
const getRegionTree = async () => {
|
const getRegionTree = async () => {
|
||||||
const res = await request.get('/api/region/tree')
|
regionTree.value = await baseDataStore.fetchRegionTree()
|
||||||
if (res.code === 200) {
|
|
||||||
regionTree.value = res.data
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取学校列表
|
// 获取学校列表
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue