TestConfig.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div class="space-y-3">
  3. <!-- 失败时重试 -->
  4. <div class="space-y-2">
  5. <div class="flex items-center justify-between beautify">
  6. <label class="text-sm font-medium text-gray-700">失败时重试</label>
  7. <el-switch v-model="retryState" @change="toggleRetry" />
  8. </div>
  9. <div class="space-y-2" v-if="config.retryEnabled">
  10. <div class="pl-[10px] flex item-center justify-between">
  11. <p class="m-0 text-sm text-gray-600 w-1/2">最大重试次数</p>
  12. <el-slider v-model="config.maxRetries" class="w-1/2" show-input :min="0" :max="10" size="default" />
  13. </div>
  14. <div class="pl-[10px] flex item-center justify-between">
  15. <p class="m-0 text-sm text-gray-600 w-1/2">重试间隔(ms)</p>
  16. <el-slider v-model="config.retryInterval" class="w-1/2" :min="100" :max="5000" show-input
  17. size="default" />
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </template>
  23. <script setup lang="ts">
  24. import { ref, watch } from 'vue'
  25. interface TestConfig {
  26. retryEnabled: boolean
  27. maxRetries?: number
  28. retryInterval?: number
  29. }
  30. interface Props {
  31. modelValue: TestConfig
  32. }
  33. interface Emits {
  34. (e: 'update:modelValue', value: TestConfig): void
  35. }
  36. const props = defineProps<Props>()
  37. const emit = defineEmits<Emits>()
  38. const retryState = ref(false)
  39. const config = ref<TestConfig>(props.modelValue || {
  40. retryEnabled: false,
  41. maxRetries: 0,
  42. retryInterval: 100
  43. })
  44. watch(
  45. () => props.modelValue,
  46. (newVal) => {
  47. config.value = newVal || {
  48. retryEnabled: false,
  49. }
  50. }
  51. )
  52. const toggleRetry = () => {
  53. config.value.retryEnabled = !config.value.retryEnabled
  54. handleConfigChange()
  55. }
  56. const handleConfigChange = () => {
  57. emit('update:modelValue', config.value)
  58. }
  59. </script>
  60. <style lang="less" scoped>
  61. .beautify {
  62. padding-bottom: 6px;
  63. border-bottom: 1px solid #eee;
  64. }
  65. </style>