Skip to content

Commit 21f7a85

Browse files
committed
fix(demo): account list page validate and save
1 parent 8e4f486 commit 21f7a85

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/views/demo/system/account/AccountModal.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
emits: ['success', 'register'],
1717
setup(_, { emit }) {
1818
const isUpdate = ref(true);
19+
const rowId = ref('');
1920
2021
const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
2122
labelWidth: 100,
@@ -32,6 +33,7 @@
3233
isUpdate.value = !!data?.isUpdate;
3334
3435
if (unref(isUpdate)) {
36+
rowId.value = data.record.id;
3537
setFieldsValue({
3638
...data.record,
3739
});
@@ -59,7 +61,7 @@
5961
// TODO custom api
6062
console.log(values);
6163
closeModal();
62-
emit('success');
64+
emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } });
6365
} finally {
6466
setModalProps({ confirmLoading: false });
6567
}

src/views/demo/system/account/account.data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const accountFormSchema: FormSchema[] = [
6161
label: '密码',
6262
component: 'InputPassword',
6363
required: true,
64-
show: false,
64+
ifShow: false,
6565
},
6666
{
6767
label: '角色',

src/views/demo/system/account/index.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@
4545
components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction },
4646
setup() {
4747
const [registerModal, { openModal }] = useModal();
48-
const [registerTable, { reload }] = useTable({
48+
const [registerTable, { reload, updateTableDataRecord }] = useTable({
4949
title: '账号列表',
5050
api: getAccountList,
51+
rowKey: 'id',
5152
columns,
5253
formConfig: {
5354
labelWidth: 120,
@@ -82,8 +83,15 @@
8283
console.log(record);
8384
}
8485
85-
function handleSuccess() {
86-
reload();
86+
function handleSuccess({ isUpdate, values }) {
87+
if (isUpdate) {
88+
// 演示不刷新表格直接更新内部数据。
89+
// 注意:updateTableDataRecord要求表格的rowKey属性为string并且存在于每一行的record的keys中
90+
const result = updateTableDataRecord(values.id, values);
91+
console.log(result);
92+
} else {
93+
reload();
94+
}
8795
}
8896
8997
function handleSelect(deptId = '') {

0 commit comments

Comments
 (0)