zhou zhou
14 小时以前 46d872c1a5b77aa8799de4a64888a0a24a1422d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<template>
  <div class="flex-cb mb-4 last:mb-2" :class="{ 'mobile-hide': config.mobileHide }">
    <span class="text-sm">{{ config.label }}</span>
 
    <!-- 开关类型 -->
    <ElSwitch v-if="config.type === 'switch'" :model-value="modelValue" @change="handleChange" />
 
    <!-- 数字输入类型 -->
    <ElInputNumber
      v-else-if="config.type === 'input-number'"
      :model-value="modelValue"
      :min="config.min"
      :max="config.max"
      :step="config.step"
      :style="config.style"
      :controls-position="config.controlsPosition"
      @change="handleChange"
    />
 
    <!-- 选择器类型 -->
    <ElSelect
      v-else-if="config.type === 'select'"
      :model-value="modelValue"
      :style="config.style"
      @change="handleChange"
    >
      <ElOption
        v-for="option in normalizedOptions"
        :key="option.value"
        :label="option.label"
        :value="option.value"
      />
    </ElSelect>
  </div>
</template>
 
<script setup>
  const props = defineProps({
    config: { required: true },
    modelValue: { required: true }
  })
  const emit = defineEmits(['change'])
  const normalizedOptions = computed(() => {
    if (!props.config.options) return []
    try {
      if (typeof props.config.options === 'object' && 'value' in props.config.options) {
        return props.config.options.value || []
      }
      return Array.isArray(props.config.options) ? props.config.options : []
    } catch (error) {
      console.warn('Error processing options for config:', props.config.key, error)
      return []
    }
  })
  const handleChange = (value) => {
    try {
      emit('change', value)
    } catch (error) {
      console.error('Error handling change for config:', props.config.key, error)
    }
  }
</script>
 
<style lang="scss" scoped>
  @media screen and (width <= 768px) {
    .mobile-hide {
      display: none !important;
    }
  }
</style>