151 lines
4.6 KiB
Vue
151 lines
4.6 KiB
Vue
<template>
|
|
<div class="page">
|
|
<div class="page-toolbar">
|
|
<n-input
|
|
v-model:value="query.keyword"
|
|
:placeholder="t('pages.queryLog.keywordPlaceholder')"
|
|
clearable
|
|
style="width: 200px"
|
|
@keyup.enter="onSearch"
|
|
/>
|
|
<n-input
|
|
v-model:value="query.archiveNo"
|
|
:placeholder="t('pages.artwork.archiveNo')"
|
|
clearable
|
|
style="width: 150px"
|
|
@keyup.enter="onSearch"
|
|
/>
|
|
<n-input
|
|
v-model:value="query.batchNo"
|
|
:placeholder="t('pages.traceCode.batchNo')"
|
|
clearable
|
|
style="width: 150px"
|
|
@keyup.enter="onSearch"
|
|
/>
|
|
<n-select
|
|
v-model:value="query.result"
|
|
:options="resultOptions"
|
|
clearable
|
|
:placeholder="t('pages.queryLog.result')"
|
|
style="width: 140px"
|
|
@update:value="onSearch"
|
|
/>
|
|
<n-date-picker
|
|
v-model:value="range"
|
|
type="datetimerange"
|
|
clearable
|
|
style="width: 340px"
|
|
@update:value="onRange"
|
|
/>
|
|
<n-button type="primary" @click="onSearch">
|
|
<template #icon><n-icon :component="SearchOutline" /></template>
|
|
{{ t('common.action.search') }}
|
|
</n-button>
|
|
</div>
|
|
|
|
<n-data-table
|
|
:columns="columns"
|
|
:data="rows"
|
|
:loading="loading"
|
|
:pagination="pagination"
|
|
remote
|
|
:row-key="(r) => r.id"
|
|
@update:page="onPage"
|
|
/>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { h, onMounted, reactive, ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { NTag, type DataTableColumns } from 'naive-ui';
|
|
import { SearchOutline } from '@vicons/ionicons5';
|
|
import dayjs from 'dayjs';
|
|
import { QueryResult } from '@artveris/shared';
|
|
import { queryLogApi } from '@/api';
|
|
import { fmt, statusType } from '@/utils/format';
|
|
|
|
const { t } = useI18n();
|
|
const rows = ref<any[]>([]);
|
|
const loading = ref(false);
|
|
const range = ref<[number, number] | null>(null);
|
|
const query = reactive<{ keyword: string; archiveNo: string; batchNo: string; result: string | null; startTime?: string; endTime?: string; page: number; pageSize: number }>({
|
|
keyword: '',
|
|
archiveNo: '',
|
|
batchNo: '',
|
|
result: null,
|
|
page: 1,
|
|
pageSize: 10,
|
|
});
|
|
const pagination = reactive({ page: 1, pageSize: 10, itemCount: 0 });
|
|
const resultOptions = Object.values(QueryResult).map((v) => ({ label: t(`common.queryResult.${v}`), value: v }));
|
|
|
|
const columns: DataTableColumns<any> = [
|
|
{ title: () => t('pages.traceCode.shortCode'), key: 'shortCode', width: 120, render: (r) => r.shortCode || '-' },
|
|
{ title: () => t('pages.artwork.archiveNo'), key: 'archiveNo', width: 140, render: (r) => r.archiveNo || '-' },
|
|
{ title: () => t('pages.traceCode.batchNo'), key: 'batchNo', width: 130, render: (r) => r.batchNo || '-' },
|
|
{
|
|
title: () => t('pages.queryLog.result'),
|
|
key: 'queryResult',
|
|
width: 104,
|
|
render: (r) => h(NTag, { size: 'small', type: statusType(r.queryResult) }, { default: () => t(`common.queryResult.${r.queryResult}`) }),
|
|
},
|
|
{ title: () => t('pages.traceCode.queryCount'), key: 'queryCount', width: 90, render: (r) => (r.queryCount ?? '-') },
|
|
{ title: () => t('pages.traceCode.firstActivatedAt'), key: 'firstActivatedAt', width: 160, render: (r) => fmt(r.firstActivatedAt) },
|
|
{
|
|
title: () => t('pages.queryLog.ip'),
|
|
key: 'ip',
|
|
width: 190,
|
|
render: (r) => `${r.ip || '-'} / ${r.region || '-'}`,
|
|
},
|
|
{
|
|
title: () => t('pages.queryLog.device'),
|
|
key: 'deviceType',
|
|
width: 150,
|
|
render: (r) => [r.deviceType, r.os, r.browser].filter(Boolean).join(' / ') || '-',
|
|
},
|
|
{ title: () => t('pages.queryLog.queriedAt'), key: 'queriedAt', width: 160, render: (r) => fmt(r.queriedAt) },
|
|
];
|
|
|
|
async function load() {
|
|
loading.value = true;
|
|
try {
|
|
const res: any = await queryLogApi.list({
|
|
keyword: query.keyword || undefined,
|
|
archiveNo: query.archiveNo || undefined,
|
|
batchNo: query.batchNo || undefined,
|
|
result: query.result || undefined,
|
|
startTime: query.startTime,
|
|
endTime: query.endTime,
|
|
page: query.page,
|
|
pageSize: query.pageSize,
|
|
});
|
|
rows.value = res.list;
|
|
pagination.itemCount = res.total;
|
|
pagination.page = res.page;
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
function onRange(val: [number, number] | null) {
|
|
if (val) {
|
|
query.startTime = dayjs(val[0]).toISOString();
|
|
query.endTime = dayjs(val[1]).toISOString();
|
|
} else {
|
|
query.startTime = undefined;
|
|
query.endTime = undefined;
|
|
}
|
|
onSearch();
|
|
}
|
|
function onSearch() {
|
|
query.page = 1;
|
|
load();
|
|
}
|
|
function onPage(p: number) {
|
|
query.page = p;
|
|
load();
|
|
}
|
|
|
|
onMounted(load);
|
|
</script>
|