main.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { createApp } from 'vue'
  2. import App from './App'
  3. import router from '../router/index'
  4. import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
  5. import 'normalize.css'
  6. import 'vant/lib/index.css'
  7. import '../styles/index.less'
  8. import { state } from '@/state'
  9. import { browser, setAuth } from '@/helpers/utils'
  10. import Vue3Lottie from 'vue3-lottie'
  11. import 'vue3-lottie/dist/style.css'
  12. const app = createApp(App).use(Vue3Lottie)
  13. // 获取token
  14. promisefiyPostMessage({ api: 'getToken' }).then((res: any) => {
  15. console.log(res, 'res')
  16. const content = res.content
  17. if (content?.accessToken) {
  18. setAuth(content.tokenType + ' ' + content.accessToken)
  19. }
  20. })
  21. postMessage(
  22. {
  23. api: 'getVersion'
  24. },
  25. (res: any) => {
  26. state.version = res.content.version
  27. console.log(res, 'version')
  28. }
  29. )
  30. // import Vconsole from 'vconsole'
  31. // const vconsole = new Vconsole()
  32. const paymentType = (window as any).paymentType // 浏览器设置
  33. if (browser().isTeacher || paymentType === 'TEACHER') {
  34. state.platformType = 'TEACHER'
  35. } else if (browser().isStudent || paymentType === 'STUDENT') {
  36. state.platformType = 'STUDENT'
  37. } else if (browser().isSchool || paymentType === 'SCHOOL') {
  38. state.platformType = 'SCHOOL'
  39. } else {
  40. state.platformType = 'SCHOOL'
  41. }
  42. if (state.platformType === 'TEACHER') {
  43. state.platformApi = '/api-teacher'
  44. }
  45. if (state.platformType === 'STUDENT') {
  46. state.platformApi = '/api-student'
  47. } else {
  48. state.platformApi = '/api-school'
  49. }
  50. app.use(router)
  51. app.mount('#app')