refactor: 统一API请求路径并优化请求逻辑

将多个页面中的API请求路径统一为相对路径,并在`utils/login.js`中自动补全为完整URL。优化了请求方法,默认为POST,同时支持GET请求。简化了代码结构,提高了代码的可维护性和一致性。
This commit is contained in:
2025-04-10 19:01:02 +08:00
parent 764df18ad0
commit 1af84dc1ee
11 changed files with 235 additions and 247 deletions

View File

@@ -10,21 +10,21 @@ Page({
selectID: null,
isScan: !1
},
onLoad: function(a) {
onLoad: function (a) {
var i = this;
e.pageStart(t).then(function(e) {
e.pageStart(t).then(function (e) {
i.getList(), console.log("app.globalData.devicecode", t.globalData.user.money, t.globalData.devicecode),
i.setData({
isScan: !!t.globalData.devicecode
});
i.setData({
isScan: !!t.globalData.devicecode
});
});
},
onShow: function() {
onShow: function () {
this.isneedUpload && (this.getList(), this.isneedUpload = !1);
},
onPullDownRefresh: function() {},
onShareAppMessage: function() {},
toPage: function(t) {
onPullDownRefresh: function () { },
onShareAppMessage: function () { },
toPage: function (t) {
var e = t.currentTarget.dataset.url;
e ? wx.navigateTo({
url: "/pages/".concat(e)
@@ -34,7 +34,7 @@ Page({
duration: 2e3
});
},
selectItem: function(t) {
selectItem: function (t) {
var e = t.currentTarget.dataset, a = (e.index, e.code);
if (1 != e.available) return wx.showToast({
title: "该洗车券不可用~",
@@ -45,39 +45,39 @@ Page({
});
},
isloading: !1,
getList: function(i) {
getList: function (i) {
var o = this;
if (this.isloading) return !1;
wx.showLoading(), this.setData({
loading: !0
}), this.isloading = !0, e.request(t.globalData.config.carwashcoupon.lists, {}, !0).then(function(t) {
}), this.isloading = !0, e.request('/miniprogram/coupons/lists', { devicecode: t.globalData.devicecode }, !0).then(function (t) {
if (o.isloading = !1, o.setData({
loading: !1
}), wx.hideLoading(), 200 != t.code) return wx.showModal({
title: "提示",
content: t.message
}), !1;
t.data.list.map(function(t) {
t.data.data.map(function (t) {
t.starttime = a.changeTimeyear(new Date(1e3 * t.starttime)), t.deadline = a.changeTimeyear(new Date(1e3 * t.deadline));
}), o.setData({
list: t.data.list,
list: t.data.data,
user: t.data.user,
showLoding: !1
});
}).catch(function(t) {
}).catch(function (t) {
o.isloading = !1, o.setData({
loading: !1
}), wx.hideLoading();
});
},
toScan: function() {
toScan: function () {
var a = this;
if (this.isSubmit) return !1;
wx.scanCode({
success: function(i) {
success: function (i) {
wx.showLoading({
title: ""
}), t.globalData.qrcode = i.result, e.request("https://t-jm.v0750.com/miniprogram/identify", i, !0).then(function(e) {
}), t.globalData.qrcode = i.result, e.request("/miniprogram/identify", i, !0).then(function (e) {
if (wx.hideLoading(), 200 != e.code) return wx.showModal({
title: "提示",
content: e.message
@@ -85,7 +85,7 @@ Page({
t.globalData.devicecode = e.data.devicecode || t.globalData.devicecode, a.setData({
isScan: !!e.data.devicecode
}), a.getList();
}).catch(function(t) {
}).catch(function (t) {
wx.hideLoading(), a.isSubmit = !1;
});
}
@@ -94,7 +94,7 @@ Page({
isSubmit: !1,
isneedUpload: !1,
isshowModal: !1,
toStart: function() {
toStart: function () {
var t = this;
return console.log("this.isSubmit", this.isSubmit), !this.isSubmit && (0 == this.data.list.length ? (wx.showModal({
title: "提示",
@@ -104,25 +104,25 @@ Page({
content: "请选择洗车券"
}), !1));
},
startup: function() {
startup: function () {
var a = this;
wx.showModal({
title: "提示",
content: "你当前将要使用的机器编号是:".concat(t.globalData.devicecode, ",确认开机吗?"),
success: function(i) {
success: function (i) {
i.confirm && (a.isSubmit = !0, wx.showLoading({
title: "正在启动"
}), e.request(t.globalData.config.machine.carwashcodestartup, {
}), e.request('/miniprogram/machine/carwashcodestartup', {
washcode: a.data.selectID
}, !0).then(function(t) {
}, !0).then(function (t) {
a.isSubmit = !1, wx.hideLoading(), 200 == t.code && wx.redirectTo({
url: "/pages/user/user"
});
}).catch(function(t) {
}).catch(function (t) {
a.isSubmit = !1, wx.hideLoading();
}));
},
fail: function(t) {
fail: function (t) {
console.log("fail:", t);
}
});