提交 b4344dca authored 作者: leon's avatar leon

fix用户编辑修改

上级 3f4f5512
......@@ -25,10 +25,7 @@
</template>
<FormAction v-bind="getFormActionBindProps" @toggle-advanced="handleToggleAdvanced">
<template
#[item]="data"
v-for="item in ['resetBefore', 'submitBefore', 'advanceBefore', 'advanceAfter']"
>
<template #[item]="data" v-for="item in ['resetBefore', 'submitBefore', 'advanceBefore', 'advanceAfter']">
<slot :name="item" v-bind="data || {}"></slot>
</template>
</FormAction>
......@@ -111,9 +108,7 @@
};
});
const getBindValue = computed(
() => ({ ...attrs, ...props, ...unref(getProps) } as Recordable),
);
const getBindValue = computed(() => ({ ...attrs, ...props, ...unref(getProps) } as Recordable));
const getSchema = computed((): FormSchema[] => {
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
......@@ -133,9 +128,7 @@
}
}
if (unref(getProps).showAdvancedButton) {
return cloneDeep(
schemas.filter((schema) => schema.component !== 'Divider') as FormSchema[],
);
return cloneDeep(schemas.filter((schema) => schema.component !== 'Divider') as FormSchema[]);
} else {
return cloneDeep(schemas as FormSchema[]);
}
......@@ -210,6 +203,9 @@
(schemas) => {
resetSchema(schemas ?? []);
},
{
deep: true,
},
);
watch(
......@@ -296,9 +292,7 @@
formActionType: formActionType as any,
setFormModel,
getFormClass,
getFormActionBindProps: computed(
(): Recordable => ({ ...getProps.value, ...advanceState }),
),
getFormActionBindProps: computed((): Recordable => ({ ...getProps.value, ...advanceState })),
...formActionType,
};
},
......
......@@ -16,7 +16,7 @@
<script lang="ts" setup name="UserDrawer">
import { defineEmits, ref, computed, unref } from 'vue';
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema, StatusValEnum } from './schema';
import { formSchema, StatusValEnum, PASSWORD } from './schema';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import * as UserApi from '/@/api/system/userApi';
import { useAsyncState } from '@vueuse/core';
......@@ -27,12 +27,25 @@
const isUpdate = ref(true);
const entityId = ref(0);
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
const useFormProps: any = ref({
labelWidth: 120,
schemas: formSchema,
showActionButtonGroup: false,
});
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm(useFormProps.value);
/**
* @description: 编辑时候影藏密码表单项 , 创建时候显示
*/
const handlePwdFiled = () => {
useFormProps.value.schemas?.forEach((item: any) => {
if (item.field === PASSWORD) {
item.show = !unref(isUpdate);
}
});
};
// id 查询
const {
state: detail,
......@@ -55,6 +68,8 @@
isUpdate.value = !!data?.isUpdate;
entityId.value = data?.record?.id;
handlePwdFiled();
if (unref(isUpdate)) {
await execute();
if (detail.value) {
......@@ -63,14 +78,16 @@
label: data.record.distributor?.name || getDistributorText(data.record.distributorId),
value: data.record.distributorId,
};
formData.roleList =
formData.roleList?.map((item: any) => {
return {
label: item.remark,
value: item.id,
};
}) || [];
console.log('formData', formData);
// 因为角色是单选。所以这里要把数组转换成单个对象
let roleObj = {};
if (formData.roleList && formData.roleList[0]) {
const item = formData.roleList[0];
roleObj = {
label: item.remark,
value: item.id,
};
}
formData.roleList = roleObj;
await setFieldsValue(formData);
}
}
......
......@@ -96,6 +96,8 @@ for (const key in YesNoEnum) {
const colProps = { xs: { span: 24 }, sm: { span: 24 }, lg: { span: 8 } };
const colPropsInDrawer = { span: 24 };
export const PASSWORD = 'password';
export const schema = {
model: 'User',
viewInPage: true,
......@@ -132,7 +134,7 @@ export const schema = {
table: {},
},
{
field: 'password',
field: PASSWORD,
label: '密码',
defaultValue: undefined,
form: {
......@@ -191,11 +193,10 @@ export const schema = {
valueField: 'id',
allowClear: false,
placeholder: '角色',
mode: 'multiple',
},
colProps,
component: 'ApiSelect',
rules: [{ required: true, type: 'array', message: '请选择角色' }],
rules: [{ required: true, type: 'object', message: '请选择角色' }],
},
table: {
customRender: ({ text }) => {
......@@ -325,7 +326,7 @@ export const schema = {
};
const queryFields = ['distributorId', 'username', 'realName', 'mobile', 'status', 'deleteStatus', 'createTime'];
const editFields = ['distributorId', 'username', 'realName', 'mobile', 'roleList', 'deleteStatus'];
const editFields = ['distributorId', 'username', PASSWORD, 'realName', 'mobile', 'roleList', 'deleteStatus'];
const tableFields = [
'distributorId',
'username',
......@@ -341,7 +342,6 @@ const descriptionFields = [
'id',
'distributorId',
'username',
'password',
'realName',
'mobile',
'status',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论