fix: fix lint and add new form-ui features

feat(form-ui): 在 dependencies 里提供访问extendApi的能力
This commit is contained in:
allen
2026-04-15 14:21:39 +08:00
parent 991408b451
commit 33e2582f60
8 changed files with 192 additions and 189 deletions

View File

@@ -49,6 +49,27 @@ const FieldComponent = computed(() => {
}
});
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;
}
@@ -78,8 +99,8 @@ defineExpose({
/>
</div>
<div class="flex items-center flex-none text-muted-foreground pl-2 gap-2">
<span v-if="data.option.min && data.option.max">
[{{ data.option.min }},{{ data.option.max }}]
<span v-if="limitDisplay">
{{ limitDisplay }}
</span>
<span v-if="data.option.step && data.option.step !== 1">
step:{{ data.option.step }}

View File

@@ -1,4 +1,6 @@
<script setup lang="ts">
import type { Recordable } from '@vben-core/typings';
import type { CollapsibleParamSchema } from './type';
import { computed, nextTick, ref, useTemplateRef, watch } from 'vue';
@@ -29,7 +31,10 @@ const props = withDefaults(defineProps<Props>(), {
const emits = defineEmits<{ 'update:value': [any, string] }>();
const modelValue = defineModel('value');
const modelValue = defineModel('value', {
default: {} as Recordable<CollapsibleParamSchema['defaultValue']>,
});
const visibleRefs = useTemplateRef('visibleRefs');
const collapsibleRefs = useTemplateRef('collapsibleRefs');
@@ -59,11 +64,13 @@ const bodyStyle = computed(() => {
});
function init(force = false) {
const nextValue = { ...modelValue.value };
const nextValue: Recordable<CollapsibleParamSchema['defaultValue']> = {
...modelValue.value,
};
for (const param of props.params) {
if (force || nextValue[param.key] === undefined) {
nextValue[param.key] = param.defaultValue ?? null;
nextValue[param.key] = param.defaultValue ?? undefined;
}
}
@@ -74,25 +81,40 @@ function toggleCollapsed() {
open.value = !open.value;
}
async function onParamValueChange(value: any, key: string) {
async function onParamValueChange(_: any, key: string) {
await nextTick();
emits('update:value', modelValue.value, key);
}
function resetValue() {
function resetValues() {
if (visibleRefs.value)
for (const rowRef of visibleRefs.value) {
rowRef.reset();
rowRef?.reset();
}
if (collapsibleRefs.value)
for (const rowRef of collapsibleRefs.value) {
rowRef.reset();
rowRef?.reset();
}
init(true);
}
function updateValues(
values: Recordable<CollapsibleParamSchema['defaultValue']>,
) {
const newValue = {} as Recordable<CollapsibleParamSchema['defaultValue']>;
for (const key in values) {
if (!Object.hasOwn(values, key)) continue;
if (!Object.hasOwn(modelValue.value, key)) continue;
newValue[key] = values[key];
modelValue.value = { ...modelValue.value, ...newValue };
}
}
watch(
() => props.params,
() => init(),
@@ -101,7 +123,8 @@ watch(
defineExpose({
toggleCollapsed,
resetValue,
resetValues,
updateValues,
});
</script>