chore(frontend): introduce prettier + eslint and prune unused code
- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports) - Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier - Add root scripts: format, format:check, lint, lint:fix - Reformat 257 files across admin-web, ops-web, desktop-client, packages - Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters - Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex - Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,12 +17,7 @@
|
||||
allow-clear
|
||||
@press-enter="reload"
|
||||
/>
|
||||
<a-range-picker
|
||||
v-model:value="dateRange"
|
||||
show-time
|
||||
style="width: 360px"
|
||||
@change="reload"
|
||||
/>
|
||||
<a-range-picker v-model:value="dateRange" show-time style="width: 360px" @change="reload" />
|
||||
<a-button @click="reload">刷新</a-button>
|
||||
</div>
|
||||
|
||||
@@ -45,7 +40,7 @@
|
||||
</template>
|
||||
<template v-else-if="column.key === 'operator'">
|
||||
<template v-if="record.operator_id">
|
||||
<span>{{ record.operator_name || "—" }}</span>
|
||||
<span>{{ record.operator_name || '—' }}</span>
|
||||
<span style="color: #94a3b8; margin-left: 6px">#{{ record.operator_id }}</span>
|
||||
</template>
|
||||
<span v-else style="color: #94a3b8">系统</span>
|
||||
@@ -53,7 +48,7 @@
|
||||
<template v-else-if="column.key === 'target'">
|
||||
<span v-if="record.target_type">
|
||||
{{ record.target_type }}
|
||||
<template v-if="record.target_id"> #{{ record.target_id }}</template>
|
||||
<template v-if="record.target_id">#{{ record.target_id }}</template>
|
||||
</span>
|
||||
<span v-else style="color: #94a3b8">—</span>
|
||||
</template>
|
||||
@@ -78,136 +73,136 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { TablePaginationConfig } from "ant-design-vue";
|
||||
import { message } from "ant-design-vue";
|
||||
import dayjs, { type Dayjs } from "dayjs";
|
||||
import { computed, onMounted, reactive, ref, watch } from "vue";
|
||||
import type { TablePaginationConfig } from 'ant-design-vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import dayjs, { type Dayjs } from 'dayjs'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
|
||||
import { OpsApiError, http } from "@/lib/http";
|
||||
import { OpsApiError, http } from '@/lib/http'
|
||||
|
||||
interface AuditRow {
|
||||
id: number;
|
||||
operator_id: number | null;
|
||||
operator_name: string | null;
|
||||
action: string;
|
||||
target_type: string | null;
|
||||
target_id: string | null;
|
||||
metadata: Record<string, unknown> | null;
|
||||
ip: string | null;
|
||||
ip_region: string | null;
|
||||
user_agent: string | null;
|
||||
request_id: string | null;
|
||||
created_at: string;
|
||||
id: number
|
||||
operator_id: number | null
|
||||
operator_name: string | null
|
||||
action: string
|
||||
target_type: string | null
|
||||
target_id: string | null
|
||||
metadata: Record<string, unknown> | null
|
||||
ip: string | null
|
||||
ip_region: string | null
|
||||
user_agent: string | null
|
||||
request_id: string | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
interface ListResult {
|
||||
items: AuditRow[];
|
||||
total: number;
|
||||
page: number;
|
||||
size: number;
|
||||
items: AuditRow[]
|
||||
total: number
|
||||
page: number
|
||||
size: number
|
||||
}
|
||||
|
||||
const filter = reactive({
|
||||
action: "",
|
||||
});
|
||||
const operatorIdInput = ref<string>("");
|
||||
const dateRange = ref<[Dayjs, Dayjs] | null>(null);
|
||||
action: '',
|
||||
})
|
||||
const operatorIdInput = ref<string>('')
|
||||
const dateRange = ref<[Dayjs, Dayjs] | null>(null)
|
||||
|
||||
const columns = [
|
||||
{ title: "时间", key: "created_at", width: 180 },
|
||||
{ title: "操作员", key: "operator", width: 200 },
|
||||
{ title: "动作", key: "action", width: 220 },
|
||||
{ title: "对象", key: "target", width: 200 },
|
||||
{ title: "元数据", key: "metadata" },
|
||||
{ title: "IP", key: "ip", width: 220 },
|
||||
];
|
||||
{ title: '时间', key: 'created_at', width: 180 },
|
||||
{ title: '操作员', key: 'operator', width: 200 },
|
||||
{ title: '动作', key: 'action', width: 220 },
|
||||
{ title: '对象', key: 'target', width: 200 },
|
||||
{ title: '元数据', key: 'metadata' },
|
||||
{ title: 'IP', key: 'ip', width: 220 },
|
||||
]
|
||||
|
||||
const rows = ref<AuditRow[]>([]);
|
||||
const loading = ref(false);
|
||||
const page = ref(1);
|
||||
const size = ref(50);
|
||||
const total = ref(0);
|
||||
const rows = ref<AuditRow[]>([])
|
||||
const loading = ref(false)
|
||||
const page = ref(1)
|
||||
const size = ref(50)
|
||||
const total = ref(0)
|
||||
|
||||
const pagination = computed<TablePaginationConfig>(() => ({
|
||||
current: page.value,
|
||||
pageSize: size.value,
|
||||
total: total.value,
|
||||
showSizeChanger: true,
|
||||
pageSizeOptions: ["20", "50", "100", "200"],
|
||||
}));
|
||||
pageSizeOptions: ['20', '50', '100', '200'],
|
||||
}))
|
||||
|
||||
watch(operatorIdInput, () => {
|
||||
// user typing — no auto-load, wait for Enter or refresh
|
||||
});
|
||||
})
|
||||
|
||||
async function reload() {
|
||||
loading.value = true;
|
||||
loading.value = true
|
||||
try {
|
||||
const params: Record<string, unknown> = {
|
||||
page: page.value,
|
||||
size: size.value,
|
||||
};
|
||||
if (filter.action.trim()) params.action = filter.action.trim();
|
||||
}
|
||||
if (filter.action.trim()) params.action = filter.action.trim()
|
||||
if (operatorIdInput.value.trim()) {
|
||||
const id = Number(operatorIdInput.value.trim());
|
||||
const id = Number(operatorIdInput.value.trim())
|
||||
if (!Number.isFinite(id) || id <= 0) {
|
||||
message.warning("操作员 ID 必须是正整数");
|
||||
loading.value = false;
|
||||
return;
|
||||
message.warning('操作员 ID 必须是正整数')
|
||||
loading.value = false
|
||||
return
|
||||
}
|
||||
params.operator_id = id;
|
||||
params.operator_id = id
|
||||
}
|
||||
if (dateRange.value) {
|
||||
params.start_at = dateRange.value[0].toISOString();
|
||||
params.end_at = dateRange.value[1].toISOString();
|
||||
params.start_at = dateRange.value[0].toISOString()
|
||||
params.end_at = dateRange.value[1].toISOString()
|
||||
}
|
||||
|
||||
const result = await http.get<ListResult>("/audits", params);
|
||||
rows.value = result.items;
|
||||
total.value = result.total;
|
||||
const result = await http.get<ListResult>('/audits', params)
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
} catch (error) {
|
||||
if (error instanceof OpsApiError) message.error(error.detail || error.message);
|
||||
if (error instanceof OpsApiError) message.error(error.detail || error.message)
|
||||
} finally {
|
||||
loading.value = false;
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function onTableChange(pag: TablePaginationConfig) {
|
||||
page.value = pag.current ?? 1;
|
||||
size.value = pag.pageSize ?? 50;
|
||||
void reload();
|
||||
page.value = pag.current ?? 1
|
||||
size.value = pag.pageSize ?? 50
|
||||
void reload()
|
||||
}
|
||||
|
||||
function formatDate(value: string): string {
|
||||
return dayjs(value).format("YYYY-MM-DD HH:mm:ss");
|
||||
return dayjs(value).format('YYYY-MM-DD HH:mm:ss')
|
||||
}
|
||||
|
||||
function formatMetadata(meta: Record<string, unknown>): string {
|
||||
try {
|
||||
return JSON.stringify(meta);
|
||||
return JSON.stringify(meta)
|
||||
} catch {
|
||||
return String(meta);
|
||||
return String(meta)
|
||||
}
|
||||
}
|
||||
|
||||
function formatIPRegion(region: string): string {
|
||||
const parts = region
|
||||
.split("|")
|
||||
.split('|')
|
||||
.map((part) => part.trim())
|
||||
.filter((part) => part && part !== "0");
|
||||
return parts.length > 0 ? parts.join(" / ") : region;
|
||||
.filter((part) => part && part !== '0')
|
||||
return parts.length > 0 ? parts.join(' / ') : region
|
||||
}
|
||||
|
||||
function resolveActionColor(action: string): string {
|
||||
if (action.endsWith(".failure") || action.includes("disable")) return "red";
|
||||
if (action.endsWith(".success") || action.includes("create")) return "green";
|
||||
if (action.includes("password") || action.includes("update")) return "orange";
|
||||
return "blue";
|
||||
if (action.endsWith('.failure') || action.includes('disable')) return 'red'
|
||||
if (action.endsWith('.success') || action.includes('create')) return 'green'
|
||||
if (action.includes('password') || action.includes('update')) return 'orange'
|
||||
return 'blue'
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void reload();
|
||||
});
|
||||
void reload()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user