import { StageGalleryModalComponent, GalleryConfig } from '@/modules/project/components/stage-gallery-modal';
@Component({
imports: [StageGalleryModalComponent]
})
export class YourComponent {
showGallery = false;
galleryConfig: GalleryConfig | null = null;
}
openGallery() {
this.galleryConfig = {
spaceId: '空间ID',
spaceName: '客厅',
stageId: '阶段ID',
stageName: '渲染',
files: [
{
id: '文件ID',
name: '文件名.jpg',
url: '文件URL',
size: 1024000, // 可选
uploadTime: new Date() // 可选
}
],
canEdit: true // 是否显示删除和上传按钮
};
this.showGallery = true;
}
<app-stage-gallery-modal
[visible]="showGallery"
[config]="galleryConfig"
(close)="showGallery = false; galleryConfig = null"
(deleteFile)="onDelete($event)"
(uploadFiles)="onUpload($event)"
(previewFile)="onPreview($event)">
</app-stage-gallery-modal>
onDelete(event: { file: any; event: Event }) {
console.log('删除:', event.file.name);
// 你的删除逻辑
}
onUpload(event: Event) {
const input = event.target as HTMLInputElement;
console.log('上传:', input.files);
// 你的上传逻辑
}
onPreview(file: any) {
console.log('预览:', file.name);
// 你的预览逻辑(非图片文件)
}
画廊会自动处理:
┌──────────────────────────────────────────┐
│ [🏠] 渲染 - 客厅 [×] │ ← 渐变紫色头部
│ 📁 6 个文件 │
├──────────────────────────────────────────┤
│ [图1] [图2] [图3] [图4] │ ← 自适应网格
│ [图5] [图6] [PDF] [图7] │ ← 阴影 + hover
├──────────────────────────────────────────┤
│ [📤 上传文件] │ ← 渐变按钮
└──────────────────────────────────────────┘
┌────────────────────┐
│ [🏠] 渲染 [×] │
│ 📁 6 个文件 │
├────────────────────┤
│ [图1] [图2] │ ← 2列布局
│ [图3] [图4] │
│ [图5] [图6] │
├────────────────────┤
│ [📤 上传文件] │ ← 全宽按钮
└────────────────────┘
| 屏幕尺寸 | 列数 | 间距 | 特殊处理 |
|---|---|---|---|
| 桌面 (>1024px) | 自适应 | 24px | hover显示删除 |
| 平板 (768-1024px) | 3列 | 20px | 始终显示删除 |
| 手机 (<768px) | 2列 | 12px | 全宽按钮 |
// 1. 使用 ChangeDetectionStrategy.OnPush
@Component({
changeDetection: ChangeDetectionStrategy.OnPush
})
// 2. 调用 markForCheck 更新视图
this.galleryConfig = newConfig;
this.cdr.markForCheck();
// 3. 关闭时清理状态
closeGallery() {
this.showGallery = false;
this.galleryConfig = null;
}
// 1. 不要在 config 中使用复杂对象
// ❌ 错误
files: this.allFiles // 引用
// ✅ 正确
files: [...this.allFiles] // 拷贝
// 2. 不要忘记处理关闭事件
// ❌ 错误
<app-stage-gallery-modal [visible]="true" />
// ✅ 正确
<app-stage-gallery-modal
[visible]="showGallery"
(close)="showGallery = false" />
NEW_GALLERY_COMPONENT.md只需4步,即可拥有精美的图片画廊!
// 1. 导入
import { StageGalleryModalComponent, GalleryConfig } from '@/components/stage-gallery-modal';
// 2. 配置
galleryConfig: GalleryConfig = { /* ... */ };
// 3. 使用
<app-stage-gallery-modal [visible]="true" [config]="galleryConfig" />
// 4. 完成!
快速上手时间: ~5分钟
集成难度: ⭐⭐☆☆☆ (简单)
视觉效果: ⭐⭐⭐⭐⭐ (精美)