Commit 1f7f27c543a28c6044e394af945f0552299a7b19
Committed by
xp.Huang
1 parent
4a57b542
fix: 修改3D地图选择问题
Showing
2 changed files
with
38 additions
and
9 deletions
1 | 1 | <script lang="ts" setup name="SelectCity"> |
2 | -import { onMounted, reactive, nextTick } from 'vue' | |
2 | +import { onMounted, reactive, nextTick, ref } from 'vue' | |
3 | 3 | import { getAreaList } from '@/api/external/common/index' |
4 | 4 | import { areaEnum } from '../config' |
5 | 5 | |
... | ... | @@ -32,10 +32,10 @@ const selectValues = reactive({ |
32 | 32 | const getAreaLists = async (level = areaEnum.PROVINCE, parentId = 1) => { |
33 | 33 | const resp = await getAreaList({ |
34 | 34 | level, |
35 | - parentId | |
35 | + parentId:(parentId as any)==='china'?1:parentId | |
36 | 36 | }) |
37 | 37 | if (!resp) return [] |
38 | - return resp.map((item: Recordable) => ({ label: item.name, value: item.code })) | |
38 | + return resp.map((item: Recordable) => ({ label: item.name, value: item.code,parentId:item.parentId })) | |
39 | 39 | } |
40 | 40 | |
41 | 41 | onMounted(async () => { |
... | ... | @@ -48,16 +48,22 @@ onMounted(async () => { |
48 | 48 | for (let i in selectValues) Reflect.set(selectValues, i, props.optionData?.mapRegion.saveSelect[i]) |
49 | 49 | }) |
50 | 50 | |
51 | + | |
52 | +const disabledCity = ref<boolean>(false)//直辖市禁用 | |
51 | 53 | const onHandleSelectProvince = async (value: number | string, options: Recordable) => { |
52 | - selectValues.cityValue = null | |
54 | + selectValues.cityValue = null | |
53 | 55 | selectValues.countyValue = null |
54 | - // if(props.drillingIn){ | |
55 | - // emits('handleSelectArea',{value,options}) | |
56 | - // } | |
57 | 56 | if (value === 'china') return (selectValues.levelStr = areaEnum.COUNTRY) |
58 | - selectOptions.cityOptions = await getAreaLists(areaEnum.CITY, value as number) | |
57 | + const cityOptions = await getAreaLists(areaEnum.CITY, value as number) | |
58 | + selectOptions.cityOptions = cityOptions | |
59 | 59 | selectValues.levelStr = areaEnum.PROVINCE |
60 | 60 | selectValues.areaName = options.label |
61 | + if(value==110000 || value ==120000 || value ==500000 || value==310000 || value==810000 || value==820000){//直辖市的话就不能跟省份的逻辑一样了 | |
62 | + selectOptions.cityOptions = cityOptions.map((item:any)=>({...item,value:item.parentId})) | |
63 | + disabledCity.value = true | |
64 | + return | |
65 | + } | |
66 | + disabledCity.value = false | |
61 | 67 | } |
62 | 68 | |
63 | 69 | const onHandleSelectCity = async (value: number, options: Recordable) => { |
... | ... | @@ -96,6 +102,7 @@ defineExpose({ |
96 | 102 | /> |
97 | 103 | <n-select |
98 | 104 | v-if="!props.drillingIn" |
105 | + :disabled="disabledCity" | |
99 | 106 | @change="onHandleSelectCity" |
100 | 107 | placeholder="请选择城市" |
101 | 108 | v-model:value="selectValues.cityValue" | ... | ... |
... | ... | @@ -275,17 +275,39 @@ const onHandleSelectValues = async (values: regionInfo) => { |
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | + | |
279 | +const mdutcgValues = ref<any>([])//直辖市的区县数据 | |
280 | +//循环获取直辖市下面得区县数据 | |
281 | +const allFetch = (arr:any) => { | |
282 | + return Promise.all( | |
283 | + arr.map(async(item:any)=>{ | |
284 | + try{ | |
285 | + const values = await getAreaLists(areaEnum.COUNTY, item.adcode as any) | |
286 | + return {...values} | |
287 | + }catch(err){ | |
288 | + console.log(err,'err') | |
289 | + return | |
290 | + } | |
291 | + }) | |
292 | + ) | |
293 | +} | |
294 | + | |
278 | 295 | const setDatasetArea = async () => { |
279 | 296 | const { adcode, areaName,saveSelect } = unref(mapRegionCache) || {} |
280 | 297 | const {levelStr} = saveSelect || {} |
281 | 298 | const cityOptions = await getAreaLists(levelStr===areaEnum.CITY?areaEnum.COUNTY:areaEnum.CITY, adcode) |
299 | + mdutcgValues.value = cityOptions | |
300 | + if(adcode==110000 || adcode==120000 || adcode==500000 || adcode==310000 || adcode==810000 || adcode==820000){//直辖市 | |
301 | + const values = await allFetch(cityOptions) || [] | |
302 | + mdutcgValues.value = values.flatMap((obj:any) => Object.values(obj)) | |
303 | + } | |
282 | 304 | // 循环 push 城市数据 |
283 | 305 | datasetMap3DList.value.forEach((item: any) => { |
284 | 306 | item.name = areaName |
285 | 307 | item.city_name = null |
286 | 308 | item.adcode = null, |
287 | 309 | item.value = null |
288 | - item.cityOptions = cityOptions && cityOptions.length ? cityOptions : [{ adcode, label: areaName, value: areaName }] | |
310 | + item.cityOptions = unref(mdutcgValues) && unref(mdutcgValues).length ? unref(mdutcgValues) : [{ adcode, label: areaName, value: areaName }] | |
289 | 311 | }) |
290 | 312 | } |
291 | 313 | ... | ... |