刘光辉
6 小时以前 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
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
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import type { LocalTemplateForm } from './templateDetail';
 
import type { TemplateCatalogItem, TemplateCategoryTreeNode, TemplatePageQuery } from '#/api/x/eln/templates';
 
import { onMounted, ref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicLeftTree } from '@jnpf/ui';
import { useDrawer } from '@jnpf/ui/drawer';
import { BasicForm, useForm } from '@jnpf/ui/form';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { getTemplateCategoryTree, getTemplateDirectory } from '#/api/x/eln/templates';
import GlobalFormModal from '#/components/GlobalFormModal/index.vue';
 
import VersionDrawer from './VersionDrawer.vue';
 
defineOptions({ name: 'ElnTemplateCatalog' });
 
const { createMessage } = useMessage();
const [registerVersionDrawer, { openDrawer: openVersionDrawer }] = useDrawer();
const localFormRef = ref<LocalTemplateForm>();
const templateCategoryTree = ref<TemplateCategoryTreeNode[]>([]);
const templateCategoryTreeLoading = ref(false);
const selectedTemplateCategoryId = ref('');
 
const columns: BasicColumn[] = [
  { dataIndex: 'mubanBianhao', minWidth: 150, title: '模板编号' },
  { dataIndex: 'jianyanXiangmuMingcheng', minWidth: 160, slots: { default: 'jianyanXiangmu' }, title: '检验项目' },
  { dataIndex: 'mubanFenleiMingcheng', minWidth: 140, slots: { default: 'mubanFenlei' }, title: '模板分类' },
  { dataIndex: 'shengxiaoMubanBanben', minWidth: 110, slots: { default: 'shengxiaoMubanBanben' }, title: '生效版本' },
  { dataIndex: 'bizStatus', slots: { default: 'bizStatus' }, title: '发布状态', width: 100 },
  { dataIndex: 'bizEnabled', slots: { default: 'bizEnabled' }, title: '启用状态', width: 100 },
  { dataIndex: 'shengxiaoRiqi', format: 'date|YYYY-MM-DD', title: '生效时间', width: 120 },
  { align: 'right', dataIndex: 'ziduanShu', slots: { default: 'ziduanShu' }, title: '字段数', width: 90 },
  { dataIndex: 'gengxinShijian', format: 'date|YYYY-MM-DD HH:mm:ss', title: '更新时间', width: 165 },
  { dataIndex: 'chuangjianShijian', format: 'date|YYYY-MM-DD HH:mm:ss', title: '创建时间', width: 165 },
];
 
const [registerSearchForm, { getFieldsValue, resetFields }] = useForm({
  baseColProps: { lg: 8, md: 12, sm: 12, xl: 6, xs: 24 },
  compact: true,
  labelWidth: 76,
  schemas: [
    {
      component: 'Input',
      componentProps: { placeholder: '模板编号或检验项目', submitOnPressEnter: true },
      field: 'keyword',
      label: '关键字',
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [
          { fullName: '草稿', id: 'DRAFT' },
          { fullName: '已发布', id: 'PUBLISHED' },
        ],
        placeholder: '全部',
      },
      field: 'bizStatus',
      label: '发布状态',
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [
          { fullName: '启用', id: 'enabled' },
          { fullName: '停用', id: 'disabled' },
        ],
        placeholder: '全部',
      },
      field: 'bizEnabled',
      label: '启用状态',
    },
  ],
  showActionButtonGroup: true,
  showAdvancedButton: false,
});
 
const [registerTable, { reload }] = useVxeTable({
  actionColumn: { dataIndex: 'action', fixed: 'right', title: '操作', width: 90 },
  api: fetchTemplatePage,
  beforeFetch: normalizeQuery,
  columns,
  pagination: {
    pageSize: 20,
    pageSizeOptions: ['20', '50', '100'],
    showQuickJumper: true,
    showSizeChanger: true,
    showTotal: (total) => `共 ${total} 个模板`,
  },
  rowKey: 'mubanBianhao',
  showIndexColumn: false,
});
 
function normalizeQuery(raw: Record<string, unknown>): TemplatePageQuery {
  const query: Record<string, unknown> = { ...raw };
  for (const key of ['keyword', 'mubanBianhao', 'mubanFenlei']) {
    if (typeof query[key] === 'string') query[key] = query[key].trim();
    if (!query[key]) delete query[key];
  }
  for (const key of ['bizEnabled', 'bizStatus']) {
    if (!query[key]) delete query[key];
  }
  query.currentPage = Math.max(1, Number(query.currentPage) || 1);
  query.pageSize = Math.max(1, Number(query.pageSize) || 20);
  return query as unknown as TemplatePageQuery;
}
 
