index.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <script setup lang='ts'>
  2. import {LDNormalModal, LDErrorBoundary, LDSuspenseLoading} from '@components';
  3. import {toRefs} from 'vue';
  4. import {useVModel} from '@vueuse/core';
  5. import {useFormState} from './hooks';
  6. import {useI18n} from 'vue-i18n';
  7. import ErrorBoundary from 'veboundary';
  8. import Info from './Info.vue';
  9. defineOptions({name: 'RolePageModal'});
  10. type Props = {
  11. visible: boolean;
  12. id: string;
  13. onFetch: () => void;
  14. };
  15. const props = defineProps<Props>();
  16. const {visible, id} = toRefs(props);
  17. const emits = defineEmits<{(event: 'update:visible'): void}>();
  18. const visibleValue = useVModel(props, 'visible', emits);
  19. const [isLoading, {onSubmit, setValues}] = useFormState(
  20. id,
  21. visible,
  22. {
  23. onFetch: props.onFetch,
  24. onClose() {
  25. visibleValue.value = false;
  26. },
  27. },
  28. );
  29. const {t} = useI18n();
  30. </script>
  31. <template>
  32. <LDNormalModal
  33. :isAdd="id.length === 0"
  34. v-model="visibleValue"
  35. :title="t(`role.modal.title[${id.length > 0 ? 1 : 0}]`)"
  36. @submit="onSubmit"
  37. :isLoading="isLoading"
  38. :height="480"
  39. >
  40. <ErrorBoundary>
  41. <template #fallback="{error, reset}">
  42. <LDErrorBoundary :msg="error.message" @reset="reset" />
  43. </template>
  44. <Suspense>
  45. <template #fallback>
  46. <LDSuspenseLoading />
  47. </template>
  48. <Info :id="id" :setValues="setValues" />
  49. </Suspense>
  50. </ErrorBoundary>
  51. </LDNormalModal>
  52. </template>