const install = (Vue, vm) => {
	Vue.prototype.$u.http.setConfig({
			// baseUrl: 'http://192.168.2.100:3202',
			baseUrl: 'https://fen.ccttiot.com/prod-api',
			loadingText: '努力加载中~',
			loadingTime: 800,
			// 设置自定义头部content-type
			header: {
				'content-type': 'application/json;charset=UTF-8',
			}, 
		})

// 请求拦截部分,如配置,每次请求前都会执行
	Vue.prototype.$u.http.interceptor.request = (config) => {
		const token = uni.getStorageSync('token')
		config.header.Authorization = token 
		// #ifdef H5
			config.header.Authorization = 'Bearer '+token
		// #endif
		if(config.url == '/user/login') config.header.noToken = true
		// 最后需要将config进行return
		return config
	}
	
	// 响应拦截,如配置,每次请求结束都会执行本方法
		Vue.prototype.$u.http.interceptor.response = (res) => {
			if(res.code == 401) {
				uni.login({
					success: function(ret) {
						console.log("main.js==>res", ret)
					}
				})
				wx.login({
				    success(res) {
				        if (res.code) {
				            console.log('登录!', res);
				            let data = {
				                loginCode: res.code,
				                deptId: 100
				            };
							vm.$u.post('/app/auth/wxLogin',data).then(res=>{
								uni.setStorageSync('code', res.code);
				        		if (res.code == 10003) {
				        			// uni.navigateTo({
				        			// 	url:'/pages/login/login'
				        			// })
				        		} else if (res.code == 200) {
									uni.setStorageSync('token', res.token);
				        			// console.log("老用户登录",res.data)
				        			// uni.switchTab({
				        			// 	url:'/pages/index/index'
				        			// })
				        		}
				        	})
				        }
				    },
				})
			}
			return res
		}
}
export default {
	install
}