车间能级提升-智能设备管理系统
朱桂飞
2025-01-09 3e8f7f239bedae0b4f04a1ac6bd443ba6298f73c
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<script setup lang="ts">
import type { Recordable } from '@vben/types';
 
import { nextTick } from 'vue';
 
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
import { getPopupContainer, listToTree } from '@vben/utils';
 
import { Popconfirm, Space } from 'ant-design-vue';
 
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter/vxe-table';
 
import { treeList, treeRemove } from './api';
import { columns, querySchema } from './data';
import treeModal from './tree-modal.vue';
 
const formOptions: VbenFormProps = {
  commonConfig: {
    labelWidth: 80,
  },
  schema: querySchema(),
  wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
};
 
const gridOptions: VxeGridProps = {
  columns,
  height: 'auto',
  keepSource: true,
  pagerConfig: {
    enabled: false,
  },
  proxyConfig: {
    ajax: {
      query: async (_, formValues = {}) => {
        const resp = await treeList({
          ...formValues,
        });
        const treeData = listToTree(resp, {
          id: 'id',
          pid: 'parentId',
          children: 'children',
        });
        return { rows: treeData };
      },
      // 默认请求接口后展开全部 不需要可以删除这段
      querySuccess: () => {
        nextTick(() => {
          expandAll();
        });
      },
    },
  },
  rowConfig: {
    isHover: true,
    keyField: 'id',
  },
 
  treeConfig: {
    parentField: 'parentId',
    rowField: 'id',
    transform: false,
  },
};
 
const [BasicTable, tableApi] = useVbenVxeGrid({ formOptions, gridOptions });
const [TreeModal, modalApi] = useVbenModal({
  connectedComponent: treeModal,
});
 
function handleAdd() {
  modalApi.setData({ update: false });
  modalApi.open();
}
 
async function handleEdit(row: Recordable<any>) {
  modalApi.setData({ id: row.id, update: true });
  modalApi.open();
}
 
async function handleDelete(row: Recordable<any>) {
  await treeRemove(row.id);
  await tableApi.query();
}
 
function expandAll() {
  tableApi.grid?.setAllTreeExpand(true);
}
 
function collapseAll() {
  tableApi.grid?.setAllTreeExpand(false);
}
</script>
 
<template>
  <Page :auto-content-height="true">
    <BasicTable>
      <template #toolbar-actions>
        <span class="pl-[7px] text-[16px]">测试树列表</span>
      </template>
      <template #toolbar-tools>
        <Space>
          <a-button @click="collapseAll">
            {{ $t('pages.common.collapse') }}
          </a-button>
          <a-button @click="expandAll">
            {{ $t('pages.common.expand') }}
          </a-button>
          <a-button
            type="primary"
            v-access:code="['system:tree:add']"
            @click="handleAdd"
          >
            {{ $t('pages.common.add') }}
          </a-button>
        </Space>
      </template>
      <template #action="{ row }">
        <Space>
          <ghost-button
            v-access:code="['system:tree:edit']"
            @click.stop="handleEdit(row)"
          >
            {{ $t('pages.common.edit') }}
          </ghost-button>
          <Popconfirm
            :get-popup-container="getPopupContainer"
            placement="left"
            title="确认删除?"
            @confirm="handleDelete(row)"
          >
            <ghost-button
              danger
              v-access:code="['system:tree:remove']"
              @click.stop=""
            >
              {{ $t('pages.common.delete') }}
            </ghost-button>
          </Popconfirm>
        </Space>
      </template>
    </BasicTable>
    <TreeModal @reload="tableApi.query()" />
  </Page>
</template>