fix: demo validator usage & types import
parent
e808fe74c1
commit
12a81a7a7d
|
|
@ -30,17 +30,18 @@ const layouts = [
|
||||||
const layout = ref(layouts[0].value);
|
const layout = ref(layouts[0].value);
|
||||||
|
|
||||||
function getNumberValidator(key: string, limit?: [number, number]) {
|
function getNumberValidator(key: string, limit?: [number, number]) {
|
||||||
const validator = z.number({
|
let validator = z.number({
|
||||||
required_error: `${key} 值不能为空`,
|
required_error: `${key} 值不能为空`,
|
||||||
invalid_type_error: `${key} 值只能为数字`,
|
invalid_type_error: `${key} 值只能为数字`,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (limit) {
|
if (limit) {
|
||||||
validator.min(limit[0], { message: `${key} 值不在区间范围内` });
|
validator = validator
|
||||||
validator.max(limit[1], { message: `${key} 值不在区间范围内` });
|
.min(limit[0], { message: `${key} 值不在区间范围内` })
|
||||||
|
.max(limit[1], { message: `${key} 值不在区间范围内` });
|
||||||
}
|
}
|
||||||
|
|
||||||
return validator;
|
return validator.default(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const paramsSchema = [
|
const paramsSchema = [
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@ const modelValue = defineModel('value');
|
||||||
const finalOption = computed(() => {
|
const finalOption = computed(() => {
|
||||||
const { type, ...otherOption } = props.data.option;
|
const { type, ...otherOption } = props.data.option;
|
||||||
|
|
||||||
if (type === 'number') {
|
if (type === 'number' || type === 'exponential') {
|
||||||
return {
|
return {
|
||||||
step: props.data.option.step ?? 1,
|
step: props.data.option.step ?? 1,
|
||||||
min: props.data.option.min,
|
min: props.data.option.min,
|
||||||
max: props.data.option.max,
|
max: props.data.option.max,
|
||||||
precision: props.data.option.precision ?? 0,
|
precision: props.data.option.precision ?? 0,
|
||||||
|
...otherOption,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,10 @@ const bodyStyle = computed(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
if (!modelValue.value) {
|
||||||
|
modelValue.value = {};
|
||||||
|
}
|
||||||
|
|
||||||
for (const param of props.params) {
|
for (const param of props.params) {
|
||||||
modelValue.value[param.key] = param.defaultValue ?? null;
|
modelValue.value[param.key] = param.defaultValue ?? null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { CollapsibleRootEmits, CollapsibleRootProps } from 'reka-ui';
|
import type { CollapsibleRootEmits, CollapsibleRootProps } from 'reka-ui';
|
||||||
|
|
||||||
|
import type { ClassType } from '@vben-core/typings';
|
||||||
|
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
import { ChevronsDown } from 'lucide-vue-next';
|
import { ChevronsDown } from 'lucide-vue-next';
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ export interface CollapsibleParamOption {
|
||||||
min?: number;
|
min?: number;
|
||||||
precision?: number;
|
precision?: number;
|
||||||
step?: number;
|
step?: number;
|
||||||
type: 'exponential' | 'number' | 'select' | 'string';
|
type?: 'exponential' | 'number' | 'select' | 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CollapsibleParamSchema {
|
export interface CollapsibleParamSchema {
|
||||||
defaultValue: number | number[] | string | string[];
|
defaultValue?: number | number[] | string | string[];
|
||||||
description: string;
|
description: string;
|
||||||
key: string;
|
key: string;
|
||||||
option: CollapsibleParamOption;
|
option: CollapsibleParamOption;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { CollapsibleParamSchema } from '@vben-core/shadcn-ui';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
|
|
@ -18,20 +20,21 @@ const layouts = [
|
||||||
const layout = ref(layouts[0].value);
|
const layout = ref(layouts[0].value);
|
||||||
|
|
||||||
function getNumberValidator(key: string, limit?: [number, number]) {
|
function getNumberValidator(key: string, limit?: [number, number]) {
|
||||||
const validator = z.number({
|
let validator = z.number({
|
||||||
required_error: `${key} 值不能为空`,
|
required_error: `${key} 值不能为空`,
|
||||||
invalid_type_error: `${key} 值只能为数字`,
|
invalid_type_error: `${key} 值只能为数字`,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (limit) {
|
if (limit) {
|
||||||
validator.min(limit[0], { message: `${key} 值不在区间范围内` });
|
validator = validator
|
||||||
validator.max(limit[1], { message: `${key} 值不在区间范围内` });
|
.min(limit[0], { message: `${key} 值不在区间范围内` })
|
||||||
|
.max(limit[1], { message: `${key} 值不在区间范围内` });
|
||||||
}
|
}
|
||||||
|
|
||||||
return validator.default(null);
|
return validator.default(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const paramsSchema = [
|
const paramsSchema: CollapsibleParamSchema[] = [
|
||||||
{
|
{
|
||||||
key: 'micro_batch_size',
|
key: 'micro_batch_size',
|
||||||
description: `批次大小,代表模型训练过程中,模型更新模型参数的数据步长,可理解为模型每看多少数据即更新一次模型参数,
|
description: `批次大小,代表模型训练过程中,模型更新模型参数的数据步长,可理解为模型每看多少数据即更新一次模型参数,
|
||||||
|
|
@ -95,7 +98,7 @@ const paramsSchema = [
|
||||||
max: 2_147_483_647,
|
max: 2_147_483_647,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
] as CollapsibleParamSchema[];
|
];
|
||||||
|
|
||||||
const paramsValidator = z.object({
|
const paramsValidator = z.object({
|
||||||
micro_batch_size: getNumberValidator('micro_batch_size', [8, 1024]),
|
micro_batch_size: getNumberValidator('micro_batch_size', [8, 1024]),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue