<script>
	export default {
		globalData: {
		   url: 'https://h5.bike.woqichuxing.cn/api',//域名
		 },
		
		onLaunch: function() {
			console.log('App Launch')
			let token = uni.getStorageSync('token')
			    if (!token) {
			      uni.reLaunch({
			        url: '/pages/login',
			      })
			    }
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			request(api, params, method) {
			    var that = this;
			    return new Promise((resolve, reject) => {
			      uni.request({
			        url: that.globalData.url + api,
			        data: params,
			        header: {
			          'content-type': 'application/json',
			          'Accept': 'application/json',
			          'Cache-Control': 'no-cache',
			          'Authorization': uni.getStorageSync('token'),
			        },
			        method: method,
			        success: (res) => {
			          resolve(res)
			          if (res.statusCode !== 200) {
			            if (res.statusCode == 401) {
			              uni.showToast({
			                title: '登录过期,请重新登录',
			                icon:'none'
			              })
						 uni.reLaunch({
						   url: '/pages/login',
						 })
			            } else {
			              uni.showModal({
			                title: '提示',
			                content: res.data.message,
			                showCancel: false
			              })
			              return
			            }
			
			          }
			        },
			        fail: (err) => {
			          reject(err, '请求失败')
			        },
			        complete: () => {
			          that.globalData.req = true
			        }
			      })
			    })
			  }
		}
	}
</script>

<style>
	/*每个页面公共css */
	page{
		background-color: #efefef;
	}

</style>
