main.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import Vue from 'vue'
  2. import axios from './router/axios'
  3. import VueAxios from 'vue-axios'
  4. import App from './App'
  5. import router from './router/router'
  6. import './permission' // 权限
  7. import './error' // 日志
  8. import './cache' //页面缓存
  9. import store from './store'
  10. import { loadStyle } from './util/util'
  11. import * as urls from '@/config/env'
  12. import Element from 'element-ui'
  13. import { iconfontUrl, iconfontVersion } from '@/config/env'
  14. import i18n from './lang' // Internationalization
  15. import './styles/common.scss'
  16. import basicBlock from './components/basic-block/main'
  17. import basicContainer from './components/basic-container/main'
  18. import thirdRegister from './components/third-register/main'
  19. import avueUeditor from 'avue-plugin-ueditor'
  20. import website from '@/config/website'
  21. import crudCommon from '@/mixins/crud'
  22. import Example from './components/example'
  23. import Pagination from './components/Pagination'
  24. import directive from './util/directives'
  25. import { dictDataEcho } from './util/util' //字典数据回显
  26. //cdn迁移进src目录
  27. import './assets/cdn/element-ui/2.15.1/theme-chalk/index.css'
  28. import './assets/cdn/animate/3.5.2/animate.css'
  29. import './assets/cdn/iconfont/avue/iconfont.css'
  30. import './assets/cdn/iconfont/saber/iconfont.css'
  31. import './assets/cdn/avue/2.8.18/index.css'
  32. import { set } from 'nprogress'
  33. import { setToken } from '@/util/auth'
  34. // 注册全局crud驱动
  35. window.$crudCommon = crudCommon
  36. // 加载Vue拓展
  37. Vue.use(router)
  38. Vue.use(VueAxios, axios)
  39. Vue.use(Element, {
  40. i18n: (key, value) => i18n.t(key, value),
  41. })
  42. Vue.use(window.AVUE, {
  43. size: 'small',
  44. tableSize: 'small',
  45. calcHeight: 65,
  46. i18n: (key, value) => i18n.t(key, value),
  47. })
  48. Vue.use(Example)
  49. Vue.use(Pagination)
  50. Vue.use(set)
  51. Vue.use(directive)
  52. Element.Select.props.filterable = {
  53. type: Boolean,
  54. default: true,
  55. }
  56. Element.Select.props.clearable = {
  57. type: Boolean,
  58. default: true,
  59. }
  60. Element.TimePicker.props.editable = {
  61. type: Boolean,
  62. default: false,
  63. }
  64. Element.TimeSelect.props.editable = {
  65. type: Boolean,
  66. default: false,
  67. }
  68. Element.DatePicker.props.editable = {
  69. type: Boolean,
  70. default: false,
  71. }
  72. Element.Dialog.props.closeOnClickModal.default = false
  73. Element.Dialog.props.appendToBody.default = true
  74. // 注册全局容器
  75. Vue.component('basicContainer', basicContainer)
  76. Vue.component('basicBlock', basicBlock)
  77. Vue.component('thirdRegister', thirdRegister)
  78. Vue.component('avueUeditor', avueUeditor)
  79. Vue.component('Example', Example)
  80. Vue.component('Pagination', Pagination)
  81. Vue.prototype.msgSuccess = function (msg) {
  82. this.$message({ showClose: true, message: msg, type: 'success' })
  83. }
  84. Vue.prototype.msgError = function (msg) {
  85. this.$message({ showClose: true, message: msg, type: 'error' })
  86. }
  87. Vue.prototype.msgWarning = function (msg) {
  88. this.$message({ showClose: true, message: msg, type: 'warning' })
  89. }
  90. Vue.prototype.msgInfo = function (msg) {
  91. this.$message.info(msg)
  92. }
  93. Vue.prototype.dictDataEcho = dictDataEcho
  94. // 加载相关url地址
  95. Object.keys(urls).forEach((key) => {
  96. Vue.prototype[key] = urls[key]
  97. })
  98. // 加载website
  99. Vue.prototype.website = website
  100. // 动态加载阿里云字体库
  101. iconfontVersion.forEach((ele) => {
  102. loadStyle(iconfontUrl.replace('$key', ele))
  103. })
  104. //乾坤代码
  105. Vue.config.productionTip = false
  106. let instance = null
  107. function render({ props = {} } = {}) {
  108. console.log(props)
  109. const { container } = props
  110. instance = new Vue({
  111. router,
  112. store,
  113. i18n,
  114. data() { },
  115. render: (h) => h(App),
  116. }).$mount(container ? container.querySelector('#fjhxCloudVue') : '#fjhxCloudVue')
  117. console.log(instance)
  118. }
  119. // 独立运行时
  120. ; (function () {
  121. console.log(window.__POWERED_BY_QIANKUN__)
  122. if (window.__POWERED_BY_QIANKUN__) {
  123. __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__
  124. } else {
  125. render()
  126. }
  127. })()
  128. export async function bootstrap() {
  129. console.log('vue app bootstraped')
  130. }
  131. export async function mount(props) {
  132. //设置token
  133. console.log(props.data.token)
  134. //挂载父路由
  135. Vue.prototype.$parentRouter = props.data.router
  136. if (props.data.token != null) {
  137. //注入父应用传来的登录信息
  138. setToken(props.data.token.access_token)
  139. store.commit('SET_TOKEN', props.data.token.access_token)
  140. store.commit('SET_REFRESH_TOKEN', props.data.token.refresh_token)
  141. store.commit('SET_TENANT_ID', props.data.token.tenant_id)
  142. store.commit('SET_USER_INFO', props.data.token)
  143. //设置监听事件触发方法,全局共享
  144. props.onGlobalStateChange((state, prev) => {
  145. // state: 变更后的状态; prev 变更前的状态
  146. console.log(state, prev, '子组件监听')
  147. })
  148. }
  149. //发送数据给全局
  150. // props.setGlobalState({ token: 21312312 })
  151. render(props)
  152. }
  153. export async function unmount() {
  154. // instance.$destroy();
  155. instance.$el.innerHTML = ''
  156. instance = null
  157. // router = null;
  158. }
  159. Vue.config.productionTip = false