Files
console-dev/app/pages/logbook/index.vue
T

400 lines
13 KiB
Vue

<script>
/**
* 操作日志:系统/API 日志与关键词、排序通过分页接口查询;路由 type 仅接受 api,其余回落为 system。
*/
import "~/assets/styles/logbook.Y7gm684m.css";
import { toDisplayString } from "vue";
import { watch } from "vue";
import { createBlock } from "vue";
import { ref } from "vue";
import { withCtx } from "vue";
import { createCommentVNode } from "vue";
import { computed } from "vue";
import { isRef } from "vue";
import { createElementBlock } from "vue";
import { createElementVNode } from "vue";
import { createTextVNode } from "vue";
import { unref } from "vue";
import { defineComponent } from "vue";
import { createVNode } from "vue";
import { openBlock } from "vue";
import { withKeys } from "vue";
import { useRoute } from "#app";
import { operationMessage } from "~/lib/auth.js";
import button from "primevue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
import message from "primevue/message";
import inputtext from "primevue/inputtext";
import { r as dict_r } from "~/lib/dict.js";
import datatable from "primevue/datatable";
import paginator from "primevue/paginator";
import select from "primevue/select";
import column from "primevue/column";
import ListEmpty from "~/components/ListEmpty.vue";
import { t as useListPage_t } from "~/lib/useListPage.js";
var k = {
class: `list-page`,
},
A = {
class: `list-toolbar`,
},
j = {
class: `list-toolbar-right`,
},
M = {
class: `list-table`,
},
N = {
class: `col-mono`,
},
P = {
key: 1,
class: `list-foot`,
},
F = _plugin_vue_export_helper_t(
defineComponent({
__name: `index`,
setup(f) {
let y = ref(``),
F = ref(``),
I = useRoute(),
L = ref(I.query.type === `api` ? `api` : `system`),
R = ref(`id`),
z = ref(`desc`),
{
list: B,
total: V,
loading: H,
error: U,
page: W,
limit: G,
onPage: K,
reload: q,
} = useListPage_t(`/log`, {
limit: 20,
params: () => ({
keywords: F.value,
type: L.value,
orderby: R.value,
sort: z.value,
}),
});
watch(
() => I.query.type,
(e) => {
let t = e === `api` ? `api` : `system`;
L.value !== t && ((L.value = t), q());
},
);
let J = computed(() => !!F.value || L.value !== `system`);
// 搜索输入在确认后复制到已应用关键词,并让分页工具重新查询。
function Y() {
((F.value = y.value.trim()), q());
}
// 清空筛选并恢复默认 ID 倒序和系统日志类型,再刷新列表。
function X() {
((y.value = ``),
(F.value = ``),
(L.value = `system`),
(R.value = `id`),
(z.value = `desc`),
q());
}
// 表格使用公共分页工具返回的列表和错误,搜索草稿与已生效关键词保持分离。
return (t, r) => {
let o = select,
f = inputtext,
g = button,
O = ListEmpty,
F = column,
I = datatable,
Z = message,
Q = paginator;
return (
openBlock(),
createElementBlock(`div`, k, [
(r[5] ||= createElementVNode(
`div`,
{
class: `list-head`,
},
[createElementVNode(`h2`, null, `操作日志`)],
-1,
)),
createElementVNode(`div`, A, [
createElementVNode(`div`, j, [
createVNode(
o,
{
modelValue: unref(L),
"onUpdate:modelValue": (r[0] ||= (e) =>
isRef(L) ? (L.value = e) : null),
options: [
{
label: `系统日志`,
value: `system`,
},
{
label: `API 日志`,
value: `api`,
},
],
"option-label": `label`,
"option-value": `value`,
"aria-label": `日志类型`,
onChange: unref(q),
},
null,
8,
[`modelValue`, `onChange`],
),
createVNode(
o,
{
modelValue: unref(R),
"onUpdate:modelValue": (r[1] ||= (e) =>
isRef(R) ? (R.value = e) : null),
options: [
{
label: `记录 ID`,
value: `id`,
},
{
label: `创建时间`,
value: `create_time`,
},
{
label: `操作内容`,
value: `description`,
},
{
label: `IP`,
value: `ip`,
},
],
"option-label": `label`,
"option-value": `value`,
"aria-label": `日志排序字段`,
onChange: unref(q),
},
null,
8,
[`modelValue`, `onChange`],
),
createVNode(
o,
{
modelValue: unref(z),
"onUpdate:modelValue": (r[2] ||= (e) =>
isRef(z) ? (z.value = e) : null),
options: [
{
label: `降序`,
value: `desc`,
},
{
label: `升序`,
value: `asc`,
},
],
"option-label": `label`,
"option-value": `value`,
"aria-label": `日志排序方向`,
onChange: unref(q),
},
null,
8,
[`modelValue`, `onChange`],
),
createVNode(
f,
{
modelValue: unref(y),
"onUpdate:modelValue": (r[3] ||= (e) =>
isRef(y) ? (y.value = e) : null),
class: `list-search`,
placeholder: `输入关键字`,
onKeyup: withKeys(Y, [`enter`]),
},
null,
8,
[`modelValue`],
),
createVNode(g, {
label: `清除筛选`,
icon: `pi pi-filter-slash`,
severity: `secondary`,
text: ``,
size: `small`,
onClick: X,
}),
]),
]),
createElementVNode(`div`, M, [
createVNode(
I,
{
value: unref(B),
loading: unref(H),
lazy: ``,
rows: unref(G),
totalRecords: unref(V),
first: (unref(W) - 1) * unref(G),
dataKey: `id`,
},
{
empty: withCtx(() => [
createVNode(
O,
{
icon: `pi pi-history`,
title: unref(H) ? `加载中…` : `暂无日志`,
description: unref(J)
? `换个关键字试试`
: `账户操作与登录记录会显示在这里`,
},
null,
8,
[`title`, `description`],
),
]),
default: withCtx(() => [
createVNode(
F,
{
header: `创建时间`,
style: {
width: `180px`,
},
},
{
body: withCtx(({ data: n }) => [
createTextVNode(
toDisplayString(
(`formatTime` in t
? t.formatTime
: unref(dict_r))(n.create_time),
),
1,
),
]),
_: 1,
},
),
createVNode(
F,
{
field: `id`,
header: `ID`,
style: {
width: `120px`,
},
},
{
body: withCtx(({ data: t }) => [
createTextVNode(`#` + toDisplayString(t.id), 1),
]),
_: 1,
},
),
createVNode(
F,
{
header: `操作内容`,
style: {
"min-width": `320px`,
},
},
{
body: withCtx(({ data: t }) => [
createTextVNode(
toDisplayString(
unref(operationMessage)(t.description),
),
1,
),
]),
_: 1,
},
),
createVNode(
F,
{
header: `IP`,
style: {
width: `200px`,
},
},
{
body: withCtx(({ data: t }) => [
createElementVNode(
`span`,
N,
toDisplayString(t.ip || `—`),
1,
),
]),
_: 1,
},
),
]),
_: 1,
},
8,
[`value`, `loading`, `rows`, `totalRecords`, `first`],
),
]),
unref(U)
? (openBlock(),
createBlock(
Z,
{
key: 0,
severity: `error`,
closable: !1,
},
{
default: withCtx(() => [
createTextVNode(toDisplayString(unref(U)), 1),
]),
_: 1,
},
))
: createCommentVNode(``, !0),
unref(V) > 0
? (openBlock(),
createElementBlock(`div`, P, [
(r[4] ||= createElementVNode(
`div`,
{
class: `list-bulk`,
},
null,
-1,
)),
createVNode(
Q,
{
rows: unref(G),
totalRecords: unref(V),
first: (unref(W) - 1) * unref(G),
rowsPerPageOptions: [20, 50, 100],
onPage: unref(K),
},
null,
8,
[`rows`, `totalRecords`, `first`, `onPage`],
),
]))
: createCommentVNode(``, !0),
])
);
};
},
}),
[[`__scopeId`, `data-v-0e32233b`]],
);
export {};
export default F;
</script>