import App from './App'
import config from '@/config'
const baseUrl = config.baseUrl
Vue.prototype.$baseUrl = baseUrl;
const baseImageUrl = config.baseImageUrl
Vue.prototype.$baseImageUrl = baseImageUrl
const wsUrl = config.wsUrl
Vue.prototype.$wsUrl = wsUrl;

// main.js，注意要在use方法之后执行
import uView from "uview-ui";
Vue.use(uView);
// orderSocket
import {
	connect,
	sendSocketMessage,
	closeSocket
} from './utils/orderSocket.js'
let SocketTask;
let timerId;
export function startSocketConnect(driverId) {
	SocketTask = null
	SocketTask = connect(driverId);
	if (!timerId && uni.getStorageSync('driverInfo')) {
		timerId = setInterval(() => {
			sendSocketMessage(SocketTask)
		}, 10000);
	}

}

export function closeSocketMain(driverId) {
	clearInterval(timerId);
	closeSocket(SocketTask);
}
Vue.prototype.$startSocketConnect = startSocketConnect
Vue.prototype.$closeSocketMain = closeSocketMain
// tabBarSocket
import {
	tabBarconnect,
	closeMsgSocket,
	sendMsg
} from './utils/tebBarSocket.js'
let msgTimer;
let msgSocket;
export function startMsgSocket(userId) {
	msgSocket = null
	msgSocket = tabBarconnect(userId);
	if (!msgTimer && uni.getStorageSync('driverInfo')) {
		msgTimer = setInterval(() => {
			sendMsg(msgSocket)
		}, 10000);
	}
	Vue.prototype.$msgSocket = msgSocket


}

Vue.prototype.$startMsgSocket = startMsgSocket; //userid
export function tabBarcloseSocket() {

	closeMsgSocket;
}
export function getclearInterval() {
	console.log('执行关闭请求');
	clearInterval(timerId);
	clearInterval(msgTimer);
	timerId = undefined;
	msgTimer = undefined;

}
Vue.prototype.$getclearInterval = getclearInterval;
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
import {
	request
} from "@/utils/request.js"
Vue.prototype.$request = request
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif
