422c8931d6
实现: 在rust内存里维护错误事件队列, webview调用tauri command传入, 后台任务agent工具等直接插入 把rust , webview console的日志统一写到AppData文件夹下的(滚动保存的)日志文件. rust对传入的错误进行筛选,脱敏, 防抖,后通知前端提醒用户. 用户提醒是一个不阻塞的小UI, 展开后可以选择错误上报, 可以附加文字描述 上传时附带最近日志, 错误堆栈等信息 元数据存在数据库, 考虑到字符串信息很难查询, 所以在api server打包成zip存在OSS. 管理页面新增错误报告的查看页面     --------- Co-authored-by: 段舒康 <kdletters@qq.com> Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/240 Co-authored-by: 王德宇 <kvtodev@outlook.com> Co-committed-by: 王德宇 <kvtodev@outlook.com>
102 lines
3.2 KiB
TypeScript
102 lines
3.2 KiB
TypeScript
/** 后台单页应用可导航的路由标识。 */
|
|
export type AdminRouteId =
|
|
| 'dashboard'
|
|
| 'overview'
|
|
| 'tables'
|
|
| 'debug'
|
|
| 'tracking'
|
|
| 'error-reports'
|
|
| 'gray-release'
|
|
| 'redeem'
|
|
| 'invite'
|
|
| 'profile-wallet'
|
|
| 'tasks'
|
|
| 'recharge-products'
|
|
| 'recharge-orders'
|
|
| 'editor-generation-pricing'
|
|
| 'editor-showcase'
|
|
| 'editor-assets'
|
|
| 'accounts';
|
|
|
|
export type AdminTabPermission = Exclude<AdminRouteId, 'accounts'>;
|
|
|
|
/** 后台导航项定义,hash 是浏览器地址栏和移动底栏共用入口。 */
|
|
export interface AdminRouteDefinition {
|
|
id: AdminRouteId;
|
|
label: string;
|
|
hash: string;
|
|
ownerOnly?: boolean;
|
|
}
|
|
|
|
export const adminRoutes: AdminRouteDefinition[] = [
|
|
{ id: 'dashboard', label: 'Dashboard', hash: '#dashboard' },
|
|
{ id: 'overview', label: '服务总览', hash: '#overview' },
|
|
{ id: 'tables', label: '表查询', hash: '#tables' },
|
|
{ id: 'debug', label: 'API 调试', hash: '#debug' },
|
|
{ id: 'tracking', label: '埋点数据', hash: '#tracking' },
|
|
{ id: 'error-reports', label: '错误报告', hash: '#error-reports' },
|
|
{ id: 'gray-release', label: '灰度发布', hash: '#gray-release' },
|
|
{ id: 'redeem', label: '兑换码', hash: '#redeem' },
|
|
{ id: 'invite', label: '邀请码', hash: '#invite' },
|
|
{ id: 'profile-wallet', label: '账号配置', hash: '#profile-wallet' },
|
|
{ id: 'tasks', label: '任务配置', hash: '#tasks' },
|
|
{ id: 'recharge-products', label: '充值商品', hash: '#recharge-products' },
|
|
{ id: 'recharge-orders', label: '充值管理', hash: '#recharge-orders' },
|
|
{
|
|
id: 'editor-generation-pricing',
|
|
label: '模型定价',
|
|
hash: '#editor-generation-pricing',
|
|
},
|
|
{ id: 'editor-showcase', label: '精选审核', hash: '#editor-showcase' },
|
|
{ id: 'editor-assets', label: '素材查询', hash: '#editor-assets' },
|
|
{ id: 'accounts', label: '账号管理', hash: '#accounts', ownerOnly: true },
|
|
];
|
|
|
|
export interface AdminRouteAccess {
|
|
accountRole: 'owner' | 'member';
|
|
tabPermissions: string[];
|
|
}
|
|
|
|
export function getAccessibleAdminRoutes(
|
|
admin: AdminRouteAccess,
|
|
): AdminRouteDefinition[] {
|
|
if (admin.accountRole === 'owner') {
|
|
return adminRoutes;
|
|
}
|
|
|
|
const permissions = new Set(admin.tabPermissions);
|
|
return adminRoutes.filter(
|
|
(route) => !route.ownerOnly && permissions.has(route.id),
|
|
);
|
|
}
|
|
|
|
export function resolveAccessibleAdminRoute(
|
|
hash: string,
|
|
routes: AdminRouteDefinition[],
|
|
): AdminRouteId | null {
|
|
const normalizedHash = hash.trim().toLowerCase().split('?')[0] ?? '';
|
|
return (
|
|
routes.find((route) => route.hash === normalizedHash)?.id ??
|
|
routes[0]?.id ??
|
|
null
|
|
);
|
|
}
|
|
|
|
/** 根据地址栏 hash 解析后台路由,未知 hash 回落到 Dashboard。 */
|
|
export function resolveAdminRoute(hash: string): AdminRouteId {
|
|
const normalizedHash = hash.trim().toLowerCase().split('?')[0] ?? '';
|
|
return (
|
|
adminRoutes.find((route) => route.hash === normalizedHash)?.id ??
|
|
'dashboard'
|
|
);
|
|
}
|
|
|
|
/** 根据后台路由标识反查 hash,供导航点击时同步地址栏。 */
|
|
export function routeHash(routeId: AdminRouteId) {
|
|
return (
|
|
adminRoutes.find((route) => route.id === routeId)?.hash ??
|
|
adminRoutes[0]?.hash ??
|
|
'#dashboard'
|
|
);
|
|
}
|