refactor: 统一API请求路径并优化请求逻辑
将多个页面中的API请求路径统一为相对路径,并在`utils/login.js`中自动补全为完整URL。优化了请求方法,默认为POST,同时支持GET请求。简化了代码结构,提高了代码的可维护性和一致性。
This commit is contained in:
@@ -31,31 +31,31 @@ Page({
|
||||
// 获取地理位置
|
||||
wx.getLocation({
|
||||
type: 'gcj02',
|
||||
success: function(res) {
|
||||
success: function (res) {
|
||||
// 存储经纬度
|
||||
wx.setStorageSync('latitude', res.latitude);
|
||||
wx.setStorageSync('longitude', res.longitude);
|
||||
e.globalData.latitude = res.latitude;
|
||||
e.globalData.longitude = res.longitude;
|
||||
// 获取网点列表
|
||||
t.request('https://t-jm.v0750.com/miniprogram/branch/lists', {
|
||||
t.request('/miniprogram/branch/lists', {
|
||||
latitude: res.latitude || '',
|
||||
longitude: res.longitude || ''
|
||||
}, !0).then(function(res) {
|
||||
}, !0).then(function (res) {
|
||||
a.setData({
|
||||
wangdianList: res.data || []
|
||||
});
|
||||
});
|
||||
},
|
||||
fail: function() {
|
||||
fail: function () {
|
||||
// 即使获取位置失败也加载网点列表,只是不传入经纬度参数
|
||||
t.request('https://t-jm.v0750.com/miniprogram/branch/lists', {}, !0).then(function(res) {
|
||||
t.request('/miniprogram/branch/lists', {}, !0).then(function (res) {
|
||||
a.setData({
|
||||
wangdianList: res.data || []
|
||||
});
|
||||
});
|
||||
},
|
||||
complete: function() {
|
||||
complete: function () {
|
||||
t.pageStart(e).then(function (t) {
|
||||
a.getData();
|
||||
a.setData({
|
||||
@@ -65,14 +65,11 @@ Page({
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
getData: function () {
|
||||
var a = this;
|
||||
|
||||
// 获取首页数据
|
||||
t.request(e.globalData.config.home, {}, !0).then(function (e) {
|
||||
t.request('/miniprogram/index/home', { method: 'GET' }, !0).then(function (e) {
|
||||
a.setData({
|
||||
banner: e.data.banner,
|
||||
user: e.data.user,
|
||||
tmplIds: e.data.tmplIds,
|
||||
joinUs: e.data.joinUs,
|
||||
notice: e.data.notice,
|
||||
@@ -90,6 +87,15 @@ Page({
|
||||
});
|
||||
});
|
||||
},
|
||||
getData: function () {
|
||||
var a = this;
|
||||
// 获取首页数据
|
||||
t.request('/miniprogram/index/balance', {}, !0).then(function (e) {
|
||||
a.setData({
|
||||
user: e.data || [],
|
||||
});
|
||||
});
|
||||
},
|
||||
load: function (e) {
|
||||
console.log(e);
|
||||
var t = e.currentTarget.dataset.index, a = this.data.swiperWidth * e.detail.height / e.detail.width;
|
||||
@@ -100,7 +106,7 @@ Page({
|
||||
onShow: function () {
|
||||
this.setData({
|
||||
isScan: !!e.globalData.devicecode || this.data.isScan
|
||||
}), e.globalData.config && e.globalData.config.home && (this.getData(), this.isneedUpload = !1);
|
||||
}), (this.getData(), this.isneedUpload = !1);
|
||||
},
|
||||
toPage: function (t) {
|
||||
console.info(t);
|
||||
@@ -127,7 +133,7 @@ Page({
|
||||
success: function (i) {
|
||||
console.log(i), wx.showLoading({
|
||||
title: ""
|
||||
}), e.globalData.qrcode = i.result, t.request("https://t-jm.v0750.com/miniprogram/identify", i, !0).then(function (t) {
|
||||
}), e.globalData.qrcode = i.result, t.request("/miniprogram/identify", i, !0).then(function (t) {
|
||||
console.log("data", t), wx.hideLoading(), e.globalData.devicecode = t.data.devicecode || e.globalData.devicecode,
|
||||
a.setData({
|
||||
isScan: !!t.data.devicecode
|
||||
@@ -199,7 +205,7 @@ Page({
|
||||
wx.requestSubscribeMessage({
|
||||
tmplIds: this.data.tmplIds,
|
||||
success: function (e) {
|
||||
console.log("requestSubscribeMessage", e), t.request("https://t-jm.v0750.com/miniprogram/index/newtmpl", e, !0).then(function (e) { }).catch(function (e) { });
|
||||
console.log("requestSubscribeMessage", e), t.request("/miniprogram/index/newtmpl", e, !0).then(function (e) { }).catch(function (e) { });
|
||||
},
|
||||
fail: function (e) {
|
||||
console.log("requestSubscribeMessagefail", e);
|
||||
|
||||
Reference in New Issue
Block a user