main.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { createApp } from 'vue'
  2. import App from './App.vue'
  3. import dayjs from 'dayjs'
  4. import 'dayjs/locale/zh-cn'
  5. import router from '../router/index-student'
  6. import vueFilter from '@/helpers/vueFilter'
  7. import { listenerMessage, postMessage, promisefiyPostMessage } from '@/helpers/native-message'
  8. import 'normalize.css'
  9. import '../styles/index.less'
  10. import { state } from '@/state'
  11. import { browser, setAuth } from '@/helpers/utils'
  12. const app = createApp(App)
  13. // import Vconsole from 'vconsole'
  14. // const vconsole = new Vconsole()
  15. postMessage(
  16. {
  17. api: 'getVersion'
  18. },
  19. (res: any) => {
  20. state.version = res.content.version
  21. }
  22. )
  23. // 判断是否是管乐团学生端,用来获取基础数据
  24. if (browser().isOrchestraStudent) {
  25. // await promisefiyPostMessage({
  26. // api: 'setCache',
  27. // content: {
  28. // key: 'h5-colexiu-token',
  29. // value: ''
  30. // }
  31. // })
  32. // 获取管乐团token
  33. promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
  34. const content = res.content
  35. state.orchestraInfo.token = content.token
  36. state.orchestraInfo.phone = content.phone
  37. state.orchestraInfo.nickname = content.nickname
  38. state.orchestraInfo.avatar = content.avatar
  39. state.orchestraInfo.unionId = content.unionId || 0
  40. })
  41. // 从缓存里面获取token
  42. promisefiyPostMessage({ api: 'getCache', content: { key: 'h5-colexiu-token' } }).then((res: any) => {
  43. const content = res.content
  44. if (content.value) {
  45. setAuth(content.value)
  46. }
  47. })
  48. }
  49. if (browser().isTeacher) {
  50. state.platformType = 'TEACHER'
  51. } else if (browser().isStudent) {
  52. state.platformType = 'STUDENT'
  53. } else {
  54. state.platformType = 'STUDENT'
  55. }
  56. if (state.platformType === 'TEACHER') {
  57. state.platformApi = '/api-teacher'
  58. } else {
  59. state.platformApi = '/api-student'
  60. }
  61. dayjs.locale('zh-ch')
  62. app.config.globalProperties.$dayjs = dayjs
  63. app.config.globalProperties.$filters = vueFilter
  64. app.use(router)
  65. app.mount('#app')