提交 21f7a854 编写于 作者: 无木

fix(demo): account list page validate and save

上级 8e4f486f
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
emits: ['success', 'register'], emits: ['success', 'register'],
setup(_, { emit }) { setup(_, { emit }) {
const isUpdate = ref(true); const isUpdate = ref(true);
const rowId = ref('');
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({ const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
labelWidth: 100, labelWidth: 100,
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
isUpdate.value = !!data?.isUpdate; isUpdate.value = !!data?.isUpdate;
if (unref(isUpdate)) { if (unref(isUpdate)) {
rowId.value = data.record.id;
setFieldsValue({ setFieldsValue({
...data.record, ...data.record,
}); });
...@@ -59,7 +61,7 @@ ...@@ -59,7 +61,7 @@
// TODO custom api // TODO custom api
console.log(values); console.log(values);
closeModal(); closeModal();
emit('success'); emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } });
} finally { } finally {
setModalProps({ confirmLoading: false }); setModalProps({ confirmLoading: false });
} }
......
...@@ -61,7 +61,7 @@ export const accountFormSchema: FormSchema[] = [ ...@@ -61,7 +61,7 @@ export const accountFormSchema: FormSchema[] = [
label: '密码', label: '密码',
component: 'InputPassword', component: 'InputPassword',
required: true, required: true,
show: false, ifShow: false,
}, },
{ {
label: '角色', label: '角色',
......
...@@ -45,9 +45,10 @@ ...@@ -45,9 +45,10 @@
components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction }, components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction },
setup() { setup() {
const [registerModal, { openModal }] = useModal(); const [registerModal, { openModal }] = useModal();
const [registerTable, { reload }] = useTable({ const [registerTable, { reload, updateTableDataRecord }] = useTable({
title: '账号列表', title: '账号列表',
api: getAccountList, api: getAccountList,
rowKey: 'id',
columns, columns,
formConfig: { formConfig: {
labelWidth: 120, labelWidth: 120,
...@@ -82,8 +83,15 @@ ...@@ -82,8 +83,15 @@
console.log(record); console.log(record);
} }
function handleSuccess() { function handleSuccess({ isUpdate, values }) {
reload(); if (isUpdate) {
// 演示不刷新表格直接更新内部数据。
// 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
const result = updateTableDataRecord(values.id, values);
console.log(result);
} else {
reload();
}
} }
function handleSelect(deptId = '') { function handleSelect(deptId = '') {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册