index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import VueI18n from 'vue-i18n'
  2. import 'normalize.css/normalize.css'
  3. import MakingForm from './components/Container.vue'
  4. import GenerateForm from './components/GenerateForm.vue'
  5. import GenerateAntdForm from './components/AntdvGenerator/GenerateForm.vue'
  6. import enUS from './lang/en-US'
  7. import zhCN from './lang/zh-CN'
  8. import './iconfont/iconfont.css'
  9. import './styles/cover.scss'
  10. import './styles/index.scss'
  11. import './styles/editor.scss'
  12. const loadLang = function (Vue, lang, locale, i18n) {
  13. if (locale) {
  14. locale('en-US', {...locale('en-US'), ...enUS})
  15. locale('zh-CN', {...locale('zh-CN'), ...zhCN})
  16. Vue.config.lang = lang
  17. } else if (i18n){
  18. i18n.setLocaleMessage('en-US', {...i18n.messages['en-US'], ...enUS})
  19. i18n.setLocaleMessage('zh-CN', {...i18n.messages['zh-CN'], ...zhCN})
  20. i18n.locale = lang
  21. } else {
  22. Vue.use(VueI18n)
  23. Vue.locale('en-US', {...Vue.locale('en-US'), ...enUS})
  24. Vue.locale('zh-CN', {...Vue.locale('zh-CN'), ...zhCN})
  25. Vue.config.lang = lang
  26. }
  27. }
  28. const expire = 11588262399000
  29. MakingForm.install = function (Vue, opts = {
  30. lang: 'zh-CN',
  31. locale: null,
  32. i18n: null
  33. }) {
  34. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  35. if (expire >= new Date().getTime()) {
  36. Vue.component(MakingForm.name, MakingForm)
  37. }
  38. }
  39. GenerateForm.install = function (Vue, opts = {
  40. lang: 'zh-CN',
  41. locale: null,
  42. i18n: null
  43. }) {
  44. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  45. if (expire >= new Date().getTime()) {
  46. Vue.component(GenerateForm.name, GenerateForm)
  47. }
  48. }
  49. GenerateAntdForm.install = function (Vue, opts = {
  50. lang: 'zh-CN',
  51. locale: null,
  52. i18n: null
  53. }) {
  54. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  55. if (expire >= new Date().getTime()) {
  56. Vue.component(GenerateAntdForm.name, GenerateAntdForm)
  57. }
  58. }
  59. const components = [
  60. MakingForm,
  61. GenerateForm,
  62. GenerateAntdForm
  63. ]
  64. const install = function (Vue, opts = {
  65. lang: 'zh-CN',
  66. locale: null,
  67. i18n: null,
  68. components: []
  69. }) {
  70. opts = {
  71. lang: 'zh-CN',
  72. locale: null,
  73. i18n: null,
  74. components: [],
  75. ...opts
  76. }
  77. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  78. if (expire >= new Date().getTime()) {
  79. components.forEach(component => {
  80. Vue.component(component.name, component)
  81. })
  82. opts.components && opts.components.forEach(item => {
  83. Vue.component(item.name, item.component)
  84. })
  85. }
  86. }
  87. if (typeof window !== 'undefined' && window.Vue) {
  88. install(window.Vue);
  89. }
  90. export {
  91. install,
  92. MakingForm,
  93. GenerateForm,
  94. GenerateAntdForm
  95. }
  96. export default {
  97. install,
  98. MakingForm,
  99. GenerateForm,
  100. GenerateAntdForm
  101. }