main.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 qs from 'query-string'
  16. import { browser, setAuth } from '@/helpers/utils'
  17. import request from '@/helpers/request'
  18. const app = createApp(App)
  19. const getClassroomDefaultInfo = async () => {
  20. state.sourcType = 'kt'
  21. await promisefiyPostMessage({ api: 'getUserAccount' }).then(
  22. async (res: any) => {
  23. const content = res.content
  24. // state.orchestraInfo.token = content.token.split(' ')[1]
  25. // state.orchestraInfo.phone = content.phone
  26. // state.orchestraInfo.nickname = content.nickname
  27. // state.orchestraInfo.avatar = content.avatar
  28. // state.orchestraInfo.unionId = content.unionId || 0
  29. console.log(content, 'orchestra')
  30. const { data } = await request.post('/api-auth/smsLogin', {
  31. requestType: 'form',
  32. data: {
  33. clientId: 'student',
  34. clientSecret: 'student',
  35. phone: content.phone,
  36. isSurportRegister: true,
  37. token: content.token.split(' ')[1]
  38. }
  39. })
  40. const { authentication } = data
  41. setAuth(authentication.token_type + ' ' + authentication.access_token)
  42. }
  43. )
  44. }
  45. const initProject = async () => {
  46. // import Vconsole from 'vconsole'
  47. // const vconsole = new Vconsole()
  48. // 设置是否显示导航栏 0 显示 1 不显示
  49. postMessage({ api: 'setBarStatus', content: { status: 0 } })
  50. postMessage({
  51. api: 'backIconChange',
  52. content: { backIconHide: true }
  53. })
  54. postMessage(
  55. {
  56. api: 'getVersion'
  57. },
  58. (res: any) => {
  59. state.version = res.content.version
  60. }
  61. )
  62. // 判断是否是管乐团学生端,用来获取基础数据
  63. if (browser().isOrchestraStudent) {
  64. // 获取管乐团token
  65. promisefiyPostMessage({ api: 'getUserAccount' }).then((res: any) => {
  66. const content = res.content
  67. state.orchestraInfo.token = content.token.split(' ')[1]
  68. state.orchestraInfo.phone = content.phone
  69. state.orchestraInfo.nickname = content.nickname
  70. state.orchestraInfo.avatar = content.avatar
  71. state.orchestraInfo.unionId = content.unionId || 0
  72. })
  73. // 从缓存里面获取token
  74. promisefiyPostMessage({
  75. api: 'getCache',
  76. content: { key: 'h5-colexiu-token' }
  77. }).then((res: any) => {
  78. const content = res.content
  79. if (content.value) {
  80. setAuth(content.value)
  81. }
  82. })
  83. }
  84. // 判断是否是课堂乐器学生端,用来获取基础数据
  85. const parseSearch: any = qs.parse(location.search)
  86. const hashSearch = qs.parse(location.hash.split('?')[1])
  87. const source: string = parseSearch.source || hashSearch.source || ''
  88. const Authorization: string =
  89. parseSearch.Authorization || hashSearch.Authorization || ''
  90. if (source === 'kt') {
  91. // 获取课堂乐器token
  92. if (Authorization) {
  93. state.sourcType = 'kt'
  94. } else {
  95. await getClassroomDefaultInfo()
  96. }
  97. }
  98. if (browser().isTeacher) {
  99. state.platformType = 'TEACHER'
  100. } else if (browser().isStudent) {
  101. state.platformType = 'STUDENT'
  102. } else {
  103. state.platformType = 'STUDENT'
  104. }
  105. if (state.platformType === 'TEACHER') {
  106. state.platformApi = '/api-teacher'
  107. } else {
  108. state.platformApi = '/api-student'
  109. }
  110. dayjs.locale('zh-ch')
  111. app.config.globalProperties.$dayjs = dayjs
  112. app.config.globalProperties.$filters = vueFilter
  113. app.use(router)
  114. app.mount('#app')
  115. }
  116. initProject()