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.
		
		
		
		
		
			
		
			
				
					
					
						
							61 lines
						
					
					
						
							1.5 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							61 lines
						
					
					
						
							1.5 KiB
						
					
					
				| import Vue from 'vue' | |
| import store from '@/store' | |
| 
 | |
| let NEWAPIURL = process.env.NODE_ENV == 'development' ? 'https://guide.sz-trip.com/' : 'https://guide.sz-trip.com/' | |
| Vue.prototype.NEWAPIURL = NEWAPIURL | |
| // #ifdef H5 | |
|  NEWAPIURL = '/api' | |
| // #endif | |
|  | |
| Vue.prototype.Post = (params, apiurl) => { | |
|     if (uni.getStorageSync('userInfo') && JSON.parse(uni.getStorageSync('userInfo')).token) params.token = JSON.parse(uni.getStorageSync('userInfo')).token | |
| 	else if (store.state.user.userInfo.token) params.token = store.state.user.userInfo.token | |
| 	// params.token = '84bf42c7-e4b9-48b7-976e-2dddcc596d39' | |
| 	return new Promise((resolve, reject) => { | |
| 		uni.showLoading({ | |
| 			title: '加载中' | |
| 		}) | |
| 		uni.request({ | |
| 			method: params.method || 'GET', | |
| 			url: NEWAPIURL + apiurl, | |
| 			data: params || {}, | |
| 			header: params.header || { | |
| 				'content-type': 'application/json', | |
| 				'token': params.token || '' | |
| 			}, | |
| 			success: res => { | |
| 				uni.hideLoading() | |
| 				if (res.data.code === 200 || res.data.code === 1) { | |
| 					resolve(res.data) | |
| 				} else { | |
| 					setTimeout(() => { | |
| 						uni.showToast({ | |
| 							title: res.data.msg, | |
| 							icon: 'none' | |
| 						}) | |
| 						reject(res.data) | |
| 					}, 0) | |
| 					if (res.data.code === 401) { | |
| 						store.commit('changeLoginPath') | |
| 					} | |
| 				} | |
| 			}, | |
| 			fail: err => { | |
| 				console.log('err', err) | |
| 				uni.hideLoading() | |
| 				setTimeout(() => { | |
| 					uni.showToast({ | |
| 						title: err.msg || err.data.msg, | |
| 						icon: 'none' | |
| 					}) | |
| 				}, 0) | |
| 				if (err.data.code === 401) { | |
| 					store.commit('changeLoginPath') | |
| 				} | |
| 				reject(err) | |
| 			} | |
| 		}) | |
| 	}) | |
| } | |
| 
 | |
| export default NEWAPIURL
 | |
| 
 |