refactor: 统一API请求路径并优化请求逻辑
将多个页面中的API请求路径统一为相对路径,并在`utils/login.js`中自动补全为完整URL。优化了请求方法,默认为POST,同时支持GET请求。简化了代码结构,提高了代码的可维护性和一致性。
This commit is contained in:
@@ -6,59 +6,59 @@ Page({
|
||||
info: {},
|
||||
id: ""
|
||||
},
|
||||
onLoad: function(t) {
|
||||
onLoad: function (t) {
|
||||
var o = this;
|
||||
wx.showLoading({
|
||||
title: ""
|
||||
}), this.setData({
|
||||
id: t.id || 1
|
||||
}), i.pageStart(e).then(function(e) {
|
||||
}), i.pageStart(e).then(function (e) {
|
||||
o.getList();
|
||||
});
|
||||
},
|
||||
getList: function() {
|
||||
getList: function () {
|
||||
var o = this;
|
||||
wx.showLoading({
|
||||
title: ""
|
||||
}), i.request(e.globalData.config.carwashcoupon.details, {
|
||||
}), i.request('/miniprogram/carwashcoupon/details', {
|
||||
id: this.data.id
|
||||
}, !0).then(function(e) {
|
||||
}, !0).then(function (e) {
|
||||
if (wx.hideLoading(), 200 != e.code) return wx.showModal({
|
||||
title: "提示",
|
||||
content: e.message
|
||||
}), !1;
|
||||
e.data.starttime = t.changeTimeyear(new Date(1e3 * e.data.starttime)), e.data.deadline = t.changeTimeyear(new Date(1e3 * e.data.deadline)),
|
||||
o.setData({
|
||||
info: e.data,
|
||||
showLoding: !1
|
||||
}, function() {});
|
||||
}).catch(function(e) {
|
||||
e.data.starttime = t.changeTimeyear(new Date(1e3 * e.data.starttime)), e.data.deadline = t.changeTimeyear(new Date(1e3 * e.data.deadline)),
|
||||
o.setData({
|
||||
info: e.data,
|
||||
showLoding: !1
|
||||
}, function () { });
|
||||
}).catch(function (e) {
|
||||
wx.hideLoading();
|
||||
});
|
||||
},
|
||||
isSubmit: !1,
|
||||
received: function() {
|
||||
received: function () {
|
||||
if (this.isSubmit) return !1;
|
||||
var t = this;
|
||||
this.isSubmit = !0, wx.showLoading(), console.log("received"), i.request(e.globalData.config.carwashcoupon.receive, {
|
||||
this.isSubmit = !0, wx.showLoading(), console.log("received"), i.request('/miniprogram/carwashcoupon/receive', {
|
||||
id: t.data.id,
|
||||
token: t.data.info.token
|
||||
}, !0).then(function(e) {
|
||||
console.log("receiveddqta", e), wx.hideLoading(), t.isSubmit = !1, console.log("recief"),
|
||||
wx.showModal({
|
||||
title: "提示",
|
||||
content: e.message,
|
||||
success: function(e) {
|
||||
e.confirm && wx.redirectTo({
|
||||
url: "/pages/index/index"
|
||||
});
|
||||
}
|
||||
});
|
||||
}).catch(function(e) {
|
||||
}, !0).then(function (e) {
|
||||
console.log("receiveddqta", e), wx.hideLoading(), t.isSubmit = !1, console.log("recief"),
|
||||
wx.showModal({
|
||||
title: "提示",
|
||||
content: e.message,
|
||||
success: function (e) {
|
||||
e.confirm && wx.redirectTo({
|
||||
url: "/pages/index/index"
|
||||
});
|
||||
}
|
||||
});
|
||||
}).catch(function (e) {
|
||||
wx.hideLoading(), t.isSubmit = !1, console.log("提示提示提示提示", e), 201 == e.code && wx.showModal({
|
||||
title: "提示",
|
||||
content: e.message,
|
||||
success: function(e) {
|
||||
success: function (e) {
|
||||
if (!e.confirm) return console.log("弹窗取消"), !1;
|
||||
wx.redirectTo({
|
||||
url: "/pages/index/index"
|
||||
|
||||
Reference in New Issue
Block a user