refactor: 统一API请求路径并优化请求逻辑
将多个页面中的API请求路径统一为相对路径,并在`utils/login.js`中自动补全为完整URL。优化了请求方法,默认为POST,同时支持GET请求。简化了代码结构,提高了代码的可维护性和一致性。
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
// pages/wangdian/wangdian.js
|
||||
var t = require("../../utils/login.js");
|
||||
|
||||
Page({
|
||||
|
||||
/**
|
||||
@@ -98,55 +100,45 @@ Page({
|
||||
},
|
||||
// 获取网点详情信息
|
||||
getBranchDetail() {
|
||||
wx.request({
|
||||
url: 'https://t-jm.v0750.com/miniprogram/branch/detail',
|
||||
data: {
|
||||
number: this.data.number,
|
||||
latitude: wx.getStorageSync('latitude'),
|
||||
longitude: wx.getStorageSync('longitude'),
|
||||
},
|
||||
t.request('/miniprogram/branch/detail', {
|
||||
number: this.data.number,
|
||||
latitude: wx.getStorageSync('latitude'),
|
||||
longitude: wx.getStorageSync('longitude'),
|
||||
method: 'GET',
|
||||
success: (res) => {
|
||||
if (res.data && res.data.code == 200) {
|
||||
this.setData({
|
||||
banner: res.data.data.banner || [],
|
||||
info: res.data.data.info || {}
|
||||
});
|
||||
}
|
||||
}, !0).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.setData({
|
||||
banner: res.data.banner || [],
|
||||
info: res.data.info || {},
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
// 获取机器列表
|
||||
getMachineList() {
|
||||
wx.request({
|
||||
url: 'https://t-jm.v0750.com/miniprogram/branch/machine',
|
||||
data: {
|
||||
number: this.data.number,
|
||||
},
|
||||
method: 'POST',
|
||||
success: (res) => {
|
||||
if (res.data && res.data.code == 200) {
|
||||
this.setData({
|
||||
jiqilist: res.data.data || []
|
||||
});
|
||||
|
||||
// 计算机器数量, 与空闲机器数量 free machine
|
||||
let machineCount = this.data.jiqilist.length;
|
||||
let freeMachineCount = 0;
|
||||
for (let i = 0; i < this.data.jiqilist.length; i++) {
|
||||
if (this.data.jiqilist[i].devicestatus == 0) {
|
||||
freeMachineCount++;
|
||||
}
|
||||
t.request('/miniprogram/branch/machine', {
|
||||
number: this.data.number,
|
||||
}).then((res) => {
|
||||
if (res.code == 200) {
|
||||
this.setData({
|
||||
jiqilist: res.data || [],
|
||||
});
|
||||
// 计算机器数量, 与空闲机器数量 free machine
|
||||
let machineCount = this.data.jiqilist.length;
|
||||
let freeMachineCount = 0;
|
||||
for (let i = 0; i < this.data.jiqilist.length; i++) {
|
||||
if (this.data.jiqilist[i].devicestatus == 0) {
|
||||
freeMachineCount++;
|
||||
}
|
||||
// 更新数据
|
||||
this.setData({
|
||||
machineCount,
|
||||
freeMachineCount
|
||||
});
|
||||
|
||||
}
|
||||
// 更新数据
|
||||
this.setData({
|
||||
machineCount,
|
||||
freeMachineCount
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user