fix: devtools warning

master^2
allen 2026-04-15 16:39:56 +08:00
parent ec9b323195
commit 4a968d9379
4 changed files with 46 additions and 18 deletions

View File

@ -42,12 +42,17 @@ const { b } = useNamespace('collapsible-params');
const open = ref(props.defaultOpen); const open = ref(props.defaultOpen);
// 1
const finalVisibleCount = computed(() =>
Math.max(1, Math.floor(props.visibleCount)),
);
const visibleRows = computed(() => { const visibleRows = computed(() => {
return props.params.slice(0, props.visibleCount); return props.params.slice(0, finalVisibleCount.value);
}); });
const collapsibleRows = computed(() => { const collapsibleRows = computed(() => {
return props.params.slice(props.visibleCount); return props.params.slice(finalVisibleCount.value);
}); });
const bodyStyle = computed(() => { const bodyStyle = computed(() => {

View File

@ -1,3 +1,10 @@
export interface CollapsibleParamsProps {
defaultOpen?: boolean;
maxHeight?: number | string;
params: CollapsibleParamSchema[];
visibleCount?: number;
}
export interface CollapsibleParamOption { export interface CollapsibleParamOption {
[key: string]: any; [key: string]: any;
max?: number; max?: number;

View File

@ -42,6 +42,8 @@ import type { Sortable } from '@vben/hooks';
import type { TipTapProps } from '@vben/plugins/tiptap'; import type { TipTapProps } from '@vben/plugins/tiptap';
import type { Recordable } from '@vben/types'; import type { Recordable } from '@vben/types';
import type { CollapsibleParamsProps } from '@vben-core/shadcn-ui';
import { import {
computed, computed,
defineAsyncComponent, defineAsyncComponent,
@ -68,8 +70,9 @@ import { $t } from '@vben/locales';
import { VbenTiptap } from '@vben/plugins/tiptap'; import { VbenTiptap } from '@vben/plugins/tiptap';
import { isEmpty } from '@vben/utils'; import { isEmpty } from '@vben/utils';
import { message, Modal, notification } from 'ant-design-vue'; import { VbenCollapsibleParams } from '@vben-core/shadcn-ui';
import { message, Modal, notification } from 'ant-design-vue';
type AdapterUploadProps = UploadProps & { type AdapterUploadProps = UploadProps & {
aspectRatio?: string; aspectRatio?: string;
crop?: boolean; crop?: boolean;
@ -606,6 +609,7 @@ export type ComponentType =
| 'Cascader' | 'Cascader'
| 'Checkbox' | 'Checkbox'
| 'CheckboxGroup' | 'CheckboxGroup'
| 'CollapsibleParams'
| 'DatePicker' | 'DatePicker'
| 'DefaultButton' | 'DefaultButton'
| 'Divider' | 'Divider'
@ -640,6 +644,7 @@ export interface ComponentPropsMap {
Cascader: CascaderProps; Cascader: CascaderProps;
Checkbox: CheckboxProps; Checkbox: CheckboxProps;
CheckboxGroup: CheckboxGroupProps; CheckboxGroup: CheckboxGroupProps;
CollapsibleParams: CollapsibleParamsProps;
DatePicker: DatePickerProps; DatePicker: DatePickerProps;
DefaultButton: ButtonProps; DefaultButton: ButtonProps;
Divider: DividerProps; Divider: DividerProps;
@ -725,6 +730,7 @@ async function initComponentAdapter() {
TimePicker, TimePicker,
TreeSelect: withDefaultPlaceholder(TreeSelect, 'select'), TreeSelect: withDefaultPlaceholder(TreeSelect, 'select'),
Upload: withPreviewUpload(), Upload: withPreviewUpload(),
CollapsibleParams: VbenCollapsibleParams,
}; };
// 将组件注册到全局共享状态中 // 将组件注册到全局共享状态中

View File

@ -1,4 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { RadioGroupProps } from 'ant-design-vue';
import type { FormLayout } from '@vben/common-ui'; import type { FormLayout } from '@vben/common-ui';
import type { CollapsibleParamSchema } from '@vben-core/shadcn-ui'; import type { CollapsibleParamSchema } from '@vben-core/shadcn-ui';
@ -15,12 +17,12 @@ import { useVbenForm, z } from '#/adapter/form';
import DocButton from '../doc-button.vue'; import DocButton from '../doc-button.vue';
const layouts: { label: string; value: FormLayout }[] = [ const layouts: RadioGroupProps['options'] = [
{ label: 'Vertical', value: 'vertical' }, { label: 'Vertical', value: 'vertical' },
{ label: 'Horizontal', value: 'horizontal' }, { label: 'Horizontal', value: 'horizontal' },
]; ];
const layout = ref(layouts[0]?.value ?? 'vertical'); const layout = ref<FormLayout>('vertical');
function getNumberValidator(key: string, limit?: [number?, number?]) { function getNumberValidator(key: string, limit?: [number?, number?]) {
let validator = z.number({ let validator = z.number({
@ -144,13 +146,16 @@ const [BaseForm, baseFormApi] = useVbenForm({
class: 'w-auto', class: 'w-auto',
}, },
label: 'QAT', label: 'QAT',
formItemClass: 'col-span-2',
defaultValue: false, defaultValue: false,
}, },
{ {
component: VbenCollapsibleParams, component: 'CollapsibleParams',
componentProps: { componentProps: {
params: paramsSchema, params: paramsSchema,
// maxHeight: 200, // // maxHeight: 200, //
// defaultOpen: true, // false
// visibleCount: 0 // 3111
}, },
modelPropName: 'value', modelPropName: 'value',
fieldName: 'params', fieldName: 'params',
@ -194,7 +199,6 @@ const [BaseForm, baseFormApi] = useVbenForm({
} else { } else {
paramsRef?.updateValues?.({ paramsRef?.updateValues?.({
calib_steps: null, calib_steps: null,
micro_batch_size: 8,
}); });
} }
}, },
@ -208,9 +212,15 @@ const [BaseForm, baseFormApi] = useVbenForm({
}, },
}, },
rules: paramsValidator, rules: paramsValidator,
// defaultValue: { defaultValue: {
// micro_batch_size: 24, micro_batch_size: 8,
// }, learning_rate: 1e-5,
eval_steps: 50,
num_train_epochs: 3,
max_length: 32_768,
warmup_ratio: 0.05,
save_steps: 50,
},
}, },
{ {
component: 'RichEditor', component: 'RichEditor',
@ -230,21 +240,21 @@ function onSubmit(values: Record<string, any>) {
}); });
} }
function onLayoutChange(layout: FormLayout) { function onLayoutChange() {
baseFormApi.setState({ baseFormApi.setState({
layout, layout: layout.value,
}); });
} }
function handleSetFormValue() { function handleSetFormValue() {
baseFormApi.setFieldValue('params', { baseFormApi.setFieldValue('params', {
micro_batch_size: 8, micro_batch_size: 1024,
learning_rate: 1e-5, learning_rate: 1e-5,
eval_steps: 50, eval_steps: 150,
num_train_epochs: 3, num_train_epochs: 13,
max_length: 32_768, max_length: 131_072,
warmup_ratio: 0.05, warmup_ratio: 0.05,
save_steps: 50, save_steps: 150,
}); });
} }
@ -282,7 +292,7 @@ async function handleSubmitFormValue() {
:options="layouts" :options="layouts"
option-type="button" option-type="button"
v-model:value="layout" v-model:value="layout"
@update:value="onLayoutChange" @change="onLayoutChange"
/> />
<Button type="primary" @click="handleSetFormValue"> <Button type="primary" @click="handleSetFormValue">
设置表单值 设置表单值