feat: 拆分上链与出库管理界面
This commit is contained in:
@@ -144,93 +144,23 @@
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<n-modal v-model:show="outboundModal" preset="card" :title="outboundModalTitle" style="width: 620px">
|
||||
<n-form :model="outboundForm" label-placement="top">
|
||||
<n-grid :cols="2" :x-gap="16">
|
||||
<n-form-item-gi :label="t('pages.outbound.outTime')" :required="!outboundReadonly">
|
||||
<n-date-picker v-if="!outboundReadonly" v-model:formatted-value="outboundForm.outTime" value-format="yyyy-MM-dd HH:mm" type="datetime" clearable style="width: 100%" />
|
||||
<n-text v-else>{{ outboundForm.outTime || '-' }}</n-text>
|
||||
</n-form-item-gi>
|
||||
<n-form-item-gi :label="t('common.label.remark')">
|
||||
<n-input v-if="!outboundReadonly" v-model:value="outboundForm.remark" />
|
||||
<n-text v-else>{{ outboundForm.remark || '-' }}</n-text>
|
||||
</n-form-item-gi>
|
||||
</n-grid>
|
||||
<n-form-item :label="t('pages.outbound.outImage')">
|
||||
<media-upload v-if="!outboundReadonly || outImages.length" v-model="outImages" type="image" :max="8" :disabled="outboundReadonly" />
|
||||
<n-text v-else>-</n-text>
|
||||
</n-form-item>
|
||||
|
||||
<template v-if="targetOnchain && targetProof">
|
||||
<n-divider style="margin: 4px 0 12px">{{ t('pages.blockchain.title') }}</n-divider>
|
||||
<n-descriptions
|
||||
:column="1"
|
||||
label-placement="left"
|
||||
size="small"
|
||||
bordered
|
||||
:label-style="{ whiteSpace: 'nowrap', verticalAlign: 'middle' }"
|
||||
:content-style="{ verticalAlign: 'middle' }"
|
||||
>
|
||||
<n-descriptions-item :label="t('pages.blockchain.status')">
|
||||
<n-tag size="small" :type="proofStatusType(targetProof)">{{ proofStatusText(targetProof) }}</n-tag>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item v-if="targetProof.dataHash" :label="t('pages.blockchain.dataHash')">
|
||||
<span class="onchain-val"><span class="onchain-mono">{{ targetProof.dataHash }}</span>
|
||||
<n-button quaternary circle size="tiny" :title="t('common.action.copy')" @click="copyValue(targetProof.dataHash)"><template #icon><n-icon :component="CopyOutline" /></template></n-button>
|
||||
</span>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item v-if="targetProof.txHash" :label="t('pages.blockchain.txHash')">
|
||||
<span class="onchain-val"><span class="onchain-mono">{{ targetProof.txHash }}</span>
|
||||
<n-button quaternary circle size="tiny" :title="t('common.action.copy')" @click="copyValue(targetProof.txHash)"><template #icon><n-icon :component="CopyOutline" /></template></n-button>
|
||||
</span>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item v-if="targetProof.tokenId !== null && targetProof.tokenId !== undefined" :label="t('pages.blockchain.tokenId')">
|
||||
<span class="onchain-val"><span class="onchain-mono">{{ targetProof.tokenId }}</span>
|
||||
<n-button quaternary circle size="tiny" :title="t('common.action.copy')" @click="copyValue(targetProof.tokenId)"><template #icon><n-icon :component="CopyOutline" /></template></n-button>
|
||||
</span>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item v-if="targetProof.contractAddress" :label="t('pages.blockchain.contract')">
|
||||
<span class="onchain-val"><span class="onchain-mono">{{ targetProof.contractAddress }}</span>
|
||||
<n-button quaternary circle size="tiny" :title="t('common.action.copy')" @click="copyValue(targetProof.contractAddress)"><template #icon><n-icon :component="CopyOutline" /></template></n-button>
|
||||
</span>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item v-if="targetProof.blockHeight" :label="t('pages.blockchain.blockHeight')">
|
||||
<span class="onchain-val"><span>{{ targetProof.blockHeight }}</span>
|
||||
<n-button quaternary circle size="tiny" :title="t('common.action.copy')" @click="copyValue(targetProof.blockHeight)"><template #icon><n-icon :component="CopyOutline" /></template></n-button>
|
||||
</span>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item v-if="targetProof.onchainAt" :label="t('pages.blockchain.onchainAt')">
|
||||
<span class="onchain-val"><span>{{ fmt(targetProof.onchainAt) }}</span>
|
||||
<n-button quaternary circle size="tiny" :title="t('common.action.copy')" @click="copyValue(fmt(targetProof.onchainAt))"><template #icon><n-icon :component="CopyOutline" /></template></n-button>
|
||||
</span>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item v-if="targetProof.explorerUrl" :label="t('pages.blockchain.explorer')">
|
||||
<span class="onchain-val"><a :href="targetProof.explorerUrl" target="_blank" rel="noopener" class="onchain-mono" style="color: var(--brand)">{{ targetProof.explorerUrl }}</a>
|
||||
<n-button quaternary circle size="tiny" :title="t('common.action.copy')" @click="copyValue(targetProof.explorerUrl)"><template #icon><n-icon :component="CopyOutline" /></template></n-button>
|
||||
</span>
|
||||
</n-descriptions-item>
|
||||
</n-descriptions>
|
||||
</template>
|
||||
|
||||
<n-alert v-if="!targetOnchain" type="info" :bordered="false" class="onchain-tip">
|
||||
{{ t('pages.outbound.onchainAutoTip') }}
|
||||
</n-alert>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<div style="text-align: right">
|
||||
<n-button class="mr8" @click="outboundModal = false">
|
||||
{{ targetOnchain ? t('common.action.close') : t('common.action.cancel') }}
|
||||
</n-button>
|
||||
<!-- 只读角色(无写权限)从状态列点开时仅可查看,隐藏保存/触发按钮 -->
|
||||
<template v-if="!targetOnchain && auth.canWrite">
|
||||
<n-button v-if="!targetOutbound" class="mr8" :loading="outboundSaving" @click="saveOutbound(false)">{{ t('pages.outbound.saveRecord') }}</n-button>
|
||||
<n-button type="primary" :loading="outboundTriggering" @click="saveOutbound(true)">
|
||||
{{ targetOutbound ? t('pages.blockchain.trigger') : t('pages.outbound.saveAndTriggerOnchain') }}
|
||||
</n-button>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
<outbound-record-modal
|
||||
v-model:show="outboundRecordVisible"
|
||||
:trace-code="operationTarget"
|
||||
@changed="reloadAfterOperation"
|
||||
/>
|
||||
<onchain-proof-modal
|
||||
v-model:show="proofVisible"
|
||||
:trace-code="operationTarget"
|
||||
@run="runOnchainRow"
|
||||
@changed="reloadAfterOperation"
|
||||
/>
|
||||
<batch-job-modal
|
||||
v-model:show="jobVisible"
|
||||
:job-id="jobId"
|
||||
:title="t('pages.operations.onchainProgress')"
|
||||
@completed="reloadAfterOperation"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -239,17 +169,19 @@ import { computed, h, onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { NButton, NDropdown, NIcon, NTag, NText, type DataTableColumns, type DropdownOption } from 'naive-ui';
|
||||
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline, EllipsisHorizontalOutline, FilterOutline, CopyOutline } from '@vicons/ionicons5';
|
||||
import dayjs from 'dayjs';
|
||||
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline, EllipsisHorizontalOutline, FilterOutline } from '@vicons/ionicons5';
|
||||
import { TraceCodeStatus } from '@artveris/shared';
|
||||
import { traceCodeApi, jobApi, artworkApi, outboundApi } from '@/api';
|
||||
import { traceCodeApi, jobApi, artworkApi, onchainApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { message, dialog } from '@/utils/feedback';
|
||||
import { fmt, statusType } from '@/utils/format';
|
||||
import { downloadFile } from '@/utils/download';
|
||||
import { useTablePage } from '@/composables/useTablePage';
|
||||
import { useRemoteSort } from '@/utils/tableSort';
|
||||
import MediaUpload from '@/components/MediaUpload.vue';
|
||||
import { localizeOperationReason } from '@/utils/operationReason';
|
||||
import BatchJobModal from '@/components/BatchJobModal.vue';
|
||||
import OnchainProofModal from '@/components/OnchainProofModal.vue';
|
||||
import OutboundRecordModal from '@/components/OutboundRecordModal.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
artworkId?: number;
|
||||
@@ -334,35 +266,35 @@ const editingGroup = ref<number | null>(null);
|
||||
const batchModal = ref(false);
|
||||
const batchTarget = ref<any | null>(null);
|
||||
const batchForm = reactive<{ batchValue: number | string | null }>({ batchValue: null });
|
||||
const outboundModal = ref(false);
|
||||
const outboundSaving = ref(false);
|
||||
const outboundTriggering = ref(false);
|
||||
const outboundTarget = ref<any | null>(null);
|
||||
const outImages = ref<any[]>([]);
|
||||
const outboundForm = reactive<any>({
|
||||
outTime: null,
|
||||
remark: '',
|
||||
});
|
||||
const outboundRecordVisible = ref(false);
|
||||
const proofVisible = ref(false);
|
||||
const operationTarget = ref<any | null>(null);
|
||||
const jobVisible = ref(false);
|
||||
const jobId = ref('');
|
||||
|
||||
function rowIsOutbound(row: any) {
|
||||
if (!row) return false;
|
||||
return Boolean(row.outTime || getOutImages(row).length);
|
||||
return Boolean(row.outbound || row.outTime || getOutImages(row).length);
|
||||
}
|
||||
function rowIsOnchain(row: any) {
|
||||
// 已提交上链即视为已上链:ONCHAIN(已确认)/CONFIRMING(确认中)/PENDING(待处理) 均不允许重复上链,仅 FAILED 可重试
|
||||
const s = row?.latestAnyProof?.status;
|
||||
return s === 'ONCHAIN' || s === 'CONFIRMING' || s === 'PENDING';
|
||||
const s = proofOf(row)?.status || row?.proofStatus;
|
||||
return s === 'ONCHAIN' || s === 'CONFIRMING' || s === 'SUBMITTING' || s === 'PENDING';
|
||||
}
|
||||
function outboundMenuLabel(row: any) {
|
||||
if (rowIsOnchain(row)) return t('pages.traceCode.onchainInfo');
|
||||
if (rowIsOutbound(row)) return t('pages.traceCode.triggerOnchainOnly');
|
||||
return t('pages.traceCode.registerOutbound');
|
||||
function proofOf(row: any) {
|
||||
return row?.latestAnyProof ?? row?.proof ?? null;
|
||||
}
|
||||
function canRunOnchain(row: any) {
|
||||
if (typeof row?.onchainEligible === 'boolean') return row.onchainEligible;
|
||||
const status = proofOf(row)?.status || row?.proofStatus || 'NONE';
|
||||
return status === 'NONE' || status === 'FAILED';
|
||||
}
|
||||
function outboundActionLabel(row: any) {
|
||||
return rowIsOutbound(row) ? t('pages.outbound.editRecord') : t('pages.outbound.registerRecord');
|
||||
}
|
||||
function onchainActionLabel(row: any) {
|
||||
if (rowIsOnchain(row) || proofOf(row)) return t('pages.traceCode.onchainInfo');
|
||||
return canRunOnchain(row) ? t('pages.blockchain.trigger') : t('pages.operations.onchainUnavailable');
|
||||
}
|
||||
const targetOutbound = computed(() => rowIsOutbound(outboundTarget.value));
|
||||
const targetOnchain = computed(() => rowIsOnchain(outboundTarget.value));
|
||||
const outboundReadonly = computed(() => targetOutbound.value || targetOnchain.value);
|
||||
const targetProof = computed<any>(() => outboundTarget.value?.latestProof ?? outboundTarget.value?.latestAnyProof ?? null);
|
||||
const outboundModalTitle = computed(() => outboundMenuLabel(outboundTarget.value));
|
||||
|
||||
const columns = computed<DataTableColumns<any>>(() => {
|
||||
const cols: DataTableColumns<any> = [
|
||||
@@ -426,7 +358,7 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
align: 'center',
|
||||
render: (r) => r.group?.name || h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noGroup') }),
|
||||
},
|
||||
// 出库状态:点击打开该行「出库上链」详情弹窗(弹窗按状态自动呈现登记/上链/只读信息形态)
|
||||
// 出库状态仅打开出库记录,不再夹带上链操作。
|
||||
{
|
||||
title: () =>
|
||||
renderFilterTitle(t('pages.traceCode.outboundStatus'), query.outboundStatus, outboundStatusOptions.value, (value) =>
|
||||
@@ -438,7 +370,7 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
render: (r) =>
|
||||
h(
|
||||
'span',
|
||||
{ class: 'cell-click', title: outboundMenuLabel(r), onClick: () => openOutboundModal(r) },
|
||||
{ class: 'cell-click', title: outboundActionLabel(r), onClick: () => openOutboundRecord(r) },
|
||||
[
|
||||
r.outTime || getOutImages(r).length
|
||||
? h(NTag, { size: 'small', type: 'success' }, { default: () => t('pages.traceCode.outRegistered') })
|
||||
@@ -446,7 +378,7 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
],
|
||||
),
|
||||
},
|
||||
// 上链状态:同上,点击进详情弹窗
|
||||
// 上链状态仅打开存证详情。
|
||||
{
|
||||
title: () => t('pages.traceCode.onchainStatus'),
|
||||
key: 'onchainStatus',
|
||||
@@ -455,10 +387,14 @@ const columns = computed<DataTableColumns<any>>(() => {
|
||||
render: (r) =>
|
||||
h(
|
||||
'span',
|
||||
{ class: 'cell-click', title: outboundMenuLabel(r), onClick: () => openOutboundModal(r) },
|
||||
{
|
||||
class: 'cell-click',
|
||||
title: localizeOperationReason(r.onchainReason) || onchainActionLabel(r),
|
||||
onClick: () => openProof(r),
|
||||
},
|
||||
[
|
||||
r.latestAnyProof
|
||||
? h(NTag, { size: 'small', type: proofStatusType(r.latestAnyProof) }, { default: () => proofStatusText(r.latestAnyProof) })
|
||||
proofOf(r)
|
||||
? h(NTag, { size: 'small', type: proofStatusType(proofOf(r)) }, { default: () => proofStatusText(proofOf(r)) })
|
||||
: h(NText, { depth: 3 }, { default: () => t('pages.traceCode.noOnchain') }),
|
||||
],
|
||||
),
|
||||
@@ -833,9 +769,17 @@ function rowActionOptions(row: any): DropdownOption[] {
|
||||
const options: DropdownOption[] = [
|
||||
{ label: t('pages.traceCode.changeGroup'), key: 'changeGroup', children: rowGroupOptions.value },
|
||||
{ label: t('pages.traceCode.changeBatch'), key: 'batch:open' },
|
||||
{ label: outboundMenuLabel(row), key: 'outbound:open' },
|
||||
{ label: outboundActionLabel(row), key: 'outbound:open' },
|
||||
canRunOnchain(row)
|
||||
? {
|
||||
label: proofOf(row)?.status === 'FAILED' ? t('pages.blockchain.retry') : t('pages.blockchain.trigger'),
|
||||
key: 'onchain:run',
|
||||
}
|
||||
: proofOf(row)
|
||||
? { label: t('pages.traceCode.onchainInfo'), key: 'onchain:info' }
|
||||
: { label: t('pages.operations.onchainUnavailable'), key: 'onchain:unavailable', disabled: true },
|
||||
];
|
||||
if (canManualConfirm(row.latestAnyProof)) {
|
||||
if (canManualConfirm(proofOf(row))) {
|
||||
options.push({ label: t('pages.traceCode.reconfirmOnchain'), key: 'onchain:confirm' });
|
||||
}
|
||||
options.push(
|
||||
@@ -865,12 +809,22 @@ async function onRowAction(row: any, key: string) {
|
||||
}
|
||||
|
||||
if (key === 'outbound:open') {
|
||||
openOutboundModal(row);
|
||||
openOutboundRecord(row);
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'onchain:run') {
|
||||
await runOnchainRow(row);
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'onchain:info') {
|
||||
openProof(row);
|
||||
return;
|
||||
}
|
||||
|
||||
if (key === 'onchain:confirm') {
|
||||
await confirmProof(row.latestAnyProof);
|
||||
await confirmProof(proofOf(row));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -958,10 +912,6 @@ async function applyBatchMove() {
|
||||
emit('changed');
|
||||
}
|
||||
|
||||
function formatDateTime(value?: string | Date | null) {
|
||||
return value ? dayjs(value).format('YYYY-MM-DD HH:mm') : null;
|
||||
}
|
||||
|
||||
function fileName(key: string) {
|
||||
return key.split('/').pop() || key;
|
||||
}
|
||||
@@ -973,58 +923,43 @@ function getOutImages(row: any) {
|
||||
);
|
||||
}
|
||||
|
||||
async function copyValue(value: unknown) {
|
||||
const text = value === null || value === undefined ? '' : String(value);
|
||||
if (!text) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
message.success(t('common.msg.copied'));
|
||||
} catch {
|
||||
message.error(t('common.msg.copyFailed'));
|
||||
}
|
||||
function openOutboundRecord(row: any) {
|
||||
operationTarget.value = row;
|
||||
outboundRecordVisible.value = true;
|
||||
}
|
||||
|
||||
function openOutboundModal(row: any) {
|
||||
outboundTarget.value = row;
|
||||
// 出库时间必填:未出库时默认此刻;已出库时回显既有时间(只读)
|
||||
outboundForm.outTime = row.outTime ? formatDateTime(row.outTime) : dayjs().format('YYYY-MM-DD HH:mm');
|
||||
outboundForm.remark = row.remark || '';
|
||||
outImages.value = getOutImages(row);
|
||||
outboundModal.value = true;
|
||||
function openProof(row: any) {
|
||||
operationTarget.value = row;
|
||||
proofVisible.value = true;
|
||||
}
|
||||
|
||||
async function saveOutbound(triggerOnchain: boolean) {
|
||||
if (!outboundTarget.value) return;
|
||||
if (!outboundReadonly.value && !outboundForm.outTime) {
|
||||
message.warning(t('pages.outbound.outTimeRequired'));
|
||||
return;
|
||||
}
|
||||
if (triggerOnchain) {
|
||||
outboundTriggering.value = true;
|
||||
function runOnchainRow(row: any) {
|
||||
operationTarget.value = row;
|
||||
dialog.warning({
|
||||
title: t('pages.blockchain.trigger'),
|
||||
content: t('pages.operations.singleOnchainConfirm', { code: row.shortCode }),
|
||||
positiveText: t('common.action.confirm'),
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: () => submitOnchainRow(row),
|
||||
});
|
||||
}
|
||||
|
||||
async function submitOnchainRow(row: any) {
|
||||
const result: any = await onchainApi.createJob({ mode: 'IDS', ids: [String(row.id)] });
|
||||
proofVisible.value = false;
|
||||
const id = String(result?.jobId || result?.id || result?.job?.id || '');
|
||||
if (id) {
|
||||
jobId.value = id;
|
||||
jobVisible.value = true;
|
||||
} else {
|
||||
outboundSaving.value = true;
|
||||
}
|
||||
try {
|
||||
if (!outboundReadonly.value) {
|
||||
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),
|
||||
remark: outboundForm.remark || null,
|
||||
});
|
||||
}
|
||||
if (triggerOnchain) {
|
||||
await traceCodeApi.onchain(String(outboundTarget.value.id));
|
||||
}
|
||||
message.success(t('common.msg.saved'));
|
||||
outboundModal.value = false;
|
||||
outboundTarget.value = null;
|
||||
await load();
|
||||
emit('changed');
|
||||
} finally {
|
||||
outboundSaving.value = false;
|
||||
outboundTriggering.value = false;
|
||||
message.success(t('pages.operations.jobSubmitted'));
|
||||
}
|
||||
await load();
|
||||
}
|
||||
|
||||
async function reloadAfterOperation() {
|
||||
await load();
|
||||
emit('changed');
|
||||
}
|
||||
|
||||
function resetGroupForm() {
|
||||
@@ -1175,9 +1110,6 @@ onUnmounted(() => {
|
||||
.mr8 {
|
||||
margin-right: 8px;
|
||||
}
|
||||
.onchain-tip {
|
||||
margin-top: 4px;
|
||||
}
|
||||
/* 表格单元格由 n-data-table 子组件渲染,不带本组件 scope 属性,必须用 :deep() 才能命中 */
|
||||
:deep(.cell-link) {
|
||||
color: var(--brand);
|
||||
@@ -1196,23 +1128,6 @@ onUnmounted(() => {
|
||||
:deep(.cell-click:hover) {
|
||||
opacity: 0.75;
|
||||
}
|
||||
.onchain-mono {
|
||||
font-family: 'JetBrains Mono', Consolas, monospace;
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
.onchain-val {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
.onchain-val > :first-child {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.onchain-val .n-button {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
@media (max-width: 720px) {
|
||||
.toolbar-control,
|
||||
.toolbar-control.wide,
|
||||
|
||||
Reference in New Issue
Block a user