fix(admin): restore review workspace and add user account editing
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
* 前端隐藏按钮只是体验,后端不拦就等于没有权限系统。
|
||||
*/
|
||||
import { requestClient } from '#/api/request';
|
||||
import { t } from '#/locales/t';
|
||||
import { sha256File } from '#/utils/file-sha256';
|
||||
|
||||
/**
|
||||
* 账号下拉框里「全部」的取值,和后端 `admin_api.ALL_ACCOUNTS` 是同一个约定。
|
||||
@@ -53,10 +55,54 @@ export interface RoleItem {
|
||||
user_count: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 权限菜单里的一条:一级菜单(group_name)→ 页面(page_name)→ 权限码。
|
||||
*
|
||||
* - source = builtin:随代码发布,只读
|
||||
* - source = custom:管理员在「权限菜单」页自己加的,可改可删
|
||||
* - source = discovered:代码里用到却没登记,后端启动时自动登记到「未归类」
|
||||
*/
|
||||
export interface PermissionItem {
|
||||
code: string;
|
||||
enabled: boolean;
|
||||
group_name: string;
|
||||
icon: string;
|
||||
/** page = 能打开页面;action = 页面里的操作;link = 左侧菜单链接 */
|
||||
kind: 'action' | 'link' | 'page';
|
||||
link_mode: '' | 'iframe' | 'tab';
|
||||
link_url: string;
|
||||
name: string;
|
||||
page_name: string;
|
||||
/** 持有这个权限码的角色 */
|
||||
roles: string[];
|
||||
sort_order: number;
|
||||
source: 'builtin' | 'custom' | 'discovered';
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
/** 新增/修改自定义条目时提交的字段 */
|
||||
export interface PermissionForm {
|
||||
code: string;
|
||||
enabled: boolean;
|
||||
group_name: string;
|
||||
icon: string;
|
||||
kind: 'action' | 'link';
|
||||
link_mode: 'iframe' | 'tab';
|
||||
link_url: string;
|
||||
name: string;
|
||||
page_name: string;
|
||||
sort_order: number;
|
||||
}
|
||||
|
||||
/** 左侧菜单里管理员自己加的链接(后端已按当前用户的权限过滤) */
|
||||
export interface CustomMenuItem {
|
||||
code: string;
|
||||
group_name: string;
|
||||
icon: string;
|
||||
link_mode: '' | 'iframe' | 'tab';
|
||||
link_url: string;
|
||||
name: string;
|
||||
sort_order: number;
|
||||
}
|
||||
|
||||
export interface UserItem {
|
||||
@@ -243,6 +289,30 @@ export function fetchPermissions() {
|
||||
return requestClient.get<{ permissions: PermissionItem[] }>('/permissions');
|
||||
}
|
||||
|
||||
export function createPermission(data: PermissionForm) {
|
||||
return requestClient.post<{ permissions: PermissionItem[] }>(
|
||||
'/permissions',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export function updatePermission(code: string, data: PermissionForm) {
|
||||
return requestClient.put<{ permissions: PermissionItem[] }>(
|
||||
`/permissions/${encodeURIComponent(code)}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
export function deletePermission(code: string) {
|
||||
return requestClient.delete<{ permissions: PermissionItem[] }>(
|
||||
`/permissions/${encodeURIComponent(code)}`,
|
||||
);
|
||||
}
|
||||
|
||||
export function fetchCustomMenus() {
|
||||
return requestClient.get<{ menus: CustomMenuItem[] }>('/custom-menus');
|
||||
}
|
||||
|
||||
export function saveRole(data: {
|
||||
code: string;
|
||||
name: string;
|
||||
@@ -272,7 +342,7 @@ export function createUser(data: {
|
||||
|
||||
export function updateUser(
|
||||
id: number,
|
||||
data: { active: boolean; role: string },
|
||||
data: { active: boolean; role: string; username?: string; password?: string },
|
||||
) {
|
||||
return requestClient.put<{ users: UserItem[] }>(`/users/${id}`, data);
|
||||
}
|
||||
@@ -440,6 +510,7 @@ export function saveConfig(data: DesktopConfig) {
|
||||
|
||||
// ── 桌面端版本升级 ───────────────────────────────────────────────────────────
|
||||
export interface ReleasePolicy {
|
||||
package_media_id?: string;
|
||||
auto_install: boolean;
|
||||
download_url: string;
|
||||
force_upgrade: boolean;
|
||||
@@ -456,6 +527,8 @@ export interface ReleasePolicy {
|
||||
}
|
||||
|
||||
export interface ReleasePackage {
|
||||
package_media_id: string;
|
||||
download_url_expires_in: number;
|
||||
download_url: string;
|
||||
file_name: string;
|
||||
package_sha256: string;
|
||||
@@ -500,6 +573,7 @@ export function fetchRelease() {
|
||||
}
|
||||
|
||||
export function saveRelease(data: {
|
||||
package_media_id?: string;
|
||||
auto_install: boolean;
|
||||
download_url: string;
|
||||
force_upgrade: boolean;
|
||||
@@ -515,19 +589,6 @@ export function saveRelease(data: {
|
||||
return requestClient.post<ReleasePolicy>('/release', data);
|
||||
}
|
||||
|
||||
async function sha256File(file: File) {
|
||||
if (!globalThis.crypto?.subtle) {
|
||||
throw new Error('当前浏览器不支持安全哈希,请使用 HTTPS 或本机地址打开管理端');
|
||||
}
|
||||
const digest = await globalThis.crypto.subtle.digest(
|
||||
'SHA-256',
|
||||
await file.arrayBuffer(),
|
||||
);
|
||||
return [...new Uint8Array(digest)]
|
||||
.map((value) => value.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
}
|
||||
|
||||
function putCosBlob(
|
||||
url: string,
|
||||
body: Blob,
|
||||
@@ -542,14 +603,14 @@ function putCosBlob(
|
||||
xhr.setRequestHeader(key, value);
|
||||
});
|
||||
xhr.upload.onprogress = (event) => onProgress?.(event.loaded);
|
||||
xhr.onerror = () => reject(new Error('无法连接腾讯 COS,请检查网络和 Bucket CORS 配置'));
|
||||
xhr.ontimeout = () => reject(new Error('上传腾讯 COS 超时,请重试'));
|
||||
xhr.onerror = () => reject(new Error(t('无法连接腾讯 COS,请检查网络和 Bucket CORS 配置')));
|
||||
xhr.ontimeout = () => reject(new Error(t('上传腾讯 COS 超时,请重试')));
|
||||
xhr.onload = () => {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
resolve((xhr.getResponseHeader('ETag') || '').replaceAll('"', ''));
|
||||
return;
|
||||
}
|
||||
reject(new Error(`腾讯 COS 上传失败(HTTP ${xhr.status})`));
|
||||
reject(new Error(t('腾讯 COS 上传失败(HTTP {status})', { status: xhr.status })));
|
||||
};
|
||||
xhr.send(body);
|
||||
});
|
||||
@@ -562,7 +623,7 @@ async function uploadMultipartPackage(
|
||||
) {
|
||||
const multipart = prepared.multipart;
|
||||
if (!multipart?.upload_id || !multipart.parts.length) {
|
||||
throw new Error('COS 分块上传参数不完整');
|
||||
throw new Error(t('COS 分块上传参数不完整'));
|
||||
}
|
||||
const partSize = multipart.part_size;
|
||||
const uploaded = new Map<number, number>();
|
||||
@@ -605,7 +666,7 @@ async function uploadMultipartPackage(
|
||||
}
|
||||
if (lastError) throw lastError;
|
||||
if (!etag) {
|
||||
throw new Error('COS 未返回 ETag,请在 Bucket CORS 中暴露 ETag 响应头');
|
||||
throw new Error(t('COS 未返回 ETag,请在 Bucket CORS 中暴露 ETag 响应头'));
|
||||
}
|
||||
uploaded.set(part.part_number, part.size_bytes);
|
||||
completed.set(part.part_number, etag);
|
||||
@@ -633,13 +694,15 @@ export async function uploadReleasePackage(
|
||||
onProgress?: (percent: number) => void,
|
||||
) {
|
||||
if (!file.name.toLowerCase().endsWith('.exe')) {
|
||||
throw new Error('升级包必须是 Windows EXE 安装包');
|
||||
throw new Error(t('升级包必须是 Windows EXE 安装包'));
|
||||
}
|
||||
if (file.size <= 0 || file.size > 1024 ** 3) {
|
||||
throw new Error('安装包大小必须大于 0 且不能超过 1GB');
|
||||
throw new Error(t('安装包大小必须大于 0 且不能超过 1GB'));
|
||||
}
|
||||
onProgress?.(1);
|
||||
const packageSha256 = await sha256File(file);
|
||||
const packageSha256 = await sha256File(file, (fraction) => {
|
||||
onProgress?.(1 + Math.floor(fraction * 4));
|
||||
});
|
||||
onProgress?.(5);
|
||||
const prepared = await requestClient.post<ReleaseUploadPrepared>(
|
||||
'/release/package/prepare',
|
||||
@@ -658,7 +721,7 @@ export async function uploadReleasePackage(
|
||||
onProgress?.(100);
|
||||
return result;
|
||||
}
|
||||
if (!prepared.upload_url) throw new Error('COS 预上传接口没有返回上传地址');
|
||||
if (!prepared.upload_url) throw new Error(t('COS 预上传接口没有返回上传地址'));
|
||||
await putCosBlob(
|
||||
prepared.upload_url,
|
||||
file,
|
||||
@@ -715,8 +778,6 @@ export function testModel(data: {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// 每次实际上游请求的计量,包含所有候选、裁判和重试;不复用最终回答日志的条数。
|
||||
export interface ModelUsageSummary {
|
||||
request_count: number;
|
||||
known_count: number;
|
||||
|
||||
Reference in New Issue
Block a user