support restore

This commit is contained in:
Julian Freeman
2026-01-19 12:18:08 -04:00
parent f96033e421
commit 6439759b04
2 changed files with 26 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { useGalleryStore } from "../stores/gallery"; import { useGalleryStore } from "../stores/gallery";
import { Settings, CheckSquare, Type, Palette, Copy, Eraser, PlusSquare, Brush, Sparkles, Trash2, RotateCw } from 'lucide-vue-next'; import { Settings, CheckSquare, Type, Palette, Copy, Eraser, PlusSquare, Brush, Sparkles, Trash2, RotateCw, RotateCcw } from 'lucide-vue-next';
import { computed } from "vue"; import { computed } from "vue";
const store = useGalleryStore(); const store = useGalleryStore();
@@ -227,6 +227,15 @@ const applyAll = () => {
<Eraser class="w-5 h-5" /> <Eraser class="w-5 h-5" />
执行移除 执行移除
</button> </button>
<button
v-if="store.selectedImage && store.selectedImage.path !== store.selectedImage.originalPath"
@click="store.selectedIndex >= 0 && store.restoreImage(store.selectedIndex)"
class="w-full bg-gray-700 hover:bg-gray-600 text-gray-300 py-2 rounded text-sm transition-colors flex items-center justify-center gap-2"
>
<RotateCcw class="w-4 h-4" />
还原原图
</button>
</div> </div>
</div> </div>

View File

@@ -11,6 +11,7 @@ export interface MaskStroke {
export interface ImageItem { export interface ImageItem {
path: string; path: string;
originalPath: string;
thumbnail: string; thumbnail: string;
name: string; name: string;
width?: number; width?: number;
@@ -59,9 +60,21 @@ export const useGalleryStore = defineStore("gallery", () => {
}); });
function setImages(newImages: ImageItem[]) { function setImages(newImages: ImageItem[]) {
images.value = newImages; images.value = newImages.map(img => ({
...img,
// Ensure originalPath is set if not already present from backend
originalPath: img.originalPath || img.path
}));
selectedIndex.value = -1; selectedIndex.value = -1;
} }
function restoreImage(index: number) {
const img = images.value[index];
if (img) {
img.path = img.originalPath;
img.maskStrokes = []; // Also clear any masks if restoring
}
}
function updateWatermarkSettings(settings: Partial<WatermarkSettings>) { function updateWatermarkSettings(settings: Partial<WatermarkSettings>) {
watermarkSettings.value = { ...watermarkSettings.value, ...settings }; watermarkSettings.value = { ...watermarkSettings.value, ...settings };
@@ -238,6 +251,7 @@ export const useGalleryStore = defineStore("gallery", () => {
clearMask, clearMask,
detectAllWatermarks, detectAllWatermarks,
recalcAllWatermarks, recalcAllWatermarks,
processInpainting processInpainting,
restoreImage
}; };
}); });