刘光辉
4 小时以前 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
<script lang="ts" setup>
import type { BasicColumn } from '@jnpf/ui/vxeTable';
 
import type { WatermarkConfig, WatermarkQuery } from '#/api/x/dms/watermark';
 
import { useMessage, usePermission } from '@jnpf/hooks';
import { useModal } from '@jnpf/ui/modal';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { deleteWatermark, getWatermarkPage, setWatermarkEnabled } from '#/api/x/dms/watermark';
 
import FormModal from './FormModal.vue';
import { sceneText, VERSION_SCOPE_LABELS, WATERMARK_TYPE_LABELS } from './model';
 
defineOptions({ name: 'DmsWatermarkManagement' });
 
const { createConfirm, createMessage } = useMessage();
const { hasBtnP } = usePermission();
const [registerModal, { openModal }] = useModal();
const columns: BasicColumn[] = [
  { title: '水印名称', dataIndex: 'name', minWidth: 160, slots: { default: 'name' } },
  { title: '水印类型', dataIndex: 'watermarkType', width: 100, slots: { default: 'type' } },
  { title: '使用范围', dataIndex: 'versionScope', width: 110, slots: { default: 'scope' } },
  { title: '水印加载', dataIndex: 'loadScenes', minWidth: 150, slots: { default: 'scenes' } },
  { title: '是否启用', dataIndex: 'enabled', width: 100, slots: { default: 'enabled' } },
  { title: '配置内容', dataIndex: 'contentTemplate', minWidth: 220, slots: { default: 'content' } },
  { title: '所属企业', dataIndex: 'enterpriseName', minWidth: 180 },
  { title: '更新时间', dataIndex: 'updatedAt', width: 165, format: 'date|YYYY-MM-DD HH:mm:ss' },
];
 
const [registerTable, { reload }] = useVxeTable({
  api: fetchPage,
  columns,
  immediate: true,
  emptyText: '暂无水印配置',
  rowKey: 'id',
  showIndexColumn: false,
  useSearchForm: true,
  formConfig: {
    baseColProps: { xs: 24, sm: 12, md: 8, xl: 6 },
    compact: true,
    schemas: [
      { field: 'keyword', label: '关键词', component: 'Input', componentProps: { placeholder: '名称、内容或所属企业', submitOnPressEnter: true } },
      {
        field: 'watermarkType',
        label: '水印类型',
        component: 'Select',
        componentProps: { allowClear: true, options: Object.entries(WATERMARK_TYPE_LABELS).map(([id, fullName]) => ({ id, fullName })) },
      },
      {
        field: 'enabled',
        label: '启用状态',
        component: 'Select',
        componentProps: {
          allowClear: true,
          options: [
            { id: true, fullName: '已启用' },
            { id: false, fullName: '已停用' },
          ],
        },
      },
    ],
  },
  pagination: {
    pageSize: 20,
    pageSizeOptions: ['20', '50', '100'],
    showQuickJumper: true,
    showSizeChanger: true,
    showTotal: (total) => `共 ${total} 条记录`,
  },
  actionColumn: { dataIndex: 'action', fixed: 'right', title: '操作', width: 190 },
});
 
async function fetchPage(raw: Record<string, unknown>) {
  const query = { ...raw, currentPage: Number(raw.currentPage) || 1, pageSize: Math.min(Number(raw.pageSize) || 20, 200) } as WatermarkQuery;
  const response = await getWatermarkPage(query);
  return { data: response.data };
}
 
function openForm(mode: 'create' | 'edit' | 'view', record?: WatermarkConfig) {
  openModal(true, { id: record?.id, mode });
}
 
async function toggle(record: WatermarkConfig, enabled: boolean) {
  if (!record.id || record.revision === undefined) return;
  try {
    await setWatermarkEnabled(record.id, record.revision, enabled);
    createMessage.success(enabled ? '水印已启用' : '水印已停用');
    await reload();
  } catch {
    createMessage.error('状态更新失败,请刷新后重试');
  }
}
 
function remove(record: WatermarkConfig) {
  createConfirm({
    title: '删除水印配置',
    content: `确认删除“${record.name}”?`,
    iconType: 'warning',
    onOk: async () => {
      if (!record.id || record.revision === undefined) return;
      try {
        await deleteWatermark(record.id, record.revision);
        createMessage.success('水印配置已删除');
        await reload();
      } catch {
        createMessage.error('删除失败,请刷新后重试');
      }
    },
  });
}
</script>
 
<template>
  <div class="jnpf-content-wrapper watermark-page">
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content">
        <BasicVxeTable @register="registerTable">
          <template #tableTitle>
            <a-button v-if="hasBtnP('dms.watermark.create', false)" type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="openForm('create')">
              新增配置
            </a-button>
          </template>
          <template #name="{ record }">
            <a-button type="link" class="name-link" @click="openForm('view', record)">{{ record.name }}</a-button>
          </template>
          <template #type="{ record }">
            <a-tag :bordered="false" color="blue">{{ WATERMARK_TYPE_LABELS[record.watermarkType] || record.watermarkType }}</a-tag>
          </template>
          <template #scope="{ record }">{{ VERSION_SCOPE_LABELS[record.versionScope] || record.versionScope }}</template>
          <template #scenes="{ record }">{{ sceneText(record.loadScenes) }}</template>
          <template #enabled="{ record }">
            <JnpfSwitch
              :value="record.enabled"
              :checked-value="true"
              :un-checked-value="false"
              :disabled="!hasBtnP('dms.watermark.toggle', false)"
              @change="(value) => toggle(record, value)" />
          </template>
          <template #content="{ record }">
            <span class="cell-ellipsis" :title="record.contentTemplate || record.imageUrl || '—'">{{ record.contentTemplate || record.imageUrl || '—' }}</span>
          </template>
          <template #action="{ record }">
            <TableAction
              :actions="[
                { label: '查看', onClick: () => openForm('view', record) },
                { label: '编辑', ifShow: hasBtnP('dms.watermark.update', false), onClick: () => openForm('edit', record) },
                { label: '删除', color: 'error', ifShow: hasBtnP('dms.watermark.delete', false), onClick: () => remove(record) },
              ]" />
          </template>
        </BasicVxeTable>
      </div>
    </div>
    <FormModal @register="registerModal" @saved="reload" />
  </div>
</template>
 
<style lang="scss" scoped>
.watermark-page,
.watermark-page :deep(.jnpf-content-wrapper-content) {
  min-width: 0;
}
.name-link {
  padding: 0;
  height: auto;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-ellipsis {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>