Commit 21f7a854fe2455315287d04e895661ff739bce17

Authored by 无木
1 parent 8e4f486f

fix(demo): account list page validate and save

src/views/demo/system/account/AccountModal.vue
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 emits: ['success', 'register'], 16 emits: ['success', 'register'],
17 setup(_, { emit }) { 17 setup(_, { emit }) {
18 const isUpdate = ref(true); 18 const isUpdate = ref(true);
  19 + const rowId = ref('');
19 20
20 const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({ 21 const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
21 labelWidth: 100, 22 labelWidth: 100,
@@ -32,6 +33,7 @@ @@ -32,6 +33,7 @@
32 isUpdate.value = !!data?.isUpdate; 33 isUpdate.value = !!data?.isUpdate;
33 34
34 if (unref(isUpdate)) { 35 if (unref(isUpdate)) {
  36 + rowId.value = data.record.id;
35 setFieldsValue({ 37 setFieldsValue({
36 ...data.record, 38 ...data.record,
37 }); 39 });
@@ -59,7 +61,7 @@ @@ -59,7 +61,7 @@
59 // TODO custom api 61 // TODO custom api
60 console.log(values); 62 console.log(values);
61 closeModal(); 63 closeModal();
62 - emit('success'); 64 + emit('success', { isUpdate: unref(isUpdate), values: { ...values, id: rowId.value } });
63 } finally { 65 } finally {
64 setModalProps({ confirmLoading: false }); 66 setModalProps({ confirmLoading: false });
65 } 67 }
src/views/demo/system/account/account.data.ts
@@ -61,7 +61,7 @@ export const accountFormSchema: FormSchema[] = [ @@ -61,7 +61,7 @@ export const accountFormSchema: FormSchema[] = [
61 label: '密码', 61 label: '密码',
62 component: 'InputPassword', 62 component: 'InputPassword',
63 required: true, 63 required: true,
64 - show: false, 64 + ifShow: false,
65 }, 65 },
66 { 66 {
67 label: '角色', 67 label: '角色',
src/views/demo/system/account/index.vue
@@ -45,9 +45,10 @@ @@ -45,9 +45,10 @@
45 components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction }, 45 components: { BasicTable, PageWrapper, DeptTree, AccountModal, TableAction },
46 setup() { 46 setup() {
47 const [registerModal, { openModal }] = useModal(); 47 const [registerModal, { openModal }] = useModal();
48 - const [registerTable, { reload }] = useTable({ 48 + const [registerTable, { reload, updateTableDataRecord }] = useTable({
49 title: '账号列表', 49 title: '账号列表',
50 api: getAccountList, 50 api: getAccountList,
  51 + rowKey: 'id',
51 columns, 52 columns,
52 formConfig: { 53 formConfig: {
53 labelWidth: 120, 54 labelWidth: 120,
@@ -82,8 +83,15 @@ @@ -82,8 +83,15 @@
82 console.log(record); 83 console.log(record);
83 } 84 }
84 85
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 + }
87 } 95 }
88 96
89 function handleSelect(deptId = '') { 97 function handleSelect(deptId = '') {