2026-02-27 15:33:23 +08:00
|
|
|
|
import { For } from 'solid-js';
|
|
|
|
|
|
import type { DeckStore } from '../hooks/deckStore';
|
|
|
|
|
|
|
|
|
|
|
|
export interface LayerEditorPanelProps {
|
|
|
|
|
|
store: DeckStore;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-27 22:56:06 +08:00
|
|
|
|
const ORIENTATION_OPTIONS = [
|
|
|
|
|
|
{ value: 'n', label: '↑ 北' },
|
|
|
|
|
|
{ value: 'e', label: '→ 东' },
|
|
|
|
|
|
{ value: 's', label: '↓ 南' },
|
|
|
|
|
|
{ value: 'w', label: '← 西' }
|
|
|
|
|
|
] as const;
|
|
|
|
|
|
|
2026-03-27 15:17:25 +08:00
|
|
|
|
const ALIGN_OPTIONS = [
|
|
|
|
|
|
{ value: '', label: '对齐' },
|
|
|
|
|
|
{ value: 'l', label: '← 左' },
|
|
|
|
|
|
{ value: 'c', label: '≡ 中' },
|
|
|
|
|
|
{ value: 'r', label: '→ 右' }
|
|
|
|
|
|
] as const;
|
|
|
|
|
|
|
2026-02-27 15:33:23 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 图层编辑面板:图层可见性切换、位置编辑、复制代码
|
|
|
|
|
|
*/
|
|
|
|
|
|
export function LayerEditorPanel(props: LayerEditorPanelProps) {
|
|
|
|
|
|
const { store } = props;
|
|
|
|
|
|
|
2026-03-13 17:26:00 +08:00
|
|
|
|
// 根据当前激活的面获取图层配置
|
|
|
|
|
|
const currentLayerConfigs = () =>
|
|
|
|
|
|
store.state.activeSide === 'front'
|
|
|
|
|
|
? store.state.frontLayerConfigs
|
|
|
|
|
|
: store.state.backLayerConfigs;
|
|
|
|
|
|
|
2026-02-27 22:56:06 +08:00
|
|
|
|
const updateLayerOrientation = (layerProp: string, orientation: 'n' | 's' | 'e' | 'w') => {
|
2026-03-13 17:26:00 +08:00
|
|
|
|
const updateFn = store.state.activeSide === 'front'
|
|
|
|
|
|
? store.actions.updateFrontLayerConfig
|
|
|
|
|
|
: store.actions.updateBackLayerConfig;
|
|
|
|
|
|
updateFn(layerProp, { orientation });
|
2026-02-27 22:56:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-02-28 12:28:23 +08:00
|
|
|
|
const updateLayerFontSize = (layerProp: string, fontSize?: number) => {
|
2026-03-13 17:26:00 +08:00
|
|
|
|
const updateFn = store.state.activeSide === 'front'
|
|
|
|
|
|
? store.actions.updateFrontLayerConfig
|
|
|
|
|
|
: store.actions.updateBackLayerConfig;
|
|
|
|
|
|
updateFn(layerProp, { fontSize });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-27 15:17:25 +08:00
|
|
|
|
const updateLayerAlign = (layerProp: string, align?: 'l' | 'c' | 'r') => {
|
|
|
|
|
|
const updateFn = store.state.activeSide === 'front'
|
|
|
|
|
|
? store.actions.updateFrontLayerConfig
|
|
|
|
|
|
: store.actions.updateBackLayerConfig;
|
|
|
|
|
|
updateFn(layerProp, { align });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-03-13 17:26:00 +08:00
|
|
|
|
const toggleLayerVisible = (layerProp: string) => {
|
|
|
|
|
|
const toggleFn = store.state.activeSide === 'front'
|
|
|
|
|
|
? store.actions.toggleFrontLayerVisible
|
|
|
|
|
|
: store.actions.toggleBackLayerVisible;
|
|
|
|
|
|
toggleFn(layerProp);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const setEditingLayer = (layerProp: string) => {
|
|
|
|
|
|
store.actions.setEditingLayer(
|
|
|
|
|
|
store.state.editingLayer === layerProp ? null : layerProp
|
|
|
|
|
|
);
|
2026-02-28 12:28:23 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-02-27 15:33:23 +08:00
|
|
|
|
return (
|
|
|
|
|
|
<div class="w-64 flex-shrink-0">
|
2026-03-13 17:26:00 +08:00
|
|
|
|
<h3 class="font-bold mb-2 mt-0">
|
|
|
|
|
|
图层 ({store.state.activeSide === 'front' ? '正面' : '背面'})
|
|
|
|
|
|
</h3>
|
2026-02-27 15:33:23 +08:00
|
|
|
|
|
|
|
|
|
|
<div class="space-y-2">
|
2026-03-13 17:26:00 +08:00
|
|
|
|
<For each={currentLayerConfigs()}>
|
2026-02-27 15:33:23 +08:00
|
|
|
|
{(layer) => (
|
2026-02-28 12:28:23 +08:00
|
|
|
|
<div class="flex flex-row flex-wrap gap-1 p-2 bg-gray-50 rounded">
|
2026-02-27 22:56:06 +08:00
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
checked={layer.visible}
|
2026-03-13 17:26:00 +08:00
|
|
|
|
onChange={() => toggleLayerVisible(layer.prop)}
|
2026-02-27 22:56:06 +08:00
|
|
|
|
class="cursor-pointer"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span class="text-sm flex-1">{layer.prop}</span>
|
|
|
|
|
|
</div>
|
2026-03-13 12:34:39 +08:00
|
|
|
|
{layer.visible && (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<button
|
2026-03-13 17:26:00 +08:00
|
|
|
|
onClick={() => setEditingLayer(layer.prop)}
|
2026-02-28 12:28:23 +08:00
|
|
|
|
class={`text-xs px-2 py-1 rounded cursor-pointer ${
|
2026-03-13 12:34:39 +08:00
|
|
|
|
store.state.editingLayer === layer.prop
|
|
|
|
|
|
? 'bg-blue-500 text-white'
|
|
|
|
|
|
: 'bg-gray-200 text-gray-700 hover:bg-gray-300'
|
2026-02-28 12:28:23 +08:00
|
|
|
|
}`}
|
2026-03-13 12:34:39 +08:00
|
|
|
|
>
|
2026-02-28 12:28:23 +08:00
|
|
|
|
{store.state.editingLayer === layer.prop ? '✓ 框选' : '框选'}
|
2026-03-13 12:34:39 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
|
<select
|
|
|
|
|
|
value={layer.orientation || 'n'}
|
|
|
|
|
|
onChange={(e) => updateLayerOrientation(layer.prop, e.target.value as 'n' | 's' | 'e' | 'w')}
|
|
|
|
|
|
class="text-xs px-2 py-1 rounded border border-gray-300 bg-white cursor-pointer"
|
|
|
|
|
|
>
|
|
|
|
|
|
<For each={ORIENTATION_OPTIONS}>
|
|
|
|
|
|
{(opt) => (
|
|
|
|
|
|
<option value={opt.value}>{opt.label}</option>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</For>
|
|
|
|
|
|
</select>
|
2026-03-27 15:17:25 +08:00
|
|
|
|
<select
|
|
|
|
|
|
value={layer.align || ''}
|
|
|
|
|
|
onChange={(e) => updateLayerAlign(layer.prop, e.target.value as 'l' | 'c' | 'r' | undefined || undefined)}
|
|
|
|
|
|
class="text-xs px-2 py-1 rounded border border-gray-300 bg-white cursor-pointer"
|
|
|
|
|
|
>
|
|
|
|
|
|
<For each={ALIGN_OPTIONS}>
|
|
|
|
|
|
{(opt) => (
|
|
|
|
|
|
<option value={opt.value}>{opt.label}</option>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</For>
|
|
|
|
|
|
</select>
|
2026-03-13 12:34:39 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
|
<label class="text-xs text-gray-600">字体/mm</label>
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="number"
|
|
|
|
|
|
value={layer.fontSize || ''}
|
|
|
|
|
|
placeholder="默认"
|
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
|
const value = e.target.value;
|
|
|
|
|
|
updateLayerFontSize(layer.prop, value ? Number(value) : undefined);
|
|
|
|
|
|
}}
|
|
|
|
|
|
class="w-16 text-xs px-2 py-1 rounded border border-gray-300 bg-white"
|
|
|
|
|
|
step="0.1"
|
|
|
|
|
|
min="0.1"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
2026-02-27 15:33:23 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</For>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<hr class="my-4" />
|
|
|
|
|
|
|
|
|
|
|
|
<button
|
2026-03-13 17:26:00 +08:00
|
|
|
|
onClick={() => store.actions.copyCode()}
|
|
|
|
|
|
class="w-full bg-blue-600 hover:bg-blue-700 text-white px-3 py-2 rounded text-sm font-medium cursor-pointer flex items-center gap-2 justify-center"
|
2026-02-27 15:33:23 +08:00
|
|
|
|
>
|
2026-03-13 17:26:00 +08:00
|
|
|
|
<span>📋</span>
|
|
|
|
|
|
<span>复制代码</span>
|
2026-02-27 15:33:23 +08:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|