main.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 { browser, setAuth } from './helpers/utils';
  12. import { state } from './state';
  13. // 获取token
  14. promisefiyPostMessage({ api: 'getToken' }).then((res: any) => {
  15. const content = res.content;
  16. if (content?.accessToken) {
  17. setAuth(content.tokenType + ' ' + content.accessToken);
  18. }
  19. });
  20. // 设置是否显示导航栏 0 不显示 1 显示
  21. postMessage({ api: 'setBarStatus', content: { status: 0 } });
  22. // 导航栏高度
  23. postMessage({ api: 'getNavHeight' }, (res: any) => {
  24. const { content } = res;
  25. const dpi = content.dpi || 2;
  26. if (content.navHeight) {
  27. const navHeight = content.navHeight / dpi;
  28. console.log(navHeight, 'navHeight');
  29. state.navBarHeight = navHeight;
  30. }
  31. });
  32. const url = window.location.href;
  33. const urlIsTeacher =
  34. /mteaonline.dayaedu.com/.test(url) || /mteatest.dayaedu.com/.test(url) || /gym.lexiaoya.cn\/lessonPlayTeacher/.test(url) || /test.gym.lexiaoya.cn\/lessonPlayTeacher/.test(url)
  35. ? true
  36. : false;
  37. // const paymentType = (window as any).paymentType; // 浏览器设置
  38. // 判断是哪个环境
  39. if (urlIsTeacher || browser().isTeacher) {
  40. state.platformType = 'TEACHER';
  41. state.platformApi = '/api-teacher';
  42. } else {
  43. state.platformType = 'STUDENT';
  44. state.platformApi = '/api-student';
  45. }
  46. const app = createApp(App);
  47. dayjs.locale('zh-ch');
  48. setupStore(app);
  49. app.use(router);
  50. app.mount('#app');