刘光辉
3 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
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
<script lang="ts" setup>
import type { BasicColumn, PaginationProps } from '@jnpf/ui/vxeTable';
 
import type { DmsFileCenterItem, DmsFileOperationLogItem } from '#/api/x/dms/fileCenter';
 
import { computed, ref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { BasicVxeTable, useVxeTable } from '@jnpf/ui/vxeTable';
import { formatToDateTime } from '@jnpf/utils';
 
import { SearchOutlined } from '@ant-design/icons-vue';
 
import { getFileOperationLogs } from '#/api/x/dms/fileCenter';
 
const columns: BasicColumn[] = [
  { dataIndex: 'occurredAt', slots: { default: 'occurredAt' }, title: '操作时间', width: 180 },
  { dataIndex: 'operationContent', key: 'operationContent', title: '操作内容' },
];
const item = ref<DmsFileCenterItem>();
const records = ref<DmsFileOperationLogItem[]>([]);
const keyword = ref('');
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const loading = ref(false);
const loadFailed = ref(false);
const { createMessage } = useMessage();
const [registerModal] = useModalInner(init);
const [registerTable, { getPaginationRef }] = useVxeTable({
  columns,
  rowKey: 'id',
  showIndexColumn: false,
  showTableSetting: false,
});
 
const title = computed(() => `操作记录 - ${item.value?.fileName || item.value?.name || ''}`);
const pagination = computed<PaginationProps>(() => ({
  current: currentPage.value,
  pageSize: pageSize.value,
  pageSizeOptions: ['10', '20', '50'],
  showQuickJumper: total.value > pageSize.value,
  showSizeChanger: true,
  showTotal: (value) => `共 ${value} 条`,
  total: total.value,
}));
 
function init(data: { item: DmsFileCenterItem }) {
  item.value = data.item;
  records.value = [];
  keyword.value = '';
  currentPage.value = 1;
  pageSize.value = 10;
  total.value = 0;
  loadFailed.value = false;
  void loadRecords();
}
 
async function loadRecords() {
  if (!item.value) return;
  loading.value = true;
  loadFailed.value = false;
  try {
    const response = await getFileOperationLogs(item.value.id, {
      currentPage: currentPage.value,
      keyword: keyword.value.trim() || undefined,
      pageSize: pageSize.value,
    });
    records.value = response.data.list || [];
    total.value = response.data.total || 0;
    currentPage.value = response.data.currentPage || currentPage.value;
    pageSize.value = response.data.pageSize || pageSize.value;
  } catch {
    records.value = [];
    total.value = 0;
    loadFailed.value = true;
    createMessage.error('操作记录加载失败');
  } finally {
    loading.value = false;
  }
}
 
function search() {
  currentPage.value = 1;
  void loadRecords();
}
 
function clearSearch() {
  keyword.value = '';
  currentPage.value = 1;
  void loadRecords();
}
 
function handleTableChange() {
  const value = getPaginationRef();
  if (!value || typeof value !== 'object') return;
  currentPage.value = value.current || 1;
  pageSize.value = value.pageSize || 10;
  void loadRecords();
}
 
function displayTime(value?: string) {
  return value ? formatToDateTime(value, 'YYYY-MM-DD HH:mm:ss') : '—';
}
</script>
 
<template>
  <BasicModal v-bind="$attrs" :footer="null" :min-height="430" :title="title" width="min(860px, calc(100vw - 24px))" destroy-on-close @register="registerModal">
    <div class="operation-log-body">
      <div class="operation-log-toolbar">
        <jnpf-input v-model:value="keyword" allow-clear :maxlength="100" placeholder="请输入搜索关键字" @press-enter="search" @change="!keyword && search()">
          <template #prefix><SearchOutlined /></template>
        </jnpf-input>
        <a-tooltip title="搜索">
          <a-button aria-label="搜索操作记录" @click="search"><SearchOutlined /></a-button>
        </a-tooltip>
        <a-button type="link" @click="clearSearch">清空</a-button>
      </div>
 
      <a-alert v-if="loadFailed" class="operation-log-error" type="error" show-icon message="操作记录暂时无法加载" />
      <BasicVxeTable
        class="operation-log-table"
        :data-source="records"
        empty-text="暂无操作记录"
        :ellipsis="false"
        height="360px"
        :loading="loading"
        :pagination="pagination"
        @change="handleTableChange"
        @register="registerTable">
        <template #occurredAt="{ record }">{{ displayTime(record.occurredAt) }}</template>
      </BasicVxeTable>
    </div>
  </BasicModal>
</template>
 
<style lang="scss" scoped>
.operation-log-body {
  min-width: 0;
  padding: 14px 18px 18px;
}
 
.operation-log-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  width: min(430px, 100%);
  margin-bottom: 14px;
}
 
.operation-log-error {
  margin-bottom: 12px;
}
 
:deep(.vxe-cell) {
  overflow-wrap: anywhere;
}
</style>