fix: naive ui form reset does not meet expectations (#4569)
* fix: naive ui form reset does not meet expectations * fix: typopull/48/MERGE
parent
402eaf4275
commit
d37e2f599c
|
@ -3,8 +3,8 @@ import { baseRequestClient, requestClient } from '#/api/request';
|
||||||
export namespace AuthApi {
|
export namespace AuthApi {
|
||||||
/** 登录接口参数 */
|
/** 登录接口参数 */
|
||||||
export interface LoginParams {
|
export interface LoginParams {
|
||||||
password: string;
|
password?: string;
|
||||||
username: string;
|
username?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 登录接口返回值 */
|
/** 登录接口返回值 */
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { baseRequestClient, requestClient } from '#/api/request';
|
||||||
export namespace AuthApi {
|
export namespace AuthApi {
|
||||||
/** 登录接口参数 */
|
/** 登录接口参数 */
|
||||||
export interface LoginParams {
|
export interface LoginParams {
|
||||||
password: string;
|
password?: string;
|
||||||
username: string;
|
username?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 登录接口返回值 */
|
/** 登录接口返回值 */
|
||||||
|
|
|
@ -84,7 +84,10 @@ setupVbenForm<FormComponentType>({
|
||||||
Upload: NUpload,
|
Upload: NUpload,
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
|
// naive-ui组件不接受onChang事件,所以需要禁用
|
||||||
disabledOnChangeListener: true,
|
disabledOnChangeListener: true,
|
||||||
|
// naive-ui组件的空值为null,不能是undefined,否则重置表单时不生效
|
||||||
|
emptyStateValue: null,
|
||||||
baseModelPropName: 'value',
|
baseModelPropName: 'value',
|
||||||
modelPropNameMap: {
|
modelPropNameMap: {
|
||||||
Checkbox: 'checked',
|
Checkbox: 'checked',
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { baseRequestClient, requestClient } from '#/api/request';
|
||||||
export namespace AuthApi {
|
export namespace AuthApi {
|
||||||
/** 登录接口参数 */
|
/** 登录接口参数 */
|
||||||
export interface LoginParams {
|
export interface LoginParams {
|
||||||
password: string;
|
password?: string;
|
||||||
username: string;
|
username?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 登录接口返回值 */
|
/** 登录接口返回值 */
|
||||||
|
|
|
@ -43,8 +43,13 @@ export function setupVbenForm<
|
||||||
>(options: VbenFormAdapterOptions<T>) {
|
>(options: VbenFormAdapterOptions<T>) {
|
||||||
const { components, config, defineRules } = options;
|
const { components, config, defineRules } = options;
|
||||||
|
|
||||||
DEFAULT_FORM_COMMON_CONFIG.disabledOnChangeListener =
|
const { disabledOnChangeListener = false, emptyStateValue = undefined } =
|
||||||
config?.disabledOnChangeListener ?? false;
|
(config || {}) as FormCommonConfig;
|
||||||
|
|
||||||
|
Object.assign(DEFAULT_FORM_COMMON_CONFIG, {
|
||||||
|
disabledOnChangeListener,
|
||||||
|
emptyStateValue,
|
||||||
|
});
|
||||||
|
|
||||||
if (defineRules) {
|
if (defineRules) {
|
||||||
for (const key of Object.keys(defineRules)) {
|
for (const key of Object.keys(defineRules)) {
|
||||||
|
|
|
@ -33,6 +33,7 @@ const {
|
||||||
description,
|
description,
|
||||||
disabled,
|
disabled,
|
||||||
disabledOnChangeListener,
|
disabledOnChangeListener,
|
||||||
|
emptyStateValue,
|
||||||
fieldName,
|
fieldName,
|
||||||
formFieldProps,
|
formFieldProps,
|
||||||
label,
|
label,
|
||||||
|
@ -55,7 +56,7 @@ const formApi = formRenderProps.form;
|
||||||
|
|
||||||
const isInValid = computed(() => errors.value?.length > 0);
|
const isInValid = computed(() => errors.value?.length > 0);
|
||||||
|
|
||||||
const fieldComponent = computed(() => {
|
const FieldComponent = computed(() => {
|
||||||
const finalComponent = isString(component)
|
const finalComponent = isString(component)
|
||||||
? componentMap.value[component]
|
? componentMap.value[component]
|
||||||
: component;
|
: component;
|
||||||
|
@ -213,7 +214,7 @@ function fieldBindEvent(slotProps: Record<string, any>) {
|
||||||
if (bindEventField) {
|
if (bindEventField) {
|
||||||
return {
|
return {
|
||||||
[`onUpdate:${bindEventField}`]: handler,
|
[`onUpdate:${bindEventField}`]: handler,
|
||||||
[bindEventField]: value,
|
[bindEventField]: value === undefined ? emptyStateValue : value,
|
||||||
onChange: disabledOnChangeListener
|
onChange: disabledOnChangeListener
|
||||||
? undefined
|
? undefined
|
||||||
: (e: Record<string, any>) => {
|
: (e: Record<string, any>) => {
|
||||||
|
@ -300,7 +301,7 @@ function autofocus() {
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<component
|
<component
|
||||||
:is="fieldComponent"
|
:is="FieldComponent"
|
||||||
ref="fieldComponentRef"
|
ref="fieldComponentRef"
|
||||||
:class="{
|
:class="{
|
||||||
'border-destructive focus:border-destructive hover:border-destructive/80 focus:shadow-[0_0_0_2px_rgba(255,38,5,0.06)]':
|
'border-destructive focus:border-destructive hover:border-destructive/80 focus:shadow-[0_0_0_2px_rgba(255,38,5,0.06)]':
|
||||||
|
|
|
@ -87,6 +87,7 @@ const computedSchema = computed(
|
||||||
controlClass = '',
|
controlClass = '',
|
||||||
disabled,
|
disabled,
|
||||||
disabledOnChangeListener = false,
|
disabledOnChangeListener = false,
|
||||||
|
emptyStateValue = undefined,
|
||||||
formFieldProps = {},
|
formFieldProps = {},
|
||||||
formItemClass = '',
|
formItemClass = '',
|
||||||
hideLabel = false,
|
hideLabel = false,
|
||||||
|
@ -107,6 +108,7 @@ const computedSchema = computed(
|
||||||
return {
|
return {
|
||||||
disabled,
|
disabled,
|
||||||
disabledOnChangeListener,
|
disabledOnChangeListener,
|
||||||
|
emptyStateValue,
|
||||||
hideLabel,
|
hideLabel,
|
||||||
hideRequiredMark,
|
hideRequiredMark,
|
||||||
labelWidth,
|
labelWidth,
|
||||||
|
|
|
@ -153,6 +153,10 @@ export interface FormCommonConfig {
|
||||||
* @default false
|
* @default false
|
||||||
*/
|
*/
|
||||||
disabledOnChangeListener?: boolean;
|
disabledOnChangeListener?: boolean;
|
||||||
|
/**
|
||||||
|
* 所有表单项的空状态值,默认都是undefined,naive-ui的空状态值是null
|
||||||
|
*/
|
||||||
|
emptyStateValue?: null | undefined;
|
||||||
/**
|
/**
|
||||||
* 所有表单项的控件样式
|
* 所有表单项的控件样式
|
||||||
* @default {}
|
* @default {}
|
||||||
|
@ -341,6 +345,7 @@ export interface VbenFormAdapterOptions<
|
||||||
config?: {
|
config?: {
|
||||||
baseModelPropName?: string;
|
baseModelPropName?: string;
|
||||||
disabledOnChangeListener?: boolean;
|
disabledOnChangeListener?: boolean;
|
||||||
|
emptyStateValue?: null | undefined;
|
||||||
modelPropNameMap?: Partial<Record<T, string>>;
|
modelPropNameMap?: Partial<Record<T, string>>;
|
||||||
};
|
};
|
||||||
defineRules?: {
|
defineRules?: {
|
||||||
|
|
|
@ -67,10 +67,7 @@ interface AuthenticationProps {
|
||||||
submitButtonText?: string;
|
submitButtonText?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LoginAndRegisterParams {
|
type LoginAndRegisterParams = Record<string, any>;
|
||||||
password: string;
|
|
||||||
username: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface LoginCodeParams {
|
interface LoginCodeParams {
|
||||||
code: string;
|
code: string;
|
||||||
|
|
|
@ -193,8 +193,8 @@ async function init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// form 由 vben-form代替,所以不适配formConfig,这里给出警告
|
// form 由 vben-form代替,所以不适配formConfig,这里给出警告
|
||||||
const formConfig = defaultGridOptions.formConfig;
|
const formConfig = options.value.formConfig;
|
||||||
if (formConfig?.enabled) {
|
if (formConfig) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'[Vben Vxe Table]: The formConfig in the grid is not supported, please use the `formOptions` props',
|
'[Vben Vxe Table]: The formConfig in the grid is not supported, please use the `formOptions` props',
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { acceptHMRUpdate, defineStore } from 'pinia';
|
import { acceptHMRUpdate, defineStore } from 'pinia';
|
||||||
|
|
||||||
interface BasicUserInfo {
|
interface BasicUserInfo {
|
||||||
|
[key: string]: any;
|
||||||
/**
|
/**
|
||||||
* 头像
|
* 头像
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
export * from './helpers';
|
export * from './helpers';
|
||||||
|
export * from '@vben-core/shared/cache';
|
||||||
export * from '@vben-core/shared/color';
|
export * from '@vben-core/shared/color';
|
||||||
export * from '@vben-core/shared/utils';
|
export * from '@vben-core/shared/utils';
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { baseRequestClient, requestClient } from '#/api/request';
|
||||||
export namespace AuthApi {
|
export namespace AuthApi {
|
||||||
/** 登录接口参数 */
|
/** 登录接口参数 */
|
||||||
export interface LoginParams {
|
export interface LoginParams {
|
||||||
password: string;
|
password?: string;
|
||||||
username: string;
|
username?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 登录接口返回值 */
|
/** 登录接口返回值 */
|
||||||
|
|
Loading…
Reference in New Issue