export const apiResquest = (prams) => { //prams 为我们需要调用的接口API的参数 下面会贴具体代码
uni.showLoading({
title: '加载中'
})
// 判断请求类型
let headerData = {
'content-type': 'application/json',
'system-type': 1,
'Authorization': uni.getStorageSync('token') ? "Bearer " + uni.getStorageSync('token') : ''
}
let dataObj = null
dataObj = prams.query
return new Promise((resolve, reject) => {
let ip = process.env.VUE_APP_BASE_URL;
const token = uni.getStorageSync("token");
let url = ip + '/' + prams.url; //请求的网络地址和局地的api地址组合
console.log("请求的url地址");
console.log(url);
uni.showLoading({
title: '加载中',
mask: true
})
return uni.request({
url: url,
data: dataObj,
method: prams.method || 'GET',
header: headerData,
success: (res) => {
uni.hideLoading()
//这里是成功的返回码,大家根据自己的实际情况调整
if (res.data.code != 200) {
uni.showToast({
title:res.data.msg?res.data.msg:'请求失败',
duration: 2000,
icon: "none"
})
return;
}
resolve(res.data);
console.log(res.data)
},
fail: (err) => {
reject(err);
console.log(err)
uni.hideLoading()
uni.showModal({
title: '提示',
showCancel: false,
content: '请求超时'
})
}
});
})
}
接口
import {
apiResquest
} from './request.js'
//获取商品列表
export const goodlist = (query) => {
let str = query
return apiResquest({
url: `api/goods?${str}`,
method: 'GET'
})
}
// 获取日程
export const get_calendar_app = (query) => {
return apiResquest({
url: `api/calendar_app`,
// method: 'GET',
query:{
...query
}
})
}
//修改日程 添加日程 删除日程
export const calendar_app = (query, method) => {
return apiResquest({
url: 'api/calendar_app',
method: method,
query: {
...query
}
})
}
// 数据字典
export const getdic = (query) => {
return apiResquest({
url: `api/get_dictionary_value_info`,
method: 'GET',
query: {
...query
}
})
}