Compare commits
2 Commits
652cf6df1a
...
20449811e0
| Author | SHA1 | Date |
|---|---|---|
|
|
20449811e0 | |
|
|
22d633f9be |
|
|
@ -1,6 +1,6 @@
|
|||
# 见物管理后台
|
||||
|
||||
用平台管理员账号登录,输入空间 ID 查询空间名称、物品和图片数量。删除需要再次输入空间 ID。服务端记录操作人和时间,并异步清理原图和缩略图。
|
||||
用平台管理员账号登录。空间列表每页 25 条,可以按名称查找,也可输入完整空间 ID 直达详情。列表只返回名称和 ID,物品和照片数量打开详情时读取。删除需要再次输入空间 ID。服务端记录操作人和时间,并异步清理原图和缩略图。
|
||||
|
||||
```sh
|
||||
npm ci
|
||||
|
|
@ -9,3 +9,5 @@ docker build -t item-atlas-admin:dev .
|
|||
```
|
||||
|
||||
镜像监听 8080。容器环境变量 `ATLAS_GATEWAY_URL` 指向内网网关。`VITE_OIDC_URL`、`VITE_OIDC_REALM` 是构建参数,对应管理员登录所用的 Keycloak。应用只向同源 `/api/admin/` 发请求,由 Nginx 转发。Keycloak 的回调、权限和入口配置见 [身份和图片部署](../../docs/deployment/identity-and-media.md)。
|
||||
|
||||
列表使用 `GET /api/admin/households?q=&limit=25&offset=0`,按名称及 ID 排序。名称按字面包含匹配,查询长度最多 100,页大小为 1 至 100。响应中的 `hasMore` 决定是否提供下一页。查询、详情和删除沿用 `atlas-admin` 客户端与 `atlas-space-admin` 角色鉴权。部署后台镜像前先部署包含列表接口的物品服务,然后在内部入口用管理员与普通账号分别检查权限。
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ import { computed, onMounted, ref } from 'vue'
|
|||
import Keycloak from 'keycloak-js'
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
||||
|
||||
interface Space { id: string; name: string; items: number; photos: number }
|
||||
interface SpaceSummary { id: string; name: string }
|
||||
interface Space extends SpaceSummary { items: number; photos: number }
|
||||
interface SpacePage { spaces: SpaceSummary[]; hasMore: boolean }
|
||||
|
||||
const pageSize = 25
|
||||
|
||||
const keycloak = new Keycloak({
|
||||
url: import.meta.env.VITE_OIDC_URL || 'https://api-atlas.tutudog.com/auth',
|
||||
|
|
@ -14,27 +18,32 @@ const logout = () => keycloak.logout({ redirectUri: window.location.origin + '/'
|
|||
const initialized = ref(false)
|
||||
const authorized = ref(false)
|
||||
const input = ref('')
|
||||
const activeQuery = ref('')
|
||||
const pageOffset = ref(0)
|
||||
const page = ref<SpacePage>()
|
||||
const space = ref<Space>()
|
||||
const busy = ref(false)
|
||||
const error = ref('')
|
||||
const success = ref('')
|
||||
const confirming = ref(false)
|
||||
const confirmation = ref('')
|
||||
const validId = computed(() => /^[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}$/i.test(input.value.trim()))
|
||||
const isId = (value: string) => /^[\da-f]{8}(-[\da-f]{4}){3}-[\da-f]{12}$/i.test(value)
|
||||
const pageNumber = computed(() => pageOffset.value / pageSize + 1)
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await keycloak.init({ onLoad: 'login-required', pkceMethod: 'S256', checkLoginIframe: false })
|
||||
authorized.value = keycloak.tokenParsed?.atlas_roles?.includes('atlas-space-admin') === true
|
||||
if (!authorized.value) error.value = '当前账号没有空间管理权限。'
|
||||
if (authorized.value) await loadPage(0, '')
|
||||
else error.value = '当前账号没有空间管理权限。'
|
||||
} catch {
|
||||
error.value = '无法连接登录服务,请刷新页面后重试。'
|
||||
} finally { initialized.value = true }
|
||||
})
|
||||
|
||||
async function request(id: string, method = 'GET') {
|
||||
async function request(path = '', method = 'GET') {
|
||||
await keycloak.updateToken(30)
|
||||
const response = await fetch(`/api/admin/households/${id}`, {
|
||||
const response = await fetch(`/api/admin/households${path}`, {
|
||||
method, cache: 'no-store', headers: { Authorization: `Bearer ${keycloak.token}` },
|
||||
})
|
||||
if (!response.ok) {
|
||||
|
|
@ -45,12 +54,39 @@ async function request(id: string, method = 'GET') {
|
|||
return response
|
||||
}
|
||||
|
||||
async function findSpace() {
|
||||
if (!validId.value || busy.value) return
|
||||
async function readPage(offset: number, query: string) {
|
||||
const params = new URLSearchParams({ q: query, limit: String(pageSize), offset: String(offset) })
|
||||
const result: SpacePage = await (await request(`?${params}`)).json()
|
||||
page.value = result
|
||||
pageOffset.value = offset
|
||||
activeQuery.value = query
|
||||
}
|
||||
|
||||
async function loadPage(offset: number, query = activeQuery.value) {
|
||||
if (busy.value) return
|
||||
busy.value = true
|
||||
space.value = undefined
|
||||
success.value = error.value = ''
|
||||
try { space.value = await (await request(input.value.trim())).json() }
|
||||
try { await readPage(offset, query) }
|
||||
catch (failure) { error.value = failure instanceof Error ? failure.message : '列表加载失败。' }
|
||||
finally { busy.value = false }
|
||||
}
|
||||
|
||||
function findSpace() {
|
||||
const query = input.value.trim()
|
||||
if (isId(query)) {
|
||||
page.value = undefined
|
||||
return openSpace(query)
|
||||
}
|
||||
return loadPage(0, query)
|
||||
}
|
||||
|
||||
async function openSpace(id: string) {
|
||||
if (busy.value) return
|
||||
busy.value = true
|
||||
space.value = undefined
|
||||
success.value = error.value = ''
|
||||
try { space.value = await (await request(`/${id}`)).json() }
|
||||
catch (failure) { error.value = failure instanceof Error ? failure.message : '查询失败。' }
|
||||
finally { busy.value = false }
|
||||
}
|
||||
|
|
@ -60,10 +96,21 @@ async function deleteSpace() {
|
|||
busy.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
await request(space.value.id, 'DELETE')
|
||||
await request(`/${space.value.id}`, 'DELETE')
|
||||
success.value = '空间已删除,原图和缩略图已进入清理队列。'
|
||||
space.value = undefined
|
||||
confirming.value = false
|
||||
if (page.value) {
|
||||
try {
|
||||
await readPage(pageOffset.value, activeQuery.value)
|
||||
if (page.value.spaces.length === 0 && pageOffset.value > 0) {
|
||||
await readPage(pageOffset.value - pageSize, activeQuery.value)
|
||||
}
|
||||
} catch {
|
||||
page.value = undefined
|
||||
error.value = '空间已删除,列表刷新失败。请重新查询。'
|
||||
}
|
||||
}
|
||||
} catch (failure) { error.value = failure instanceof Error ? failure.message : '删除失败。' }
|
||||
finally { busy.value = false }
|
||||
}
|
||||
|
|
@ -81,10 +128,10 @@ async function deleteSpace() {
|
|||
<p v-if="!initialized">正在验证登录</p>
|
||||
<template v-if="authorized">
|
||||
<form @submit.prevent="findSpace">
|
||||
<label for="space-id">空间 ID</label>
|
||||
<label for="space-search">查找空间</label>
|
||||
<div class="lookup">
|
||||
<el-input id="space-id" v-model="input" placeholder="输入要查询的空间 UUID" :disabled="busy" />
|
||||
<el-button native-type="submit" type="primary" :disabled="!validId" :loading="busy && !confirming">查询</el-button>
|
||||
<el-input id="space-search" v-model="input" placeholder="空间名称或完整 ID" maxlength="100" clearable :disabled="busy" />
|
||||
<el-button native-type="submit" type="primary" :disabled="busy">查询</el-button>
|
||||
</div>
|
||||
</form>
|
||||
<el-card v-if="space" shadow="never">
|
||||
|
|
@ -96,6 +143,22 @@ async function deleteSpace() {
|
|||
</el-descriptions>
|
||||
<el-button type="danger" plain @click="confirmation = ''; confirming = true">删除空间</el-button>
|
||||
</el-card>
|
||||
<section v-if="page" v-loading="busy" class="space-list" aria-label="空间列表">
|
||||
<el-table :data="page.spaces" row-key="id" empty-text="没有匹配的空间">
|
||||
<el-table-column prop="name" label="空间名称" min-width="160" />
|
||||
<el-table-column prop="id" label="空间 ID" min-width="250" />
|
||||
<el-table-column label="操作" width="85">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" :disabled="busy" @click="openSpace(row.id)">查看</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<nav class="pages" aria-label="空间列表翻页">
|
||||
<el-button :disabled="busy || pageOffset === 0" @click="loadPage(pageOffset - pageSize)">上一页</el-button>
|
||||
<span>第 {{ pageNumber }} 页</span>
|
||||
<el-button :disabled="busy || !page.hasMore" @click="loadPage(pageOffset + pageSize)">下一页</el-button>
|
||||
</nav>
|
||||
</section>
|
||||
<el-dialog v-model="confirming" title="删除空间" width="min(500px, 92vw)" :close-on-click-modal="false" :close-on-press-escape="!busy" :show-close="!busy">
|
||||
<p>物品和位置将被删除,成员会失去访问权限。原图和缩略图也会清理。</p>
|
||||
<label for="confirm-id">请输入空间 ID {{ space?.id }}</label>
|
||||
|
|
@ -113,7 +176,7 @@ async function deleteSpace() {
|
|||
|
||||
<style>
|
||||
body { margin: 0; background: #f4f6fa; font-family: system-ui, sans-serif; color: #222c41; }
|
||||
main { max-width: 720px; margin: 0 auto; padding: 26px 20px; }
|
||||
main { max-width: 920px; margin: 0 auto; padding: 26px 20px; }
|
||||
header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
|
||||
h1 { margin: 0; font-size: 26px; }
|
||||
h1 small { color: #596476; font-size: 15px; font-weight: 500; margin-left: 8px; }
|
||||
|
|
@ -121,4 +184,6 @@ h2 { margin-top: 0; }
|
|||
form, .el-alert { margin-bottom: 18px; }
|
||||
label { display: block; margin-bottom: 8px; }
|
||||
.lookup { display: flex; gap: 10px; }
|
||||
.space-list { min-height: 120px; margin-top: 18px; }
|
||||
.pages { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin: 16px 0; }
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,24 @@
|
|||
import { createApp } from 'vue'
|
||||
import { ElAlert, ElButton, ElCard, ElConfigProvider, ElDescriptions, ElDescriptionsItem, ElDialog, ElInput } from 'element-plus'
|
||||
import {
|
||||
ElAlert, ElButton, ElCard, ElConfigProvider, ElDescriptions, ElDescriptionsItem,
|
||||
ElDialog, ElInput, ElLoading, ElTable, ElTableColumn,
|
||||
} from 'element-plus'
|
||||
import 'element-plus/es/components/alert/style/css'
|
||||
import 'element-plus/es/components/button/style/css'
|
||||
import 'element-plus/es/components/card/style/css'
|
||||
import 'element-plus/es/components/descriptions/style/css'
|
||||
import 'element-plus/es/components/dialog/style/css'
|
||||
import 'element-plus/es/components/input/style/css'
|
||||
import 'element-plus/es/components/loading/style/css'
|
||||
import 'element-plus/es/components/table/style/css'
|
||||
import App from './App.vue'
|
||||
|
||||
const app = createApp(App)
|
||||
for (const component of [ElAlert, ElButton, ElCard, ElConfigProvider, ElDescriptions, ElDescriptionsItem, ElDialog, ElInput]) {
|
||||
app.directive('loading', ElLoading.directive)
|
||||
for (const component of [
|
||||
ElAlert, ElButton, ElCard, ElConfigProvider, ElDescriptions, ElDescriptionsItem,
|
||||
ElDialog, ElInput, ElTable, ElTableColumn,
|
||||
]) {
|
||||
app.component(component.name!, component)
|
||||
}
|
||||
app.mount('#app')
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package com.tutudog.itematlas.inventory;
|
|||
import static com.tutudog.itematlas.inventory.HouseholdDtos.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.net.URI;
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
|
|
@ -14,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
@RestController
|
||||
class HouseholdController {
|
||||
private static final String ROOT = "/api/households";
|
||||
private static final String ADMIN = "/api/admin/households";
|
||||
private static final String FAMILY = ROOT + "/{household}";
|
||||
private final HouseholdService service;
|
||||
|
||||
|
|
@ -39,12 +43,21 @@ class HouseholdController {
|
|||
return ResponseEntity.accepted().build();
|
||||
}
|
||||
|
||||
@GetMapping("/api/admin/households/{household}")
|
||||
@GetMapping(ADMIN)
|
||||
ResponseEntity<ManagedSpacePage> managedSpaces(
|
||||
@RequestParam(defaultValue = "") @Size(max = 100) String q,
|
||||
@RequestParam(defaultValue = "25") @Min(1) @Max(100) int limit,
|
||||
@RequestParam(defaultValue = "0") @Min(0) @Max(10000) int offset) {
|
||||
return ResponseEntity.ok().cacheControl(CacheControl.noStore())
|
||||
.body(service.managedSpaces(q.strip(), limit, offset));
|
||||
}
|
||||
|
||||
@GetMapping(ADMIN + "/{household}")
|
||||
ResponseEntity<ManagedSpace> managed(@PathVariable UUID household) {
|
||||
return ResponseEntity.ok().cacheControl(CacheControl.noStore()).body(service.managedSpace(household));
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/admin/households/{household}")
|
||||
@DeleteMapping(ADMIN + "/{household}")
|
||||
ResponseEntity<Void> deleteManaged(@PathVariable UUID household, Principal user) {
|
||||
service.deleteManagedSpace(household, user.getName());
|
||||
return ResponseEntity.accepted().build();
|
||||
|
|
|
|||
|
|
@ -5,10 +5,13 @@ import jakarta.validation.constraints.NotNull;
|
|||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
final class HouseholdDtos {
|
||||
record Household(UUID id, String name, String role) {}
|
||||
record ManagedSpaceSummary(UUID id, String name) {}
|
||||
record ManagedSpacePage(List<ManagedSpaceSummary> spaces, boolean hasMore) {}
|
||||
record ManagedSpace(UUID id, String name, long items, long photos) {}
|
||||
record HouseholdInput(@NotBlank @Size(max = 100) String name, @Size(max = 80) String displayName) {}
|
||||
enum MemberRole { EDITOR, VIEWER }
|
||||
|
|
|
|||
|
|
@ -41,6 +41,17 @@ class HouseholdService {
|
|||
deleteSpaceData(household);
|
||||
}
|
||||
|
||||
ManagedSpacePage managedSpaces(String query, int limit, int offset) {
|
||||
List<ManagedSpaceSummary> rows = db.sql("""
|
||||
SELECT id, name FROM household
|
||||
WHERE strpos(lower(name), lower(:query)) > 0
|
||||
ORDER BY name, id LIMIT :limit OFFSET :offset
|
||||
""").param("query", query).param("limit", limit + 1).param("offset", offset)
|
||||
.query((rs, row) -> new ManagedSpaceSummary(rs.getObject("id", UUID.class), rs.getString("name"))).list();
|
||||
boolean more = rows.size() > limit;
|
||||
return new ManagedSpacePage(rows.subList(0, Math.min(rows.size(), limit)), more && offset + limit <= 10000);
|
||||
}
|
||||
|
||||
ManagedSpace managedSpace(UUID household) {
|
||||
return db.sql("""
|
||||
SELECT h.id,h.name,(SELECT count(*) FROM item WHERE household_id=h.id AND archived_at IS NULL),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import subprocess
|
|||
import time
|
||||
import uuid
|
||||
from urllib.error import HTTPError
|
||||
from urllib.parse import urlencode
|
||||
from urllib.request import urlopen
|
||||
|
||||
from smoke import call, make_request
|
||||
|
|
@ -160,6 +161,8 @@ def main():
|
|||
second = call("POST", space + "/items", {"name": "相册", "quantity": 1, "locationId": location}, status=201)
|
||||
remaining = json.loads(upload(f"{space}/items/{second['id']}/photos", jpeg))["id"]
|
||||
room, room_photo = verify_location_photos(house, space, jpeg)
|
||||
call("GET", "/api/admin/households", user=None, status=401)
|
||||
call("GET", "/api/admin/households", status=403)
|
||||
call("DELETE", space, user="viewer", status=403)
|
||||
call("DELETE", f"/api/admin/households/{house}", status=403)
|
||||
call("DELETE", space, status=202)
|
||||
|
|
@ -170,15 +173,23 @@ def main():
|
|||
if os.environ.get("ATLAS_SMOKE_ADMIN_TOKEN"):
|
||||
from smoke import TOKENS
|
||||
TOKENS["admin"] = os.environ["ATLAS_SMOKE_ADMIN_TOKEN"]
|
||||
another = call("POST", "/api/households", {"name": "管理端验收"}, status=201)["id"]
|
||||
unique_name = f"管理端验收-{uuid.uuid4().hex[:8]}"
|
||||
another = call("POST", "/api/households", {"name": unique_name}, status=201)["id"]
|
||||
api = f"/api/households/{another}"
|
||||
admin = f"/api/admin/households/{another}"
|
||||
search = "/api/admin/households?" + urlencode({"q": unique_name, "limit": 1})
|
||||
assert call("GET", search, user="admin") == {
|
||||
"spaces": [{"id": another, "name": unique_name}], "hasMore": False,
|
||||
}
|
||||
assert call("GET", search + "&offset=1", user="admin")["spaces"] == []
|
||||
call("GET", "/api/admin/households?limit=101", user="admin", status=400)
|
||||
place = call("POST", api + "/locations", {"name": "盒子"}, status=201)["id"]
|
||||
second = call("POST", api + "/items", {"name": "纸盒", "quantity": 1, "locationId": place}, status=201)
|
||||
attached = json.loads(upload(f"{api}/items/{second['id']}/photos", jpeg))["id"]
|
||||
place_photo = json.loads(upload(f"{api}/locations/{place}/photos", jpeg))["id"]
|
||||
assert call("GET", admin, user="admin")["photos"] == 2
|
||||
call("DELETE", admin, user="admin", status=202)
|
||||
assert call("GET", search, user="admin")["spaces"] == []
|
||||
call("GET", api, status=404)
|
||||
await_absence(another, second["id"], attached)
|
||||
await_absence(another, place, place_photo, "locations")
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ Kubernetes 的控制面和应用在同一虚拟机内。Helm 管理应用和可
|
|||
| --- | --- |
|
||||
| `pc-atlas.tutudog.com` | PC 网页,独立证书和续期定时器 |
|
||||
| `m-atlas.tutudog.com` | 移动网页(H5),独立证书和续期定时器 |
|
||||
| `admin-atlas.tutudog.com` | 管理后台规划域名,目前通过内部入口使用 |
|
||||
| `admin-atlas.tutudog.com` | 管理后台规划域名,发布时使用受限入口 |
|
||||
| `api-atlas.tutudog.com` | 项目专用 HTTPS 入口,独立证书和续期定时器。`/api/` 到网关,`/auth/` 到正式身份服务 |
|
||||
|
||||
已有 frp 足够用于首版演示。5 Mbps 约为每秒 0.625 MB 的理论上限。前端资源压缩和缓存,照片以缩略图为先,上传按大小和并发限制。
|
||||
|
|
|
|||
Loading…
Reference in New Issue