Ben Lin
2024-06-25 f73947395184fd635df3d74c1c4b2701d0c708c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<template>
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <DeptTree class="w-1/4 xl:w-1/5" @select="handleSelect" />
    <div class="m-4 vxebasic-form-container">
      <VxeBasicTable ref="tableRef" v-bind="gridOptions">
        <template #action="{ row }">
          <TableAction outside :actions="createActions(row)" />
        </template>
      </VxeBasicTable>
    </div>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { reactive, ref } from 'vue';
  import { ActionItem, TableAction } from '@/components/Table';
  import { getAccountList } from '@/api/demo/system';
  import { PageWrapper } from '@/components/Page';
  import DeptTree from '../account/DeptTree.vue';
  import { columns, searchFormSchema } from './vxeAccount.data';
  import { BasicTableProps, VxeBasicTable, VxeGridInstance } from '@/components/VxeTable';
 
  const tableRef = ref<VxeGridInstance>();
  const searchInfo = ref();
  const gridOptions = reactive<BasicTableProps>({
    id: 'VxeTable',
    keepSource: true,
    columns: columns,
    formConfig: {
      enabled: true,
      items: searchFormSchema,
    },
    height: 'auto',
    proxyConfig: {
      ajax: {
        query: async ({ page, form }) => {
          return getAccountList({
            page: page.currentPage,
            pageSize: page.pageSize,
            ...form,
            searchInfo: searchInfo.value,
          });
        },
      },
    },
  });
 
  const handleSelect = (deptId = '') => {
    searchInfo.value = deptId;
    if (tableRef.value) {
      tableRef.value.commitProxy('query');
    }
  };
 
  // 操作按钮(权限控制)
  const createActions = (record) => {
    const actions: ActionItem[] = [
      {
        label: '详情',
        onClick: () => {
          console.log(record);
        },
      },
      {
        label: '编辑',
        onClick: () => {},
      },
      {
        label: '删除',
        color: 'error',
        popConfirm: {
          title: '是否确认删除',
          confirm: () => {
            tableRef.value?.remove(record);
          },
        },
      },
    ];
 
    return actions;
  };
</script>
<style lang="less" scope>
  .vxebasic-form-container {
    flex: auto;
  }
</style>