perf: 优化地区选择器代码

master
Yer 2023-08-10 11:29:57 +08:00
parent 00a56473f1
commit 7bbb657379
3 changed files with 25 additions and 1 deletions

View File

@ -75,13 +75,21 @@ export default {
if (res.result.length && val.id !== 0) { if (res.result.length && val.id !== 0) {
this.chiosend[index] = val this.chiosend[index] = val
} }
else if(!res.result.length){
this.chiosend[index] = val
}
this.data[level] = res.result; this.data[level] = res.result;
if (level == 'city') { if (level == 'city') {
this.data.area = [] this.data.area = []
this.data.street = [] this.data.street = []
this.chiosend.splice(1, 3, "","","");
} }
if (level == 'area') { if (level == 'area') {
this.data.street = [] this.data.street = []
this.chiosend.splice(2, 2, "","");
}
if (level == 'street') {
this.chiosend.splice(3, 1, "");
} }
}); });
} }

View File

@ -72,16 +72,24 @@ export default {
} }
else { else {
API_Setup.getChildRegion(val.id).then((res) => { API_Setup.getChildRegion(val.id).then((res) => {
if ( val.id !== 0) { if (res.result.length && val.id !== 0) {
this.chiosend[index] = val
}
else if(!res.result.length){
this.chiosend[index] = val this.chiosend[index] = val
} }
this.data[level] = res.result; this.data[level] = res.result;
if (level == 'city') { if (level == 'city') {
this.data.area = [] this.data.area = []
this.data.street = [] this.data.street = []
this.chiosend.splice(1, 3, "","","");
} }
if (level == 'area') { if (level == 'area') {
this.data.street = [] this.data.street = []
this.chiosend.splice(2, 2, "","");
}
if (level == 'street') {
this.chiosend.splice(3, 1, "");
} }
}); });
} }

View File

@ -75,13 +75,21 @@ export default {
if (res.result.length && val.id !== 0) { if (res.result.length && val.id !== 0) {
this.chiosend[index] = val this.chiosend[index] = val
} }
else if(!res.result.length){
this.chiosend[index] = val
}
this.data[level] = res.result; this.data[level] = res.result;
if (level == 'city') { if (level == 'city') {
this.data.area = [] this.data.area = []
this.data.street = [] this.data.street = []
this.chiosend.splice(1, 3, "","","");
} }
if (level == 'area') { if (level == 'area') {
this.data.street = [] this.data.street = []
this.chiosend.splice(2, 2, "","");
}
if (level == 'street') {
this.chiosend.splice(3, 1, "");
} }
}); });
} }