generated from Leo_Ding/web-template
Merge branch 'master' of https://gitlab.guxuan.icu/Leo_Ding/hahaPension_admin
This commit is contained in:
commit
b3377a317a
@ -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>
|
||||||
|
|
||||||
|
|||||||
@ -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()
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user