index.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import Vue from 'vue';
  2. import '@/styles/font/font.css';
  3. import '@/styles/common.scss';
  4. import ElementUI from 'element-ui';
  5. import 'element-ui/lib/theme-chalk/index.css';
  6. import '@/icons';
  7. import '@/utils/directive';
  8. import '@/styles/index.scss';
  9. import '@/utils/filter';
  10. import '@/utils/mathjax'; // 必须在引入mathjax前引入mathjax的配置文件
  11. import 'mathjax/es5/tex-mml-svg';
  12. import VueSignaturePad from 'vue-signature-pad';
  13. import BookEep from './BookEep.vue';
  14. import pkg from './package.json';
  15. import { setRuntimeServices } from '@/utils/runtime-services';
  16. import { ensureExtendedFonts } from '@/common/data';
  17. import EepSvgIcon from '@/common/SvgIcon';
  18. const components = [BookEep];
  19. const version = pkg.version;
  20. Vue.use(ElementUI, {
  21. size: 'small',
  22. });
  23. Vue.use(VueSignaturePad);
  24. // 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
  25. const install = (VueInstance, options = {}) => {
  26. if (install.installed) return;
  27. install.installed = true;
  28. // 在 BookEep 组件子树内强制 SvgIcon 解析到库内实现,避免宿主全局同名组件覆盖
  29. // 必须无条件覆盖:Vue 2 的 $options.components 通过原型链继承全局组件,
  30. // 用 if 守卫会导致永远跳过后注册的覆盖逻辑。
  31. if (!VueInstance.__EEP_UI_ICON_MIXIN_INSTALLED__) {
  32. VueInstance.__EEP_UI_ICON_MIXIN_INSTALLED__ = true;
  33. VueInstance.mixin({
  34. beforeCreate() {
  35. if (this.$options.name === 'BookEep') {
  36. this.__eepUiScope = true;
  37. } else if (this.$parent && this.$parent.__eepUiScope) {
  38. this.__eepUiScope = true;
  39. }
  40. if (!this.__eepUiScope) return;
  41. const components = this.$options.components || (this.$options.components = {});
  42. // 无条件覆盖,因为 Vue 2 的 $options.components 继承自全局 Vue.options.components,
  43. // 宿主已注册的 SvgIcon 会出现在原型链上,导致 if (!components.SvgIcon) 永远为 false
  44. components.EepSvgIcon = EepSvgIcon;
  45. components.SvgIcon = EepSvgIcon;
  46. },
  47. });
  48. }
  49. setRuntimeServices({
  50. router: options.router,
  51. store: options.store,
  52. });
  53. // 自动注册扩展字体(惰性加载,与主应用共享 _extendedFontsLoaded 标记,仅首次请求)
  54. ensureExtendedFonts();
  55. components.forEach((component) => {
  56. VueInstance.component(component.name || 'BookEep', component);
  57. });
  58. };
  59. // 判断是否是直接引入文件,如果是,就不用调用 Vue.use()
  60. if (typeof window !== 'undefined' && window.Vue) {
  61. install(window.Vue);
  62. }
  63. if (typeof window !== 'undefined') {
  64. window.__EEP_UI_VERSION__ = version;
  65. }
  66. // 导出的对象必须具有 install,才能被 Vue.use() 方法安装
  67. export default {
  68. install,
  69. version,
  70. };
  71. export { version };