AiragLogList.vue
7.2 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<template>
<div>
<!--引用表格-->
<BasicTable @register="registerTable" :rowSelection="rowSelection" @change="handleTableChange">
<!--插槽:table标题-->
<template #tableTitle>
<a-button type="primary" v-auth="'airaglog:airag_log:add'" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增</a-button>
<a-button type="primary" v-auth="'airaglog:airag_log:exportXls'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
<j-upload-button type="primary" v-auth="'airaglog:airag_log:importExcel'" preIcon="ant-design:import-outlined" @click="onImportXls"
>导入</j-upload-button
>
<a-dropdown v-if="selectedRowKeys.length > 0">
<template #overlay>
<a-menu>
<a-menu-item key="1" @click="batchHandleDelete">
<Icon icon="ant-design:delete-outlined" />
删除
</a-menu-item>
</a-menu>
</template>
<a-button v-auth="'airaglog:airag_log:deleteBatch'"
>批量操作
<Icon icon="mdi:chevron-down" />
</a-button>
</a-dropdown>
<!-- 高级查询 -->
<!-- <super-query :config="superQueryConfig" @search="handleSuperQuery" />-->
</template>
<!--操作栏-->
<template #action="{ record }">
<TableAction :actions="getTableAction(record)" />
</template>
<!--字段回显插槽-->
<template #bodyCell="{ column, record, index, text }"> </template>
</BasicTable>
<!-- 表单区域 -->
<AiragLogModal @register="registerModal" @success="handleSuccess" />
</div>
</template>
<script lang="ts" name="airaglog-airagLog" setup>
import {ref, reactive, computed} from 'vue';
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
import AiragLogModal from './components/AiragLogModal.vue';
import { columns, searchFormSchema, superQuerySchema } from './AiragLog.data';
import { list, deleteOne, batchDelete, getImportUrl, getExportUrl } from './AiragLog.api';
import { useUserStore } from '/@/store/modules/user';
import { defHttp } from '@/utils/http/axios';
const queryParam = reactive<any>({});
const checkedKeys = ref<Array<string | number>>([]);
const userStore = useUserStore();
// 分页信息
const pagination = ref({
current: 1,
pageSize: 10,
total: 0,
});
// 处理表格变化事件(包括分页变化)
function handleTableChange(pag) {
if (pag) {
pagination.value = {
current: pag.current,
pageSize: pag.pageSize,
total: pag.total,
};
}
}
// 创建带序号列的列配置
const tableColumns = computed(() => {
return columns.map((col) => {
if (col.dataIndex === 'index') {
// 序号列特殊处理
return {
...col,
customRender: ({ index }) => {
return (pagination.value.current - 1) * pagination.value.pageSize + index + 1;
},
};
}
return col;
});
});
//注册model
const [registerModal, { openModal }] = useModal();
//注册table数据
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
tableProps: {
title: '日志管理',
api: list,
columns: tableColumns.value,
canResize: false,
formConfig: {
//labelWidth: 120,
schemas: searchFormSchema,
autoSubmitOnEnter: true,
showAdvancedButton: true,
fieldMapToNumber: [],
// 添加时间字段映射配置
fieldMapToTime: [
[
'createTimeStr', // 表单字段名
['createTime_begin', 'createTime_end'], // 映射后的开始/结束字段
'YYYY-MM-DD HH:mm:ss', // 日期时间格式
],
],
},
pagination: {
current: 1,
pageSize: 10,
showSizeChanger: true,
pageSizeOptions: ['10', '20', '30'],
showTotal: (total) => `共 ${total} 条`,
},
actionColumn: {
width: 120,
fixed: 'right',
},
beforeFetch: (params) => {
// 将未选择的"是否存入"转换为 -1
if (params.isStorage === undefined || params.isStorage === null) {
params.isStorage = -1;
}
return Object.assign(params, queryParam);
},
},
exportConfig: {
name: '日志管理',
url: getExportUrl,
params: queryParam,
},
importConfig: {
url: getImportUrl,
success: handleSuccess,
},
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext;
// 高级查询配置
const superQueryConfig = reactive(superQuerySchema);
/**
* 高级查询事件
*/
function handleSuperQuery(params) {
Object.keys(params).map((k) => {
queryParam[k] = params[k];
});
reload();
}
/**
* 新增事件
*/
function handleAdd() {
openModal(true, {
isUpdate: false,
showFooter: true,
});
}
/**
* 编辑事件
*/
function handleEdit(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: true,
});
}
/**
* 详情
*/
function handleDetail(record: Recordable) {
openModal(true, {
record,
isUpdate: true,
showFooter: false,
});
}
/**
* 删除事件
*/
async function handleDelete(record) {
await deleteOne({ id: record.id }, handleSuccess);
}
/**
* 批量删除事件
*/
async function batchHandleDelete() {
await batchDelete({ ids: selectedRowKeys.value }, handleSuccess);
}
/**
* 成功回调
*/
function handleSuccess() {
(selectedRowKeys.value = []) && reload();
}
/**
* 操作栏
*/
function getTableAction(record) {
if (record.isStorage == 0)
return [
{
label: '存入问题库',
onClick: () => handleSaveToQuestionLibrary(record),
auth: 'airaglog:airag_log:saveToQuestionLibrary',
},
];
else
return [
{
label: '',
},
];
}
/**
* 存入问题库事件
*/
async function handleSaveToQuestionLibrary(record) {
openModal(true, {
record,
isUpdate: true,
showFooter: true,
showSaveButton: true,
onConfirm: async (record) => {
try {
await defHttp.post({ url: '/airaglog/airagLog/saveToQuestionLibrary', params: record });
// 刷新列表
reload();
} catch (error) {
console.error('存入问题库失败', error);
}
},
});
}
/**
* 下拉操作栏
*/
function getDropDownAction(record) {
return [
{
label: '详情',
onClick: handleDetail.bind(null, record),
},
{
label: '删除',
popConfirm: {
title: '是否确认删除',
confirm: handleDelete.bind(null, record),
placement: 'topLeft',
},
auth: 'airaglog:airag_log:delete',
},
];
}
</script>
<style lang="less" scoped>
:deep(.ant-picker),
:deep(.ant-input-number) {
width: 100%;
}
</style>