This commit is contained in:
qiuyuan 2025-10-11 14:07:18 +08:00
commit b3377a317a
4 changed files with 27 additions and 32 deletions

View File

@ -8,6 +8,8 @@
<script setup>
import { ref, watch, onMounted,defineModel } from 'vue';
import apis from '@/apis'
import { useDicsStore } from '@/store'
const dicsStore = useDicsStore()
// 使 defineModel v-model
const modelValue = defineModel();
// props
@ -51,25 +53,11 @@ const emit = defineEmits(['change']);
//
const options = ref([]);
onMounted(() => {
// 使 store
options.value = dicsStore.provinceOptions
});
//
const loadProvinces = async () => {
try {
const response = await apis.common.getAreaList({current:1,pageSize:100});
console.log('获取省份响应:', response);
if (Array.isArray(response.data)) {
options.value = response.data.map(province => ({
...province,
isLeaf: !province.hasChild //
}));
console.log('省份数据加载成功:', options.value);
} else {
console.warn('获取省份失败:', response.data.message);
}
} catch (error) {
console.error('请求省份数据失败:', error);
}
};
//
const loadData = async (selectedOptions) => {
@ -108,10 +96,7 @@ const handleChange = (value, selectedOptions) => {
emit('change', value, selectedOptions.map(option => option.label));
};
//
onMounted(() => {
loadProvinces();
});
</script>

View File

@ -163,6 +163,7 @@ defineOptions({
useMultiTab()
const appStore = useAppStore()
const dicsStore = useDicsStore()
dicsStore.loadProvinces() //
dicsStore.loadAllDictData() //
const { sideMenuList, topMenuList } = useMenu()

View File

@ -9,6 +9,7 @@ import useAppStore from './app'
const useDicsStore = defineStore('dics', {
state: () => ({
dictOptions: {},
provinceOptions: [],
}),
getters: {
/**
@ -58,6 +59,23 @@ const useDicsStore = defineStore('dics', {
},
actions: {
// 初始加载省份
async loadProvinces() {
try {
const response = await apis.common.getAreaList({ current: 1, pageSize: 100 })
console.log('获取省份响应:', response)
if (Array.isArray(response.data)) {
this.provinceOptions = response.data.map((province) => ({
...province,
isLeaf: !province.hasChild, // 一定有子节点(市)
}))
} else {
console.warn('获取省份失败:', response.data.message)
}
} catch (error) {
console.error('请求省份数据失败:', error)
}
},
/**
* 从后端加载所有字典数据
* @param commit
@ -76,7 +94,7 @@ const useDicsStore = defineStore('dics', {
if (res?.data) {
this.dictOptions = res.data
if (res.data.length > 0) {
const dictTypes = res.data.map(item => item.code)
const dictTypes = res.data.map((item) => item.code)
const requests = dictTypes.map((type) => getDictByType(type))
const results = await Promise.all(requests)
// 将结果按 type 存入 dictOptions

View File

@ -56,12 +56,6 @@
<a-col :span="8">
<div ><span class="label">生存状态:</span> {{ formData.survivalStatus || '-' }}</div>
</a-col>
<a-col :span="8">
<div ><span class="label">服务状态:</span> {{ formData.serviceStatus || '-' }}</div>
</a-col>
@ -69,9 +63,6 @@
<a-col :span="8">
<div ><span class="label">服务形式:</span> {{ formData.serviceForm || '-' }}</div>
</a-col>
<a-col :span="24">
<div >
<span class="label">户籍地址:</span>