App.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <!-- eslint-disable @typescript-eslint/no-explicit-any -->
  2. <!-- eslint-disable @typescript-eslint/ban-ts-comment -->
  3. <script setup lang="ts">
  4. import { ref, onMounted, nextTick } from 'vue'
  5. import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'
  6. import type { Config, Handle } from '@form-create/designer'
  7. // import { formCreate } from '@form-create/designer'
  8. import { formConfig } from './form.config.ts'
  9. import FcDesigner from '@form-create/designer'
  10. import { RcSelect } from './plugins/components/rc-select.config.ts'
  11. import { RcRadio } from './plugins/components/rc-radio.config.ts'
  12. import { MenuOptions } from './plugins/menu/options.ts'
  13. import type { FcDesignerInstance } from '@form-create/designer' // 注册组件
  14. import { RcCheckbox } from './plugins/components/rc-checkbox.ts'
  15. /**
  16. * @see https://view.form-create.com/methods
  17. */
  18. declare global {
  19. interface Window {
  20. __QIANKUN__EVENT__: {
  21. on: (name: string, fn: (...arg: any[]) => void) => void
  22. emit: (name: string, ...arg: any[]) => void
  23. } // 事件中心
  24. __QIANKUN__REQUSET__: () => void // 请求API接口
  25. __QIANKUN__GUID__: () => string // 获取唯一标识
  26. __QIANKUN__OPEN__TAG__: () => void // 打开标签页
  27. }
  28. }
  29. // 表单实例
  30. const designer = ref<FcDesignerInstance | null>(null)
  31. const api = ref(null)
  32. // 表单模板元素
  33. // 判断是独立运行的还是qiankun子应用
  34. const height = ref(qiankunWindow.__POWERED_BY_QIANKUN__ ? '90vh' : '100vh')
  35. const config = ref<Config>(formConfig)
  36. // 顶部更多操作按钮
  37. const handle = ref<Handle>([])
  38. // console.log('子应用', window.__QIANKUN__EVENT__)
  39. const onSave = (config: { options: string; rule: string }) => {
  40. const rule = config.rule
  41. console.log(rule)
  42. }
  43. onMounted(() => {
  44. designer.value?.openPreview()
  45. nextTick(() => {
  46. // @ts-ignore
  47. designer.value!.preview.state = false
  48. })
  49. })
  50. onMounted(() => {
  51. // 注册拖拽规则
  52. designer.value?.addComponent(RcSelect)
  53. designer.value?.addComponent(RcRadio)
  54. designer.value?.addComponent(RcCheckbox)
  55. // 注册菜单
  56. designer.value?.addMenu(MenuOptions)
  57. })
  58. </script>
  59. <template>
  60. <fc-designer
  61. ref="designer"
  62. :height="height"
  63. :handle="handle"
  64. :config="config"
  65. @save="onSave"
  66. v-model:api="api"
  67. />
  68. </template>