312 lines
11 KiB
HTML
312 lines
11 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="zh-CN">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
<title>步骤详解 - 定义 WidgetType 枚举</title>
|
||
|
|
<style>
|
||
|
|
:root {
|
||
|
|
--bg-primary: #0a0e1a;
|
||
|
|
--bg-secondary: #111827;
|
||
|
|
--bg-card: #1a2035;
|
||
|
|
--bg-card-hover: #1f2a45;
|
||
|
|
--border-color: #2d3a5c;
|
||
|
|
--text-primary: #e2e8f0;
|
||
|
|
--text-secondary: #94a3b8;
|
||
|
|
--text-muted: #64748b;
|
||
|
|
--accent-purple: #8b5cf6;
|
||
|
|
--accent-purple-light: #a78bfa;
|
||
|
|
--accent-cyan: #06b6d4;
|
||
|
|
--accent-green: #10b981;
|
||
|
|
--shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.4);
|
||
|
|
}
|
||
|
|
|
||
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
|
|
|
||
|
|
body {
|
||
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||
|
|
background: var(--bg-primary);
|
||
|
|
color: var(--text-primary);
|
||
|
|
line-height: 1.7;
|
||
|
|
padding: 2rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.container { max-width: 1000px; margin: 0 auto; }
|
||
|
|
|
||
|
|
.back-link {
|
||
|
|
display: inline-flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 0.5rem;
|
||
|
|
color: var(--accent-purple-light);
|
||
|
|
text-decoration: none;
|
||
|
|
margin-bottom: 2rem;
|
||
|
|
padding: 0.5rem 1rem;
|
||
|
|
background: var(--bg-card);
|
||
|
|
border-radius: 8px;
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
transition: all 0.2s ease;
|
||
|
|
}
|
||
|
|
|
||
|
|
.back-link:hover {
|
||
|
|
background: var(--bg-card-hover);
|
||
|
|
transform: translateX(-4px);
|
||
|
|
}
|
||
|
|
|
||
|
|
.header {
|
||
|
|
background: var(--bg-card);
|
||
|
|
border-radius: 16px;
|
||
|
|
padding: 2rem;
|
||
|
|
margin-bottom: 2rem;
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
box-shadow: var(--shadow-lg);
|
||
|
|
border-left: 4px solid var(--accent-purple);
|
||
|
|
}
|
||
|
|
|
||
|
|
.step-badge {
|
||
|
|
display: inline-block;
|
||
|
|
background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
|
||
|
|
color: white;
|
||
|
|
padding: 0.3rem 1rem;
|
||
|
|
border-radius: 20px;
|
||
|
|
font-size: 0.85rem;
|
||
|
|
font-weight: 600;
|
||
|
|
margin-bottom: 1rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.header h1 {
|
||
|
|
font-size: 2rem;
|
||
|
|
margin-bottom: 0.5rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.header .desc {
|
||
|
|
color: var(--text-secondary);
|
||
|
|
font-size: 1rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.section {
|
||
|
|
background: var(--bg-card);
|
||
|
|
border-radius: 12px;
|
||
|
|
padding: 1.5rem;
|
||
|
|
margin-bottom: 1.5rem;
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
}
|
||
|
|
|
||
|
|
.section h2 {
|
||
|
|
font-size: 1.3rem;
|
||
|
|
margin-bottom: 1rem;
|
||
|
|
color: var(--accent-purple-light);
|
||
|
|
display: flex;
|
||
|
|
align-items: center;
|
||
|
|
gap: 0.5rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.section p {
|
||
|
|
color: var(--text-secondary);
|
||
|
|
margin-bottom: 1rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.code-block {
|
||
|
|
background: var(--bg-secondary);
|
||
|
|
padding: 1.25rem;
|
||
|
|
border-radius: 8px;
|
||
|
|
font-family: 'Fira Code', 'Cascadia Code', monospace;
|
||
|
|
font-size: 0.85rem;
|
||
|
|
color: var(--accent-cyan);
|
||
|
|
overflow-x: auto;
|
||
|
|
line-height: 1.6;
|
||
|
|
margin-bottom: 1rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.code-block .comment { color: var(--text-muted); }
|
||
|
|
.code-block .keyword { color: var(--accent-purple-light); }
|
||
|
|
.code-block .string { color: var(--accent-green); }
|
||
|
|
|
||
|
|
.info-grid {
|
||
|
|
display: grid;
|
||
|
|
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||
|
|
gap: 1rem;
|
||
|
|
margin-top: 1rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.info-card {
|
||
|
|
background: var(--bg-secondary);
|
||
|
|
padding: 1rem;
|
||
|
|
border-radius: 8px;
|
||
|
|
border: 1px solid var(--border-color);
|
||
|
|
}
|
||
|
|
|
||
|
|
.info-card h4 {
|
||
|
|
font-size: 0.9rem;
|
||
|
|
margin-bottom: 0.5rem;
|
||
|
|
color: var(--accent-purple-light);
|
||
|
|
}
|
||
|
|
|
||
|
|
.info-card p {
|
||
|
|
font-size: 0.85rem;
|
||
|
|
color: var(--text-secondary);
|
||
|
|
margin: 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.file-path {
|
||
|
|
font-family: 'Fira Code', monospace;
|
||
|
|
font-size: 0.8rem;
|
||
|
|
color: var(--accent-cyan);
|
||
|
|
background: rgba(6, 182, 212, 0.1);
|
||
|
|
padding: 0.25rem 0.5rem;
|
||
|
|
border-radius: 4px;
|
||
|
|
}
|
||
|
|
|
||
|
|
ul { list-style: none; padding: 0; }
|
||
|
|
ul li {
|
||
|
|
padding: 0.4rem 0;
|
||
|
|
color: var(--text-secondary);
|
||
|
|
display: flex;
|
||
|
|
align-items: flex-start;
|
||
|
|
gap: 0.5rem;
|
||
|
|
}
|
||
|
|
ul li::before {
|
||
|
|
content: "▸";
|
||
|
|
color: var(--accent-purple);
|
||
|
|
flex-shrink: 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
.warning {
|
||
|
|
background: rgba(245, 158, 11, 0.1);
|
||
|
|
border: 1px solid rgba(245, 158, 11, 0.3);
|
||
|
|
border-radius: 8px;
|
||
|
|
padding: 1rem;
|
||
|
|
margin-top: 1rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.warning h4 {
|
||
|
|
color: #fbbf24;
|
||
|
|
margin-bottom: 0.5rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
.warning p {
|
||
|
|
color: var(--text-secondary);
|
||
|
|
margin: 0;
|
||
|
|
font-size: 0.9rem;
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="container">
|
||
|
|
<a href="../../物料组件添加流程.html" class="back-link">← 返回主文档</a>
|
||
|
|
|
||
|
|
<div class="header">
|
||
|
|
<div class="step-badge">步骤 1</div>
|
||
|
|
<h1>定义 WidgetType 枚举</h1>
|
||
|
|
<p class="desc">在共享契约层为新增物料组件定义全局唯一类型标识</p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- 功能描述 -->
|
||
|
|
<div class="section">
|
||
|
|
<h2>📋 功能描述</h2>
|
||
|
|
<p><code>WidgetType</code> 是整个低代码平台中物料组件的<strong>唯一类型标识</strong>。它定义了所有可在设计器中使用的组件类型,是类型系统的源头。新增任何物料组件都必须先在此枚举中添加对应的类型值。</p>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- 模块描述 -->
|
||
|
|
<div class="section">
|
||
|
|
<h2>🧩 模块描述</h2>
|
||
|
|
<p>该文件位于 <code>packages/types</code> 共享契约层,被以下模块引用:</p>
|
||
|
|
<ul>
|
||
|
|
<li><strong>form-designer</strong> - 页面设计器层,用于组件注册和物料面板配置</li>
|
||
|
|
<li><strong>widget-pc</strong> - PC 端组件库,用于组件映射</li>
|
||
|
|
<li><strong>lowcode-create</strong> - 渲染引擎,用于运行时组件识别</li>
|
||
|
|
<li><strong>business-components</strong> - 业务组件层,用于字段类型映射</li>
|
||
|
|
</ul>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- 文件信息 -->
|
||
|
|
<div class="section">
|
||
|
|
<h2>📁 文件信息</h2>
|
||
|
|
<div class="info-grid">
|
||
|
|
<div class="info-card">
|
||
|
|
<h4>文件路径</h4>
|
||
|
|
<p><span class="file-path">packages/types/widget-pc/WidgetType.ts</span></p>
|
||
|
|
</div>
|
||
|
|
<div class="info-card">
|
||
|
|
<h4>操作类型</h4>
|
||
|
|
<p><strong style="color: #fbbf24;">修改</strong> - 在已有枚举中添加新值</p>
|
||
|
|
</div>
|
||
|
|
<div class="info-card">
|
||
|
|
<h4>影响范围</h4>
|
||
|
|
<p>全局类型定义,修改后所有引用处自动获得类型提示</p>
|
||
|
|
</div>
|
||
|
|
<div class="info-card">
|
||
|
|
<h4>所属层级</h4>
|
||
|
|
<p>共享契约层 (packages/types)</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- 代码示例 -->
|
||
|
|
<div class="section">
|
||
|
|
<h2>💻 代码示例</h2>
|
||
|
|
<p>在 WidgetType 枚举中添加新组件类型:</p>
|
||
|
|
<div class="code-block">
|
||
|
|
<span class="comment">// packages/types/widget-pc/WidgetType.ts</span>
|
||
|
|
|
||
|
|
<span class="keyword">export enum</span> WidgetType {
|
||
|
|
<span class="comment">// 布局组件</span>
|
||
|
|
Root = <span class="string">'Root'</span>,
|
||
|
|
Row = <span class="string">'Row'</span>,
|
||
|
|
Col = <span class="string">'Col'</span>,
|
||
|
|
Tabs = <span class="string">'Tabs'</span>,
|
||
|
|
TabPane = <span class="string">'TabPane'</span>,
|
||
|
|
|
||
|
|
<span class="comment">// 容器组件</span>
|
||
|
|
GroupPanel = <span class="string">'GroupPanel'</span>,
|
||
|
|
FlexLayout = <span class="string">'FlexLayout'</span>,
|
||
|
|
|
||
|
|
<span class="comment">// 通用组件</span>
|
||
|
|
CommonTxt = <span class="string">'CommonTxt'</span>,
|
||
|
|
CommonBtn = <span class="string">'CommonBtn'</span>,
|
||
|
|
CommonImg = <span class="string">'CommonImg'</span>,
|
||
|
|
CommonLink = <span class="string">'CommonLink'</span>,
|
||
|
|
|
||
|
|
<span class="comment">// ← 在此处添加你的新组件类型</span>
|
||
|
|
MyNewComponent = <span class="string">'MyNewComponent'</span>,
|
||
|
|
}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- 命名规范 -->
|
||
|
|
<div class="section">
|
||
|
|
<h2>📝 命名规范</h2>
|
||
|
|
<ul>
|
||
|
|
<li>使用 <strong>PascalCase</strong> 命名,与 Vue 组件名保持一致</li>
|
||
|
|
<li>枚举值(字符串)应与枚举名相同</li>
|
||
|
|
<li>示例:<code>MyNewComponent = 'MyNewComponent'</code></li>
|
||
|
|
<li>参考现有命名:CommonBtn、GroupPanel、FlexLayout 等</li>
|
||
|
|
</ul>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- 注意事项 -->
|
||
|
|
<div class="section">
|
||
|
|
<h2>⚠️ 注意事项</h2>
|
||
|
|
<div class="warning">
|
||
|
|
<h4>重要提醒</h4>
|
||
|
|
<p>必须在 <code>packages/types/widget-pc/WidgetType.ts</code> 中定义,<strong>不要</strong>在 form-designer 本地的 types 中定义。真正的类型源头在共享契约层 packages/types。</p>
|
||
|
|
</div>
|
||
|
|
<ul style="margin-top: 1rem;">
|
||
|
|
<li>修改此文件后需要重新构建 types 包</li>
|
||
|
|
<li>确保类型名不与现有类型冲突</li>
|
||
|
|
<li>类型添加后需要在后续步骤中完成所有注册</li>
|
||
|
|
</ul>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- 下一步 -->
|
||
|
|
<div class="section" style="border-left: 4px solid var(--accent-green);">
|
||
|
|
<h2>➡️ 下一步</h2>
|
||
|
|
<p>完成 WidgetType 定义后,继续执行:</p>
|
||
|
|
<ul>
|
||
|
|
<li><strong>步骤 2</strong>:创建 Vue 渲染组件 (<span class="file-path">form-designer/src/config/widget/xxx.vue</span>)</li>
|
||
|
|
<li><strong>步骤 3</strong>:创建 Helper 配置文件 (<span class="file-path">form-designer/src/config/widget-helper/xxxHelper.ts</span>)</li>
|
||
|
|
</ul>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</body>
|
||
|
|
</html>
|