@@ -11,6 +11,7 @@ import AdminLogin from './components/AdminLogin.vue'
|
||||
import AdminLoginLogs from './components/AdminLoginLogs.vue'
|
||||
import AdminMapSource from './components/AdminMapSource.vue'
|
||||
import AdminMqttForward from './components/AdminMqttForward.vue'
|
||||
import AdminSignManagement from './components/AdminSignManagement.vue'
|
||||
import AdminUsers from './components/AdminUsers.vue'
|
||||
import ChatPanel from './components/ChatPanel.vue'
|
||||
import ConfirmDeleteModal from './components/ConfirmDeleteModal.vue'
|
||||
@@ -18,6 +19,7 @@ import HelpPage from './components/HelpPage.vue'
|
||||
import MeshMap from './components/MeshMap.vue'
|
||||
import NodeDetailedPage from './components/NodeDetailedPage.vue'
|
||||
import NodeListPanel from './components/NodeListPanel.vue'
|
||||
import SignedPage from './components/SignedPage.vue'
|
||||
import { fallbackMapSource, loadEnabledMapSources } from './mapSource'
|
||||
import type { AdminUser, HealthStatus, MapBoundsChangePayload, MapBoundsQuery, MapRenderable, MapViewportItem, MapViewportPoint, NodeInfo, NodeInfoById, PositionRecord, PublicMapTileSource, TextMessage } from './types'
|
||||
|
||||
@@ -27,10 +29,12 @@ const isAdminPage = adminPath.startsWith('/admin')
|
||||
const isMqttForwardAdminPage = adminPath === '/admin/mqtt_forward' || adminPath === '/admin/mqtt_forward/'
|
||||
const isBotAdminPage = adminPath === '/admin/bot' || adminPath === '/admin/bot/'
|
||||
const isBotDirectAdminPage = adminPath === '/admin/bot/direct' || adminPath === '/admin/bot/direct/'
|
||||
const isSignAdminPage = adminPath === '/admin/sign' || adminPath === '/admin/sign/'
|
||||
const detailMatch = currentPath.match(/^\/detailed\/(.+)$/)
|
||||
const detailedNodeId = detailMatch ? decodeURIComponent(detailMatch[1]) : ''
|
||||
const isDetailedPage = !!detailedNodeId
|
||||
const isHelpPage = currentPath === '/help'
|
||||
const isSignedPage = currentPath === '/signed'
|
||||
const adminUser = ref<AdminUser | null>(null)
|
||||
const adminChecking = ref(false)
|
||||
|
||||
@@ -509,7 +513,7 @@ onMounted(() => {
|
||||
return
|
||||
}
|
||||
checkAdminSession()
|
||||
if (isDetailedPage || isHelpPage) {
|
||||
if (isDetailedPage || isHelpPage || isSignedPage) {
|
||||
return
|
||||
}
|
||||
loadMapSource()
|
||||
@@ -545,6 +549,7 @@ onBeforeUnmount(() => {
|
||||
<a href="/admin/mqtt_forward/" :class="{ active: isMqttForwardAdminPage }">MQTT转发</a>
|
||||
<a href="/admin/bot" :class="{ active: isBotAdminPage }">机器人</a>
|
||||
<a href="/admin/bot/direct" :class="{ active: isBotDirectAdminPage }">机器人私聊</a>
|
||||
<a href="/admin/sign" :class="{ active: isSignAdminPage }">签到管理</a>
|
||||
<a href="/admin/map_source" :class="{ active: adminPath === '/admin/map_source' }">地图图源</a>
|
||||
<a href="/admin/help_edit" :class="{ active: adminPath === '/admin/help_edit' }">帮助编辑</a>
|
||||
<a href="/admin/log/login" :class="{ active: adminPath === '/admin/log/login' }">登录日志</a>
|
||||
@@ -564,6 +569,7 @@ onBeforeUnmount(() => {
|
||||
<template v-else>
|
||||
|
||||
<span class="counter">节点 {{ nodeTotal }} · 已加载消息 {{ messages.length }} · 坐标 {{ mapItems.length }} / {{ mapReportTotal }}{{ mapViewportMode === 'clusters' ? ' · 已聚合' : '' }}{{ mapReportsLoading ? ' · 坐标加载中...' : '' }}</span>
|
||||
<a class="topbar-link" href="/signed">签到列表</a>
|
||||
<a class="topbar-link" href="/help">使用帮助</a>
|
||||
<a class="topbar-link" href="/admin">管理</a>
|
||||
<button @click="() => refresh()" :disabled="loading">{{ loading ? '刷新中...' : '刷新' }}</button>
|
||||
@@ -587,6 +593,7 @@ onBeforeUnmount(() => {
|
||||
<AdminMqttForward v-else-if="isMqttForwardAdminPage" />
|
||||
<AdminBot v-else-if="isBotAdminPage" />
|
||||
<AdminBotDirect v-else-if="isBotDirectAdminPage" />
|
||||
<AdminSignManagement v-else-if="isSignAdminPage" />
|
||||
<AdminMapSource v-else-if="adminPath === '/admin/map_source'" />
|
||||
<AdminHelpEdit v-else-if="adminPath === '/admin/help_edit'" />
|
||||
<AdminLoginLogs v-else-if="adminPath === '/admin/log/login'" />
|
||||
@@ -604,6 +611,10 @@ onBeforeUnmount(() => {
|
||||
<HelpPage />
|
||||
</template>
|
||||
|
||||
<template v-else-if="isSignedPage">
|
||||
<SignedPage />
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ import type {
|
||||
PositionRecord,
|
||||
PublicMapTileSourceResponse,
|
||||
PublicMapTileSourcesResponse,
|
||||
SignRecord,
|
||||
SignRecordPayload,
|
||||
TelemetryRecord,
|
||||
TextMessage,
|
||||
BotDirectMessage,
|
||||
@@ -167,6 +169,26 @@ export function getTextMessages(limit = 100, offset = 0, nodeIdOrOptions: string
|
||||
return getJSON<ListResponse<TextMessage>>(listPath('/api/text-messages', limit, offset, nodeIdOrOptions))
|
||||
}
|
||||
|
||||
export function getSignRecords(limit = 100, offset = 0, nodeIdOrOptions: string | ListQueryOptions = ''): Promise<ListResponse<SignRecord>> {
|
||||
return getJSON<ListResponse<SignRecord>>(listPath('/api/signs', limit, offset, nodeIdOrOptions))
|
||||
}
|
||||
|
||||
export function getAdminSignRecords(limit = 100, offset = 0, nodeIdOrOptions: string | ListQueryOptions = ''): Promise<ListResponse<SignRecord>> {
|
||||
return getJSON<ListResponse<SignRecord>>(listPath('/api/admin/signs', limit, offset, nodeIdOrOptions))
|
||||
}
|
||||
|
||||
export function createAdminSignRecord(payload: SignRecordPayload): Promise<{ item: SignRecord }> {
|
||||
return postJSON<{ item: SignRecord }>('/api/admin/signs', payload)
|
||||
}
|
||||
|
||||
export function updateAdminSignRecord(id: number, payload: SignRecordPayload): Promise<{ item: SignRecord }> {
|
||||
return putJSON<{ item: SignRecord }>(`/api/admin/signs/${id}`, payload)
|
||||
}
|
||||
|
||||
export function deleteAdminSignRecord(id: number): Promise<{ status: string }> {
|
||||
return deleteJSON<{ status: string }>(`/api/admin/signs/${id}`)
|
||||
}
|
||||
|
||||
export function deleteTextMessage(id: number): Promise<{ status: string }> {
|
||||
return deleteJSON<{ status: string }>(`/api/admin/text-messages/${id}`)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { createAdminSignRecord, deleteAdminSignRecord, getAdminSignRecords, updateAdminSignRecord } from '../api'
|
||||
import type { SignRecord, SignRecordPayload } from '../types'
|
||||
|
||||
const pageSize = 25
|
||||
const records = ref<SignRecord[]>([])
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const message = ref('')
|
||||
const page = ref(1)
|
||||
const total = ref(0)
|
||||
const newNodeID = ref('')
|
||||
const newLongName = ref('')
|
||||
const newShortName = ref('')
|
||||
const newSignText = ref('')
|
||||
const newSignTime = ref(toDateTimeLocal(new Date().toISOString()))
|
||||
const edits = ref<Record<number, SignRecordPayload>>({})
|
||||
|
||||
function formatTime(value: string): string {
|
||||
return new Date(value).toLocaleString()
|
||||
}
|
||||
|
||||
function toDateTimeLocal(value: string): string {
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return ''
|
||||
}
|
||||
const offset = date.getTimezoneOffset() * 60000
|
||||
return new Date(date.getTime() - offset).toISOString().slice(0, 16)
|
||||
}
|
||||
|
||||
function toRFC3339(value: string): string | undefined {
|
||||
if (!value) {
|
||||
return undefined
|
||||
}
|
||||
const date = new Date(value)
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
throw new Error('签到时间格式无效')
|
||||
}
|
||||
return date.toISOString()
|
||||
}
|
||||
|
||||
function canPrev(): boolean {
|
||||
return page.value > 1
|
||||
}
|
||||
|
||||
function canNext(): boolean {
|
||||
return page.value * pageSize < total.value || records.value.length === pageSize
|
||||
}
|
||||
|
||||
function signPayload(nodeID: string, longName: string, shortName: string, signText: string, signTime: string): SignRecordPayload {
|
||||
if (!nodeID.trim()) {
|
||||
throw new Error('节点 ID 不能为空')
|
||||
}
|
||||
if (!signText.trim()) {
|
||||
throw new Error('签到文本不能为空')
|
||||
}
|
||||
return {
|
||||
node_id: nodeID.trim(),
|
||||
long_name: longName.trim(),
|
||||
short_name: shortName.trim(),
|
||||
sign_text: signText.trim(),
|
||||
sign_time: toRFC3339(signTime),
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshSigns(nextPage = page.value) {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const safePage = Math.max(1, nextPage)
|
||||
const response = await getAdminSignRecords(pageSize, (safePage - 1) * pageSize)
|
||||
records.value = response.items
|
||||
total.value = response.total ?? response.offset + response.items.length
|
||||
page.value = safePage
|
||||
edits.value = {}
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function createSign() {
|
||||
error.value = ''
|
||||
message.value = ''
|
||||
let payload: SignRecordPayload
|
||||
try {
|
||||
payload = signPayload(newNodeID.value, newLongName.value, newShortName.value, newSignText.value, newSignTime.value)
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err)
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
await createAdminSignRecord(payload)
|
||||
newNodeID.value = ''
|
||||
newLongName.value = ''
|
||||
newShortName.value = ''
|
||||
newSignText.value = ''
|
||||
newSignTime.value = toDateTimeLocal(new Date().toISOString())
|
||||
message.value = '签到记录已新增'
|
||||
await refreshSigns(1)
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function startEdit(record: SignRecord) {
|
||||
edits.value = {
|
||||
...edits.value,
|
||||
[record.id]: {
|
||||
node_id: record.node_id,
|
||||
long_name: record.long_name || '',
|
||||
short_name: record.short_name || '',
|
||||
sign_text: record.sign_text,
|
||||
sign_time: toDateTimeLocal(record.sign_time),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function cancelEdit(id: number) {
|
||||
const next = { ...edits.value }
|
||||
delete next[id]
|
||||
edits.value = next
|
||||
}
|
||||
|
||||
async function saveSign(record: SignRecord) {
|
||||
const edit = edits.value[record.id]
|
||||
if (!edit) {
|
||||
return
|
||||
}
|
||||
error.value = ''
|
||||
message.value = ''
|
||||
let payload: SignRecordPayload
|
||||
try {
|
||||
payload = signPayload(edit.node_id, edit.long_name, edit.short_name, edit.sign_text, edit.sign_time || '')
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err)
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
await updateAdminSignRecord(record.id, payload)
|
||||
message.value = '签到记录已保存'
|
||||
await refreshSigns()
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function removeSign(record: SignRecord) {
|
||||
if (!window.confirm(`确定要删除节点 ${record.node_id} 的签到记录吗?`)) {
|
||||
return
|
||||
}
|
||||
error.value = ''
|
||||
message.value = ''
|
||||
loading.value = true
|
||||
try {
|
||||
await deleteAdminSignRecord(record.id)
|
||||
message.value = '签到记录已删除'
|
||||
await refreshSigns(records.value.length === 1 ? page.value - 1 : page.value)
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => refreshSigns())
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-dashboard">
|
||||
<div class="panel admin-status-panel">
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<p class="eyebrow">Sign</p>
|
||||
<h2>签到管理</h2>
|
||||
</div>
|
||||
<button class="admin-button" :disabled="loading" @click="refreshSigns()">{{ loading ? '刷新中...' : '刷新签到' }}</button>
|
||||
</div>
|
||||
|
||||
<form class="admin-form" @submit.prevent="createSign">
|
||||
<label>
|
||||
<span>节点 ID</span>
|
||||
<input v-model="newNodeID" autocomplete="off" placeholder="!1234abcd" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Long Name</span>
|
||||
<input v-model="newLongName" autocomplete="off" placeholder="Long Name" />
|
||||
</label>
|
||||
<label>
|
||||
<span>Short Name</span>
|
||||
<input v-model="newShortName" autocomplete="off" placeholder="Short" />
|
||||
</label>
|
||||
<label>
|
||||
<span>签到时间</span>
|
||||
<input v-model="newSignTime" type="datetime-local" />
|
||||
</label>
|
||||
<label class="admin-form-wide">
|
||||
<span>签到文本</span>
|
||||
<input v-model="newSignText" autocomplete="off" placeholder="签到文本" />
|
||||
</label>
|
||||
<button class="admin-button" :disabled="loading" type="submit">新增签到</button>
|
||||
</form>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-if="message" class="success">{{ message }}</p>
|
||||
|
||||
<div class="node-table-wrap">
|
||||
<table class="node-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>节点 ID</th>
|
||||
<th>Long Name</th>
|
||||
<th>Short Name</th>
|
||||
<th>签到文本</th>
|
||||
<th>签到时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="record in records" :key="record.id">
|
||||
<template v-if="edits[record.id]">
|
||||
<td>{{ record.id }}</td>
|
||||
<td><input v-model="edits[record.id].node_id" class="admin-table-input" /></td>
|
||||
<td><input v-model="edits[record.id].long_name" class="admin-table-input" /></td>
|
||||
<td><input v-model="edits[record.id].short_name" class="admin-table-input" /></td>
|
||||
<td><input v-model="edits[record.id].sign_text" class="admin-table-input" /></td>
|
||||
<td><input v-model="edits[record.id].sign_time" class="admin-table-input" type="datetime-local" /></td>
|
||||
<td>
|
||||
<button class="admin-button" :disabled="loading" @click="saveSign(record)">保存</button>
|
||||
<button class="admin-button" :disabled="loading" @click="cancelEdit(record.id)">取消</button>
|
||||
</td>
|
||||
</template>
|
||||
<template v-else>
|
||||
<td>{{ record.id }}</td>
|
||||
<td>{{ record.node_id }}</td>
|
||||
<td>{{ record.long_name || '-' }}</td>
|
||||
<td>{{ record.short_name || '-' }}</td>
|
||||
<td>{{ record.sign_text }}</td>
|
||||
<td>{{ formatTime(record.sign_time) }}</td>
|
||||
<td>
|
||||
<button class="admin-button" :disabled="loading" @click="startEdit(record)">编辑</button>
|
||||
<button class="admin-button danger" :disabled="loading" @click="removeSign(record)">删除</button>
|
||||
</td>
|
||||
</template>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-if="records.length === 0" class="empty">{{ loading ? '加载中...' : '暂无签到记录' }}</div>
|
||||
</div>
|
||||
|
||||
<div class="pagination">
|
||||
<button class="admin-button" :disabled="!canPrev() || loading" @click="refreshSigns(page - 1)">上一页</button>
|
||||
<span>第 {{ page }} 页 / 共 {{ total }} 条</span>
|
||||
<button class="admin-button" :disabled="!canNext() || loading" @click="refreshSigns(page + 1)">下一页</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,87 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { getSignRecords } from '../api'
|
||||
import type { SignRecord } from '../types'
|
||||
|
||||
const pageSize = 25
|
||||
const records = ref<SignRecord[]>([])
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const page = ref(1)
|
||||
const total = ref(0)
|
||||
|
||||
function formatTime(value: string): string {
|
||||
return new Date(value).toLocaleString()
|
||||
}
|
||||
|
||||
function canPrev(): boolean {
|
||||
return page.value > 1
|
||||
}
|
||||
|
||||
function canNext(): boolean {
|
||||
return page.value * pageSize < total.value || records.value.length === pageSize
|
||||
}
|
||||
|
||||
async function loadRecords(nextPage = page.value) {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const safePage = Math.max(1, nextPage)
|
||||
const response = await getSignRecords(pageSize, (safePage - 1) * pageSize)
|
||||
records.value = response.items
|
||||
total.value = response.total ?? response.offset + response.items.length
|
||||
page.value = safePage
|
||||
} catch (err) {
|
||||
error.value = err instanceof Error ? err.message : String(err)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => loadRecords())
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-dashboard">
|
||||
<div class="panel admin-status-panel">
|
||||
<div class="panel-header">
|
||||
<div>
|
||||
<p class="eyebrow">Signed</p>
|
||||
<h2>签到用户</h2>
|
||||
</div>
|
||||
<span class="counter">共 {{ total }} 条签到记录</span>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<div class="node-table-wrap">
|
||||
<table class="node-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>节点 ID</th>
|
||||
<th>Long Name</th>
|
||||
<th>Short Name</th>
|
||||
<th>签到文本</th>
|
||||
<th>签到时间</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="record in records" :key="record.id">
|
||||
<td>{{ record.node_id }}</td>
|
||||
<td>{{ record.long_name || '-' }}</td>
|
||||
<td>{{ record.short_name || '-' }}</td>
|
||||
<td>{{ record.sign_text }}</td>
|
||||
<td>{{ formatTime(record.sign_time) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-if="records.length === 0" class="empty">{{ loading ? '加载中...' : '暂无签到记录' }}</div>
|
||||
</div>
|
||||
|
||||
<div class="pagination">
|
||||
<button class="admin-button" :disabled="!canPrev() || loading" @click="loadRecords(page - 1)">上一页</button>
|
||||
<span>第 {{ page }} 页</span>
|
||||
<button class="admin-button" :disabled="!canNext() || loading" @click="loadRecords(page + 1)">下一页</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -149,6 +149,23 @@ export interface TextMessage {
|
||||
content_json: string
|
||||
}
|
||||
|
||||
export interface SignRecord {
|
||||
id: number
|
||||
node_id: string
|
||||
long_name: string | null
|
||||
short_name: string | null
|
||||
sign_text: string
|
||||
sign_time: string
|
||||
}
|
||||
|
||||
export interface SignRecordPayload {
|
||||
node_id: string
|
||||
long_name: string
|
||||
short_name: string
|
||||
sign_text: string
|
||||
sign_time?: string
|
||||
}
|
||||
|
||||
// 机器人 PKI 私聊(bot_direct_messages 表)。direction 区分本地 bot 视角的进出方向。
|
||||
export interface BotDirectMessage {
|
||||
id: number
|
||||
|
||||
Reference in New Issue
Block a user