main.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { createApp } from 'vue';
  2. import App from './App';
  3. import router from './router/index';
  4. import dayjs from 'dayjs';
  5. import 'dayjs/locale/zh-cn';
  6. import 'vant/lib/index.css';
  7. import './component-ui/index.less';
  8. import './styles/index.less';
  9. import { promisefiyPostMessage, postMessage } from './helpers/native-message';
  10. import { state } from './state';
  11. import { storage } from '@/helpers/storage';
  12. import { ACCESS_TOKEN } from '@/store/mutation-types';
  13. import { setupStore } from './store';
  14. import { Lazyload, setToastDefaultOptions } from 'vant';
  15. import useErrorLog from './hooks/useErrorLog';
  16. setToastDefaultOptions({ duration: 3000 });
  17. // 获取token
  18. promisefiyPostMessage({ api: 'getToken' }).then((res: any) => {
  19. const content = res.content;
  20. if (content?.accessToken) {
  21. storage.set(ACCESS_TOKEN, content.tokenType + ' ' + content.accessToken);
  22. }
  23. });
  24. // 导航栏高度
  25. postMessage({ api: 'getNavHeight' }, (res: any) => {
  26. const { content } = res as any;
  27. const dpi = content.dpi || 2;
  28. if (content.navHeight) {
  29. const navHeight = content.navHeight / dpi;
  30. console.log(navHeight, 'navHeight');
  31. state.navBarHeight = navHeight;
  32. }
  33. });
  34. // import Vconsole from 'vconsole';
  35. // const vconsole = new Vconsole();
  36. const app = createApp(App);
  37. app.use(Lazyload);
  38. // store plugin: pinia
  39. setupStore(app);
  40. dayjs.locale('zh-ch');
  41. app.use(router);
  42. // 监听错误信息
  43. const errorLog = useErrorLog();
  44. errorLog.startListenErrorLog();
  45. app.mount('#app');