混凝土运输管理微信小程序、替班
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

95 lines
1.5 KiB

function http(uri, data, callback, method = 'GET'){
uni.request({
url: import.meta.env.VITE_GLOB_API + uri,
data: enhanceData(data),
method: method,
header: { 'auth': '1AS9F1HPC4FBC9EN00J7KX2L5RJ99XHZ' },
success: (res) => {
callback(res.data)
},
fail: () => {
uni.showLoading({})
setTimeout(()=>{
uni.hideLoading()
uni.showToast({icon:"none", title:"网络异常"})
}, 3000)
}
});
}
function deleted(uri, data, callback){
http(uri, data, callback, 'DELETE')
}
function post(uri, data, callback){
http(uri, data, callback, 'POST')
}
function get(uri, data, callback){
http(uri, data, callback, 'GET')
}
function enhanceData(data){
const userid = uni.getStorageSync("userid")
const enter_id = uni.getStorageSync("enter_id")
if (!data){
data = {}
}
if (userid){
data.userid = userid
}
if (enter_id){
data.enter_id = enter_id
}
return data
}
function sync(method, uri, data){
return new Promise((resolve, reject) => {
uni.request({
url: uri,
data: data,
method: method,
header: { 'auth': '1AS9F1HPC4FBC9EN00J7KX2L5RJ99XHZ' },
success: (res) => {
resolve(res.data)
},
fail: (err) => {
reject(err);
}
})
})
}
let cache = null
function async(method, uri, data){
const promise = sync(method, uri, data).then(res => {
cache = res
}).catch(err => {
})
}
function syncHttp(uri, data, method = 'GET'){
async(method, uri, data)
}
export default {
http: http,
delete: deleted,
post: post,
get: get,
syncHttp: syncHttp
}