import Vue from 'vue'
import App from './App'
import store from "./store/index.js"
import check from './check/index.js'
import TIM from 'tim-js-sdk'
import tim from './commen/tim/tim.js'
import commen from './commen/commen.js'
// 引入全局uView
import uView from 'uview-ui';
Vue.use(uView);

Vue.config.productionTip = false

Vue.prototype.check=check;
Vue.prototype.apiUrl="http://app.zhaodizhu.cn/api"
// Vue.prototype.apiUrl="http://landlord.t.brotop.cn/api"
Vue.prototype.imgUrl="http://qiniu.zhaodizhu.cn"
Vue.prototype.tim = tim.tim  			//tim sdk 引入后生成的tim服务
Vue.prototype.$TIM = TIM				//tim 的状态/事件 常量
Vue.prototype.$commen = commen
Vue.prototype.$request=function(url,data='',type = 1){
	// var that=this
	return new Promise((reslove,reject)=>{
		if(type == 1){
			uni.showLoading({
				title:'加载中...'
			})
		}
		if(type == 3){
			uni.showLoading({
				title:'发布中'
			})
		}
		if(type == 2){
			uni.showLoading({
				title:'保存中...'
			})
		}
		uni.request({
			url:this.apiUrl+url,
			method:"POST",
			header: {
				'token': uni.getStorageSync('token')
			},
			data:data,
			success:(res)=>{
				// console.log('接口返回数据',res);
				if(res.data.code == 401){
					uni.setStorageSync("token",'')
					uni.reLaunch({
						url:"/pages/index/login"
					})
				}
				if(res.data.code == 0 || res.data.code==1){
					reslove(res.data)
				}
				uni.hideLoading()
			},
			fail: (err) => {
				console.log('请求失败',err)
			}
		})
	})
}
Vue.prototype.$href=function(data,type=1){
	if(uni.getStorageSync("token")){
		if(type==1){
			uni.navigateTo({
				url:data
			})
		}
		if(type==2){
			uni.switchTab({
				url:data
			})
		}
		if(type==3){
			uni.redirectTo({
				url:data
			})
		}
	}else{
		uni.reLaunch({
			url:"/pages/index/login?backurl="+data
		})
	}
}
Vue.prototype.$back=function(data,type=1){
	if(uni.getStorageSync("token")){
		if(type==1){
			uni.navigateTo({
				url:data
			})
		}else{
			uni.switchTab({
				url:data
			})
		}
			

	}else{
		uni.reLaunch({
			url:"/pages/login/login?backurl=1"
		})
	}
}
App.mpType = 'app'

const app = new Vue({
	store,
    ...App
})
app.$mount()