index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 enUS from './lang/en-US'
  6. import zhCN from './lang/zh-CN'
  7. import './iconfont/iconfont.css'
  8. import './styles/cover.scss'
  9. import './styles/index.scss'
  10. const loadLang = function (Vue, lang, locale, i18n) {
  11. if (locale) {
  12. locale('en-US', {...locale('en-US'), ...enUS})
  13. locale('zh-CN', {...locale('zh-CN'), ...zhCN})
  14. Vue.config.lang = lang
  15. } else if (i18n) {
  16. i18n.setLocaleMessage('en-US', {...i18n.messages['en-US'], ...enUS})
  17. i18n.setLocaleMessage('zh-CN', {...i18n.messages['zh-CN'], ...zhCN})
  18. i18n.locale = lang
  19. } else {
  20. Vue.use(VueI18n)
  21. const localI18n = new VueI18n({
  22. locale: lang,
  23. messages: {
  24. 'en-US': {...enUS},
  25. 'zh-CN': {...zhCN}
  26. }
  27. })
  28. const init = Vue.prototype._init
  29. Vue.prototype._init = function (options) {
  30. init.call(this, {
  31. i18n: localI18n,
  32. ...options
  33. })
  34. }
  35. }
  36. }
  37. MakingForm.install = function (Vue, opts = {
  38. lang: 'zh-CN',
  39. locale: null,
  40. i18n: null
  41. }) {
  42. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  43. Vue.component(MakingForm.name, MakingForm)
  44. }
  45. GenerateForm.install = function (Vue, opts = {
  46. lang: 'zh-CN',
  47. locale: null,
  48. i18n: null
  49. }) {
  50. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  51. Vue.component(GenerateForm.name, GenerateForm)
  52. }
  53. const components = [
  54. MakingForm,
  55. GenerateForm
  56. ]
  57. const install = function (Vue, opts = {
  58. lang: 'zh-CN',
  59. locale: null,
  60. i18n: null
  61. }) {
  62. opts = {
  63. lang: 'zh-CN',
  64. locale: null,
  65. i18n: null,
  66. ...opts
  67. }
  68. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  69. components.forEach(component => {
  70. Vue.component(component.name, component)
  71. })
  72. }
  73. if (typeof window !== 'undefined' && window.Vue) {
  74. install(window.Vue);
  75. }
  76. export {
  77. install,
  78. MakingForm,
  79. GenerateForm
  80. }
  81. export default {
  82. install,
  83. MakingForm,
  84. GenerateForm
  85. }