feat: 优化在微信小程序中接口返回的错误信息 会被uni.hideLoading取消展示错误信息问题

master
学习很差啦 2023-04-11 18:41:34 +08:00
parent c070ed01f7
commit 2bdb8682e1
38 changed files with 70 additions and 58 deletions

View File

@ -98,7 +98,7 @@
}) : "", }) : "",
getAllCoupons(submitData) getAllCoupons(submitData)
.then((res) => { .then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
if (res.data.code == 200) { if (res.data.code == 200) {
// //
@ -113,7 +113,7 @@
} }
}) })
.catch((err) => { .catch((err) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
/** /**

View File

@ -217,7 +217,7 @@ export default {
this.navList[index].dataList.push(...data); this.navList[index].dataList.push(...data);
} }
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },

View File

@ -244,7 +244,7 @@
// //
await API_Trade.initiatePay(paymentMethod, paymentClient, params).then( await API_Trade.initiatePay(paymentMethod, paymentClient, params).then(
(signXml) => { (signXml) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
// //
if (!signXml.data.success) { if (!signXml.data.success) {
uni.showToast({ uni.showToast({
@ -334,7 +334,7 @@
} }
} }
); );
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
} else { } else {
window.location.href = JSON.parse(response.result).h5_url; window.location.href = JSON.parse(response.result).h5_url;
const searchParams = { const searchParams = {
@ -352,7 +352,7 @@
}) })
},3000) },3000)
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
} }
} else if (paymentMethod === "WALLET") { } else if (paymentMethod === "WALLET") {
uni.showToast({ uni.showToast({

View File

@ -204,7 +204,7 @@ export default {
this.goodsDetail = response.data.result.data; this.goodsDetail = response.data.result.data;
this.selectedGoods = response.data.result.data; this.selectedGoods = response.data.result.data;
this.goodsSpec = response.data.result.specs; this.goodsSpec = response.data.result.specs;
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
this.PromotionList = response.data.result.promotionMap; this.PromotionList = response.data.result.promotionMap;
// //

View File

@ -133,7 +133,7 @@ export default {
this.form.consigneeAddressPath = val.data.result.name; // '' this.form.consigneeAddressPath = val.data.result.name; // ''
this.form.lat = val.latitude; // this.form.lat = val.latitude; //
this.form.lon = val.longitude; // this.form.lon = val.longitude; //
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
} }
this.mapFlag = !this.mapFlag; // this.mapFlag = !this.mapFlag; //
@ -276,10 +276,10 @@ export default {
params.___path = params.consigneeAddressPath; params.___path = params.consigneeAddressPath;
this.$set(this, "form", params); this.$set(this, "form", params);
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}, },
// rulesonReadyonLoad // rulesonReadyonLoad
onReady() { onReady() {

View File

@ -101,7 +101,7 @@ export default {
this.addressList = res.data.result.records; this.addressList = res.data.result.records;
console.log(this.addressList); console.log(this.addressList);
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
// //

View File

@ -103,7 +103,7 @@ export default {
}); });
this.addressList = res.data.result.records; this.addressList = res.data.result.records;
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
// //

View File

@ -76,7 +76,7 @@ export default {
this.storeAddressList = res.data.result.records; this.storeAddressList = res.data.result.records;
console.log(this.storeAddressList); console.log(this.storeAddressList);
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
}, },

View File

@ -96,7 +96,7 @@ export default {
this.status = "nomore"; this.status = "nomore";
this.empty = true; this.empty = true;
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
// //
@ -111,7 +111,7 @@ export default {
this.status = "nomore"; this.status = "nomore";
this.empty = true; this.empty = true;
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
}, },

View File

@ -78,7 +78,7 @@ export default {
if (res.data.result) { if (res.data.result) {
this.distributionData = res.data.result; this.distributionData = res.data.result;
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
}, },

View File

@ -75,7 +75,7 @@ export default {
if (res.data.result) { if (res.data.result) {
this.distributionData = res.data.result; this.distributionData = res.data.result;
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
}, },

View File

@ -110,7 +110,7 @@ export default {
title: "加载中", title: "加载中",
}); });
getTalkList(params).then((res) => { getTalkList(params).then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
if (res.data.success) { if (res.data.success) {
this.talkList = res.data.result; this.talkList = res.data.result;
console.log(this.talkList, 'this.talkListthis.talkList'); console.log(this.talkList, 'this.talkListthis.talkList');

View File

@ -58,7 +58,7 @@ export default {
title:"加载中" title:"加载中"
}) })
API_Message.getLogisticsMessages(this.params).then(async response => { API_Message.getLogisticsMessages(this.params).then(async response => {
uni.hideLoading() if (this.$store.state.isShowToast){ uni.hideLoading() }
const { data } = response const { data } = response
if (!data || !data.length) { if (!data || !data.length) {
this.messageList.push(...data.data) this.messageList.push(...data.data)

View File

@ -59,7 +59,7 @@ export default {
title: "加载中" title: "加载中"
}); });
API_Message.getMessages(this.params).then(async response => { API_Message.getMessages(this.params).then(async response => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
const { data } = response; const { data } = response;
if (!data || !data.length) { if (!data || !data.length) {
this.messageList.push(...data.data); this.messageList.push(...data.data);

View File

@ -197,7 +197,7 @@
title: "加载中", title: "加载中",
}); });
getGoodsCollection(this.navList[0].params, "GOODS").then((res) => { getGoodsCollection(this.navList[0].params, "GOODS").then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
if (res.data.success) { if (res.data.success) {
let data = res.data.result; let data = res.data.result;
@ -225,7 +225,7 @@
title: "加载中", title: "加载中",
}); });
getGoodsCollection(this.navList[1].params, "store").then((res) => { getGoodsCollection(this.navList[1].params, "store").then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
if (res.data.success) { if (res.data.success) {
let data = res.data.result; let data = res.data.result;

View File

@ -114,7 +114,7 @@
}); });
myTrackList(this.params).then((res) => { myTrackList(this.params).then((res) => {
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
if (res.statusCode == 200) { if (res.statusCode == 200) {
res.data.result.records.length && res.data.result.records.length &&
res.data.result.records.forEach((item) => { res.data.result.records.forEach((item) => {

View File

@ -72,7 +72,7 @@ export default {
title: "加载中", title: "加载中",
}); });
getPointsData(params).then((res) => { getPointsData(params).then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
if (res.data.success) { if (res.data.success) {
let data = res.data.result.records; let data = res.data.result.records;
if (data.length < 10) { if (data.length < 10) {

View File

@ -115,7 +115,7 @@
title: "正在获取验证码", title: "正在获取验证码",
}); });
sendMobile(this.codeForm.mobile, "FIND_USER").then((res) => { sendMobile(this.codeForm.mobile, "FIND_USER").then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
// this.start() // this.start()
if (res.data.success) { if (res.data.success) {
this.$refs.uCode.start(); this.$refs.uCode.start();

View File

@ -636,7 +636,7 @@ export default {
this.goodsList.push(...goodsList.data.result.records); this.goodsList.push(...goodsList.data.result.records);
this.initSortGoods(); this.initSortGoods();
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}, },
// //

View File

@ -309,7 +309,7 @@ export default {
mask: true, mask: true,
}); });
getOrderList(this.params).then((res) => { getOrderList(this.params).then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
const orderList = res.data.result.records; const orderList = res.data.result.records;
if (orderList.length > 0) { if (orderList.length > 0) {
this.orderList = this.orderList.concat(orderList); this.orderList = this.orderList.concat(orderList);
@ -345,7 +345,7 @@ export default {
this.orderList = []; this.orderList = [];
this.searchOrderList(this.current); this.searchOrderList(this.current);
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}, },
/** /**

View File

@ -224,7 +224,7 @@ export default {
this.reasonList = action; this.reasonList = action;
} }
}); });
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}, },
// //
showCitySelect() { showCitySelect() {
@ -288,7 +288,7 @@ export default {
this.form.applyRefundPrice = this.applyInfo.applyRefundPrice; this.form.applyRefundPrice = this.applyInfo.applyRefundPrice;
applyReturn(this.sn, this.form).then((resp) => { applyReturn(this.sn, this.form).then((resp) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
if (resp.data.success) { if (resp.data.success) {
this.$refs.uToast.show({ title: "提交成功", type: "success" }); this.$refs.uToast.show({ title: "提交成功", type: "success" });
uni.redirectTo({ uni.redirectTo({

View File

@ -128,7 +128,7 @@ export default {
}); });
delete this.form.courierCompany; delete this.form.courierCompany;
fillShipInfo(this.serviceDetail.sn, this.form).then((res) => { fillShipInfo(this.serviceDetail.sn, this.form).then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
if (res.statusCode === 200) { if (res.statusCode === 200) {
this.$refs.uToast.show({ this.$refs.uToast.show({
title: "提交成功", title: "提交成功",

View File

@ -352,7 +352,7 @@ export default {
title: "加载中", title: "加载中",
}); });
getServiceDetail(this.sn).then((res) => { getServiceDetail(this.sn).then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
this.serviceDetail = res.data.result; this.serviceDetail = res.data.result;
if ( if (
this.serviceDetail.serviceType == "RETURN_GOODS" || this.serviceDetail.serviceType == "RETURN_GOODS" ||

View File

@ -178,7 +178,7 @@ export default {
this.order = order.order; this.order = order.order;
this.orderGoodsList = order.orderItems; this.orderGoodsList = order.orderItems;
this.orderDetail = res.data.result; this.orderDetail = res.data.result;
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },

View File

@ -95,7 +95,7 @@ export default {
icon: "none", icon: "none",
}); });
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
}, },

View File

@ -140,7 +140,7 @@ export default {
} else { } else {
this.empty = true; this.empty = true;
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
}, },

View File

@ -202,7 +202,7 @@ export default {
title: "加载中", title: "加载中",
}); });
getOrderList(this.params).then((res) => { getOrderList(this.params).then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
const orderList = res.data.result.records; const orderList = res.data.result.records;
if (orderList.length < 10) { if (orderList.length < 10) {
this.params.loadStatus = "noMore"; this.params.loadStatus = "noMore";
@ -234,7 +234,7 @@ export default {
title: "加载中", title: "加载中",
}); });
getComments(this.params).then((res) => { getComments(this.params).then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
let orderList = res.data.result.records; let orderList = res.data.result.records;
if (orderList.length < 10) { if (orderList.length < 10) {
this.params.loadStatus = "noMore"; this.params.loadStatus = "noMore";

View File

@ -137,7 +137,7 @@ export default {
title: "加载中", title: "加载中",
}); });
commentsMemberOrder(this.form).then((res) => { commentsMemberOrder(this.form).then((res) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
if (res.data.success) { if (res.data.success) {
uni.showToast({ uni.showToast({
title: "发布评价成功", title: "发布评价成功",

View File

@ -373,7 +373,7 @@ export default {
}); });
await this.getOrderList(); await this.getOrderList();
await this.getDistribution(); await this.getDistribution();
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
if (this.routerVal.way == "PINTUAN") { if (this.routerVal.way == "PINTUAN") {
this.isAssemble = true; this.isAssemble = true;
this.routerVal.parentOrder = JSON.parse( this.routerVal.parentOrder = JSON.parse(

View File

@ -392,7 +392,7 @@ export default {
if (res.data.result.length >= 1) { if (res.data.result.length >= 1) {
this.cancelList = res.data.result; this.cancelList = res.data.result;
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
@ -473,7 +473,7 @@ export default {
}); });
setTimeout(() => { setTimeout(() => {
this.navList[this.tabCurrentIndex].orderList.splice(index, 1); this.navList[this.tabCurrentIndex].orderList.splice(index, 1);
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}, 600); }, 600);
}, },
// //
@ -493,7 +493,7 @@ export default {
let list = this.navList[1].orderList; let list = this.navList[1].orderList;
let index = list.findIndex((val) => val.id === item.id); let index = list.findIndex((val) => val.id === item.id);
index !== -1 && list.splice(index, 1); index !== -1 && list.splice(index, 1);
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}, 600); }, 600);
}, },

View File

@ -361,7 +361,7 @@ export default {
if (this.order.deliveryMethod === 'LOGISTICS') { if (this.order.deliveryMethod === 'LOGISTICS') {
this.loadLogistics(sn) this.loadLogistics(sn)
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
@ -413,7 +413,7 @@ export default {
}); });
setTimeout(() => { setTimeout(() => {
this.navList[this.tabCurrentIndex].orderList.splice(index, 1); this.navList[this.tabCurrentIndex].orderList.splice(index, 1);
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}, 600); }, 600);
}, },
// //
@ -427,7 +427,7 @@ export default {
if (res.data.result.length >= 1) { if (res.data.result.length >= 1) {
this.cancelList = res.data.result; this.cancelList = res.data.result;
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
this.cancelShow = true; this.cancelShow = true;

View File

@ -321,7 +321,7 @@
// //
uni.showLoading({}); uni.showLoading({});
let res = await sendMobile(this.mobile); let res = await sendMobile(this.mobile);
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
// this.start() // this.start()
if (res.data.success) { if (res.data.success) {
this.current = 1; this.current = 1;
@ -708,7 +708,7 @@
clearInterval(timer); clearInterval(timer);
}, 100); }, 100);
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
} }
if (!this.flage) { if (!this.flage) {
this.$refs.verification.error(); // this.$refs.verification.error(); //

View File

@ -70,7 +70,7 @@ export default {
title: "请填写内容!", title: "请填写内容!",
icon: "none", icon: "none",
}); });
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
return false; return false;
} }
API_MEM.consultating( API_MEM.consultating(
@ -86,11 +86,11 @@ export default {
}); });
this.askValue = ""; this.askValue = "";
} }
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}) })
.catch((err) => { .catch((err) => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
}); });
}, },
radioGroupChange(e) { radioGroupChange(e) {

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="wrapper"> <div class="wrapper">
<!-- 空白页--> <!-- 空白页-->
<view v-if="cartDetail.cartList == '' || cartDetail.cartList == [] || !cartDetail" class="empty"> <view v-if="!loading && (cartDetail.cartList == '' || cartDetail.cartList == [] || !cartDetail)" class="empty">
<image src="/static/emptyCart.png" mode="aspectFit"></image> <image src="/static/emptyCart.png" mode="aspectFit"></image>
<view class="empty-tips"> <view class="empty-tips">
空空如也 空空如也
@ -184,6 +184,7 @@ import { debounce } from "@/utils/tools.js";
export default { export default {
data() { data() {
return { return {
loading:false,
lightColor: this.$lightColor, lightColor: this.$lightColor,
discountDetailsFlag: false, // discountDetailsFlag: false, //
// //
@ -508,6 +509,7 @@ export default {
}); });
API_Trade.getCarts() API_Trade.getCarts()
.then((result) => { .then((result) => {
this.loading = false;
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
if (result.data.success) { if (result.data.success) {
this.cartDetail = result.data.result; this.cartDetail = result.data.result;
@ -541,10 +543,10 @@ export default {
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
} }
}) })
.catch((err) => {}); .catch((err) => {this.loading = false;});
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
} else { } else {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
} }
}, },

View File

@ -56,7 +56,7 @@
}) })
this.params.keyword = this.goods.goodsName; this.params.keyword = this.goods.goodsName;
getGoodsList(this.params).then(res => { getGoodsList(this.params).then(res => {
uni.hideLoading() if (this.$store.state.isShowToast){ uni.hideLoading() }
if (res.statusCode == 200) { if (res.statusCode == 200) {
let data = res.data; let data = res.data;
if (data.data_total == 0) { if (data.data_total == 0) {

View File

@ -6,6 +6,7 @@ Vue.use(Vuex);
const store = new Vuex.Store({ const store = new Vuex.Store({
state: { state: {
isShowToast:false, // 是否在展示Toast中
shareLink:"", //分享链接 shareLink:"", //分享链接
verificationKey: "", //获取key表示验证通过 verificationKey: "", //获取key表示验证通过
distributionId:"", //分销员Id 如果当前账户从未登录过时记录 distributionId:"", //分销员Id 如果当前账户从未登录过时记录

View File

@ -11,7 +11,7 @@ import api from "@/config/api.js";
import uuid from "@/utils/uuid.modified.js"; import uuid from "@/utils/uuid.modified.js";
import jwt from '@/js_sdk/t-jwt/jwt.js' import jwt from '@/js_sdk/t-jwt/jwt.js'
import store from "../store";
let isNavigateTo = false let isNavigateTo = false
@ -131,7 +131,7 @@ http.interceptors.response.use(
// cleanStorage(); // cleanStorage();
// isRefreshing = false; // isRefreshing = false;
// } // }
uni.showLoading() ? uni.hideLoading() : ''
let token = storage.getAccessToken(); let token = storage.getAccessToken();
if ( if (
(token && response.statusCode === 403) || (token && response.statusCode === 403) ||
@ -196,6 +196,15 @@ http.interceptors.response.use(
title: response.data.message, title: response.data.message,
icon: "none", icon: "none",
duration: 1500, duration: 1500,
success: function () {
store.state.isShowToast = true;
},
fail: function () {
store.state.isShowToast = false;
},
complete: function () {
store.state.isShowToast = false;
}
}); });
} }
} }

View File

@ -417,7 +417,7 @@ export default {
this.uploadError(index, e); this.uploadError(index, e);
}, },
complete: res => { complete: res => {
uni.hideLoading(); if (this.$store.state.isShowToast){ uni.hideLoading() };
this.uploading = false; this.uploading = false;
this.uploadFile(index + 1); this.uploadFile(index + 1);
this.$emit('on-change', res, index, this.lists); this.$emit('on-change', res, index, this.lists);