| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 | const server = 'http://127.0.0.1:8080';// const server = 'http://192.168.88.34:8080';import common from '../common/js/common.js';function get(url, data) {	return uni.request({		method: 'get',		url: server + url,		data: data || {},		header: {			'Content-type': 'application/x-www-form-urlencoded',			'satoken': uni.getStorageSync('token')		}	}).then(data => {		common.hidingLoading();		var [err, res] = data		if (err) {			return err		} else {			let resp=res.data;			if(resp.code==401){				uni.removeStorageSync('token');				common.to('/pages/login/login');				return ;			}			return res.data		}	})}function postForm(url, data) {	common.showLoading('正在提交...')	return uni.request({		method: 'post',		url: server + url,		data: data || {},		dataType: 'json',		header: {			'Content-type': 'application/x-www-form-urlencoded',			'satoken': uni.getStorageSync('token')		}	}).then(data => {		console.log(url)		common.hidingLoading();		var [err, res] = data		if (err) {			return err		} else {			let reData = res.data;			if (reData.code !== 200) {				uni.showToast({					"icon": 'none',					"title": reData.msg,					"mask": false,					"duration": 3000,					"position": 'bottom'				})				return res.data;			}			return res.data		}	})}function postJson(url, data) {	common.showLoading('正在提交...')	return uni.request({		method: 'post',		url: server + url,		data: JSON.stringify(data),		dataType: 'json',		header: {			'Content-type': 'application/json; charset=utf-8',			'satoken': uni.getStorageSync('token')		}	}).then(data => {		common.hidingLoading();		var [err, res] = data		if (err) {			return err		} else {			let reData = res.data;			if (reData.code !== 200) {				uni.showToast({					"icon": 'none',					"title": reData.msg,					"mask": false,					"duration": 3000,					"position": 'bottom'				})				return res.data;			}			return res.data		}	})}function postJsonNotLoading(url, data) {	return uni.request({		method: 'post',		url: server + url,		data: JSON.stringify(data),		dataType: 'json',		header: {			'Content-type': 'application/json; charset=utf-8',			'satoken': uni.getStorageSync('token')		}	}).then(data => {		common.hidingLoading();		var [err, res] = data		if (err) {			return err		} else {			let reData = res.data;			if (reData.code !== 200) {				uni.showToast({					"icon": 'none',					"title": reData.msg,					"mask": false,					"duration": 3000,					"position": 'bottom'				})				return res.data;			}			return res.data		}	})}function deleteFn(url, data) {	common.showLoading('正在删除...')	return uni.request({		method: 'delete',		url: server + url,		data: data || {},		dataType: 'json',		header: {			'Content-type': 'application/x-www-form-urlencoded',			'satoken': uni.getStorageSync('token')		}	}).then(data => {		common.hidingLoading();		var [err, res] = data		if (err) {			return err		} else {			return res.data		}	})}function put(url, data) {	common.showLoading('正在提交...')	return uni.request({		method: 'put',		url: server + url,		data: JSON.stringify(data),		dataType: 'json',		header: {			'Content-type': 'application/json; charset=utf-8',			'satoken': uni.getStorageSync('token')		}	}).then(data => {		common.hidingLoading();		var [err, res] = data		if (err) {			return err		} else {			return res.data		}	})}export default {	get,	deleteFn,	put,	postForm,	postJson,	postJsonNotLoading,	server}
 |