main.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // 定义全局方法
  7. const navBack = (delta = 1) => {
  8. uni.navigateBack({
  9. delta,
  10. });
  11. }
  12. let lastNavTime = 0;
  13. const navTo = (url, type = '') => {
  14. const now = Date.now();
  15. if (now - lastNavTime < 300) return; // 0.3秒内重复点击不跳转
  16. lastNavTime = now;
  17. const pageStackLen = getCurrentPages().length;
  18. if (type === 'tabbar') {
  19. uni.switchTab({ url });
  20. } else if (type === 'redirect') {
  21. uni.redirectTo({ url });
  22. } else {
  23. console.log('页面调用栈', getCurrentPages().length)
  24. if (pageStackLen >= 9) {
  25. uni.reLaunch({ url });
  26. } else {
  27. uni.navigateTo({ url });
  28. }
  29. }
  30. };
  31. const showThoast = (title,icon,duration = 1500) =>{
  32. uni.showToast({
  33. title,
  34. icon:icon?icon:'none',
  35. duration
  36. })
  37. }
  38. // #ifndef VUE3
  39. import Vue from 'vue'
  40. import './uni.promisify.adaptor'
  41. Vue.config.productionTip = false
  42. App.mpType = 'app'
  43. Vue.use(uView)
  44. Vue.prototype.$navTo = navTo
  45. Vue.prototype.$navBack = navBack
  46. Vue.prototype.$showThoast = showThoast
  47. const app = new Vue({
  48. ...App
  49. })
  50. app.$mount()
  51. // #endif
  52. // #ifdef VUE3
  53. import { createSSRApp } from 'vue'
  54. export function createApp() {
  55. const app = createSSRApp(App)
  56. app.config.globalProperties.navBack = navBack
  57. app.config.globalProperties.navTo = navTo
  58. app.config.globalProperties.showThoast = showThoast
  59. return {
  60. app
  61. }
  62. }
  63. // #endif