import Vue from 'vue'
import App from './App'
import store from './store'
import WpTabbar from '@/pages/tabbar/wpTabbar'
// 引入全局uView
import uView from '@/uni_modules/uview-ui'
import mixin from './common/mixin'
import postSelect from 'pageApp/components/postSelect.vue'
import deptSelect from 'pageApp/components/deptSelect.vue'
import dictSelect from 'pageApp/components/dictSelect.vue'
import input from 'pageApp/components/input.vue'
import show from 'pageApp/components/show.vue'
import flowSubmit from 'pageApp/components/flowSubmit.vue'
import photo from 'pageApp/components/photo.vue'
import wsRequest from 'util/webSocket/wsRequest.js'

import {
	httpRequest,
	BASE_URL,
	BASE_SOCKET_URL,
	goto,
	goTab,
	goBack,
	dateResult,
	showModal,
	getDicts,
	dictTranslation,
	getUrlType,
	getConfigData,
	getAllConfigData,
	getAllDicts
} from './util/request/api.js'
Vue.component('wp-tabbar', WpTabbar);
Vue.prototype.$httpRequest = httpRequest
Vue.prototype.$BASE_URL = BASE_URL
Vue.prototype.$BASE_SOCKET_URL = BASE_SOCKET_URL
Vue.prototype.$goto = goto
Vue.prototype.$goTab = goTab
Vue.prototype.$goBack = goBack
Vue.prototype.$dateResult = dateResult
Vue.prototype.$showModal = showModal
Vue.prototype.$getDicts = getDicts
Vue.prototype.$getUrlType = getUrlType
Vue.prototype.$dictTranslation = dictTranslation
Vue.prototype.$getConfigData = getConfigData
Vue.prototype.$getAllConfigData = getAllConfigData
Vue.prototype.$getAllDicts = getAllDicts
Vue.prototype.$wsConnection = new wsRequest(8000)

// 入口文件 main.js
Vue.prototype.$getRect = function(selector, all) {
	return new Promise(resolve => {
		uni.createSelectorQuery().
		in(this)[all ? 'selectAll' : 'select'](selector)
			.boundingClientRect(rect => {
				if (all && Array.isArray(rect) && rect.length) {
					resolve(rect)
				}
				if (!all && rect) {
					resolve(rect)
				}
			})
			.exec()
	})
}

Vue.prototype.$store = store

Vue.component('hs-post-select', postSelect)
Vue.component('hs-dept-select', deptSelect)
Vue.component('hs-dict-select', dictSelect)
Vue.component('hs-input', input)
Vue.component('hs-show', show)
Vue.component('hs-flow-submit', flowSubmit)
Vue.component('hs-photo', photo)

Vue.config.productionTip = false

App.mpType = 'app'
Vue.use(uView)

// #ifdef MP
// 引入uView对小程序分享的mixin封装
const mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js')
Vue.mixin(mpShare)
// #endif
Vue.mixin(mixin)

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

// 引入请求封装
require('./util/request/index')(app)

app.$mount()
