feat: 完善后台导入日志权限与备份恢复
This commit is contained in:
@@ -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