刘光辉
7 小时以前 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
160
161
162
163
164
165
166
167
168
169
<script lang="ts" setup>
import type { BasicColumn } from '@jnpf/ui/vxeTable';
import type { DmsPrintOperationLog, DmsPrintOperationQuery } from '#/api/x/dms/printOperation';
 
import { ref } from 'vue';
 
import { useMessage, usePermission } from '@jnpf/hooks';
import { useDrawer } from '@jnpf/ui/drawer';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
import { downloadByData } from '@jnpf/utils';
 
import dayjs from 'dayjs';
 
import { exportDmsPrintOperations, getDmsPrintOperationPage } from '#/api/x/dms/printOperation';
 
import DetailDrawer from './DetailDrawer.vue';
 
defineOptions({ name: 'DmsPrintOperations' });
 
const EXPORT_PERMISSION = 'dms.printOperation.export';
const currentQuery = ref<DmsPrintOperationQuery>({ currentPage: 1, pageSize: 20 });
const exporting = ref(false);
const { createMessage } = useMessage();
const { hasBtnP } = usePermission();
 
const PRINT_TYPE_LABELS: Record<string, string> = {
  ARCHIVE_BOX: '档案盒打印',
  BLANK_FORM: '空白表单打印',
  CONTROLLED_DOCUMENT: '受控文件打印',
  LABEL: '标签打印',
  OTHER: '其他打印',
  RECORD_DOCUMENT: '记录文件打印',
};
 
const columns: BasicColumn[] = [
  { title: '编号', dataIndex: 'documentCode', minWidth: 150, slots: { default: 'text' } },
  { title: '名称', dataIndex: 'documentName', minWidth: 220, slots: { default: 'text' } },
  { title: '批号/版本号', dataIndex: 'batchVersion', minWidth: 150, slots: { default: 'batchVersion' } },
  { title: '操作日期', dataIndex: 'operatedAt', width: 165, format: 'date|YYYY-MM-DD HH:mm:ss' },
  { title: '打印类型', dataIndex: 'printType', minWidth: 140, slots: { default: 'printType' } },
  { title: '操作人', dataIndex: 'operatorName', minWidth: 110, slots: { default: 'text' } },
  { title: '备注', dataIndex: 'remark', minWidth: 180, slots: { default: 'text' } },
];
 
const [registerDrawer, { openDrawer }] = useDrawer();
const [registerTable] = useVxeTable({
  api: fetchPage,
  beforeFetch: normalizeQuery,
  columns,
  immediate: true,
  emptyText: '当前条件下没有打印记录',
  rowKey: 'id',
  showIndexColumn: false,
  useSearchForm: true,
  formConfig: {
    baseColProps: { xs: 24, sm: 12, md: 8, xl: 6 },
    compact: true,
    showAdvancedButton: true,
    schemas: [
      {
        field: 'keyword',
        label: '关键词',
        component: 'Input',
        componentProps: { placeholder: '编号、名称、批号、版本、操作人或备注', submitOnPressEnter: true },
      },
      { field: 'documentCode', label: '编号', component: 'Input', componentProps: { placeholder: '请输入编号', submitOnPressEnter: true } },
      { field: 'documentName', label: '名称', component: 'Input', componentProps: { placeholder: '请输入名称', submitOnPressEnter: true } },
      { field: 'batchNo', label: '批号', component: 'Input', componentProps: { placeholder: '请输入批号', submitOnPressEnter: true } },
      { field: 'versionNo', label: '版本号', component: 'Input', componentProps: { placeholder: '请输入版本号', submitOnPressEnter: true } },
      { field: 'operatorName', label: '操作人', component: 'Input', componentProps: { placeholder: '请输入操作人', submitOnPressEnter: true } },
      {
        field: 'printType',
        label: '打印类型',
        component: 'Select',
        componentProps: { allowClear: true, placeholder: '请选择', options: Object.entries(PRINT_TYPE_LABELS).map(([id, fullName]) => ({ id, fullName })) },
      },
      {
        field: 'pickerVal',
        label: '操作日期',
        component: 'DateRange',
        componentProps: { allowClear: true, format: 'YYYY-MM-DD HH:mm:ss', showTime: true },
      },
    ],
    fieldMapToTime: [['pickerVal', ['startTime', 'endTime'], 'YYYY-MM-DD HH:mm:ss']],
  },
  pagination: {
    pageSize: 20,
    pageSizeOptions: ['20', '50', '100'],
    showQuickJumper: true,
    showSizeChanger: true,
    showTotal: (total) => `共 ${total} 条记录`,
  },
  actionColumn: { dataIndex: 'action', fixed: 'right', title: '操作', width: 90 },
});
 
function normalizeQuery(raw: Record<string, unknown>): DmsPrintOperationQuery {
  const query = { ...raw } as unknown as DmsPrintOperationQuery;
  query.currentPage = Number(query.currentPage) || 1;
  query.pageSize = Math.min(Number(query.pageSize) || 20, 200);
  currentQuery.value = query;
  return query;
}
 
async function fetchPage(query: DmsPrintOperationQuery) {
  const response = await getDmsPrintOperationPage(query);
  return { data: response.data };
}
 
async function handleExport() {
  exporting.value = true;
  try {
    const blob = await exportDmsPrintOperations(currentQuery.value);
    downloadByData(blob, `打印操作记录_${dayjs().format('YYYYMMDD_HHmmss')}.csv`, 'text/csv;charset=UTF-8');
  } catch {
    createMessage.error('导出失败,请稍后重试');
  } finally {
    exporting.value = false;
  }
}
 
function displayText(value?: string) {
  return value || '—';
}
</script>
 
<template>
  <div class="jnpf-content-wrapper print-operation-page">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content">
        <BasicVxeTable @register="registerTable">
          <template #tableTitle>
            <a-button v-if="hasBtnP(EXPORT_PERMISSION, false)" pre-icon="icon-ym icon-ym-btn-download" :loading="exporting" @click="handleExport"
              >导出</a-button
            >
          </template>
          <template #text="{ record, column }">
            <span class="cell-ellipsis" :title="displayText(record[column.field])">{{ displayText(record[column.field]) }}</span>
          </template>
          <template #batchVersion="{ record }">
            <span class="cell-ellipsis" :title="[record.batchNo, record.versionNo].filter(Boolean).join(' / ') || '—'">
              {{ [record.batchNo, record.versionNo].filter(Boolean).join(' / ') || '—' }}
            </span>
          </template>
          <template #printType="{ record }">
            <a-tag :bordered="false" color="blue">{{ PRINT_TYPE_LABELS[record.printType] || record.printType }}</a-tag>
          </template>
          <template #action="{ record }">
            <TableAction :actions="[{ label: '详情', onClick: () => openDrawer(true, { id: (record as DmsPrintOperationLog).id }) }]" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
    <DetailDrawer @register="registerDrawer" />
  </div>
</template>
 
<style lang="scss" scoped>
.print-operation-page,
.print-operation-page :deep(.jnpf-content-wrapper-content) {
  min-width: 0;
}
 
.cell-ellipsis {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>