async function fetchTemplatePage(query: TemplatePageQuery) {
  const response = await getTemplateDirectory(query);
  return { data: response.data };
}
 
async function loadTemplateCategoryTree() {
  templateCategoryTreeLoading.value = true;
  try {
    const response = await getTemplateCategoryTree();
    templateCategoryTree.value = normalizeTemplateCategoryTree(response.data);
  } catch (error) {
    createMessage.error(formatRequestError(error));
  } finally {
    templateCategoryTreeLoading.value = false;
  }
}
 
function normalizeTemplateCategoryTree(data: string | TemplateCategoryTreeNode[]) {
  const tree = typeof data === 'string' ? JSON.parse(data) : data;
  return Array.isArray(tree) ? (tree as TemplateCategoryTreeNode[]) : [];
}
 
function handleSearch() {
  reload({ page: 1, searchInfo: withSelectedTemplateCategory(getFieldsValue()) });
}
 
function handleTemplateCategorySelect(id: string) {
  selectedTemplateCategoryId.value = id;
  reload({ page: 1, searchInfo: withSelectedTemplateCategory(getFieldsValue()) });
}
 
function handleTemplateCategoryReset() {
  selectedTemplateCategoryId.value = '';
  reload({ page: 1, searchInfo: getFieldsValue() });
}
 
function withSelectedTemplateCategory(searchInfo: Record<string, unknown>) {
  return selectedTemplateCategoryId.value ? { ...searchInfo, mubanFenlei: selectedTemplateCategoryId.value } : searchInfo;
}
 
async function handleReset() {
  await resetFields();
  reload({ page: 1, searchInfo: withSelectedTemplateCategory({}) });
}
 
function getTableActions(row: TemplateCatalogItem): ActionItem[] {
  return [{ label: '版本', onClick: () => openVersionDrawer(true, { mubanBianhao: row.mubanBianhao }) }];
}
 
function openCreateTemplate() {
  void localFormRef.value?.open({
    modelId: '854727805680747141',
    onConfirm: () => reload(),
    title: '新增电子记录模板',
  });
}
 
function formatRequestError(error: unknown) {
  return error instanceof Error && error.message ? error.message : '操作失败,请稍后重试';
}
 
onMounted(loadTemplateCategoryTree);
</script>
 
<template>
  <div class="jnpf-content-wrapper">
    <div class="jnpf-content-wrapper-left">
      <BasicLeftTree
        title="电子记录分类"
        :field-names="{ children: 'children', key: 'f_id', title: 'fenlei_mingcheng' }"
        :loading="templateCategoryTreeLoading"
        :tree-data="templateCategoryTree"
        show-reset
        @reload="loadTemplateCategoryTree"
        @reset="handleTemplateCategoryReset"
        @select="handleTemplateCategorySelect" />
    </div>
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-search-box">
        <BasicForm @register="registerSearchForm" @reset="handleReset" @submit="handleSearch" />
      </div>
      <div class="jnpf-content-wrapper-content">
        <BasicVxeTable @register="registerTable">
          <template #tableTitle>
            <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="openCreateTemplate">新增模板</a-button>
          </template>
          <template #bizStatus="{ record }">
            <a-tag v-if="record.bizStatus" :color="record.bizStatus === 'PUBLISHED' ? 'success' : 'processing'">
              {{ record.bizStatus === 'PUBLISHED' ? '已发布' : '草稿' }}
            </a-tag>
            <span v-else>-</span>
          </template>
          <template #bizEnabled="{ record }">
            <a-tag v-if="record.bizEnabled" :color="record.bizEnabled === 'enabled' ? 'success' : 'default'">
              {{ record.bizEnabled === 'enabled' ? '启用' : '停用' }}
            </a-tag>
            <span v-else>-</span>
          </template>
          <template #jianyanXiangmu="{ record }">
            {{ record.jianyanXiangmuMingcheng || record.jianyanXiangmu || '-' }}
          </template>
          <template #mubanFenlei="{ record }">
            {{ record.mubanFenleiMingcheng || record.mubanFenlei || '-' }}
          </template>
          <template #shengxiaoMubanBanben="{ record }">{{ record.shengxiaoMubanBanben || '未生效' }}</template>
          <template #ziduanShu="{ record }">{{ record.ziduanShu == null ? '-' : record.ziduanShu }}</template>
          <template #action="{ record }"><TableAction :actions="getTableActions(record)" /></template>
        </BasicVxeTable>
      </div>
    </div>
 
    <GlobalFormModal ref="localFormRef" :listen-global="false" />
 
    <VersionDrawer @register="registerVersionDrawer" @reload="reload" />
  </div>
</template>
 
<style lang="scss" scoped>
:deep(.jnpf-vxe-table) {
  min-width: 0;
}
</style>