优化三级联动

This commit is contained in:
Leo_Ding 2025-10-11 09:34:53 +08:00
parent 1d4b75e6f7
commit 664cde29f7
4 changed files with 27 additions and 32 deletions

View File

@ -8,6 +8,8 @@
<script setup> <script setup>
import { ref, watch, onMounted,defineModel } from 'vue'; import { ref, watch, onMounted,defineModel } from 'vue';
import apis from '@/apis' import apis from '@/apis'
import { useDicsStore } from '@/store'
const dicsStore = useDicsStore()
// 使 defineModel v-model // 使 defineModel v-model
const modelValue = defineModel(); const modelValue = defineModel();
// props // props
@ -51,25 +53,11 @@ const emit = defineEmits(['change']);
// //
const options = ref([]); 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) => { const loadData = async (selectedOptions) => {
@ -108,10 +96,7 @@ const handleChange = (value, selectedOptions) => {
emit('change', value, selectedOptions.map(option => option.label)); emit('change', value, selectedOptions.map(option => option.label));
}; };
//
onMounted(() => {
loadProvinces();
});
</script> </script>

View File

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

View File

@ -9,6 +9,7 @@ import useAppStore from './app'
const useDicsStore = defineStore('dics', { const useDicsStore = defineStore('dics', {
state: () => ({ state: () => ({
dictOptions: {}, dictOptions: {},
provinceOptions: [],
}), }),
getters: { getters: {
/** /**
@ -58,6 +59,23 @@ const useDicsStore = defineStore('dics', {
}, },
actions: { 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 * @param commit
@ -76,7 +94,7 @@ const useDicsStore = defineStore('dics', {
if (res?.data) { if (res?.data) {
this.dictOptions = res.data this.dictOptions = res.data
if (res.data.length > 0) { 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 requests = dictTypes.map((type) => getDictByType(type))
const results = await Promise.all(requests) const results = await Promise.all(requests)
// 将结果按 type 存入 dictOptions // 将结果按 type 存入 dictOptions

View File

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