Skip to content

Commit

Permalink
fix(demo): account list page validate and save
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetfan committed Jun 7, 2021
1 parent 8e4f486 commit 21f7a85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/views/demo/system/account/AccountModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
emits: ['success', 'register'],
setup(_, { emit }) {
const isUpdate = ref(true);
const rowId = ref('');
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
labelWidth: 100,
Expand All @@ -32,6 +33,7 @@
isUpdate.value = !!data?.isUpdate;
if (unref(isUpdate)) {
rowId.value = data.record.id;
setFieldsValue({
...data.record,
});
Expand Down Expand Up @@ -59,7 +61,7 @@
// TODO custom api
console.log(values);
closeModal();
emit('success');
emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } });
} finally {
setModalProps({ confirmLoading: false });
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/demo/system/account/account.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const accountFormSchema: FormSchema[] = [
label: '密码',
component: 'InputPassword',
required: true,
show: false,
ifShow: false,
},
{
label: '角色',
Expand Down
14 changes: 11 additions & 3 deletions src/views/demo/system/account/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction },
setup() {
const [registerModal, { openModal }] = useModal();
const [registerTable, { reload }] = useTable({
const [registerTable, { reload, updateTableDataRecord }] = useTable({
title: '账号列表',
api: getAccountList,
rowKey: 'id',
columns,
formConfig: {
labelWidth: 120,
Expand Down Expand Up @@ -82,8 +83,15 @@
console.log(record);
}
function handleSuccess() {
reload();
function handleSuccess({ isUpdate, values }) {
if (isUpdate) {
// 演示不刷新表格直接更新内部数据。
// 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
const result = updateTableDataRecord(values.id, values);
console.log(result);
} else {
reload();
}
}
function handleSelect(deptId = '') {
Expand Down

0 comments on commit 21f7a85

Please sign in to comment.