import store from './store' const baseUrl = "http://192.168.1.101:8000/api"; const baseImageUrl = "http://192.168.1.101:8000/"; function initPramas() { arguments[0].url = baseUrl + arguments[0].url; // console.log(typeof arguments[0].fail) if (typeof arguments[0].fail === "undefined") { arguments[0].fail = (res) => { console.log(res) uni.showToast({ title: res.data.msg, icon: "none" }) console.log(res.data.code) } } const success = arguments[0].success arguments[0].success = (res) => { console.log(res) if (res.data.code === 0) { uni.showToast({ title: res.data.msg, icon: "none" }) arguments[0].fail(res) } if (res.data.code === 1) { success(res) } if (res.data.code === 401) { uni.navigateTo({ url: "/pages/user/login" }) } } if (typeof arguments[0].header === "undefined") { arguments[0].header = {} } if (store.state.user.token) { arguments[0].header["token"] = store.state.user.token; } return arguments[0]; } export default { baseImageUrl: baseImageUrl, get: function() { let obj = initPramas(arguments[0]); obj.method = "GET"; uni.request(obj); }, post: function() { let obj = initPramas(arguments[0]); obj.method = "POST"; obj.header["Content-type"] = "application/x-www-form-urlencoded" console.log(obj); uni.request(obj); } }