main.js 4.0 KB

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