App.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <router-view v-slot="{ Component }">
  3. <!-- <keep-alive>
  4. <component v-if="route.meta.keepAlive" :is="Component" />
  5. </keep-alive> -->
  6. <component :is="Component" />
  7. <fee-popup/>
  8. <vip-popup/>
  9. </router-view>
  10. </template>
  11. <script lang="ts">
  12. import { close } from '/src/helpers/loading'
  13. import qs from 'query-string'
  14. import request from '/src/helpers/request'
  15. import { getRequestHostname, setVoiceInit } from '/src/helpers/utils'
  16. import FeePopup from '/src/components/fee'
  17. import VipPopup from '/src/components/vip'
  18. import appstate, { IAuth, IAuthKey } from '/src/state'
  19. import './vue-tsx-shim.d'
  20. import './app.d'
  21. const getHasAuth = (list: any[]) => {
  22. let auths: IAuth = {}
  23. for (const item of list) {
  24. const code: IAuthKey = item.code
  25. auths[code] = item
  26. if (item.memberPrivilegesItems?.length) {
  27. auths = {
  28. ...auths,
  29. ...getHasAuth(item.memberPrivilegesItems)
  30. }
  31. }
  32. }
  33. return auths
  34. }
  35. close()
  36. export default {
  37. name: 'App',
  38. components: {
  39. 'fee-popup': FeePopup,
  40. 'vip-popup': VipPopup,
  41. },
  42. created() {
  43. setVoiceInit()
  44. },
  45. methods: {
  46. async FeychUser() {
  47. let saveSibiectId: number = parseFloat(sessionStorage.getItem('subjectId') || '0')
  48. let subjectId = 0
  49. appstate.subjectLoading = true
  50. try {
  51. if (getRequestHostname() === '/api-teacher') {
  52. const res = await request.get(`/teacher/queryUserInfo`)
  53. appstate.user = res.data
  54. appstate.tenantId = res.data.tenantId
  55. appstate.organId = res.data.teacherOrganId
  56. subjectId = Math.floor(saveSibiectId || res.data.subjectId.split(',')[0])
  57. } else if (getRequestHostname() === '/api-web') {
  58. const res = await request.get(`/employee/queryUserInfo`)
  59. appstate.user = res.data
  60. appstate.tenantId = res.data.tenantId
  61. appstate.organId = res.data.organIdList
  62. if (saveSibiectId) {
  63. subjectId = saveSibiectId
  64. }
  65. } else {
  66. const res = await request.get(`/student/queryUserInfo`)
  67. console.log(subjectId, 11111111111)
  68. appstate.user = res.data
  69. const student = res.data?.student
  70. appstate.tenantId = student.tenantId
  71. appstate.organId = student.organId
  72. subjectId = Math.floor(saveSibiectId || student.subjectIdList.split(',')[0])
  73. this.subjectFormat(subjectId, student.subjectNames, student.extSjectNamesMap)
  74. }
  75. // 学生端萨克斯转中音萨克斯
  76. if(getRequestHostname() == '/api-student') {
  77. subjectId = subjectId == 5 ? subjectId = 6 : subjectId
  78. }
  79. appstate.subjectId = subjectId
  80. appstate.origanSubjectId = subjectId
  81. } catch (error) {
  82. console.log(error)
  83. }
  84. appstate.subjectLoading = false
  85. },
  86. // 合并声部数据
  87. subjectFormat(subjectId: number, subjectName: string, extSubjectIds: any) {
  88. let inExt = false // 主声部是否在扩展中
  89. let tempExtSubject = []
  90. if(extSubjectIds) {
  91. for(let i in extSubjectIds) {
  92. if(subjectId === Number(i)) {
  93. inExt = true
  94. }
  95. tempExtSubject.push({
  96. id: Number(i),
  97. name: extSubjectIds[i]
  98. })
  99. }
  100. }
  101. // 是否需要添加主声部
  102. if(inExt) {
  103. appstate.extSubjectIds = tempExtSubject
  104. } else {
  105. appstate.extSubjectIds = [{id: subjectId, name: subjectName}, ...tempExtSubject]
  106. }
  107. },
  108. },
  109. async mounted() {
  110. const parseSearch: any = qs.parse(location.search)
  111. const hashSearch = qs.parse(location.hash.split('?')[1])
  112. const Authorization: string = parseSearch.Authorization || hashSearch.Authorization || ''
  113. const subjectId: string = parseSearch.subjectId || hashSearch.subjectId || ''
  114. sessionStorage.setItem('Authorization', Authorization)
  115. sessionStorage.setItem('subjectId', subjectId)
  116. try {
  117. await this.FeychUser()
  118. } catch (error) {}
  119. const allAutth = appstate.user?.userPrivileges ? getHasAuth(appstate.user.userPrivileges) : []
  120. const authKeys = Object.keys(allAutth)
  121. for (const key in appstate.modular) {
  122. if (Object.prototype.hasOwnProperty.call(appstate.modular, key)) {
  123. if (getRequestHostname() === '/api-student') {
  124. (appstate as any).modular[key] = authKeys.includes(key)
  125. } else {
  126. (appstate as any).modular[key] = true
  127. }
  128. }
  129. }
  130. },
  131. }
  132. </script>