feat: 完善后台导入日志权限与备份恢复
This commit is contained in:
@@ -3,9 +3,10 @@
|
||||
<div class="grid">
|
||||
<div v-for="(m, i) in list" :key="m.key" class="item">
|
||||
<div
|
||||
class="cell"
|
||||
class="cell previewable"
|
||||
:class="{ dragging: dragIndex === i, over: overIndex === i }"
|
||||
draggable="true"
|
||||
@click="preview(i)"
|
||||
@dragstart="onDragStart(i)"
|
||||
@dragover.prevent="onDragOver(i)"
|
||||
@drop="onDrop(i)"
|
||||
@@ -15,7 +16,7 @@
|
||||
<img v-else class="thumb" :src="m.url" :alt="m.name" />
|
||||
<div v-if="isVideo(m)" class="play"><n-icon :component="PlayCircleOutline" :size="26" /></div>
|
||||
<div class="order">{{ i + 1 }}</div>
|
||||
<button class="del" type="button" :title="t('common.action.delete')" @click="remove(i)">×</button>
|
||||
<button class="del" type="button" :title="t('common.action.delete')" @click.stop="remove(i)">×</button>
|
||||
</div>
|
||||
<n-input
|
||||
v-if="captionable"
|
||||
@@ -27,12 +28,10 @@
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 上传中占位 -->
|
||||
<div v-for="u in uploading" :key="u.id" class="item">
|
||||
<div class="cell uploading"><n-spin size="small" /></div>
|
||||
</div>
|
||||
|
||||
<!-- 上传按钮 -->
|
||||
<label v-if="list.length + uploading.length < max" class="item">
|
||||
<span class="cell add">
|
||||
<input ref="inputRef" type="file" accept="image/*,video/*" multiple hidden @change="onPick" />
|
||||
@@ -52,6 +51,7 @@ import { NIcon, NSpin, NInput } from 'naive-ui';
|
||||
import { AddOutline, PlayCircleOutline } from '@vicons/ionicons5';
|
||||
import { post } from '@/api/request';
|
||||
import { message } from '@/utils/feedback';
|
||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||
|
||||
interface MediaItem {
|
||||
key: string;
|
||||
@@ -67,16 +67,16 @@ const props = withDefaults(
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: MediaItem[]): void }>();
|
||||
const { t } = useI18n();
|
||||
|
||||
function updateCaption(i: number, v: string) {
|
||||
const arr = list.value.map((m, idx) => (idx === i ? { ...m, name: v } : m));
|
||||
emit('update:modelValue', arr);
|
||||
}
|
||||
|
||||
const inputRef = ref<HTMLInputElement | null>(null);
|
||||
const list = computed<MediaItem[]>(() => props.modelValue || []);
|
||||
const uploading = ref<{ id: number }[]>([]);
|
||||
let seq = 0;
|
||||
|
||||
function updateCaption(i: number, v: string) {
|
||||
const arr = list.value.map((m, idx) => (idx === i ? { ...m, name: v } : m));
|
||||
emit('update:modelValue', arr);
|
||||
}
|
||||
|
||||
function isVideo(m: MediaItem) {
|
||||
return m.type === 'video' || /\.(mp4|webm|mov|m4v|ogg)$/i.test(m.url || m.key || '');
|
||||
}
|
||||
@@ -117,7 +117,13 @@ function remove(i: number) {
|
||||
emit('update:modelValue', list.value.filter((_, idx) => idx !== i));
|
||||
}
|
||||
|
||||
/* 拖拽排序 */
|
||||
function preview(index: number) {
|
||||
void openMediaViewer(
|
||||
list.value.map((m) => ({ url: m.url || m.key, name: m.name || m.key, type: m.type })),
|
||||
index,
|
||||
);
|
||||
}
|
||||
|
||||
const dragIndex = ref<number | null>(null);
|
||||
const overIndex = ref<number | null>(null);
|
||||
function onDragStart(i: number) {
|
||||
@@ -183,6 +189,9 @@ function onDragEnd() {
|
||||
.cell[draggable='true'] {
|
||||
cursor: grab;
|
||||
}
|
||||
.previewable {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
.play {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<div class="media-upload" :class="{ text: listType === 'text' }">
|
||||
<div v-if="listType === 'image-card'" class="image-grid">
|
||||
<div v-for="m in items" :key="m.key" class="image-item">
|
||||
<div v-for="(m, i) in items" :key="m.key" class="image-item previewable" @click="preview(i)">
|
||||
<img v-if="isImage(m)" class="image-thumb" :src="m.url || m.key" :alt="m.name || m.key" />
|
||||
<div v-else class="file-thumb">{{ fileExt(m) }}</div>
|
||||
<button class="remove" type="button" :title="t('common.action.delete')" @click="remove(m.key)">×</button>
|
||||
<button class="remove" type="button" :title="t('common.action.delete')" @click.stop="remove(m.key)">×</button>
|
||||
</div>
|
||||
<div v-for="u in uploading" :key="u.id" class="image-item uploading">
|
||||
<n-spin size="small" />
|
||||
@@ -17,8 +17,8 @@
|
||||
</div>
|
||||
|
||||
<div v-else class="file-list">
|
||||
<div v-for="m in items" :key="m.key" class="file-row">
|
||||
<span class="file-name" :title="m.name || m.key">{{ m.name || m.key }}</span>
|
||||
<div v-for="(m, i) in items" :key="m.key" class="file-row">
|
||||
<span class="file-name" :title="m.name || m.key" @click="preview(i)">{{ m.name || m.key }}</span>
|
||||
<n-button quaternary circle size="tiny" type="error" :title="t('common.action.delete')" @click="remove(m.key)">
|
||||
×
|
||||
</n-button>
|
||||
@@ -45,6 +45,7 @@ import { NButton, NIcon, NSpin } from 'naive-ui';
|
||||
import { AddOutline, CloudUploadOutline } from '@vicons/ionicons5';
|
||||
import { post } from '@/api/request';
|
||||
import { message } from '@/utils/feedback';
|
||||
import { openMediaViewer } from '@/composables/openMediaViewer';
|
||||
|
||||
interface MediaItem {
|
||||
key: string;
|
||||
@@ -115,6 +116,13 @@ async function uploadOne(file: File) {
|
||||
function remove(key: string) {
|
||||
emit('update:modelValue', items.value.filter((m) => m.key !== key));
|
||||
}
|
||||
|
||||
function preview(index: number) {
|
||||
void openMediaViewer(
|
||||
items.value.map((m) => ({ url: m.url || m.key, name: m.name || m.key, type: m.type })),
|
||||
index,
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -143,6 +151,10 @@ function remove(key: string) {
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.previewable,
|
||||
.file-name {
|
||||
cursor: zoom-in;
|
||||
}
|
||||
.file-thumb {
|
||||
font-size: 12px;
|
||||
color: #6b7280;
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<n-button size="small" @click="openBatchModal()">{{ t('pages.traceCode.batchMove') }}</n-button>
|
||||
<n-button size="small" @click="batchStatus(false)">{{ t('pages.traceCode.batchEnable') }}</n-button>
|
||||
<n-button size="small" type="warning" @click="batchStatus(true)">{{ t('pages.traceCode.batchDisable') }}</n-button>
|
||||
<n-button size="small" type="error" @click="batchDelete">{{ t('common.action.delete') }}</n-button>
|
||||
</n-space>
|
||||
</n-card>
|
||||
|
||||
@@ -154,7 +155,7 @@
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
<n-form-item :label="t('pages.outbound.outImage')">
|
||||
<media-upload v-model="outImages" type="image" :max="1" />
|
||||
<media-upload v-model="outImages" type="image" :max="8" />
|
||||
</n-form-item>
|
||||
<n-divider style="margin: 4px 0 14px">{{ t('pages.outbound.onchainSection') }}</n-divider>
|
||||
<n-grid :cols="2" :x-gap="16">
|
||||
@@ -187,7 +188,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, onMounted, reactive, ref, watch } from 'vue';
|
||||
import { computed, h, onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NButton, NDropdown, NIcon, NTag, NText, type DataTableColumns, type DropdownOption } from 'naive-ui';
|
||||
@@ -272,6 +273,7 @@ let artworkTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
const qrModal = ref(false);
|
||||
const qrSrc = ref('');
|
||||
const qrUrl = ref('');
|
||||
let qrBlobUrl = '';
|
||||
|
||||
const groupModal = ref(false);
|
||||
const groupForm = reactive<{ name: string }>({ name: '' });
|
||||
@@ -309,7 +311,7 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
key: 'outboundStatus',
|
||||
width: 96,
|
||||
render: (r) =>
|
||||
r.outTime || r.outImage
|
||||
r.outTime || r.outImage || getOutImages(r).length
|
||||
? h(NTag, { size: 'small', type: 'success' }, { default: () => t('pages.traceCode.outRegistered') })
|
||||
: h(NText, { depth: 3 }, { default: () => t('pages.traceCode.notOutbound') }),
|
||||
},
|
||||
@@ -533,8 +535,11 @@ async function generate() {
|
||||
}
|
||||
}
|
||||
|
||||
function showQr(r: any) {
|
||||
qrSrc.value = traceCodeApi.qrUrl(r.id);
|
||||
async function showQr(r: any) {
|
||||
if (qrBlobUrl) URL.revokeObjectURL(qrBlobUrl);
|
||||
const res = await traceCodeApi.qrBlob(String(r.id));
|
||||
qrBlobUrl = URL.createObjectURL(res.data);
|
||||
qrSrc.value = qrBlobUrl;
|
||||
qrUrl.value = r.url;
|
||||
qrModal.value = true;
|
||||
}
|
||||
@@ -542,20 +547,18 @@ function showQr(r: any) {
|
||||
const exportOptions = computed(() => {
|
||||
const cur = t('pages.traceCode.exportCurrent');
|
||||
const opts: Array<{ label: string; key: string }> = [
|
||||
{ label: `Excel - ${cur}`, key: 'filter:xlsx' },
|
||||
{ label: `CSV - ${cur}`, key: 'filter:csv' },
|
||||
{ label: `Excel - ${cur}`, key: 'filter' },
|
||||
];
|
||||
if (checkedKeys.value.length) {
|
||||
const sel = t('pages.traceCode.selected', { n: checkedKeys.value.length });
|
||||
opts.push({ label: `Excel - ${sel}`, key: 'selected:xlsx' });
|
||||
opts.push({ label: `CSV - ${sel}`, key: 'selected:csv' });
|
||||
opts.push({ label: `Excel - ${sel}`, key: 'selected' });
|
||||
}
|
||||
return opts;
|
||||
});
|
||||
|
||||
async function onExport(key: string) {
|
||||
const [scope, format] = key.split(':');
|
||||
const params: Record<string, unknown> = { format };
|
||||
const scope = key;
|
||||
const params: Record<string, unknown> = {};
|
||||
if (scope === 'selected') {
|
||||
params.ids = checkedKeys.value.map(String).join(',');
|
||||
} else {
|
||||
@@ -567,7 +570,7 @@ async function onExport(key: string) {
|
||||
if (query.outboundStatus) params.outboundStatus = query.outboundStatus;
|
||||
if (query.keyword) params.keyword = query.keyword;
|
||||
}
|
||||
await downloadFile('/trace-codes/export', `trace-codes.${format}`, params);
|
||||
await downloadFile('/trace-codes/export', 'trace-codes.xlsx', params);
|
||||
}
|
||||
|
||||
async function batchAssignGroup(key: string) {
|
||||
@@ -585,6 +588,24 @@ async function batchStatus(disabled: boolean) {
|
||||
emit('changed');
|
||||
}
|
||||
|
||||
function batchDelete() {
|
||||
if (!checkedKeys.value.length) return;
|
||||
dialog.warning({
|
||||
title: t('common.action.delete'),
|
||||
content: t('common.msg.confirmDelete'),
|
||||
positiveText: t('common.action.confirm'),
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
await traceCodeApi.batchDelete(checkedKeys.value.map(String));
|
||||
checkedKeys.value = [];
|
||||
message.success(t('common.msg.deleted'));
|
||||
await loadBatches();
|
||||
await load();
|
||||
emit('changed');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function rowActionOptions(row: any): DropdownOption[] {
|
||||
return [
|
||||
{ label: t('pages.traceCode.changeGroup'), key: 'changeGroup', children: rowGroupOptions.value },
|
||||
@@ -684,6 +705,16 @@ function fileName(key: string) {
|
||||
return key.split('/').pop() || key;
|
||||
}
|
||||
|
||||
function getOutImages(row: any) {
|
||||
const list = Array.isArray(row.outImages) ? row.outImages : [];
|
||||
if (list.length) {
|
||||
return list.map((item: any) =>
|
||||
typeof item === 'string' ? { key: item, url: item, name: fileName(item), type: 'image' } : item,
|
||||
);
|
||||
}
|
||||
return row.outImage ? [{ key: row.outImage, url: row.outImageUrl || row.outImage, name: fileName(row.outImage), type: 'image' }] : [];
|
||||
}
|
||||
|
||||
function openOutboundModal(row: any) {
|
||||
outboundTarget.value = row;
|
||||
const latestProof = row.latestProof;
|
||||
@@ -692,7 +723,7 @@ function openOutboundModal(row: any) {
|
||||
outboundForm.txHash = latestProof?.txHash || '';
|
||||
outboundForm.onchainAt = formatDateTime(latestProof?.onchainAt);
|
||||
outboundForm.blockHeight = toNumber(latestProof?.blockHeight);
|
||||
outImages.value = row.outImage ? [{ key: row.outImage, url: row.outImageUrl || row.outImage, name: fileName(row.outImage) }] : [];
|
||||
outImages.value = getOutImages(row);
|
||||
outboundModal.value = true;
|
||||
}
|
||||
|
||||
@@ -707,6 +738,7 @@ async function saveOutbound(triggerOnchain: boolean) {
|
||||
await outboundApi.updateSingle(String(outboundTarget.value.id), {
|
||||
outTime: outboundForm.outTime ? dayjs(outboundForm.outTime).toISOString() : null,
|
||||
outImageKey: outImages.value[0]?.key ?? null,
|
||||
outImageKeys: outImages.value.map((item) => item.key).filter(Boolean),
|
||||
txHash: outboundForm.txHash || undefined,
|
||||
onchainAt: outboundForm.onchainAt ? dayjs(outboundForm.onchainAt).toISOString() : undefined,
|
||||
blockHeight: outboundForm.blockHeight ?? undefined,
|
||||
@@ -786,6 +818,10 @@ onMounted(async () => {
|
||||
await Promise.all([loadBatches(), loadGroups()]);
|
||||
await load();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
if (qrBlobUrl) URL.revokeObjectURL(qrBlobUrl);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user