main.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import Vue from 'vue'
  2. import Cookies from 'js-cookie'
  3. import Element from 'element-ui'
  4. import './assets/styles/element-variables.scss'
  5. import '@/assets/styles/index.scss' // global css
  6. import '@/assets/styles/common.scss'
  7. import App from './App'
  8. import store from './store'
  9. import router from './router'
  10. import directive from './directive' //directive
  11. import elementDirective from './directive/select'
  12. import './assets/icons' // icon
  13. import './permission' // permission control
  14. import { getDicts } from "@/api/system/dict/data";
  15. import { getConfigKey } from "@/api/system/config";
  16. import {cloneObject, parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/common";
  17. import Pagination from "@/components/Pagination";
  18. // 自定义表格工具组件
  19. import RightToolbar from "@/components/RightToolbar"
  20. // 富文本组件
  21. import Editor from "@/components/Editor"
  22. // 文件上传组件
  23. import FileUpload from "@/components/FileUpload"
  24. // 图片上传组件
  25. import ImageUpload from "@/components/ImageUpload"
  26. // 字典标签组件
  27. import DictTag from '@/components/DictTag'
  28. // 头部标签组件
  29. import VueMeta from 'vue-meta'
  30. import * as echarts from "echarts";
  31. import { getConfigByKey } from '@/api/system/config'
  32. Vue.prototype.$runtimeConfig = {}
  33. // 全局方法挂载
  34. import { VueJsonp } from 'vue-jsonp'
  35. Vue.use(VueJsonp)
  36. // 全局配置
  37. Vue.prototype.logImg = require(process.env.VUE_APP_LOG_URL)
  38. Vue.prototype.cloneObject = cloneObject
  39. Vue.prototype.getDicts = getDicts
  40. Vue.prototype.getConfigKey = getConfigKey
  41. Vue.prototype.parseTime = parseTime
  42. Vue.prototype.resetForm = resetForm
  43. Vue.prototype.addDateRange = addDateRange
  44. Vue.prototype.selectDictLabel = selectDictLabel
  45. Vue.prototype.selectDictLabels = selectDictLabels
  46. Vue.prototype.download = download
  47. Vue.prototype.handleTree = handleTree
  48. Vue.prototype.echarts = echarts
  49. Vue.prototype.msgSuccess = function (msg) {
  50. this.$message({ showClose: true, message: msg, type: "success" });
  51. }
  52. Vue.prototype.msgError = function (msg) {
  53. this.$message({ showClose: true, message: msg, type: "error" });
  54. }
  55. Vue.prototype.msgInfo = function (msg) {
  56. this.$message.info(msg);
  57. }
  58. // 全局组件挂载
  59. Vue.component('DictTag', DictTag)
  60. Vue.component('Pagination', Pagination)
  61. Vue.component('RightToolbar', RightToolbar)
  62. Vue.component('Editor', Editor)
  63. Vue.component('FileUpload', FileUpload)
  64. Vue.component('ImageUpload', ImageUpload)
  65. import H5Editor from "@/components/H5Editor";
  66. Vue.component('H5Editor', H5Editor)
  67. Vue.use(directive)
  68. Vue.use(VueMeta)
  69. Vue.use(elementDirective)
  70. /**
  71. * If you don't want to use mock-server
  72. * you want to use MockJs for mock api
  73. * you can execute: mockXHR()
  74. *
  75. * Currently MockJs will be used in the production environment,
  76. * please remove it before going online! ! !
  77. */
  78. Vue.use(Element, {
  79. size: Cookies.get('size') || 'medium' // set element-ui default size
  80. })
  81. Vue.config.productionTip = false
  82. async function initRuntimeConfig() {
  83. try {
  84. const res = await getConfigByKey('his.adminUi.config')
  85. const configValue = res?.data?.configValue
  86. if (!configValue) return
  87. // 后端配置 JSON
  88. const form = JSON.parse(configValue)
  89. // 字段映射表(核心优化点)
  90. const mapping = {
  91. VUE_APP_OBS_ACCESS_KEY_ID: 'obsAccessKeyId',
  92. VUE_APP_OBS_SECRET_ACCESS_KEY: 'obsSecretAccessKey',
  93. VUE_APP_OBS_SERVER: 'obsServer',
  94. VUE_APP_OBS_BUCKET: 'obsBucket',
  95. VUE_APP_VIDEO_LINE_1: 'videoLinePrimary',
  96. VUE_APP_VIDEO_LINE_2: 'videoLineSecondary',
  97. VUE_APP_VIDEO_URL: 'volcanoVideoDomain',
  98. VUE_APP_HSY_SPACE: 'volcanoVodSpace',
  99. VUE_APP_LIVE_PATH: 'livePath',
  100. VUE_APP_COS_BUCKET: 'cosBucket',
  101. VUE_APP_LIVE_WS_URL: 'liveWebSocketUrl',
  102. VUE_APP_COURSE_DEFAULT: 'courseDefaultType',
  103. VUE_APP_COS_REGION: 'cosRegion'
  104. }
  105. // 写入运行时配置
  106. Object.keys(mapping).forEach(key => {
  107. Vue.prototype.$runtimeConfig[key] = form[mapping[key]] ?? null
  108. })
  109. } catch (e) {
  110. console.error('初始化运行时配置失败', e)
  111. }
  112. }
  113. async function bootstrap() {
  114. await initRuntimeConfig()
  115. new Vue({
  116. el: '#app',
  117. router,
  118. store,
  119. render: h => h(App)
  120. })
  121. }
  122. bootstrap()