gaoluyang
2026-06-24 c0cb161bb52ce0fbdce5c66ec391d107c75e2452
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<script setup lang="ts">
import type { CollapsibleParamSchema } from './type';
 
import { computed } from 'vue';
 
import { globalShareState } from '..\..\..\..\..\base\shared\src\global-state';
 
interface Props {
  data: CollapsibleParamSchema;
}
const props = defineProps<Props>();
 
const modelValue = defineModel('value');
 
const finalOption = computed(() => {
  const { type, ...otherOption } = props.data.option;
 
  if (type === 'number' || type === 'exponential') {
    return {
      step: props.data.option.step ?? 1,
      min: props.data.option.min,
      max: props.data.option.max,
      precision: props.data.option.precision,
      ...otherOption,
    };
  }
 
  return otherOption;
});
 
const components = globalShareState.getComponents();
 
const FieldComponent = computed(() => {
  switch (props.data.option.type) {
    case 'exponential':
    case 'number': {
      return components.InputNumber;
    }
    case 'select': {
      return components.Select;
    }
    case 'string': {
      return components.Input;
    }
 
    default: {
      return components.InputNumber;
    }
  }
});
 
const limitDisplay = computed(() => {
  if (
    props.data.option.min !== null &&
    props.data.option.min !== undefined &&
    props.data.option.max !== null &&
    props.data.option.max !== undefined
  ) {
    return `[${props.data.option.min},${props.data.option.max}]`;
  }
 
  if (props.data.option.min !== null && props.data.option.min !== undefined) {
    return `min:${props.data.option.min}`;
  }
 
  if (props.data.option.max !== null && props.data.option.max !== undefined) {
    return `max:${props.data.option.max}`;
  }
 
  return '';
});
 
function reset() {
  modelValue.value = props.data.defaultValue;
}
 
defineExpose({
  reset,
});
</script>
 
<template>
  <div
    class="body-row flex items-center w-full flex-nowrap not-last-of-type:border-b"
  >
    <div
      class="body-cell pt-2 pb-2 px-5 leading-[1.5rem] flex items-center flex-nowrap"
    >
      {{ data.key }}
    </div>
    <div
      class="body-cell pt-2 pb-2 px-5 leading-[1.5rem] flex items-center flex-nowrap"
    >
      <div class="flex-auto w-full">
        <component
          :is="FieldComponent"
          v-bind="finalOption"
          v-model:value="modelValue"
        />
      </div>
      <div class="flex items-center flex-none text-muted-foreground pl-2 gap-2">
        <span v-if="limitDisplay">
          {{ limitDisplay }}
        </span>
        <span v-if="data.option.step && data.option.step !== 1">
          step:{{ data.option.step }}
        </span>
      </div>
    </div>
    <div
      class="body-cell pt-2 pb-2 px-5 leading-[1.5rem] flex items-center flex-nowrap w-full"
    >
      <p
        class="line-clamp-2"
        v-tippy="{
          content: data.description,
        }"
      >
        {{ data.description }}
      </p>
    </div>
  </div>
</template>