import App from './App'
import uviewPlus from '@/uni_modules/uview-plus'
import store from './store/index.js'
import {
	initRequest
} from '@/config/request/index'
import messages from './locale/index'
import {
	route
} from '@/uni_modules/uview-plus'

let i18nConfig = {
	locale: uni.getLocale(),
	messages
}

// #ifndef VUE3
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)

// 全局混入 route 方法
Vue.mixin({
	methods: {
		route(path) {
			route(path)
		}
	}
})

const vue2I18n = new VueI18n(i18nConfig)
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	i18n: vue2I18n,
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import {
	createI18n
} from 'vue-i18n'

const vue3I18n = createI18n(i18nConfig)
export function createApp() {
	const app = createSSRApp(App)
	app.use(vue3I18n)
	app.use(uviewPlus)
	app.use(store)
	initRequest(app)

	// 添加全局方法
	app.config.globalProperties.$route = route

	// 添加全局混入
	app.mixin({
		methods: {
			$route(path) {
				route(path)
			}
		}
	})

	return {
		app
	}
}
// #endif