import App from './App'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'

try {
	function isPromise(obj) {
		return (
			!!obj &&
			(typeof obj === "object" || typeof obj === "function") &&
			typeof obj.then === "function"
		);
	}

	// 统一 vue2 API Promise 化返回格式与 vue3 保持一致
	uni.addInterceptor({
		returnValue(res) {
			if (!isPromise(res)) {
				return res;
			}
			return new Promise((resolve, reject) => {
				res.then((res) => {
					if (res[0]) {
						reject(res[0]);
					} else {
						resolve(res[1]);
					}
				});
			});
		},
	});
} catch (error) {}

//import Permission from './directive/permission.js'
//Vue.use(Permission)

import system from '@/utils/system.js'
Vue.mixin(system);

import CusHeader from '@/components/CusHeader'
Vue.component('CusHeader',CusHeader);

//日期格式处理
import dateFormat from '@/utils/dateFormat.js'
Vue.use(dateFormat);

import btnPermission from './directive/permission.js';
import api from '@/http/index.js'
Vue.prototype.$has = btnPermission;
Vue.prototype.$api = api;
Vue.prototype.$imgBase = "http://106.54.209.120:8666/image/";

//重载uni.showToast，简化调用
Vue.prototype.$showToast = function(title, duration = 2000, icon = "none") {
	return uni.showToast({
		title,
		duration,
		icon
	})
}
//重载uni.showModal，简化调用
Vue.prototype.$showModal = function(content) {
	return uni.showModal({
		title:'温馨提示',
		content,
		showCancel:false,
		confirmText: '确定',
		confirmColor: '#007A69'
	})
}

// 引入全局uView
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)
uni.$u.config.unit = 'rpx'
const app = new Vue({
	...App
})

app.$mount()
// #endif

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