main.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { createApp } from 'vue';
  2. import App from './App';
  3. import dayjs from 'dayjs';
  4. import 'dayjs/locale/zh-cn';
  5. import { setupStore } from '@/stores';
  6. import 'vant/lib/index.css';
  7. import './component-ui/index.less';
  8. import './styles/index.less';
  9. import router from '@/router';
  10. import { promisefiyPostMessage, postMessage } from './helpers/native-message';
  11. import { setAuth } from './helpers/utils';
  12. import { state } from './state';
  13. import ResizeObserver from 'resize-observer-polyfill'
  14. // 增加判断如果不支持当前依赖再设置即可
  15. if (window.ResizeObserver === undefined) {
  16. window.ResizeObserver = ResizeObserver;
  17. }
  18. // 获取token
  19. promisefiyPostMessage({ api: 'getToken' }).then((res: any) => {
  20. const content = res.content;
  21. if (content?.accessToken) {
  22. setAuth(content.tokenType + ' ' + content.accessToken);
  23. }
  24. });
  25. // 设置是否显示导航栏 0 不显示 1 显示
  26. postMessage({ api: 'setBarStatus', content: { status: 0 } });
  27. // 导航栏高度
  28. postMessage({ api: 'getNavHeight' }, (res: any) => {
  29. const { content } = res;
  30. const dpi = content.dpi || 2;
  31. if (content.navHeight) {
  32. const navHeight = content.navHeight / dpi;
  33. console.log(navHeight, 'navHeight');
  34. state.navBarHeight = navHeight;
  35. }
  36. });
  37. const url = window.location.href;
  38. const urlIsTeacher =
  39. /mteaonline.dayaedu.com/.test(url) || /mteatest.dayaedu.com/.test(url) || /gym.lexiaoya.cn\/lessonPlayTeacher/.test(url) || /test.gym.lexiaoya.cn\/lessonPlayTeacher/.test(url)
  40. ? true
  41. : false;
  42. // const paymentType = (window as any).paymentType; // 浏览器设置
  43. // 判断是哪个环境
  44. if (urlIsTeacher) {
  45. state.platformType = 'TEACHER';
  46. state.platformApi = '/api-teacher';
  47. } else {
  48. state.platformType = 'STUDENT';
  49. state.platformApi = '/api-student';
  50. }
  51. const app = createApp(App);
  52. dayjs.locale('zh-ch');
  53. setupStore(app);
  54. app.use(router);
  55. app.mount('#app');