干燥机配套车间生产管理系统/云平台前端
baoshiwei
2023-03-10 1fb197352b6a263646e4ccd3ed1c7854ede031dd
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
<template>
  <PageWrapper>
    <a-card :bordered="false">
      <BasicTable :loading="loading" :dataSource="dataSource" @register="registerTable" @expand="onExpand" />
    </a-card>
  </PageWrapper>
</template>
 
<script lang="ts" setup>
  import { ref } from 'vue';
  import { defHttp } from '/@/utils/http/axios';
  import { PageWrapper } from '/@/components/Page';
  import { BasicTable, useTable } from '/@/components/Table';
 
  const url = '/mock/api/asynTreeList';
 
  const loading = ref<boolean>(false);
  const dataSource = ref<any[]>([]);
  const [registerTable, { setLoading }] = useTable({
    rowKey: 'id',
    bordered: true,
    canResize: false,
    // 树表格
    isTreeTable: true,
    showIndexColumn: true,
    columns: [
      { title: '名称', dataIndex: 'name' },
      { title: '组件', dataIndex: 'component' },
      { title: '排序', dataIndex: 'orderNum' },
    ],
  });
 
  async function loadData(params) {
    loading.value = true;
    let result = await defHttp.get({ url, params });
    loading.value = false;
    return result.map((item) => {
      if (item.hasChildren) {
        return { ...item, children: [] };
      } else {
        return item;
      }
    });
  }
 
  async function loadRootData() {
    dataSource.value = await loadData({ id: '0' });
  }
 
  loadRootData();
 
  async function onExpand(isExpand, rowData) {
    if (isExpand && rowData.hasChildren && rowData.children.length === 0) {
      rowData.children = await loadData({ id: rowData.id });
    }
  }
</script>