This commit is contained in:
冯辉
2026-03-12 23:23:18 +08:00
parent 06a92f2e97
commit 94439fddaa
2 changed files with 64 additions and 40 deletions

View File

@@ -108,7 +108,8 @@
<script setup> <script setup>
import { ref, reactive, onBeforeMount } from 'vue'; import { ref, reactive, onBeforeMount } from 'vue';
import useDictStore from '@/stores/useDictStore'; import useDictStore from '@/stores/useDictStore';
const { getTransformChildren } = useDictStore(); const dictStore = useDictStore();
const { getTransformChildren } = dictStore;
const props = defineProps({ const props = defineProps({
show: Boolean, show: Boolean,
@@ -151,12 +152,24 @@ const experienceOptions = ref([]);
const scaleOptions = ref([]); const scaleOptions = ref([]);
const jobTypeOptions = ref([]); const jobTypeOptions = ref([]);
// 加载状态
const loading = ref(true);
// 初始化获取数据 // 初始化获取数据
onBeforeMount(() => { onBeforeMount(async () => {
educationOptions.value = getTransformChildren('education', '学历要求').options || []; try {
experienceOptions.value = getTransformChildren('experience', '工作经验').options || []; // 先获取字典数据
scaleOptions.value = getTransformChildren('scale', '公司规模').options || []; await dictStore.getDictData();
jobTypeOptions.value = getJobTypeData(); // 再初始化选项数据
educationOptions.value = getTransformChildren('education', '学历要求').options || [];
experienceOptions.value = getTransformChildren('experience', '工作经验').options || [];
scaleOptions.value = getTransformChildren('scale', '公司规模').options || [];
jobTypeOptions.value = getJobTypeData();
} catch (error) {
console.error('获取字典数据失败:', error);
} finally {
loading.value = false;
}
}); });
// 处理选项选择 // 处理选项选择

View File

@@ -42,39 +42,50 @@ const useDictStore = defineStore("dict", () => {
noticeType: [] noticeType: []
}) })
// political_affiliation // political_affiliation
const getDictData = async (dictType, dictName) => { const getDictData = async (dictType, dictName) => {
try { try {
if (dictType && dictName) { if (dictType && dictName) {
return getDictSelectOption(dictType).then((data) => { return getDictSelectOption(dictType).then((data) => {
state[dictName] = data state[dictName] = data
return data return data
}) })
} }
const [education, experience, area, scale, sex, affiliation, nature, noticeType] = const [education, experience, area, scale, sex, affiliation, nature, noticeType] =
await Promise.all([ await Promise.all([
getDictSelectOption('education'), getDictSelectOption('education'),
getDictSelectOption('experience'), getDictSelectOption('experience'),
getDictSelectOption('area', true), getDictSelectOption('area', true),
getDictSelectOption('scale'), getDictSelectOption('scale'),
getDictSelectOption('app_sex'), getDictSelectOption('app_sex'),
getDictSelectOption('political_affiliation'), getDictSelectOption('political_affiliation'),
getDictSelectOption('company_nature'), getDictSelectOption('company_nature'),
getDictSelectOption('sys_notice_type'), getDictSelectOption('sys_notice_type'),
]); ]);
state.education = education; state.education = education;
state.experience = experience; state.experience = experience;
state.area = area; state.area = area;
state.scale = scale; state.scale = scale;
state.sex = sex; state.sex = sex;
state.affiliation = affiliation; state.affiliation = affiliation;
state.nature = nature state.nature = nature
state.noticeType = noticeType state.noticeType = noticeType
complete.value = true complete.value = true
getIndustryDict() // 获取行业 getIndustryDict() // 获取行业
} catch (error) { } catch (error) {
console.error('Error fetching dictionary data:', error); console.error('Error fetching dictionary data:', error);
} // 确保即使出错也能返回空数组
if (!dictType && !dictName) {
state.education = [];
state.experience = [];
state.area = [];
state.scale = [];
state.sex = [];
state.affiliation = [];
state.nature = [];
state.noticeType = [];
}
}
}; };
async function getIndustryDict() { async function getIndustryDict() {
@@ -129,7 +140,7 @@ const useDictStore = defineStore("dict", () => {
return { return {
label: title, label: title,
key: key || dictType, key: key || dictType,
options: state[dictType], options: state[dictType] || [],
} }
} }
return null return null