This commit is contained in:
yinsx
2026-01-23 16:56:28 +08:00
parent 5674ce116e
commit ce796e2fd7
7 changed files with 131 additions and 32 deletions

View File

@ -1,10 +1,13 @@
import { defineStore } from 'pinia';
type IconSize = '1x1' | '1x2' | '2x1' | '2x2' | '2x4';
// 模拟数据(来自截图参考)
interface Icon {
id: string;
name: string;
url: string;
size?: IconSize;
img?: string; // 可选:用于图片图标(如徽标)
bgColor?: string; // 可选:纯色背景
}
@ -45,9 +48,21 @@ const defaultIcons: Icon[] = [
const savedIcons = localStorage.getItem('itab_icons');
const normalizeIcons = (icons: Icon[]): Icon[] =>
icons.map(icon => ({ ...icon, size: icon.size ?? '1x1' }));
const loadIcons = (): Icon[] => {
if (!savedIcons) return normalizeIcons(defaultIcons);
try {
return normalizeIcons(JSON.parse(savedIcons) as Icon[]);
} catch {
return normalizeIcons(defaultIcons);
}
};
export const useLayoutStore = defineStore('layout', {
state: (): LayoutState => ({
icons: savedIcons ? JSON.parse(savedIcons) : defaultIcons,
icons: loadIcons(),
dragState: {
isDragging: false,
itemId: null,
@ -91,6 +106,13 @@ export const useLayoutStore = defineStore('layout', {
this.icons = ordered;
localStorage.setItem('itab_icons', JSON.stringify(this.icons));
},
updateIconSize(iconId: string, newSize: IconSize) {
const icon = this.icons.find(item => item.id === iconId);
if (icon) {
icon.size = newSize;
localStorage.setItem('itab_icons', JSON.stringify(this.icons));
}
},
deleteIcon(itemId: string) {
const index = this.icons.findIndex(p => p.id === itemId);
if (index !== -1) {