rc-create-option.vue 943 B

12345678910111213141516171819202122232425262728293031323334
  1. <script lang="ts" name="rc-select" setup>
  2. import type { FormCreateProps } from '@form-create/element-ui'
  3. import type { Option } from '../rc-options/createOptions.ts'
  4. import { onMounted, ref } from 'vue'
  5. const props = defineProps<{
  6. formCreateInject: FormCreateProps & {
  7. field: string
  8. }
  9. }>()
  10. const options = ref<Option[]>([])
  11. window.__QIANKUN__EVENT__?.on(props.formCreateInject.field, (tags: Option[]) => {
  12. if (props.formCreateInject.rule?.props === void 0) {
  13. return
  14. }
  15. ;(props.formCreateInject.rule.props as Record<string, Option[]>).options =
  16. // eslint-disable-next-line vue/no-mutating-props
  17. props.formCreateInject.rule.options = tags.map((item) => {
  18. return {
  19. ...item,
  20. value: item.label,
  21. }
  22. })
  23. options.value = tags
  24. })
  25. onMounted(() => {
  26. options.value = props.formCreateInject.rule!.options as unknown as Option[]
  27. })
  28. </script>
  29. <template>
  30. <slot :options="options" />
  31. </template>