main.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 {
  8. listenerMessage,
  9. postMessage,
  10. promisefiyPostMessage
  11. } from '@/helpers/native-message'
  12. import 'normalize.css'
  13. import '../styles/index.less'
  14. import { state } from '@/state'
  15. import { browser, setAuth } from '@/helpers/utils'
  16. const app = createApp(App)
  17. // import Vconsole from 'vconsole'
  18. // const vconsole = new Vconsole()
  19. // 设置是否显示导航栏 0 显示 1 不显示
  20. postMessage({ api: 'setBarStatus', content: { status: 0 } })
  21. postMessage({
  22. api: 'backIconChange',
  23. content: { backIconHide: true }
  24. })
  25. postMessage(
  26. {
  27. api: 'getVersion'
  28. },
  29. (res: any) => {
  30. state.version = res.content.version
  31. }
  32. )
  33. // 判断是否是管乐团学生端,用来获取基础数据
  34. if (browser().isOrchestraStudent) {
  35. // await promisefiyPostMessage({
  36. // api: 'setCache',
  37. // content: {
  38. // key: 'h5-colexiu-token',
  39. // value: ''
  40. // }
  41. // })
  42. // 获取管乐团token
  43. promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
  44. const content = res.content
  45. state.orchestraInfo.token = content.token.split(' ')[1]
  46. state.orchestraInfo.phone = content.phone
  47. state.orchestraInfo.nickname = content.nickname
  48. state.orchestraInfo.avatar = content.avatar
  49. state.orchestraInfo.unionId = content.unionId || 0
  50. })
  51. // 从缓存里面获取token
  52. promisefiyPostMessage({
  53. api: 'getCache',
  54. content: { key: 'h5-colexiu-token' }
  55. }).then((res: any) => {
  56. const content = res.content
  57. if (content.value) {
  58. setAuth(content.value)
  59. }
  60. })
  61. }
  62. if (browser().isTeacher) {
  63. state.platformType = 'TEACHER'
  64. } else if (browser().isStudent) {
  65. state.platformType = 'STUDENT'
  66. } else {
  67. state.platformType = 'STUDENT'
  68. }
  69. if (state.platformType === 'TEACHER') {
  70. state.platformApi = '/api-teacher'
  71. } else {
  72. state.platformApi = '/api-student'
  73. }
  74. dayjs.locale('zh-ch')
  75. app.config.globalProperties.$dayjs = dayjs
  76. app.config.globalProperties.$filters = vueFilter
  77. app.use(router)
  78. app.mount('#app')