小程序首页添加接口返回参数校验
This commit is contained in:
parent
bb54f833d3
commit
d24b5efcb7
@ -402,12 +402,12 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 如果没有热词,不启动滚动
|
// 如果没有热词,不启动滚动
|
||||||
if (this.hotWord.length === 0) {
|
if (!this.hotWord || this.hotWord.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = 0;
|
let index = 0;
|
||||||
const totalHeight = this.hotWord.length * this.itemHeight;
|
const totalHeight = this.hotWord && this.hotWord.length * this.itemHeight;
|
||||||
const containerHeight = this.itemHeight; // 容器高度,只显示一项
|
const containerHeight = this.itemHeight; // 容器高度,只显示一项
|
||||||
|
|
||||||
this.scrollInterval = setInterval(() => {
|
this.scrollInterval = setInterval(() => {
|
||||||
@ -685,8 +685,8 @@ export default {
|
|||||||
page_size: 10
|
page_size: 10
|
||||||
}, { silent: false });
|
}, { silent: false });
|
||||||
|
|
||||||
if (res.rows.length) {
|
if (res.rows && res.rows.length) {
|
||||||
let filterRes = this.filterShowList(res?.rows, 1);
|
let filterRes = this.filterShowList(res.rows, 1);
|
||||||
filterRes.forEach(item => {
|
filterRes.forEach(item => {
|
||||||
item.pic_src = picUrl + item.pic_src
|
item.pic_src = picUrl + item.pic_src
|
||||||
})
|
})
|
||||||
@ -705,11 +705,11 @@ export default {
|
|||||||
page_num: 1,
|
page_num: 1,
|
||||||
page_size: 10
|
page_size: 10
|
||||||
}, { silent: false });
|
}, { silent: false });
|
||||||
if (!res.rows.length) {
|
if (!res.rows || !res.rows.length) {
|
||||||
this.serverLeftList = []
|
this.serverLeftList = []
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.rows.length) {
|
if (res.rows && res.rows.length) {
|
||||||
this.serverLeftList = res.rows
|
this.serverLeftList = res.rows
|
||||||
let filterRes = this.filterShowList(res?.rows, 1);
|
let filterRes = this.filterShowList(res?.rows, 1);
|
||||||
filterRes.forEach(item => {
|
filterRes.forEach(item => {
|
||||||
@ -733,10 +733,10 @@ export default {
|
|||||||
page_num: 1,
|
page_num: 1,
|
||||||
page_size: 10
|
page_size: 10
|
||||||
}, { silent: false });
|
}, { silent: false });
|
||||||
if (!res.rows.length) {
|
if (!res.rows || !res.rows.length) {
|
||||||
this.serverRightList = []
|
this.serverRightList = []
|
||||||
}
|
}
|
||||||
if (res.rows.length) {
|
if (res.rows && res.rows.length) {
|
||||||
let filterRes = this.filterShowList(res?.rows, 1);
|
let filterRes = this.filterShowList(res?.rows, 1);
|
||||||
filterRes.forEach(item => {
|
filterRes.forEach(item => {
|
||||||
item.pic_src = picUrl + item.pic_src
|
item.pic_src = picUrl + item.pic_src
|
||||||
@ -756,7 +756,7 @@ export default {
|
|||||||
page_num: 1,
|
page_num: 1,
|
||||||
page_size: 10
|
page_size: 10
|
||||||
}, { silent: false });
|
}, { silent: false });
|
||||||
if (res.rows.length) {
|
if (res.rows && res.rows.length) {
|
||||||
let filterRes = this.filterShowList(res?.rows, 1);
|
let filterRes = this.filterShowList(res?.rows, 1);
|
||||||
filterRes.forEach(item => {
|
filterRes.forEach(item => {
|
||||||
item.pic_src = picUrl + item.pic_src
|
item.pic_src = picUrl + item.pic_src
|
||||||
@ -778,7 +778,7 @@ export default {
|
|||||||
page_num: 1,
|
page_num: 1,
|
||||||
page_size: 10
|
page_size: 10
|
||||||
}, { silent: false });
|
}, { silent: false });
|
||||||
if (res.rows.length) {
|
if (res.rows && res.rows.length) {
|
||||||
// let firstItem = res.rows[0];
|
// let firstItem = res.rows[0];
|
||||||
// firstItem.pic_src = picUrl + firstItem.pic_src;
|
// firstItem.pic_src = picUrl + firstItem.pic_src;
|
||||||
// rightList.push(firstItem);
|
// rightList.push(firstItem);
|
||||||
@ -941,10 +941,10 @@ export default {
|
|||||||
page_num: this.bottomPageNum,
|
page_num: this.bottomPageNum,
|
||||||
page_size: this.bottomPageSize
|
page_size: this.bottomPageSize
|
||||||
}, { silent: val ? false : true });
|
}, { silent: val ? false : true });
|
||||||
if (res.rows.length === 0) {
|
if (!res.rows || res.rows.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
};
|
};
|
||||||
if (res.rows.length == this.bottomPageSize) {
|
if (res.rows && res.rows.length == this.bottomPageSize) {
|
||||||
this.flag = true
|
this.flag = true
|
||||||
} else {
|
} else {
|
||||||
this.flag = false
|
this.flag = false
|
||||||
@ -992,7 +992,7 @@ export default {
|
|||||||
isShop: 1,
|
isShop: 1,
|
||||||
}
|
}
|
||||||
const res = await request(apiArr2.getCateList, "POST", params, { slice: false });
|
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.currentCategoryId = res.rows[0].id
|
||||||
this.activeCategoryId = `category-${this.currentCategoryId}`
|
this.activeCategoryId = `category-${this.currentCategoryId}`
|
||||||
this.getMechantList()
|
this.getMechantList()
|
||||||
@ -1013,8 +1013,8 @@ export default {
|
|||||||
let latitude = uni.getStorageSync("location").lat;
|
let latitude = uni.getStorageSync("location").lat;
|
||||||
let longitude = uni.getStorageSync("location").lng;
|
let longitude = uni.getStorageSync("location").lng;
|
||||||
res.rows.forEach((item) => {
|
res.rows.forEach((item) => {
|
||||||
item.bigImg = item.album_images.split(",");
|
item.bigImg = item.album_images?.split(",");
|
||||||
item.showImg = picUrl + item.album_images.split(",")[0];
|
item.showImg = picUrl + item.album_images?.split(",")[0];
|
||||||
const distanceInKm = calculateDistance(
|
const distanceInKm = calculateDistance(
|
||||||
latitude,
|
latitude,
|
||||||
longitude,
|
longitude,
|
||||||
@ -1042,7 +1042,7 @@ export default {
|
|||||||
return valueA - valueB;
|
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.page_num = this.page_num + 1;
|
||||||
this.flag = true;
|
this.flag = true;
|
||||||
} else {
|
} else {
|
||||||
@ -1069,8 +1069,9 @@ export default {
|
|||||||
* @returns {Array} 返回符合条件的数组内容
|
* @returns {Array} 返回符合条件的数组内容
|
||||||
*/
|
*/
|
||||||
filterShowList(list, type) {
|
filterShowList(list, type) {
|
||||||
if (list && list.length == 0) return [];
|
if (list && list.length) {
|
||||||
return list.filter((item) => item.show_status == type);
|
return list.filter((item) => item.show_status == type);
|
||||||
|
} return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
async showSearch() {
|
async showSearch() {
|
||||||
@ -1081,7 +1082,7 @@ export default {
|
|||||||
async getSearchVal() {
|
async getSearchVal() {
|
||||||
const res = await request(apiArr.hotWord, "POST", {}, { slice: false });
|
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) {
|
async switchCategory(id) {
|
||||||
@ -1170,7 +1171,7 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
hotWord: {
|
hotWord: {
|
||||||
handler(newVal) {
|
handler(newVal) {
|
||||||
if (newVal.length > 0) {
|
if (newVal && newVal.length > 0) {
|
||||||
this.startScrollAnimation();
|
this.startScrollAnimation();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user