mirror of
https://github.com/Powerful-517/yys-editor.git
synced 2026-03-05 06:55:26 +00:00
refactor: 重构属性编辑面板,支持Tab分离和节点类型切换
- 将属性面板分为游戏属性和图像属性两个Tab - 游戏属性Tab包含节点基本信息、类型切换和特定属性 - 图像属性Tab包含所有样式设置(填充、描边、阴影等) - 资产选择器节点支持在式神和御魂之间切换 - 切换节点类型时自动清空已选资产 - 优化AssetSelectorPanel,移除重复的资产库选择器
This commit is contained in:
16
src/App.vue
16
src/App.vue
@@ -12,8 +12,11 @@ import YuhunSelect from './components/flow/nodes/yys/YuhunSelect.vue';
|
||||
import PropertySelect from './components/flow/nodes/yys/PropertySelect.vue';
|
||||
import DialogManager from './components/DialogManager.vue';
|
||||
import {getLogicFlowInstance} from "@/ts/useLogicFlow";
|
||||
import { migrateGraphData, needsMigration } from '@/utils/nodeMigration';
|
||||
import { useGlobalMessage } from '@/ts/useGlobalMessage';
|
||||
|
||||
const filesStore = useFilesStore();
|
||||
const { showMessage } = useGlobalMessage();
|
||||
|
||||
const width = ref('100%');
|
||||
const height = ref('100vh');
|
||||
@@ -23,10 +26,19 @@ const contentHeight = computed(() => `${windowHeight.value - toolbarHeight}px`);
|
||||
|
||||
const normalizeGraphData = (data: any) => {
|
||||
if (data && Array.isArray((data as any).nodes) && Array.isArray((data as any).edges)) {
|
||||
// 应用数据迁移
|
||||
const { graphData: migratedData, migratedCount, migrations } = migrateGraphData(data);
|
||||
|
||||
// 如果有迁移,显示提示信息
|
||||
if (migratedCount > 0) {
|
||||
console.log(`[数据迁移] 迁移了 ${migratedCount} 个节点:`, migrations);
|
||||
showMessage('info', `已自动升级 ${migratedCount} 个节点到新版本`);
|
||||
}
|
||||
|
||||
// 清理节点数据,移除可能导致 Label 插件出错的空 _label 数组
|
||||
const cleanedData = {
|
||||
...data,
|
||||
nodes: data.nodes.map((node: any) => {
|
||||
...migratedData,
|
||||
nodes: migratedData.nodes.map((node: any) => {
|
||||
const cleanedNode = { ...node };
|
||||
if (cleanedNode.properties && Array.isArray(cleanedNode.properties._label) && cleanedNode.properties._label.length === 0) {
|
||||
delete cleanedNode.properties._label;
|
||||
|
||||
@@ -3,9 +3,10 @@ import { useDialogs } from '../ts/useDialogs'
|
||||
import ShikigamiSelect from './flow/nodes/yys/ShikigamiSelect.vue'
|
||||
import YuhunSelect from './flow/nodes/yys/YuhunSelect.vue'
|
||||
import PropertySelect from './flow/nodes/yys/PropertySelect.vue'
|
||||
import GenericImageSelector from './common/GenericImageSelector.vue'
|
||||
import { useFilesStore } from '../ts/useStore'
|
||||
|
||||
const { dialogs, closeDialog } = useDialogs();
|
||||
const { dialogs, closeDialog, closeGenericSelector } = useDialogs();
|
||||
const filesStore = useFilesStore();
|
||||
</script>
|
||||
|
||||
@@ -40,4 +41,16 @@ const filesStore = useFilesStore();
|
||||
closeDialog('property');
|
||||
}"
|
||||
/>
|
||||
<GenericImageSelector
|
||||
v-if="dialogs.generic.show && dialogs.generic.config"
|
||||
v-model="dialogs.generic.show"
|
||||
:config="dialogs.generic.config"
|
||||
@select="data => {
|
||||
dialogs.generic.callback?.(data);
|
||||
closeGenericSelector();
|
||||
}"
|
||||
@update:modelValue="value => {
|
||||
if (!value) closeGenericSelector();
|
||||
}"
|
||||
/>
|
||||
</template>
|
||||
114
src/components/common/GenericImageSelector.vue
Normal file
114
src/components/common/GenericImageSelector.vue
Normal file
@@ -0,0 +1,114 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="show"
|
||||
:title="config.title"
|
||||
>
|
||||
<span v-if="config.currentItem">
|
||||
当前选择:{{ config.currentItem[config.itemRender.labelField] }}
|
||||
</span>
|
||||
|
||||
<!-- 搜索框 -->
|
||||
<div v-if="config.searchable !== false" style="display: flex; align-items: center;">
|
||||
<el-input
|
||||
v-model="searchText"
|
||||
placeholder="请输入内容"
|
||||
style="width: 200px; margin-right: 10px;"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Tab分组 -->
|
||||
<el-tabs
|
||||
v-model="activeTab"
|
||||
type="card"
|
||||
class="demo-tabs"
|
||||
>
|
||||
<el-tab-pane
|
||||
v-for="group in config.groups"
|
||||
:key="group.name"
|
||||
:label="group.label"
|
||||
:name="group.name"
|
||||
>
|
||||
<div style="max-height: 600px; overflow-y: auto;">
|
||||
<el-space wrap size="large">
|
||||
<div
|
||||
v-for="item in filteredItems(group)"
|
||||
:key="item[config.itemRender.labelField]"
|
||||
style="display: flex; flex-direction: column; justify-content: center"
|
||||
>
|
||||
<el-button
|
||||
:style="`width: ${imageSize}px; height: ${imageSize}px;`"
|
||||
@click="handleSelect(item)"
|
||||
>
|
||||
<img
|
||||
:src="item[config.itemRender.imageField]"
|
||||
:style="`width: ${imageSize - 1}px; height: ${imageSize - 1}px;`"
|
||||
>
|
||||
</el-button>
|
||||
<span style="text-align: center; display: block;">
|
||||
{{ item[config.itemRender.labelField] }}
|
||||
</span>
|
||||
</div>
|
||||
</el-space>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import type { SelectorConfig, GroupConfig } from '@/types/selector'
|
||||
|
||||
const props = defineProps<{
|
||||
config: SelectorConfig
|
||||
modelValue: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
'select': [item: any]
|
||||
}>()
|
||||
|
||||
const show = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
})
|
||||
|
||||
const searchText = ref('')
|
||||
const activeTab = ref('ALL')
|
||||
const imageSize = computed(() => props.config.itemRender.imageSize || 100)
|
||||
|
||||
// 过滤逻辑
|
||||
const filteredItems = (group: GroupConfig) => {
|
||||
let items = props.config.dataSource
|
||||
|
||||
// 分组过滤
|
||||
if (group.name !== 'ALL') {
|
||||
if (group.filter) {
|
||||
items = items.filter(group.filter)
|
||||
} else {
|
||||
items = items.filter(item =>
|
||||
item[props.config.groupField]?.toLowerCase() === group.name.toLowerCase()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索过滤
|
||||
if (searchText.value.trim()) {
|
||||
const searchFields = props.config.searchFields || [props.config.itemRender.labelField]
|
||||
items = items.filter(item =>
|
||||
searchFields.some(field =>
|
||||
item[field]?.toLowerCase().includes(searchText.value.toLowerCase())
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
const handleSelect = (item: any) => {
|
||||
emit('select', item)
|
||||
searchText.value = ''
|
||||
activeTab.value = 'ALL'
|
||||
}
|
||||
</script>
|
||||
@@ -58,6 +58,16 @@ const componentGroups = [
|
||||
id: 'yys',
|
||||
title: '阴阳师',
|
||||
components: [
|
||||
{
|
||||
id: 'asset-selector',
|
||||
name: '资产选择器',
|
||||
type: 'assetSelector',
|
||||
description: '通用资产选择器(式神/御魂等)',
|
||||
data: {
|
||||
assetLibrary: 'shikigami',
|
||||
selectedAsset: null
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'shikigami-select',
|
||||
name: '式神选择器',
|
||||
|
||||
@@ -73,6 +73,7 @@ import ShikigamiSelectNode from './nodes/yys/ShikigamiSelectNode.vue';
|
||||
import YuhunSelectNode from './nodes/yys/YuhunSelectNode.vue';
|
||||
import PropertySelectNode from './nodes/yys/PropertySelectNode.vue';
|
||||
import ImageNode from './nodes/common/ImageNode.vue';
|
||||
import AssetSelectorNode from './nodes/common/AssetSelectorNode.vue';
|
||||
// import TextNode from './nodes/common/TextNode.vue';
|
||||
import PropertyPanel from './PropertyPanel.vue';
|
||||
import { useGlobalMessage } from '@/ts/useGlobalMessage';
|
||||
@@ -660,6 +661,7 @@ function registerNodes(lfInstance: LogicFlow) {
|
||||
register({ type: 'propertySelect', component: PropertySelectNode }, lfInstance);
|
||||
|
||||
register({ type: 'imageNode', component: ImageNode }, lfInstance);
|
||||
register({ type: 'assetSelector', component: AssetSelectorNode }, lfInstance);
|
||||
// register({ type: 'textNode', component: TextNode }, lfInstance);
|
||||
}
|
||||
|
||||
@@ -915,6 +917,11 @@ onMounted(() => {
|
||||
normalizeAllNodes();
|
||||
});
|
||||
|
||||
// 监听节点点击事件,更新选中节点
|
||||
lfInstance.on(EventType.NODE_CLICK, ({ data }) => {
|
||||
selectedNode.value = data;
|
||||
});
|
||||
|
||||
// 监听空白点击事件,取消选中
|
||||
lfInstance.on(EventType.BLANK_CLICK, () => {
|
||||
selectedNode.value = null;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import ShikigamiPanel from './panels/ShikigamiPanel.vue';
|
||||
import YuhunPanel from './panels/YuhunPanel.vue';
|
||||
import PropertyRulePanel from './panels/PropertyRulePanel.vue';
|
||||
import ImagePanel from './panels/ImagePanel.vue';
|
||||
import TextPanel from './panels/TextPanel.vue';
|
||||
import StylePanel from './panels/StylePanel.vue';
|
||||
import AssetSelectorPanel from './panels/AssetSelectorPanel.vue';
|
||||
import { ASSET_LIBRARIES } from '@/types/nodeTypes';
|
||||
import { getLogicFlowInstance } from '@/ts/useLogicFlow';
|
||||
|
||||
const props = defineProps({
|
||||
height: {
|
||||
@@ -26,15 +29,36 @@ const nodeType = computed(() => {
|
||||
return selectedNode.value.type || 'default';
|
||||
});
|
||||
|
||||
const activeTab = ref('game');
|
||||
|
||||
const panelMap: Record<string, any> = {
|
||||
shikigamiSelect: ShikigamiPanel,
|
||||
yuhunSelect: YuhunPanel,
|
||||
propertySelect: PropertyRulePanel,
|
||||
imageNode: ImagePanel,
|
||||
textNode: TextPanel
|
||||
textNode: TextPanel,
|
||||
assetSelector: AssetSelectorPanel
|
||||
};
|
||||
|
||||
const panelComponent = computed(() => panelMap[nodeType.value] || null);
|
||||
|
||||
// 判断是否支持节点类型切换(仅资产选择器节点支持)
|
||||
const supportsTypeSwitch = computed(() => nodeType.value === 'assetSelector');
|
||||
|
||||
// 当前资产库类型
|
||||
const currentAssetLibrary = computed({
|
||||
get: () => selectedNode.value?.properties?.assetLibrary || 'shikigami',
|
||||
set: (value) => {
|
||||
const lf = getLogicFlowInstance();
|
||||
if (!lf || !selectedNode.value) return;
|
||||
|
||||
lf.setProperties(selectedNode.value.id, {
|
||||
...selectedNode.value.properties,
|
||||
assetLibrary: value,
|
||||
selectedAsset: null // 切换类型时清空已选资产
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -48,27 +72,53 @@ const panelComponent = computed(() => panelMap[nodeType.value] || null);
|
||||
</div>
|
||||
|
||||
<div v-else class="property-content">
|
||||
<div class="property-section">
|
||||
<div class="section-header">基本信息</div>
|
||||
<div class="property-item">
|
||||
<div class="property-label">节点ID</div>
|
||||
<div class="property-value">{{ selectedNode.id }}</div>
|
||||
</div>
|
||||
<div class="property-item">
|
||||
<div class="property-label">节点类型</div>
|
||||
<div class="property-value">{{ nodeType }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Tab 切换 -->
|
||||
<el-tabs v-model="activeTab" class="property-tabs">
|
||||
<!-- 游戏属性 Tab -->
|
||||
<el-tab-pane label="游戏属性" name="game">
|
||||
<div class="property-section">
|
||||
<div class="section-header">基本信息</div>
|
||||
<div class="property-item">
|
||||
<div class="property-label">节点ID</div>
|
||||
<div class="property-value">{{ selectedNode.id }}</div>
|
||||
</div>
|
||||
<div class="property-item">
|
||||
<div class="property-label">节点类型</div>
|
||||
<div class="property-value">{{ nodeType }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<StylePanel :node="selectedNode" />
|
||||
<!-- 节点类型切换(仅资产选择器支持) -->
|
||||
<div v-if="supportsTypeSwitch" class="property-section">
|
||||
<div class="section-header">节点类型</div>
|
||||
<div class="property-item">
|
||||
<div class="property-label">资产类型</div>
|
||||
<el-select v-model="currentAssetLibrary" placeholder="选择资产类型" style="width: 100%">
|
||||
<el-option
|
||||
v-for="lib in ASSET_LIBRARIES"
|
||||
:key="lib.id"
|
||||
:label="lib.label"
|
||||
:value="lib.id"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<component v-if="panelComponent" :is="panelComponent" :node="selectedNode" />
|
||||
<div v-else class="property-section">
|
||||
<div class="section-header">暂无特定属性</div>
|
||||
<div class="property-item">
|
||||
<div class="property-value">当前节点类型无需额外配置。</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 特定节点属性面板 -->
|
||||
<component v-if="panelComponent" :is="panelComponent" :node="selectedNode" />
|
||||
<div v-else class="property-section">
|
||||
<div class="section-header">暂无特定属性</div>
|
||||
<div class="property-item">
|
||||
<div class="property-value">当前节点类型无需额外配置。</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- 图像属性 Tab -->
|
||||
<el-tab-pane label="图像属性" name="style">
|
||||
<StylePanel :node="selectedNode" />
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -108,6 +158,21 @@ const panelComponent = computed(() => panelMap[nodeType.value] || null);
|
||||
|
||||
.property-content {
|
||||
padding: 10px;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.property-tabs {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.property-tabs :deep(.el-tabs__content) {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.property-section {
|
||||
|
||||
102
src/components/flow/nodes/common/AssetSelectorNode.vue
Normal file
102
src/components/flow/nodes/common/AssetSelectorNode.vue
Normal file
@@ -0,0 +1,102 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, inject, onMounted, onBeforeUnmount } from 'vue';
|
||||
import { toTextStyle } from '@/ts/nodeStyle';
|
||||
import { useNodeAppearance } from '@/ts/useNodeAppearance';
|
||||
|
||||
const currentAsset = ref({ name: '未选择资产', avatar: '', library: 'shikigami' });
|
||||
const getNode = inject('getNode') as (() => any) | undefined;
|
||||
const zIndex = ref(1);
|
||||
let intervalId: number | null = null;
|
||||
|
||||
// 使用轮询方式定期更新 zIndex
|
||||
onMounted(() => {
|
||||
const node = getNode?.();
|
||||
if (node) {
|
||||
zIndex.value = node.zIndex ?? 1;
|
||||
|
||||
// 每 100ms 检查一次 zIndex 是否变化
|
||||
intervalId = window.setInterval(() => {
|
||||
const currentZIndex = node.zIndex ?? 1;
|
||||
if (zIndex.value !== currentZIndex) {
|
||||
zIndex.value = currentZIndex;
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (intervalId !== null) {
|
||||
clearInterval(intervalId);
|
||||
}
|
||||
});
|
||||
|
||||
const { containerStyle, textStyle } = useNodeAppearance({
|
||||
onPropsChange(props) {
|
||||
if (props.selectedAsset) {
|
||||
currentAsset.value = props.selectedAsset;
|
||||
}
|
||||
if (props.assetLibrary && !props.selectedAsset) {
|
||||
// 如果切换了资产库但没有选中资产,更新占位文本
|
||||
currentAsset.value = {
|
||||
name: '未选择资产',
|
||||
avatar: '',
|
||||
library: props.assetLibrary
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const mergedContainerStyle = computed(() => ({ ...containerStyle.value, boxSizing: 'border-box' }));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="node-content" :style="mergedContainerStyle">
|
||||
<div class="zindex-badge">{{ zIndex }}</div>
|
||||
<img
|
||||
v-if="currentAsset.avatar"
|
||||
:src="currentAsset.avatar"
|
||||
:alt="currentAsset.name"
|
||||
class="asset-image"
|
||||
draggable="false"
|
||||
/>
|
||||
<div v-else class="placeholder-text" :style="textStyle">点击选择资产</div>
|
||||
<div class="name-text" :style="textStyle">{{ currentAsset.name }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.node-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
}
|
||||
.zindex-badge {
|
||||
position: absolute;
|
||||
top: 4px;
|
||||
right: 4px;
|
||||
background: rgba(64, 158, 255, 0.9);
|
||||
color: white;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
padding: 2px 6px;
|
||||
border-radius: 10px;
|
||||
z-index: 10;
|
||||
pointer-events: none;
|
||||
}
|
||||
.asset-image {
|
||||
width: 85%;
|
||||
height: 85%;
|
||||
object-fit: cover;
|
||||
}
|
||||
.placeholder-text {
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
}
|
||||
.name-text {
|
||||
font-size: 14px;
|
||||
text-align: center;
|
||||
margin-top: 8px;
|
||||
}
|
||||
</style>
|
||||
83
src/components/flow/panels/AssetSelectorPanel.vue
Normal file
83
src/components/flow/panels/AssetSelectorPanel.vue
Normal file
@@ -0,0 +1,83 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { useDialogs } from '@/ts/useDialogs';
|
||||
import { getLogicFlowInstance } from '@/ts/useLogicFlow';
|
||||
import { SELECTOR_PRESETS } from '@/configs/selectorPresets';
|
||||
|
||||
const props = defineProps<{
|
||||
node: any;
|
||||
}>();
|
||||
|
||||
const { openGenericSelector } = useDialogs();
|
||||
|
||||
// 当前选中的资产库
|
||||
const currentLibrary = computed(() => props.node.properties?.assetLibrary || 'shikigami');
|
||||
|
||||
// 当前选中的资产
|
||||
const currentAsset = computed(() => {
|
||||
return props.node.properties?.selectedAsset || { name: '未选择' };
|
||||
});
|
||||
|
||||
// 打开选择器
|
||||
const handleOpenSelector = () => {
|
||||
const lf = getLogicFlowInstance();
|
||||
const node = props.node;
|
||||
if (!lf || !node) return;
|
||||
|
||||
const library = currentLibrary.value;
|
||||
const config = SELECTOR_PRESETS[library];
|
||||
|
||||
if (!config) {
|
||||
console.error('未找到资产库配置:', library);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置当前选中项
|
||||
config.currentItem = node.properties?.selectedAsset;
|
||||
|
||||
openGenericSelector(config, (selectedItem) => {
|
||||
lf.setProperties(node.id, {
|
||||
...node.properties,
|
||||
selectedAsset: selectedItem,
|
||||
assetLibrary: library
|
||||
});
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="property-section">
|
||||
<div class="section-header">资产属性</div>
|
||||
|
||||
<div class="property-item">
|
||||
<div class="property-label">当前选择</div>
|
||||
<span>{{ currentAsset.name }}</span>
|
||||
<el-button type="primary" @click="handleOpenSelector" style="width: 100%; margin-top: 8px">
|
||||
选择资产
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.property-section {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
font-weight: bold;
|
||||
margin-bottom: 12px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
}
|
||||
|
||||
.property-item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.property-label {
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
53
src/configs/nodeRegistry.ts
Normal file
53
src/configs/nodeRegistry.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 节点注册表
|
||||
* 定义所有节点类型的配置信息
|
||||
*/
|
||||
|
||||
import { NodeType, NodeCategory, type NodeTypeConfig } from '@/types/nodeTypes'
|
||||
|
||||
export const NODE_REGISTRY: Record<NodeType, NodeTypeConfig> = {
|
||||
[NodeType.RECT]: {
|
||||
type: NodeType.RECT,
|
||||
category: NodeCategory.LAYOUT,
|
||||
label: '矩形',
|
||||
description: '矩形容器,可设置背景和边框'
|
||||
},
|
||||
|
||||
[NodeType.ELLIPSE]: {
|
||||
type: NodeType.ELLIPSE,
|
||||
category: NodeCategory.LAYOUT,
|
||||
label: '椭圆',
|
||||
description: '椭圆容器,可设置背景和边框'
|
||||
},
|
||||
|
||||
[NodeType.ASSET_SELECTOR]: {
|
||||
type: NodeType.ASSET_SELECTOR,
|
||||
category: NodeCategory.ASSET,
|
||||
label: '资产选择器',
|
||||
description: '从预设资产库选择图片(式神、御魂等)',
|
||||
defaultProps: {
|
||||
assetLibrary: 'shikigami' // 默认式神库
|
||||
}
|
||||
},
|
||||
|
||||
[NodeType.IMAGE_UPLOAD]: {
|
||||
type: NodeType.IMAGE_UPLOAD,
|
||||
category: NodeCategory.ASSET,
|
||||
label: '自定义图片',
|
||||
description: '上传自定义图片或填写URL'
|
||||
},
|
||||
|
||||
[NodeType.TEXT_NODE]: {
|
||||
type: NodeType.TEXT_NODE,
|
||||
category: NodeCategory.TEXT,
|
||||
label: '文本',
|
||||
description: '可编辑的文本节点'
|
||||
},
|
||||
|
||||
[NodeType.PROPERTY_SELECT]: {
|
||||
type: NodeType.PROPERTY_SELECT,
|
||||
category: NodeCategory.TEXT,
|
||||
label: '属性选择器',
|
||||
description: '选择游戏属性并配置规则'
|
||||
}
|
||||
}
|
||||
51
src/configs/selectorPresets.ts
Normal file
51
src/configs/selectorPresets.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 选择器预设配置
|
||||
* 定义各种资产类型的选择器配置
|
||||
*/
|
||||
|
||||
import type { SelectorConfig } from '@/types/selector'
|
||||
import shikigamiData from '@/data/Shikigami.json'
|
||||
import yuhunData from '@/data/Yuhun.json'
|
||||
|
||||
export const SELECTOR_PRESETS: Record<string, SelectorConfig> = {
|
||||
shikigami: {
|
||||
title: '请选择式神',
|
||||
dataSource: shikigamiData,
|
||||
groupField: 'rarity',
|
||||
groups: [
|
||||
{ label: '全部', name: 'ALL' },
|
||||
{ label: 'UR', name: 'UR' },
|
||||
{ label: 'SP', name: 'SP' },
|
||||
{ label: 'SSR', name: 'SSR' },
|
||||
{ label: 'SR', name: 'SR' },
|
||||
{ label: 'R', name: 'R' },
|
||||
{ label: 'N', name: 'N' },
|
||||
{ label: '联动', name: 'L' },
|
||||
{ label: '呱太', name: 'G' }
|
||||
],
|
||||
itemRender: {
|
||||
imageField: 'avatar',
|
||||
labelField: 'name'
|
||||
}
|
||||
},
|
||||
|
||||
yuhun: {
|
||||
title: '请选择御魂',
|
||||
dataSource: yuhunData,
|
||||
groupField: 'type',
|
||||
groups: [
|
||||
{ label: '全部', name: 'ALL' },
|
||||
{ label: '攻击类', name: 'attack' },
|
||||
{ label: '暴击类', name: 'Crit' },
|
||||
{ label: '生命类', name: 'Health' },
|
||||
{ label: '防御类', name: 'Defense' },
|
||||
{ label: '效果命中', name: 'Effect' },
|
||||
{ label: '效果抵抗', name: 'EffectResist' },
|
||||
{ label: '特殊类', name: 'Special' }
|
||||
],
|
||||
itemRender: {
|
||||
imageField: 'avatar',
|
||||
labelField: 'name'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import { reactive } from 'vue'
|
||||
import type { SelectorConfig } from '@/types/selector'
|
||||
|
||||
const dialogs = reactive({
|
||||
shikigami: { show: false, data: null, node: null, callback: null },
|
||||
yuhun: { show: false, data: null, node: null, callback: null },
|
||||
property: { show: false, data: null, node: null, callback: null }
|
||||
property: { show: false, data: null, node: null, callback: null },
|
||||
generic: { show: false, config: null, callback: null }
|
||||
})
|
||||
|
||||
function openDialog(type: string, data = null, node = null, callback = null) {
|
||||
@@ -20,10 +22,24 @@ function closeDialog(type: string) {
|
||||
dialogs[type].callback = null
|
||||
}
|
||||
|
||||
function openGenericSelector(config: SelectorConfig, callback: (item: any) => void) {
|
||||
dialogs.generic.show = true
|
||||
dialogs.generic.config = config
|
||||
dialogs.generic.callback = callback
|
||||
}
|
||||
|
||||
function closeGenericSelector() {
|
||||
dialogs.generic.show = false
|
||||
dialogs.generic.config = null
|
||||
dialogs.generic.callback = null
|
||||
}
|
||||
|
||||
export function useDialogs() {
|
||||
return {
|
||||
dialogs,
|
||||
openDialog,
|
||||
closeDialog
|
||||
closeDialog,
|
||||
openGenericSelector,
|
||||
closeGenericSelector
|
||||
}
|
||||
}
|
||||
47
src/types/nodeTypes.ts
Normal file
47
src/types/nodeTypes.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 节点类型系统
|
||||
* 将节点分为三大类:布局容器、图形资产、结构化文本
|
||||
*/
|
||||
|
||||
export enum NodeCategory {
|
||||
LAYOUT = 'layout', // 布局容器
|
||||
ASSET = 'asset', // 图形资产
|
||||
TEXT = 'text' // 结构化文本
|
||||
}
|
||||
|
||||
export enum NodeType {
|
||||
// 布局容器类
|
||||
RECT = 'rect',
|
||||
ELLIPSE = 'ellipse',
|
||||
|
||||
// 图形资产类(统一入口,内部切换资产库)
|
||||
ASSET_SELECTOR = 'assetSelector',
|
||||
IMAGE_UPLOAD = 'imageUpload',
|
||||
|
||||
// 结构化文本类
|
||||
TEXT_NODE = 'textNode',
|
||||
|
||||
// 特殊节点(保持独立)
|
||||
PROPERTY_SELECT = 'propertySelect'
|
||||
}
|
||||
|
||||
export interface AssetLibrary {
|
||||
id: string
|
||||
label: string
|
||||
selectorPreset: string
|
||||
}
|
||||
|
||||
export const ASSET_LIBRARIES: AssetLibrary[] = [
|
||||
{ id: 'shikigami', label: '式神', selectorPreset: 'shikigami' },
|
||||
{ id: 'yuhun', label: '御魂', selectorPreset: 'yuhun' }
|
||||
// 未来可扩展:技能图标、装备等
|
||||
]
|
||||
|
||||
export interface NodeTypeConfig {
|
||||
type: NodeType
|
||||
category: NodeCategory
|
||||
label: string
|
||||
description: string
|
||||
icon?: string
|
||||
defaultProps?: Record<string, any>
|
||||
}
|
||||
34
src/types/selector.ts
Normal file
34
src/types/selector.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 通用选择器配置接口
|
||||
* 用于配置驱动的图片选择器组件
|
||||
*/
|
||||
|
||||
export interface GroupConfig {
|
||||
label: string // Tab显示标签
|
||||
name: string // Tab标识符
|
||||
filter?: (item: any) => boolean // 自定义过滤函数(可选)
|
||||
}
|
||||
|
||||
export interface SelectorConfig<T = any> {
|
||||
// 基础配置
|
||||
title: string // 对话框标题
|
||||
dataSource: T[] // 数据源
|
||||
groupField: string // 分组字段名 (如 'rarity', 'type')
|
||||
|
||||
// 分组配置
|
||||
groups: GroupConfig[] // Tab分组配置
|
||||
|
||||
// 展示配置
|
||||
itemRender: {
|
||||
imageField: string // 图片字段名 (如 'avatar')
|
||||
labelField: string // 标签字段名 (如 'name')
|
||||
imageSize?: number // 图片尺寸,默认100px
|
||||
}
|
||||
|
||||
// 搜索配置
|
||||
searchable?: boolean // 是否启用搜索,默认true
|
||||
searchFields?: string[] // 搜索字段,默认使用labelField
|
||||
|
||||
// 当前选中项
|
||||
currentItem?: T
|
||||
}
|
||||
157
src/utils/nodeMigration.ts
Normal file
157
src/utils/nodeMigration.ts
Normal file
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* 节点数据迁移工具
|
||||
* 将旧节点类型自动转换为新节点类型
|
||||
*/
|
||||
|
||||
import type { GraphData } from '@logicflow/core';
|
||||
|
||||
/**
|
||||
* 迁移映射表
|
||||
*/
|
||||
const MIGRATION_MAP: Record<string, { newType: string; transform: (node: any) => any }> = {
|
||||
shikigamiSelect: {
|
||||
newType: 'assetSelector',
|
||||
transform: (node) => ({
|
||||
...node,
|
||||
type: 'assetSelector',
|
||||
properties: {
|
||||
...node.properties,
|
||||
assetLibrary: 'shikigami',
|
||||
selectedAsset: node.properties?.shikigami || null,
|
||||
// 保留原始数据以便回退
|
||||
_migrated: {
|
||||
from: 'shikigamiSelect',
|
||||
originalData: node.properties?.shikigami
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
yuhunSelect: {
|
||||
newType: 'assetSelector',
|
||||
transform: (node) => ({
|
||||
...node,
|
||||
type: 'assetSelector',
|
||||
properties: {
|
||||
...node.properties,
|
||||
assetLibrary: 'yuhun',
|
||||
selectedAsset: node.properties?.yuhun || null,
|
||||
// 保留原始数据以便回退
|
||||
_migrated: {
|
||||
from: 'yuhunSelect',
|
||||
originalData: node.properties?.yuhun
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
imageNode: {
|
||||
newType: 'imageNode',
|
||||
transform: (node) => node // 保持不变
|
||||
},
|
||||
textNode: {
|
||||
newType: 'textNode',
|
||||
transform: (node) => node // 保持不变
|
||||
},
|
||||
propertySelect: {
|
||||
newType: 'propertySelect',
|
||||
transform: (node) => node // 保持不变
|
||||
},
|
||||
rect: {
|
||||
newType: 'rect',
|
||||
transform: (node) => node // 保持不变
|
||||
},
|
||||
ellipse: {
|
||||
newType: 'ellipse',
|
||||
transform: (node) => node // 保持不变
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 迁移单个节点
|
||||
*/
|
||||
export function migrateNode(node: any): { node: any; migrated: boolean } {
|
||||
const migration = MIGRATION_MAP[node.type];
|
||||
|
||||
if (!migration) {
|
||||
// 未知节点类型,保持不变
|
||||
return { node, migrated: false };
|
||||
}
|
||||
|
||||
const migratedNode = migration.transform(node);
|
||||
const migrated = migratedNode.type !== node.type;
|
||||
|
||||
return { node: migratedNode, migrated };
|
||||
}
|
||||
|
||||
/**
|
||||
* 迁移图数据
|
||||
*/
|
||||
export function migrateGraphData(graphData: GraphData): {
|
||||
graphData: GraphData;
|
||||
migratedCount: number;
|
||||
migrations: Array<{ id: string; from: string; to: string }>;
|
||||
} {
|
||||
if (!graphData || !graphData.nodes) {
|
||||
return { graphData, migratedCount: 0, migrations: [] };
|
||||
}
|
||||
|
||||
const migrations: Array<{ id: string; from: string; to: string }> = [];
|
||||
let migratedCount = 0;
|
||||
|
||||
const migratedNodes = graphData.nodes.map((node) => {
|
||||
const { node: migratedNode, migrated } = migrateNode(node);
|
||||
|
||||
if (migrated) {
|
||||
migratedCount++;
|
||||
migrations.push({
|
||||
id: node.id,
|
||||
from: node.type,
|
||||
to: migratedNode.type
|
||||
});
|
||||
}
|
||||
|
||||
return migratedNode;
|
||||
});
|
||||
|
||||
return {
|
||||
graphData: {
|
||||
...graphData,
|
||||
nodes: migratedNodes
|
||||
},
|
||||
migratedCount,
|
||||
migrations
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否需要迁移
|
||||
*/
|
||||
export function needsMigration(graphData: GraphData): boolean {
|
||||
if (!graphData || !graphData.nodes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return graphData.nodes.some((node) => {
|
||||
const migration = MIGRATION_MAP[node.type];
|
||||
if (!migration) return false;
|
||||
|
||||
const { node: migratedNode } = migrateNode(node);
|
||||
return migratedNode.type !== node.type;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取迁移摘要信息
|
||||
*/
|
||||
export function getMigrationSummary(graphData: GraphData): string {
|
||||
const { migratedCount, migrations } = migrateGraphData(graphData);
|
||||
|
||||
if (migratedCount === 0) {
|
||||
return '无需迁移';
|
||||
}
|
||||
|
||||
const summary = migrations
|
||||
.map((m) => `节点 ${m.id}: ${m.from} → ${m.to}`)
|
||||
.join('\n');
|
||||
|
||||
return `迁移了 ${migratedCount} 个节点:\n${summary}`;
|
||||
}
|
||||
Reference in New Issue
Block a user