F4-L1: amis-editor 页面设计器(多页入口隔离)+overlay 编辑闭环
- editor.html 独立 vite 入口,amis-editor npm 依赖与主应用本地 SDK 隔离 - 设计器:画布编辑/保存→overlay/还原标准版/预览;页面 Tab 管理员「设计」入口 - designer.spec.ts 7 用例(编辑→保存→渲染 overlay→还原,X-Schema-Layer 断言);全套 e2e 68/68 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// 页面渲染路由 /page/:templateId —— 取转换后 schema 交 amis 渲染
|
||||
// F1-4:加错误边界(schema 拉取失败/JSON 异常/amis 渲染抛错均显示页内错误卡片)
|
||||
// F4-L1:管理员可见「设计」按钮,打开设计器(editor.html 多页入口)
|
||||
import { Component, useEffect, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
@@ -7,6 +8,7 @@ import { fetchSchema } from '../api/schema';
|
||||
import { AmisRenderer } from '../components/AmisRenderer';
|
||||
import { recordRecentPage } from '../utils/recentPages';
|
||||
import { useTabTitle } from '../shell/TabTitleContext';
|
||||
import { getProfile } from '../auth/token';
|
||||
|
||||
// ---- amis 渲染层错误边界(class component,捕获子树抛错)----
|
||||
interface ErrorBoundaryState {
|
||||
@@ -69,6 +71,36 @@ function SchemaErrorCard({ templateId, summary }: { templateId: string; summary:
|
||||
);
|
||||
}
|
||||
|
||||
// ---- 管理员设计按钮 ----
|
||||
function DesignButton({ templateId }: { templateId: string }) {
|
||||
const profile = getProfile();
|
||||
const isAdmin = profile?.account === 'admin' || profile?.userId === 'ADMIN';
|
||||
if (!isAdmin) return null;
|
||||
return (
|
||||
<button
|
||||
data-testid="designer-open-btn"
|
||||
onClick={() => window.open(`/editor.html?templateId=${encodeURIComponent(templateId)}`, '_blank')}
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: 8,
|
||||
right: 12,
|
||||
zIndex: 10,
|
||||
background: '#1890ff',
|
||||
color: '#fff',
|
||||
border: 'none',
|
||||
borderRadius: 4,
|
||||
padding: '4px 12px',
|
||||
cursor: 'pointer',
|
||||
fontSize: 12,
|
||||
fontWeight: 500,
|
||||
opacity: 0.85,
|
||||
}}
|
||||
>
|
||||
设计
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
// ---- 主组件 ----
|
||||
export function PageRenderPage() {
|
||||
const { templateId = '' } = useParams();
|
||||
@@ -114,7 +146,8 @@ export function PageRenderPage() {
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div style={{ height: '100%' }} data-testid="amis-host">
|
||||
<div style={{ height: '100%', position: 'relative' }} data-testid="amis-host">
|
||||
<DesignButton templateId={templateId} />
|
||||
<AmisErrorBoundary templateId={templateId}>
|
||||
<AmisRenderer schema={schema} />
|
||||
</AmisErrorBoundary>
|
||||
|
||||
Reference in New Issue
Block a user