5 days ago | ‘chensiAb’ | ![]() |
5 days ago | ‘chensiAb’ | ![]() |
5 days ago | ‘chensiAb’ | ![]() |
5 days ago | ‘chensiAb’ | ![]() |
forms/chinaArea/CChinaArea.vue | ●●●●● patch | view | raw | blame | history | |
forms/chinaArea/ChinaLocations.js | ●●●●● patch | view | raw | blame | history |
forms/chinaArea/CChinaArea.vue
@@ -114,8 +114,9 @@ ); if (proviceIndex >= 0) { range[1] = locationTree[proviceIndex].children; range[2] = let cityChildren = locationTree[proviceIndex].children[0].children; range[2] = cityChildren; current[0] = proviceIndex; // 市 if (codes[1]) { @@ -123,7 +124,19 @@ city => city.value === codes[1], ); if (cityIndex >= 0) { range[2] = range[1][cityIndex].children; let dists = range[1][cityIndex].children; // 如果区域为空,添加默认的市级作为区域选项 if (dists.length === 0) { dists = [ { label: range[1][cityIndex]?.label || '', value: range[1][cityIndex]?.value || '', }, ]; } range[2] = dists; current[1] = cityIndex; } // 区 @@ -162,7 +175,17 @@ // 第一列滚动 if (roll.column === 0) { const cities = locationTree[roll.value].children; this.range = [this.range[0], cities, cities[0].children]; let firstCityChildren = cities[0].children; // 如果区域为空,添加默认的市级作为区域选项 if (firstCityChildren.length === 0) { firstCityChildren = [ { label: cities[0]?.label || '', value: cities[0]?.value || '', }, ]; } this.range = [this.range[0], cities, firstCityChildren]; this.current = [roll.value, 0, 0]; if (this.level === 4) { const range3 = (cities[0].children[0] || {}).children || []; @@ -172,8 +195,21 @@ } // 第二列滚动 else if (roll.column === 1) { const dists = let dists = locationTree[this.current[0]].children[roll.value].children; // 如果区域为空,添加默认的市级作为区域选项 if (dists.length === 0) { dists = [ { label: locationTree[this.current[0]].children[roll.value] ?.label || '', value: locationTree[this.current[0]].children[roll.value] ?.value || '', }, ]; } this.range = [this.range[0], this.range[1], dists]; this.current = [this.current[0], roll.value, 0]; if (this.level === 4) { @@ -207,7 +243,8 @@ const city = provice.children[detail[1]] || {}; names[1] = city.label; const dist = city.children[detail[2]] || {}; names[2] = dist.label; // 如果三级区域不存在或为空,则使用市的内容作为三级区域 names[2] = dist.label || city.label; if (this.level === 4) { const street = (dist.children || [])[detail[3]] || {}; if (street.value) { forms/chinaArea/ChinaLocations.js
@@ -31,7 +31,6 @@ }); export class ChinaLocations { onReady(callback) { if (Tools.isEmptyObject(locationRes)) { readyCallbacks.push(callback); @@ -43,7 +42,7 @@ _createLocationTree(level) { const treeDatas = []; // lv1-省 Object.keys(locationRes).forEach((provinceCode) => { Object.keys(locationRes).forEach(provinceCode => { const province = { label: locationRes[provinceCode].name, value: provinceCode, @@ -51,10 +50,10 @@ }; // lv2-市 const cityContainer = locationRes[provinceCode].children; Object.keys(cityContainer).forEach((cityCode) => { Object.keys(cityContainer).forEach(cityCode => { const city = { value: cityCode, area: cityContainer[cityCode].area, // 电话区码 area: cityContainer[cityCode].area, // 电话区码 children: [], }; if (typeof cityContainer[cityCode] === 'string') { @@ -184,12 +183,18 @@ codes[2] = distCode; // 如果存在街道,继续转街道 if (regions[3]) { const streetContainer = distContainer[distCode].children; Object.keys(streetContainer).forEach(streetCode => { if (streetContainer[streetCode] === regions[3]) { codes[3] = streetCode; } }); const streetContainer = distContainer[distCode].children; Object.keys(streetContainer).forEach( streetCode => { if ( streetContainer[streetCode] === regions[3] ) { codes[3] = streetCode; } }, ); } break; } @@ -248,4 +253,4 @@ } } export const $locations = new ChinaLocations(); export const $locations = new ChinaLocations();