Commit ba9e653b0a7dda1cc6d95fc81db0eaf4919132cf
Merge branch 'fix/3D-map-select-city-county' into 'main_dev'
fix: 修改3D地图选择问题 See merge request yunteng/thingskit-view!193
Showing
2 changed files
with
38 additions
and
9 deletions
1 | <script lang="ts" setup name="SelectCity"> | 1 | <script lang="ts" setup name="SelectCity"> |
2 | -import { onMounted, reactive, nextTick } from 'vue' | 2 | +import { onMounted, reactive, nextTick, ref } from 'vue' |
3 | import { getAreaList } from '@/api/external/common/index' | 3 | import { getAreaList } from '@/api/external/common/index' |
4 | import { areaEnum } from '../config' | 4 | import { areaEnum } from '../config' |
5 | 5 | ||
@@ -32,10 +32,10 @@ const selectValues = reactive({ | @@ -32,10 +32,10 @@ const selectValues = reactive({ | ||
32 | const getAreaLists = async (level = areaEnum.PROVINCE, parentId = 1) => { | 32 | const getAreaLists = async (level = areaEnum.PROVINCE, parentId = 1) => { |
33 | const resp = await getAreaList({ | 33 | const resp = await getAreaList({ |
34 | level, | 34 | level, |
35 | - parentId | 35 | + parentId:(parentId as any)==='china'?1:parentId |
36 | }) | 36 | }) |
37 | if (!resp) return [] | 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 | onMounted(async () => { | 41 | onMounted(async () => { |
@@ -48,16 +48,22 @@ onMounted(async () => { | @@ -48,16 +48,22 @@ onMounted(async () => { | ||
48 | for (let i in selectValues) Reflect.set(selectValues, i, props.optionData?.mapRegion.saveSelect[i]) | 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 | const onHandleSelectProvince = async (value: number | string, options: Recordable) => { | 53 | const onHandleSelectProvince = async (value: number | string, options: Recordable) => { |
52 | - selectValues.cityValue = null | 54 | + selectValues.cityValue = null |
53 | selectValues.countyValue = null | 55 | selectValues.countyValue = null |
54 | - // if(props.drillingIn){ | ||
55 | - // emits('handleSelectArea',{value,options}) | ||
56 | - // } | ||
57 | if (value === 'china') return (selectValues.levelStr = areaEnum.COUNTRY) | 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 | selectValues.levelStr = areaEnum.PROVINCE | 59 | selectValues.levelStr = areaEnum.PROVINCE |
60 | selectValues.areaName = options.label | 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 | const onHandleSelectCity = async (value: number, options: Recordable) => { | 69 | const onHandleSelectCity = async (value: number, options: Recordable) => { |
@@ -96,6 +102,7 @@ defineExpose({ | @@ -96,6 +102,7 @@ defineExpose({ | ||
96 | /> | 102 | /> |
97 | <n-select | 103 | <n-select |
98 | v-if="!props.drillingIn" | 104 | v-if="!props.drillingIn" |
105 | + :disabled="disabledCity" | ||
99 | @change="onHandleSelectCity" | 106 | @change="onHandleSelectCity" |
100 | placeholder="请选择城市" | 107 | placeholder="请选择城市" |
101 | v-model:value="selectValues.cityValue" | 108 | v-model:value="selectValues.cityValue" |
@@ -275,17 +275,39 @@ const onHandleSelectValues = async (values: regionInfo) => { | @@ -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 | const setDatasetArea = async () => { | 295 | const setDatasetArea = async () => { |
279 | const { adcode, areaName,saveSelect } = unref(mapRegionCache) || {} | 296 | const { adcode, areaName,saveSelect } = unref(mapRegionCache) || {} |
280 | const {levelStr} = saveSelect || {} | 297 | const {levelStr} = saveSelect || {} |
281 | const cityOptions = await getAreaLists(levelStr===areaEnum.CITY?areaEnum.COUNTY:areaEnum.CITY, adcode) | 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 | // 循环 push 城市数据 | 304 | // 循环 push 城市数据 |
283 | datasetMap3DList.value.forEach((item: any) => { | 305 | datasetMap3DList.value.forEach((item: any) => { |
284 | item.name = areaName | 306 | item.name = areaName |
285 | item.city_name = null | 307 | item.city_name = null |
286 | item.adcode = null, | 308 | item.adcode = null, |
287 | item.value = null | 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 |