diff --git a/src/api/agentCardKeys.js b/src/api/agentCardKeys.js new file mode 100644 index 0000000..b3c8c15 --- /dev/null +++ b/src/api/agentCardKeys.js @@ -0,0 +1,72 @@ +import { apiRequest } from "./client.js"; + +/** + * @param {string} token + * @param {RequestInit} [options] + */ +function agentRequest(token, path, options = {}) { + return apiRequest(path, { + ...options, + headers: { + Authorization: `Bearer ${token}`, + ...options.headers, + }, + }); +} + +/** + * @param {string} token + * @param {{ + * page?: number, + * pageSize?: number, + * status?: string, + * username?: string, + * oemId?: number | null, + * agentId?: number | null, + * }} [params] + */ +export function listAgentCardKeysApi( + token, + { page = 1, pageSize = 20, status = "all", username, oemId, agentId } = {}, +) { + const query = new URLSearchParams({ + page: String(page), + page_size: String(pageSize), + status, + }); + const trimmed = username?.trim(); + if (trimmed) query.set("username", trimmed); + if (oemId != null) query.set("oem_id", String(oemId)); + if (agentId != null) query.set("agent_id", String(agentId)); + return agentRequest(token, `/agent/card-keys?${query}`); +} + +/** + * @param {string} token + * @param {object} payload + */ +export function createAgentCardKeysApi(token, payload) { + return agentRequest(token, "/agent/card-keys", { + method: "POST", + body: JSON.stringify(payload), + }); +} + +/** + * @param {string} token + * @param {number} cardId + * @param {object} payload + */ +export function updateAgentCardKeyApi(token, cardId, payload) { + return agentRequest(token, `/agent/card-keys/${cardId}`, { + method: "PATCH", + body: JSON.stringify(payload), + }); +} + +/** @param {string} token @param {number} cardId */ +export function deleteAgentCardKeyApi(token, cardId) { + return agentRequest(token, `/agent/card-keys/${cardId}`, { + method: "DELETE", + }); +} diff --git a/src/api/agentUsers.js b/src/api/agentUsers.js new file mode 100644 index 0000000..cca1f9d --- /dev/null +++ b/src/api/agentUsers.js @@ -0,0 +1,72 @@ +import { apiRequest } from "./client.js"; + +/** + * @param {string} token + * @param {RequestInit} [options] + */ +function agentRequest(token, path, options = {}) { + return apiRequest(path, { + ...options, + headers: { + Authorization: `Bearer ${token}`, + ...options.headers, + }, + }); +} + +/** + * @param {string} token + * @param {{ + * page?: number, + * pageSize?: number, + * username?: string, + * oemId?: number | null, + * agentId?: number | null, + * roleId?: number | null, + * }} [params] + */ +export function listAgentUsersApi( + token, + { page = 1, pageSize = 20, username, oemId, agentId, roleId } = {}, +) { + const query = new URLSearchParams({ + page: String(page), + page_size: String(pageSize), + }); + const trimmed = username?.trim(); + if (trimmed) query.set("username", trimmed); + if (oemId != null) query.set("oem_id", String(oemId)); + if (agentId != null) query.set("agent_id", String(agentId)); + if (roleId != null) query.set("role_id", String(roleId)); + return agentRequest(token, `/agent/users?${query}`); +} + +/** + * @param {string} token + * @param {object} payload + */ +export function createAgentUserApi(token, payload) { + return agentRequest(token, "/agent/users", { + method: "POST", + body: JSON.stringify(payload), + }); +} + +/** + * @param {string} token + * @param {number} userId + * @param {object} payload + */ +export function updateAgentUserApi(token, userId, payload) { + return agentRequest(token, `/agent/users/${userId}`, { + method: "PATCH", + body: JSON.stringify(payload), + }); +} + +/** @param {string} token @param {number} userId */ +export function deleteAgentUserApi(token, userId) { + return agentRequest(token, `/agent/users/${userId}`, { + method: "DELETE", + }); +} diff --git a/src/components/agent/AgentSubNav.vue b/src/components/agent/AgentSubNav.vue index 75f91ee..1e936e6 100644 --- a/src/components/agent/AgentSubNav.vue +++ b/src/components/agent/AgentSubNav.vue @@ -6,10 +6,9 @@ const route = useRoute(); const menuItems = [ - { name: "admin-users", label: "用户管理", to: "/admin/users" }, - { name: "admin-card-keys", label: "卡密管理", to: "/admin/card-keys" }, - { name: "admin-desktop-config", label: "桌面配置", to: "/admin/desktop-config" }, - { name: "admin-overview", label: "软件配置", to: "/admin" }, + { name: "agent-users", label: "用户管理", to: "/agent/users" }, + { name: "agent-card-keys", label: "卡密管理", to: "/agent/card-keys" }, + ]; const activeName = computed(() => route.name); diff --git a/src/views/AgentView.vue b/src/views/AgentView.vue index f3ac690..588bbfd 100644 --- a/src/views/AgentView.vue +++ b/src/views/AgentView.vue @@ -1,14 +1,12 @@ diff --git a/src/views/agent/AgentCardKeysView.vue b/src/views/agent/AgentCardKeysView.vue index c577eab..c6b3ac1 100644 --- a/src/views/agent/AgentCardKeysView.vue +++ b/src/views/agent/AgentCardKeysView.vue @@ -2,12 +2,12 @@ import { computed, onMounted, ref, watch } from "vue"; import { useAuthStore, ROLE_AGENT, ROLE_OEM } from "../../stores/auth.js"; import { - listAdminCardKeysApi, - createAdminCardKeysApi, - updateAdminCardKeyApi, - deleteAdminCardKeyApi, -} from "../../api/adminCardKeys.js"; -import { listAdminUsersApi } from "../../api/adminUsers.js"; + listAgentCardKeysApi, + createAgentCardKeysApi, + updateAgentCardKeyApi, + deleteAgentCardKeyApi, +} from "../../api/agentCardKeys.js"; +import { listAgentUsersApi } from "../../api/agentUsers.js"; const auth = useAuthStore(); @@ -92,8 +92,8 @@ function showMessage(severity, message) { async function loadFilterOptions() { const [oemRes, agentRes] = await Promise.all([ - listAdminUsersApi(auth.token, { page: 1, pageSize: 200, roleId: ROLE_OEM }), - listAdminUsersApi(auth.token, { page: 1, pageSize: 200, roleId: ROLE_AGENT }), + listAgentUsersApi(auth.token, { page: 1, pageSize: 200, roleId: ROLE_OEM }), + listAgentUsersApi(auth.token, { page: 1, pageSize: 200, roleId: ROLE_AGENT }), ]); if (oemRes.ok && Array.isArray(oemRes.data?.items)) { oemOptions.value = oemRes.data.items; @@ -106,7 +106,7 @@ async function loadFilterOptions() { async function loadCards() { loading.value = true; feedback.value = { severity: "", message: "" }; - const res = await listAdminCardKeysApi(auth.token, { + const res = await listAgentCardKeysApi(auth.token, { page: page.value, pageSize: pageSize.value, status: statusFilter.value, @@ -223,9 +223,9 @@ async function saveCard() { } payload.serial_number = serial.toUpperCase(); } - res = await createAdminCardKeysApi(auth.token, payload); + res = await createAgentCardKeysApi(auth.token, payload); } else { - res = await updateAdminCardKeyApi(auth.token, editingId.value, { + res = await updateAgentCardKeyApi(auth.token, editingId.value, { duration_days: isActivated.value ? undefined : form.value.duration_days, remark: form.value.remark.trim() || null, }); @@ -252,7 +252,7 @@ async function removeCard(row) { const ok = window.confirm(`确定删除卡密「${row.serial_number}」?`); if (!ok) return; - const res = await deleteAdminCardKeyApi(auth.token, row.id); + const res = await deleteAgentCardKeyApi(auth.token, row.id); if (!res.ok) { showMessage("error", res.message || "删除失败"); return; @@ -286,7 +286,7 @@ onMounted(async () => {

卡密管理

-