befly-admin 3.4.55 → 3.4.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,174 +0,0 @@
1
- /**
2
- * 表格页面通用组合式函数
3
- * 封装分页、loading、数据加载等公共逻辑
4
- */
5
- import { ref, reactive } from 'vue';
6
- import { MessagePlugin } from 'tdesign-vue-next';
7
- import { $Http } from '@/plugins/http';
8
-
9
- /**
10
- * 创建表格页面通用逻辑
11
- * @param {Object} options 配置项
12
- * @param {string} options.apiUrl - 列表接口地址
13
- * @param {Function} [options.afterLoad] - 数据加载后的回调
14
- * @param {Function} [options.transformData] - 数据转换函数
15
- * @returns {Object} 响应式数据和方法
16
- */
17
- export function useTablePage(options) {
18
- const { apiUrl, afterLoad, transformData } = options;
19
-
20
- // 分页配置
21
- const pagerConfig = reactive({
22
- currentPage: 1,
23
- limit: 30,
24
- total: 0
25
- });
26
-
27
- // 加载状态
28
- const loading = ref(false);
29
-
30
- // 表格数据
31
- const tableData = ref([]);
32
-
33
- // 当前选中行
34
- const currentRow = ref(null);
35
-
36
- // 选中行的 keys
37
- const activeRowKeys = ref([]);
38
- const selectedRowKeys = ref([]);
39
-
40
- /**
41
- * 加载列表数据
42
- * @param {Object} [extraParams={}] - 额外的查询参数
43
- */
44
- async function loadData(extraParams = {}) {
45
- loading.value = true;
46
- try {
47
- const res = await $Http(apiUrl, {
48
- page: pagerConfig.currentPage,
49
- limit: pagerConfig.limit,
50
- ...extraParams
51
- });
52
-
53
- let data = res.data.lists || [];
54
-
55
- // 数据转换
56
- if (transformData) {
57
- data = transformData(data);
58
- }
59
-
60
- tableData.value = data;
61
- pagerConfig.total = res.data.total || 0;
62
-
63
- // 自动选中并高亮第一行
64
- if (tableData.value.length > 0) {
65
- currentRow.value = tableData.value[0];
66
- selectedRowKeys.value = [tableData.value[0].id];
67
- activeRowKeys.value = [tableData.value[0].id];
68
- } else {
69
- currentRow.value = null;
70
- selectedRowKeys.value = [];
71
- activeRowKeys.value = [];
72
- }
73
-
74
- // 执行加载后回调
75
- if (afterLoad) {
76
- afterLoad(tableData.value);
77
- }
78
- } catch (error) {
79
- console.error('加载数据失败:', error);
80
- MessagePlugin.error('加载数据失败');
81
- } finally {
82
- loading.value = false;
83
- }
84
- }
85
-
86
- /**
87
- * 刷新数据
88
- */
89
- function handleRefresh() {
90
- loadData();
91
- }
92
-
93
- /**
94
- * 分页改变
95
- * @param {Object} param
96
- * @param {number} param.currentPage - 当前页码
97
- */
98
- function onPageChange({ currentPage }) {
99
- pagerConfig.currentPage = currentPage;
100
- loadData();
101
- }
102
-
103
- /**
104
- * 每页条数改变
105
- * @param {Object} param
106
- * @param {number} param.pageSize - 每页条数
107
- */
108
- function handleSizeChange({ pageSize }) {
109
- pagerConfig.limit = pageSize;
110
- pagerConfig.currentPage = 1;
111
- loadData();
112
- }
113
-
114
- /**
115
- * 高亮行变化(点击行选中)
116
- * @param {Array} value - 选中的行 keys
117
- * @param {Object} param
118
- * @param {Array} param.activeRowData - 选中的行数据
119
- */
120
- function onActiveChange(value, { activeRowData }) {
121
- activeRowKeys.value = value;
122
- selectedRowKeys.value = value;
123
- // 更新当前高亮的行数据
124
- if (activeRowData && activeRowData.length > 0) {
125
- currentRow.value = activeRowData[0];
126
- } else if (tableData.value.length > 0) {
127
- // 如果取消高亮,默认显示第一行
128
- currentRow.value = tableData.value[0];
129
- selectedRowKeys.value = [tableData.value[0].id];
130
- activeRowKeys.value = [tableData.value[0].id];
131
- } else {
132
- currentRow.value = null;
133
- }
134
- }
135
-
136
- /**
137
- * 单选变化
138
- * @param {Array} value - 选中的行 keys
139
- * @param {Object} param
140
- * @param {Array} param.selectedRowData - 选中的行数据
141
- */
142
- function onSelectChange(value, { selectedRowData }) {
143
- selectedRowKeys.value = value;
144
- activeRowKeys.value = value;
145
- // 更新当前选中的行数据
146
- if (selectedRowData && selectedRowData.length > 0) {
147
- currentRow.value = selectedRowData[0];
148
- } else if (tableData.value.length > 0) {
149
- // 如果取消选中,默认显示第一行
150
- currentRow.value = tableData.value[0];
151
- selectedRowKeys.value = [tableData.value[0].id];
152
- activeRowKeys.value = [tableData.value[0].id];
153
- } else {
154
- currentRow.value = null;
155
- }
156
- }
157
-
158
- return {
159
- // 数据
160
- pagerConfig: pagerConfig,
161
- loading: loading,
162
- tableData: tableData,
163
- currentRow: currentRow,
164
- activeRowKeys: activeRowKeys,
165
- selectedRowKeys: selectedRowKeys,
166
- // 方法
167
- loadData: loadData,
168
- handleRefresh: handleRefresh,
169
- onPageChange: onPageChange,
170
- handleSizeChange: handleSizeChange,
171
- onActiveChange: onActiveChange,
172
- onSelectChange: onSelectChange
173
- };
174
- }