小程序首页添加接口返回参数校验

This commit is contained in:
赵毅 2025-12-09 14:49:28 +08:00
parent bb54f833d3
commit d24b5efcb7

View File

@ -402,12 +402,12 @@ export default {
}
//
if (this.hotWord.length === 0) {
if (!this.hotWord || this.hotWord.length === 0) {
return;
}
let index = 0;
const totalHeight = this.hotWord.length * this.itemHeight;
const totalHeight = this.hotWord && this.hotWord.length * this.itemHeight;
const containerHeight = this.itemHeight; //
this.scrollInterval = setInterval(() => {
@ -685,8 +685,8 @@ export default {
page_size: 10
}, { silent: false });
if (res.rows.length) {
let filterRes = this.filterShowList(res?.rows, 1);
if (res.rows && res.rows.length) {
let filterRes = this.filterShowList(res.rows, 1);
filterRes.forEach(item => {
item.pic_src = picUrl + item.pic_src
})
@ -705,11 +705,11 @@ export default {
page_num: 1,
page_size: 10
}, { silent: false });
if (!res.rows.length) {
if (!res.rows || !res.rows.length) {
this.serverLeftList = []
}
if (res.rows.length) {
if (res.rows && res.rows.length) {
this.serverLeftList = res.rows
let filterRes = this.filterShowList(res?.rows, 1);
filterRes.forEach(item => {
@ -733,10 +733,10 @@ export default {
page_num: 1,
page_size: 10
}, { silent: false });
if (!res.rows.length) {
if (!res.rows || !res.rows.length) {
this.serverRightList = []
}
if (res.rows.length) {
if (res.rows && res.rows.length) {
let filterRes = this.filterShowList(res?.rows, 1);
filterRes.forEach(item => {
item.pic_src = picUrl + item.pic_src
@ -756,7 +756,7 @@ export default {
page_num: 1,
page_size: 10
}, { silent: false });
if (res.rows.length) {
if (res.rows && res.rows.length) {
let filterRes = this.filterShowList(res?.rows, 1);
filterRes.forEach(item => {
item.pic_src = picUrl + item.pic_src
@ -778,7 +778,7 @@ export default {
page_num: 1,
page_size: 10
}, { silent: false });
if (res.rows.length) {
if (res.rows && res.rows.length) {
// let firstItem = res.rows[0];
// firstItem.pic_src = picUrl + firstItem.pic_src;
// rightList.push(firstItem);
@ -941,10 +941,10 @@ export default {
page_num: this.bottomPageNum,
page_size: this.bottomPageSize
}, { silent: val ? false : true });
if (res.rows.length === 0) {
if (!res.rows || res.rows.length === 0) {
return [];
};
if (res.rows.length == this.bottomPageSize) {
if (res.rows && res.rows.length == this.bottomPageSize) {
this.flag = true
} else {
this.flag = false
@ -992,7 +992,7 @@ export default {
isShop: 1,
}
const res = await request(apiArr2.getCateList, "POST", params, { slice: false });
if (res.rows.length) {
if (res.rows && res.rows.length) {
this.currentCategoryId = res.rows[0].id
this.activeCategoryId = `category-${this.currentCategoryId}`
this.getMechantList()
@ -1013,8 +1013,8 @@ export default {
let latitude = uni.getStorageSync("location").lat;
let longitude = uni.getStorageSync("location").lng;
res.rows.forEach((item) => {
item.bigImg = item.album_images.split(",");
item.showImg = picUrl + item.album_images.split(",")[0];
item.bigImg = item.album_images?.split(",");
item.showImg = picUrl + item.album_images?.split(",")[0];
const distanceInKm = calculateDistance(
latitude,
longitude,
@ -1042,7 +1042,7 @@ export default {
return valueA - valueB;
});
if (res.rows.length == this.page_size) {
if (res.rows && res.rows.length == this.page_size) {
this.page_num = this.page_num + 1;
this.flag = true;
} else {
@ -1069,8 +1069,9 @@ export default {
* @returns {Array} 返回符合条件的数组内容
*/
filterShowList(list, type) {
if (list && list.length == 0) return [];
return list.filter((item) => item.show_status == type);
if (list && list.length) {
return list.filter((item) => item.show_status == type);
} return [];
},
async showSearch() {
@ -1081,7 +1082,7 @@ export default {
async getSearchVal() {
const res = await request(apiArr.hotWord, "POST", {}, { slice: false });
//
this.hotWord = res.search_hot_word.split(/[,]/)
this.hotWord = res.search_hot_word ? res.search_hot_word.split(/[,]/) : []
},
async switchCategory(id) {
@ -1170,7 +1171,7 @@ export default {
watch: {
hotWord: {
handler(newVal) {
if (newVal.length > 0) {
if (newVal && newVal.length > 0) {
this.startScrollAnimation();
}
},