import App from './App'
import uView from '@/uni_modules/uview-ui'

import '@/static/css/fui.css'
import '@/static/css/flex.css'
import '@/static/css/uflex.css'

// 定义全局方法
const navBack = (delta = 1) => {
  uni.navigateBack({
    delta,
  });
}

let lastNavTime = 0;
const navTo = (url, type = '') => {
  const now = Date.now();
  if (now - lastNavTime < 300) return; // 0.3秒内重复点击不跳转
  lastNavTime = now;

  const pageStackLen = getCurrentPages().length;

  if (type === 'tabbar') {
    uni.switchTab({ url });
  } else if (type === 'redirect') {
    uni.redirectTo({ url });
  } else {
    console.log('页面调用栈', getCurrentPages().length)
    if (pageStackLen >= 9) {
      uni.reLaunch({ url });
    } else {
      uni.navigateTo({ url });
    }
  }
};

const showThoast = (title,icon,duration = 1500) =>{
	uni.showToast({
		title,
		icon:icon?icon:'none',
		duration
	})
}

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
Vue.use(uView)
Vue.prototype.$navTo = navTo
Vue.prototype.$navBack = navBack
Vue.prototype.$showThoast = showThoast

const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  app.config.globalProperties.navBack = navBack
  app.config.globalProperties.navTo = navTo
  app.config.globalProperties.showThoast = showThoast
  return {
    app
  }
}
// #endif

