index.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 EepSvgIcon from '@/common/SvgIcon';
  17. const components = [BookEep];
  18. const version = pkg.version;
  19. Vue.use(ElementUI, {
  20. size: 'small',
  21. });
  22. Vue.use(VueSignaturePad);
  23. // 定义 install 方法,接收 Vue 作为参数。如果使用 use 注册插件,则所有的组件都将被注册
  24. const install = (VueInstance, options = {}) => {
  25. if (install.installed) return;
  26. install.installed = true;
  27. // 在 BookEep 组件子树内强制 SvgIcon 解析到库内实现,避免宿主全局同名组件覆盖
  28. // 必须无条件覆盖:Vue 2 的 $options.components 通过原型链继承全局组件,
  29. // 用 if 守卫会导致永远跳过后注册的覆盖逻辑。
  30. if (!VueInstance.__EEP_UI_ICON_MIXIN_INSTALLED__) {
  31. VueInstance.__EEP_UI_ICON_MIXIN_INSTALLED__ = true;
  32. VueInstance.mixin({
  33. beforeCreate() {
  34. if (this.$options.name === 'BookEep') {
  35. this.__eepUiScope = true;
  36. } else if (this.$parent && this.$parent.__eepUiScope) {
  37. this.__eepUiScope = true;
  38. }
  39. if (!this.__eepUiScope) return;
  40. const components = this.$options.components || (this.$options.components = {});
  41. // 无条件覆盖,因为 Vue 2 的 $options.components 继承自全局 Vue.options.components,
  42. // 宿主已注册的 SvgIcon 会出现在原型链上,导致 if (!components.SvgIcon) 永远为 false
  43. components.EepSvgIcon = EepSvgIcon;
  44. components.SvgIcon = EepSvgIcon;
  45. },
  46. });
  47. }
  48. setRuntimeServices({
  49. router: options.router,
  50. store: options.store,
  51. });
  52. components.forEach((component) => {
  53. VueInstance.component(component.name || 'BookEep', component);
  54. });
  55. };
  56. // 判断是否是直接引入文件,如果是,就不用调用 Vue.use()
  57. if (typeof window !== 'undefined' && window.Vue) {
  58. install(window.Vue);
  59. }
  60. if (typeof window !== 'undefined') {
  61. window.__EEP_UI_VERSION__ = version;
  62. }
  63. // 导出的对象必须具有 install,才能被 Vue.use() 方法安装
  64. export default {
  65. install,
  66. version,
  67. };
  68. export { version };