main.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { createApp } from 'vue';
  2. import App from './App';
  3. import router, { parseQuery, setupRouter } from './router/index';
  4. import dayjs from 'dayjs';
  5. import { setupNaive } from './plugins';
  6. import { setupStore } from './store';
  7. import 'dayjs/locale/zh-cn';
  8. import './styles/index.less';
  9. import './utils/rem';
  10. import { storage } from './utils/storage';
  11. import { ACCESS_TOKEN_ADMIN } from './store/mutation-types';
  12. async function setupApp() {
  13. // 处理token
  14. const authLoadNum = sessionStorage.getItem('authLoadNum');
  15. if (location.search && authLoadNum !== '1') {
  16. const parse = location.search.substring(1, location.search.length);
  17. const result = parseQuery(parse);
  18. if (result.Authorization) {
  19. const ex = 7 * 24 * 60 * 60 * 1000;
  20. storage.set(ACCESS_TOKEN_ADMIN, result.Authorization, ex);
  21. sessionStorage.setItem('authLoadNum', '1');
  22. sessionStorage.setItem('authSource', result.source?.toString() || '');
  23. }
  24. console.log(result, 'result');
  25. } else {
  26. sessionStorage.removeItem('authLoadNum');
  27. storage.remove(ACCESS_TOKEN_ADMIN);
  28. }
  29. // app loading
  30. // const appLoading = createApp(AppLoading);
  31. // appLoading.mount('#appLoading');
  32. const app = createApp(App);
  33. setupNaive(app);
  34. // store plugin: pinia
  35. setupStore(app);
  36. setupRouter(app);
  37. dayjs.locale('zh-ch');
  38. // app.use(router);
  39. await router.isReady();
  40. // mount app
  41. app.mount('#app');
  42. if ('serviceWorker' in navigator) {
  43. navigator.serviceWorker.ready.then(registration => {
  44. registration.unregister();
  45. });
  46. }
  47. }
  48. setupApp();