main.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import App from './App'
  2. import uView from '@/uni_modules/uview-ui'
  3. import '@/static/css/fui.css'
  4. import '@/static/css/flex.css'
  5. import '@/static/css/uflex.css'
  6. // #ifndef VUE3
  7. import Vue from 'vue'
  8. import './uni.promisify.adaptor'
  9. Vue.config.productionTip = false
  10. App.mpType = 'app'
  11. Vue.use(uView)
  12. const app = new Vue({
  13. ...App
  14. })
  15. app.$mount()
  16. // #endif
  17. // 定义全局方法
  18. const navBack = (delta = 1) => {
  19. uni.navigateBack({
  20. delta,
  21. });
  22. }
  23. let lastNavTime = 0;
  24. const navTo = (url, type = '') => {
  25. const now = Date.now();
  26. if (now - lastNavTime < 300) return; // 0.3秒内重复点击不跳转
  27. lastNavTime = now;
  28. const pageStackLen = getCurrentPages().length;
  29. if (type === 'tabbar') {
  30. uni.switchTab({ url });
  31. } else if (type === 'redirect') {
  32. uni.redirectTo({ url });
  33. } else {
  34. console.log('页面调用栈', getCurrentPages().length)
  35. if (pageStackLen >= 9) {
  36. uni.reLaunch({ url });
  37. } else {
  38. uni.navigateTo({ url });
  39. }
  40. }
  41. };
  42. // #ifdef VUE3
  43. import { createSSRApp } from 'vue'
  44. export function createApp() {
  45. const app = createSSRApp(App)
  46. app.config.globalProperties.navBack = navBack
  47. app.config.globalProperties.navTo = navTo
  48. return {
  49. app
  50. }
  51. }
  52. // #endif