| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- const devBaseUrl = "http://192.168.1.24:51106";
- const proBaseUrl = "http://192.168.1.24:51106";
- // const devBaseUrl = "http://61.163.210.204:51106";
- // // const proBaseUrl = "http://61.163.210.204:51106";
- const httpGet = (url, data, checkToken = true) => {
- uni.onNetworkStatusChange(function(res) {
- if (!res.isConnected) {
- uni.showToast({
- title: '网络连接不可用!',
- icon: 'none'
- });
- }
- return false
- });
- let token = uni.getStorageSync('erpToken');
- if (checkToken) {
- if (token == '' || token == undefined || token == null) {
- uni.showToast({
- title: '账号已过期,请重新登录',
- icon: 'none',
- complete: function() {
- uni.reLaunch({
- url: '/pages/login/index'
- });
- }
- });
- }
- }
- let baseUrl = devBaseUrl;
- if (process.env.NODE_ENV === 'production') {
- baseUrl = proBaseUrl
- }
- console.log(baseUrl);
- let httpDefaultOpts = {
- url: baseUrl + url,
- data: data,
- method: 'GET',
- header: {
- 'Access-Token': token,
- 'X-Requested-With': 'XMLHttpRequest',
- "Accept": "application/json",
- "Content-Type": "application/json; charset=UTF-8"
- },
- dataType: 'json',
- }
- let promise = new Promise(function(resolve, reject) {
- uni.request(httpDefaultOpts).then(
- res => {
- resolve(res[1].data);
- }
- ).catch(
- (response) => {
- reject(response)
- }
- )
- })
- return promise
- };
- const httpPost = (url, data, checkToken = true) => {
- uni.onNetworkStatusChange(function(res) {
- if (!res.isConnected) {
- uni.showToast({
- title: '网络连接不可用!',
- icon: 'none'
- });
- }
- return false
- });
- let token = uni.getStorageSync('erpToken');
- if (checkToken) {
- if (token == '' || token == undefined || token == null) {
- uni.showToast({
- title: '账号已过期,请重新登录',
- icon: 'none',
- complete: function() {
- uni.reLaunch({
- url: '/pages/login/login'
- });
- }
- });
- }
- }
- let baseUrl = devBaseUrl;
- if (process.env.NODE_ENV === 'production') {
- baseUrl = proBaseUrl
- }
- let httpDefaultOpts = {
- url: baseUrl + url,
- data: data,
- method: 'POST',
- header: {
- 'Access-Token': token,
- 'X-Requested-With': 'XMLHttpRequest',
- "Accept": "application/json",
- "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
- },
- dataType: 'json',
- }
- let promise = new Promise(function(resolve, reject) {
- uni.request(httpDefaultOpts).then(
- (res) => {
- if (res[1].data.httpCode == 401) {
- uni.reLaunch({
- url: '/pages/login/login'
- });
- }
- resolve(res[1].data);
- }
- ).catch(
- (response) => {
- reject(response)
- }
- )
- })
- return promise
- };
- const httpPostBody = (url, data, checkToken = true) => {
- uni.onNetworkStatusChange(function(res) {
- if (!res.isConnected) {
- uni.showToast({
- title: '网络连接不可用!',
- icon: 'none'
- });
- }
- return false
- });
- let token = uni.getStorageSync('erpToken');
- if (checkToken) {
- if (token == '' || token == undefined || token == null) {
- uni.showToast({
- title: '账号已过期,请重新登录',
- icon: 'none',
- complete: function() {
- uni.reLaunch({
- url: '/pages/login/index'
- });
- }
- });
- return;
- }
- }
- let baseUrl = devBaseUrl;
- if (process.env.NODE_ENV === 'production') {
- baseUrl = proBaseUrl
- }
- let httpDefaultOpts = {
- url: baseUrl + url,
- data: data,
- method: 'POST',
- header: {
- 'Access-Token': token,
- 'X-Requested-With': 'XMLHttpRequest',
- "Accept": "application/json",
- "Content-Type": "application/json; charset=UTF-8"
- },
- dataType: 'json',
- }
- let promise = new Promise(function(resolve, reject) {
- uni.request(httpDefaultOpts).then(
- (res) => {
- resolve(res[1].data);
- }
- ).catch(
- (response) => {
- reject(response)
- }
- )
- })
- return promise
- };
- export default {
- httpGet,
- httpPost,
- httpPostBody
- }
|