Commit 6c7b419c7cbafa0eb1df21b9e8f7ef52dbf5758d

Authored by xp.Huang
2 parents 5a5f70e4 7ce38ac0

Merge branch 'fix/3D-map-select-city-null' into 'main_dev'

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

See merge request yunteng/thingskit-view!197
1 1 <script lang="ts" setup name="SelectCity">
2 2 import { onMounted, reactive, nextTick, ref } from 'vue'
3 3 import { getAreaList } from '@/api/external/common/index'
4   -import { areaEnum } from '../config'
  4 +import { areaEnum, ifSpecialCity } from '../config'
5 5
6 6 const props = defineProps({
7 7 drillingIn: {
... ... @@ -49,6 +49,7 @@ onMounted(async () => {
49 49 })
50 50
51 51
  52 +
52 53 const disabledCity = ref<boolean>(false)//直辖市禁用下面省份选择
53 54 const onHandleSelectProvince = async (value: number | string, options: Recordable) => {
54 55 selectValues.cityValue = null
... ... @@ -65,7 +66,7 @@ const onHandleSelectProvince = async (value: number | string, options: Recordabl
65 66 selectOptions.cityOptions = cityOptions
66 67 selectValues.levelStr = areaEnum.PROVINCE
67 68 selectValues.areaName = options.label
68   - if(value==110000 || value ==120000 || value ==500000 || value==310000 || value==810000 || value==820000){//直辖市的话就不能跟省份的逻辑一样了
  69 + if(ifSpecialCity(value)){//直辖市的话就不能跟省份的逻辑一样了
69 70 selectOptions.cityOptions = cityOptions.map((item:any)=>({...item,value:item.parentId}))
70 71 disabledCity.value = true
71 72 return
... ...
... ... @@ -4,6 +4,7 @@ import { chartInitConfig } from '@/settings/designSetting'
4 4 import { CreateComponentType } from '@/packages/index.d'
5 5 import cloneDeep from 'lodash/cloneDeep'
6 6 import dataMaps from './data.json'
  7 +import { getAreaList } from '@/api/external/common'
7 8
8 9 //省市区枚举
9 10 export const enum areaEnum {
... ... @@ -102,7 +103,7 @@ export const option = {
102 103 showIcon: false,
103 104 iconDistanceRight: 20,
104 105 iconDistanceTop: 20,
105   - drillingIn: false,
  106 + drillingIn: true,
106 107 dataset: dataMaps,
107 108 isShowExecute:false,
108 109 saveClickRegion: {
... ... @@ -200,6 +201,41 @@ export default class Config extends PublicConfigClass implements CreateComponent
200 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 240 export const setScale = (adcode: string | number) => {
205 241 switch (adcode) {
... ...
... ... @@ -167,9 +167,9 @@ import { CollapseItem, SettingItemBox, SettingItem } from '@/components/Pages/Ch
167 167 import { GlobalThemeJsonType } from '@/settings/chartThemes/index'
168 168 import { GlobalSetting } from '@/components/Pages/ChartItemSetting'
169 169 import SelectCity from './components/SelectCity.vue'
170   -import { regionInfo } from './config'
  170 +import { allFetch, getAreaLists, ifSpecialCity, regionInfo } from './config'
171 171 import { cloneDeep } from 'lodash'
172   -import { getAreaList } from '@/api/external/common/index'
  172 +
173 173 import { areaEnum } from '../../../Decorates/Mores/Weather/config'
174 174 import { unref } from 'vue'
175 175
... ... @@ -202,22 +202,22 @@ const STATIC_SCATTER_CONFIG = {
202 202
203 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 207 onMounted(async () => {
215 208 const {saveSelect} = unref(mapRegionCache) || {}
216 209 const {levelStr} = saveSelect || {}
217 210 datasetMap3DList.value.forEach(async (item: Recordable) => {
218 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 277
278 278
279 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 281 const setDatasetArea = async () => {
296 282 const { adcode, areaName,saveSelect } = unref(mapRegionCache) || {}
... ... @@ -302,7 +288,7 @@ const setDatasetArea = async () => {
302 288 }
303 289 mdutcgValues.value = cityOptions
304 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 292 mdutcgValues.value = values.flatMap((obj:any) => Object.values(obj))//讲获取到的多维转换成单一纬度
307 293 }
308 294 // 循环 push 城市数据
... ...
... ... @@ -248,8 +248,7 @@
248 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 250 <g opacity="1" transform="translate(47 157)">
251   - <div>
252   - <text>
  251 + <text style="text-align: center;">
253 252 <tspan
254 253 :x="fontConfig.x1"
255 254 :y="fontConfig.y1"
... ... @@ -264,7 +263,6 @@
264 263 {{ unitStr }}
265 264 </tspan>
266 265 </text>
267   - </div>
268 266 <animateMotion
269 267 v-if="openAnim"
270 268 path="M0,0 L0,2 L0 9 L0 12 L0 -12 L0 -9 L0 -2 Z"
... ...