import Vue from 'vue'
import App from './App'
import Mixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js'
import common from '@/common/common.js'
import {
	gotopage
} from '@/common/gotopage.js'
import router from '@/common/router.js'
import ConfigManager from '@/common/config.js'
import RequestManager from '@/common/request.js'
import EnvConfig from '@/common/env.js'
import {
	platform
} from '@/common/platform/PlatformFactory'

// 全局注册uni-popup组件
import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
Vue.component('uni-popup', uniPopup)

// 全局变量配置
Vue.prototype.siteBaseUrl = EnvConfig.apiBaseUrl
Vue.prototype.$baseUrl = EnvConfig.baseUrl
Vue.prototype.$imageBaseUrl = EnvConfig.imageUrl;
Vue.prototype.$z_img2 = EnvConfig.imageUrl + '/zcq/'
Vue.prototype.$img = url => EnvConfig.imageBaseUrl + url
Vue.prototype.$img1 = url => EnvConfig.iconBaseUrl + url
Vue.prototype.$sys = () => uni.getSystemInfoSync()
Vue.prototype.$loginPage = EnvConfig.loginPage
Vue.prototype.$wxloginPage = EnvConfig.wxLoginUrl
Vue.prototype.$platform = platform;
// 公共方法
Vue.prototype.gotoPage = gotopage
// 注册路由方法到Vue实例，改用自定义属性名
Vue.prototype.$customRouter = router
Vue.prototype.$navigateTo = router.navigateTo
Vue.prototype.$noMultipleClicks = common.noMultipleClicks
Vue.prototype.$c = common
// 全局配置管理器
Vue.prototype.$config = ConfigManager
// 全局请求方法
Vue.prototype.req = RequestManager.request
Vue.prototype.$request = RequestManager

// #ifdef H5
function loadScript(url) {
	var script = document.createElement('script')
	script.type = 'text/javascript'
	script.src = url
	document.head.appendChild(script)
}

loadScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js')
// #endif


Vue.config.productionTip = false
Vue.mixin(Mixin)
App.mpType = 'app'

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

// 创建全局数据对象
app.globalData = {
	siteBaseUrl: EnvConfig.apiBaseUrl
}

// // 应用启动时加载全局配置
// ConfigManager.init().then(config => {
// 	console.log('全局配置加载完成')
// }).catch(err => {
// 	console.error('全局配置加载失败', err)
// })

app.$mount()