security-setting.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <script setup lang="ts">
  2. import type { Recordable } from '@vben/types';
  3. import type { SettingProps } from './types';
  4. import {
  5. Form,
  6. FormControl,
  7. FormDescription,
  8. FormField,
  9. FormItem,
  10. FormLabel,
  11. Switch,
  12. } from '@vben-core/shadcn-ui';
  13. withDefaults(defineProps<SettingProps>(), {
  14. formSchema: () => [],
  15. });
  16. const emit = defineEmits<{
  17. change: [Recordable<any>];
  18. }>();
  19. function handleChange(fieldName: string, value: boolean) {
  20. emit('change', { fieldName, value });
  21. }
  22. </script>
  23. <template>
  24. <Form class="space-y-8">
  25. <div class="space-y-4">
  26. <template v-for="item in formSchema" :key="item.fieldName">
  27. <FormField type="checkbox" :name="item.fieldName">
  28. <FormItem
  29. class="flex flex-row items-center justify-between rounded-lg border p-4"
  30. >
  31. <div class="space-y-0.5">
  32. <FormLabel class="text-base"> {{ item.label }} </FormLabel>
  33. <FormDescription>
  34. {{ item.description }}
  35. </FormDescription>
  36. </div>
  37. <FormControl>
  38. <Switch
  39. :model-value="item.value"
  40. @update:model-value="handleChange(item.fieldName, $event)"
  41. />
  42. </FormControl>
  43. </FormItem>
  44. </FormField>
  45. </template>
  46. </div>
  47. </Form>
  48. </template>