Commit 7ce38ac0b5e7dd3d7a030ee29ada28c4e91cc31f

Authored by loveumiko
1 parent 10af0010

fix: 修复3D地图城市点击没数据问题

1 <script lang="ts" setup name="SelectCity"> 1 <script lang="ts" setup name="SelectCity">
2 import { onMounted, reactive, nextTick, ref } 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, ifSpecialCity } from '../config'
5 5
6 const props = defineProps({ 6 const props = defineProps({
7 drillingIn: { 7 drillingIn: {
@@ -49,6 +49,7 @@ onMounted(async () => { @@ -49,6 +49,7 @@ onMounted(async () => {
49 }) 49 })
50 50
51 51
  52 +
52 const disabledCity = ref<boolean>(false)//直辖市禁用下面省份选择 53 const disabledCity = ref<boolean>(false)//直辖市禁用下面省份选择
53 const onHandleSelectProvince = async (value: number | string, options: Recordable) => { 54 const onHandleSelectProvince = async (value: number | string, options: Recordable) => {
54 selectValues.cityValue = null 55 selectValues.cityValue = null
@@ -65,7 +66,7 @@ const onHandleSelectProvince = async (value: number | string, options: Recordabl @@ -65,7 +66,7 @@ const onHandleSelectProvince = async (value: number | string, options: Recordabl
65 selectOptions.cityOptions = cityOptions 66 selectOptions.cityOptions = cityOptions
66 selectValues.levelStr = areaEnum.PROVINCE 67 selectValues.levelStr = areaEnum.PROVINCE
67 selectValues.areaName = options.label 68 selectValues.areaName = options.label
68 - if(value==110000 || value ==120000 || value ==500000 || value==310000 || value==810000 || value==820000){//直辖市的话就不能跟省份的逻辑一样了 69 + if(ifSpecialCity(value)){//直辖市的话就不能跟省份的逻辑一样了
69 selectOptions.cityOptions = cityOptions.map((item:any)=>({...item,value:item.parentId})) 70 selectOptions.cityOptions = cityOptions.map((item:any)=>({...item,value:item.parentId}))
70 disabledCity.value = true 71 disabledCity.value = true
71 return 72 return
@@ -4,6 +4,7 @@ import { chartInitConfig } from '@/settings/designSetting' @@ -4,6 +4,7 @@ import { chartInitConfig } from '@/settings/designSetting'
4 import { CreateComponentType } from '@/packages/index.d' 4 import { CreateComponentType } from '@/packages/index.d'
5 import cloneDeep from 'lodash/cloneDeep' 5 import cloneDeep from 'lodash/cloneDeep'
6 import dataMaps from './data.json' 6 import dataMaps from './data.json'
  7 +import { getAreaList } from '@/api/external/common'
7 8
8 //省市区枚举 9 //省市区枚举
9 export const enum areaEnum { 10 export const enum areaEnum {
@@ -102,7 +103,7 @@ export const option = { @@ -102,7 +103,7 @@ export const option = {
102 showIcon: false, 103 showIcon: false,
103 iconDistanceRight: 20, 104 iconDistanceRight: 20,
104 iconDistanceTop: 20, 105 iconDistanceTop: 20,
105 - drillingIn: false, 106 + drillingIn: true,
106 dataset: dataMaps, 107 dataset: dataMaps,
107 isShowExecute:false, 108 isShowExecute:false,
108 saveClickRegion: { 109 saveClickRegion: {
@@ -200,6 +201,41 @@ export default class Config extends PublicConfigClass implements CreateComponent @@ -200,6 +201,41 @@ export default class Config extends PublicConfigClass implements CreateComponent
200 public option = echartOptionProfixHandle(option, includes) 201 public option = echartOptionProfixHandle(option, includes)
201 } 202 }
202 203
  204 +export const ifSpecialCity = (value:string|number) => {
  205 + if(value==110000 || value ==120000 || value ==500000 || value==310000 || value==810000 || value==820000){//直辖市的话就不能跟省份的逻辑一样了
  206 + return true
  207 + }
  208 + return false
  209 +}
  210 +
  211 +
  212 +
  213 +//循环获取直辖市下面得区县数据
  214 +
  215 +export const getAreaLists = async (level = areaEnum.PROVINCE as any, parentId = 1) => {
  216 + const resp = await getAreaList({
  217 + level,
  218 + parentId:(parentId as any)=='china'?1:parentId
  219 + })
  220 + if (!resp) return []
  221 + return resp.map((item: Recordable) => ({ label: item.name, value: item.name, adcode: item.code }))
  222 +}
  223 +
  224 +export const allFetch = (arr:any,items:string) => {
  225 + return Promise.all(
  226 + arr.map(async(item:any)=>{
  227 + try{
  228 + const values = await getAreaLists(areaEnum.COUNTY, item[items] as any)
  229 + return {...values}
  230 + }catch(err){
  231 + console.log(err,'err')
  232 + return
  233 + }
  234 + })
  235 + )
  236 +}
  237 +
  238 +
203 // 缩放配置文件 239 // 缩放配置文件
204 export const setScale = (adcode: string | number) => { 240 export const setScale = (adcode: string | number) => {
205 switch (adcode) { 241 switch (adcode) {
@@ -167,9 +167,9 @@ import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/Ch @@ -167,9 +167,9 @@ import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/Ch
167 import { GlobalThemeJsonType } from '@/settings/chartThemes/index' 167 import { GlobalThemeJsonType } from '@/settings/chartThemes/index'
168 import { GlobalSetting } from '@/components/Pages/ChartItemSetting' 168 import { GlobalSetting } from '@/components/Pages/ChartItemSetting'
169 import SelectCity from './components/SelectCity.vue' 169 import SelectCity from './components/SelectCity.vue'
170 -import { regionInfo } from './config' 170 +import { allFetch, getAreaLists, ifSpecialCity, regionInfo } from './config'
171 import { cloneDeep } from 'lodash' 171 import { cloneDeep } from 'lodash'
172 -import { getAreaList } from '@/api/external/common/index' 172 +
173 import { areaEnum } from '../../../Decorates/Mores/Weather/config' 173 import { areaEnum } from '../../../Decorates/Mores/Weather/config'
174 import { unref } from 'vue' 174 import { unref } from 'vue'
175 175
@@ -202,22 +202,22 @@ const STATIC_SCATTER_CONFIG = { @@ -202,22 +202,22 @@ const STATIC_SCATTER_CONFIG = {
202 202
203 const SelectCityRef = ref<InstanceType<typeof SelectCity>>() 203 const SelectCityRef = ref<InstanceType<typeof SelectCity>>()
204 204
205 -const getAreaLists = async (level = areaEnum.PROVINCE, parentId = 1) => {  
206 - const resp = await getAreaList({  
207 - level,  
208 - parentId:(parentId as any)=='china'?1:parentId  
209 - })  
210 - if (!resp) return []  
211 - return resp.map((item: Recordable) => ({ label: item.name, value: item.name, adcode: item.code }))  
212 -} 205 +
213 206
214 onMounted(async () => { 207 onMounted(async () => {
215 const {saveSelect} = unref(mapRegionCache) || {} 208 const {saveSelect} = unref(mapRegionCache) || {}
216 const {levelStr} = saveSelect || {} 209 const {levelStr} = saveSelect || {}
217 datasetMap3DList.value.forEach(async (item: Recordable) => { 210 datasetMap3DList.value.forEach(async (item: Recordable) => {
218 item.provinceOptions = await getAreaLists() 211 item.provinceOptions = await getAreaLists()
219 - item.cityOptions = await getAreaLists(levelStr===areaEnum.CITY?areaEnum.COUNTY:areaEnum.CITY, !item.adcode ? mapRegionCache.value.adcode : item.adcode)  
220 - item.adcode = !item.adcode ? mapRegionCache.value.adcode : item.adcode 212 + const adcode = !item.adcode ? mapRegionCache.value.adcode : item.adcode
  213 + const cityOptions = await getAreaLists(levelStr===areaEnum.CITY?areaEnum.COUNTY:areaEnum.CITY, adcode )
  214 + item.adcode = adcode
  215 + if(ifSpecialCity(adcode)){//直辖市获取区县配置的数据不一样
  216 + const values = await allFetch(cityOptions,'adcode') || []
  217 + item.cityOptions = values.flatMap((obj:any) => Object.values(obj))
  218 + return
  219 + }
  220 + item.cityOptions = cityOptions
221 }) 221 })
222 }) 222 })
223 223
@@ -277,20 +277,6 @@ const onHandleSelectValues = async (values: regionInfo) => { @@ -277,20 +277,6 @@ const onHandleSelectValues = async (values: regionInfo) => {
277 277
278 278
279 const mdutcgValues = ref<any>([])//直辖市的区县数据 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 280
295 const setDatasetArea = async () => { 281 const setDatasetArea = async () => {
296 const { adcode, areaName,saveSelect } = unref(mapRegionCache) || {} 282 const { adcode, areaName,saveSelect } = unref(mapRegionCache) || {}
@@ -302,7 +288,7 @@ const setDatasetArea = async () => { @@ -302,7 +288,7 @@ const setDatasetArea = async () => {
302 } 288 }
303 mdutcgValues.value = cityOptions 289 mdutcgValues.value = cityOptions
304 if(adcode==110000 || adcode==120000 || adcode==500000 || adcode==310000 || adcode==810000 || adcode==820000){//直辖市 290 if(adcode==110000 || adcode==120000 || adcode==500000 || adcode==310000 || adcode==810000 || adcode==820000){//直辖市
305 - const values = await allFetch(cityOptions) || [] 291 + const values = await allFetch(cityOptions,'adcode') || []
306 mdutcgValues.value = values.flatMap((obj:any) => Object.values(obj))//讲获取到的多维转换成单一纬度 292 mdutcgValues.value = values.flatMap((obj:any) => Object.values(obj))//讲获取到的多维转换成单一纬度
307 } 293 }
308 // 循环 push 城市数据 294 // 循环 push 城市数据
@@ -248,8 +248,7 @@ @@ -248,8 +248,7 @@
248 d="M399 222.392M399 222.392Q399 233.784 388.988 244.137Q379.458 253.992 362.171 261.578Q325.76 277.556 274.62 277.556Q223.493 277.556 187.299 261.649Q170.106 254.093 160.639 244.256Q150.7 233.928 150.7 222.534L152.7 222.534Q152.7 233.122 162.08 242.869Q171.273 252.421 188.104 259.818Q223.913 275.556 274.62 275.556Q325.341 275.556 361.367 259.747Q378.294 252.319 387.55 242.747Q397 232.975 397 222.392L399 222.392Z" 248 d="M399 222.392M399 222.392Q399 233.784 388.988 244.137Q379.458 253.992 362.171 261.578Q325.76 277.556 274.62 277.556Q223.493 277.556 187.299 261.649Q170.106 254.093 160.639 244.256Q150.7 233.928 150.7 222.534L152.7 222.534Q152.7 233.122 162.08 242.869Q171.273 252.421 188.104 259.818Q223.913 275.556 274.62 275.556Q325.341 275.556 361.367 259.747Q378.294 252.319 387.55 242.747Q397 232.975 397 222.392L399 222.392Z"
249 /> 249 />
250 <g opacity="1" transform="translate(47 157)"> 250 <g opacity="1" transform="translate(47 157)">
251 - <div>  
252 - <text> 251 + <text style="text-align: center;">
253 <tspan 252 <tspan
254 :x="fontConfig.x1" 253 :x="fontConfig.x1"
255 :y="fontConfig.y1" 254 :y="fontConfig.y1"
@@ -264,7 +263,6 @@ @@ -264,7 +263,6 @@
264 {{ unitStr }} 263 {{ unitStr }}
265 </tspan> 264 </tspan>
266 </text> 265 </text>
267 - </div>  
268 <animateMotion 266 <animateMotion
269 v-if="openAnim" 267 v-if="openAnim"
270 path="M0,0 L0,2 L0 9 L0 12 L0 -12 L0 -9 L0 -2 Z" 268 path="M0,0 L0,2 L0 9 L0 12 L0 -12 L0 -9 L0 -2 Z"