index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. import './styles/scrollbar.scss'
  13. const loadLang = function (Vue, lang, locale, i18n) {
  14. if (locale) {
  15. locale('en-US', {...locale('en-US'), ...enUS})
  16. locale('zh-CN', {...locale('zh-CN'), ...zhCN})
  17. Vue.config.lang = lang
  18. } else if (i18n){
  19. i18n.setLocaleMessage('en-US', {...i18n.messages['en-US'], ...enUS})
  20. i18n.setLocaleMessage('zh-CN', {...i18n.messages['zh-CN'], ...zhCN})
  21. i18n.locale = lang
  22. } else {
  23. if (!Vue.prototype.$t) {
  24. Vue.use(VueI18n)
  25. const localI18n = new VueI18n({
  26. locale: lang,
  27. messages: {
  28. 'en-US': {...enUS},
  29. 'zh-CN': {...zhCN}
  30. }
  31. })
  32. const init = Vue.prototype._init
  33. Vue.prototype._init = function (options) {
  34. init.call(this, {
  35. i18n: localI18n,
  36. ...options
  37. })
  38. }
  39. }
  40. }
  41. }
  42. const expire = 253402271999000
  43. const version = '1.6.15'
  44. const displayVersion = () => {
  45. Function(`
  46. window.console && console.log('%cFormMaking %cV${version} https://form.making.link', 'color: #1890ff;font-weight: 500;font-size: 20px;font-family: Source Sans Pro,Helvetica Neue,Arial,sans-serif;', 'color: #ccc;');
  47. `)()
  48. }
  49. const loadOptions = (opts) => {
  50. window.FormMaking_OPTIONS = {
  51. ...opts,
  52. aceurl: opts.aceurl || 'https://form.making.link/public/lib/ace',
  53. key: '03202501060166M',
  54. version
  55. }
  56. }
  57. MakingForm.install = function (Vue, opts = {
  58. lang: 'zh-CN',
  59. locale: null,
  60. i18n: null
  61. }) {
  62. opts = {
  63. key: '03202501060166M',
  64. lang: 'zh-CN',
  65. locale: null,
  66. i18n: null,
  67. ...opts
  68. }
  69. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  70. if (expire >= new Date().getTime()) {
  71. Vue.component(MakingForm.name, MakingForm)
  72. }
  73. displayVersion()
  74. loadOptions(opts)
  75. }
  76. GenerateForm.install = function (Vue, opts = {
  77. lang: 'zh-CN',
  78. locale: null,
  79. i18n: null
  80. }) {
  81. opts = {
  82. key: '03202501060166M',
  83. lang: 'zh-CN',
  84. locale: null,
  85. i18n: null,
  86. ...opts
  87. }
  88. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  89. if (expire >= new Date().getTime()) {
  90. Vue.component(GenerateForm.name, GenerateForm)
  91. }
  92. displayVersion()
  93. loadOptions(opts)
  94. }
  95. GenerateAntdForm.install = function (Vue, opts = {
  96. lang: 'zh-CN',
  97. locale: null,
  98. i18n: null
  99. }) {
  100. opts = {
  101. key: '03202501060166M',
  102. lang: 'zh-CN',
  103. locale: null,
  104. i18n: null,
  105. ...opts
  106. }
  107. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  108. if (expire >= new Date().getTime()) {
  109. Vue.component(GenerateAntdForm.name, GenerateAntdForm)
  110. }
  111. displayVersion()
  112. loadOptions(opts)
  113. }
  114. const components = [
  115. MakingForm,
  116. GenerateForm,
  117. GenerateAntdForm
  118. ]
  119. const install = function (Vue, opts = {
  120. lang: 'zh-CN',
  121. locale: null,
  122. i18n: null,
  123. components: []
  124. }) {
  125. opts = {
  126. key: '03202501060166M',
  127. lang: 'zh-CN',
  128. locale: null,
  129. i18n: null,
  130. components: [],
  131. ...opts
  132. }
  133. loadLang(Vue, opts.lang, opts.locale, opts.i18n)
  134. if (expire >= new Date().getTime()) {
  135. components.forEach(component => {
  136. Vue.component(component.name, component)
  137. })
  138. opts.components && opts.components.forEach(item => {
  139. Vue.component(item.name, item.component)
  140. })
  141. }
  142. displayVersion()
  143. loadOptions(opts)
  144. }
  145. if (typeof window !== 'undefined' && window.Vue) {
  146. install(window.Vue);
  147. }
  148. export {
  149. install,
  150. MakingForm,
  151. GenerateForm,
  152. GenerateAntdForm
  153. }
  154. export default {
  155. install,
  156. MakingForm,
  157. GenerateForm,
  158. GenerateAntdForm
  159. }