mirror of
https://github.com/Powerful-517/yys-editor.git
synced 2026-03-05 15:05:27 +00:00
refactor(selector): simplify presets with data-driven groups
This commit is contained in:
@@ -86,6 +86,8 @@ const filteredItems = (group: GroupConfig) => {
|
||||
if (group.name !== 'ALL') {
|
||||
if (group.filter) {
|
||||
items = items.filter(group.filter)
|
||||
} else if (!props.config.groupField) {
|
||||
items = []
|
||||
} else {
|
||||
items = items.filter(item =>
|
||||
item[props.config.groupField]?.toLowerCase() === group.name.toLowerCase()
|
||||
|
||||
@@ -3,6 +3,7 @@ import { computed } from 'vue';
|
||||
import { useDialogs } from '@/ts/useDialogs';
|
||||
import { getLogicFlowInstance } from '@/ts/useLogicFlow';
|
||||
import { SELECTOR_PRESETS } from '@/configs/selectorPresets';
|
||||
import type { SelectorConfig } from '@/types/selector';
|
||||
|
||||
const props = defineProps<{
|
||||
node: any;
|
||||
@@ -10,30 +11,29 @@ const props = defineProps<{
|
||||
|
||||
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];
|
||||
const preset = SELECTOR_PRESETS[library];
|
||||
|
||||
if (!config) {
|
||||
if (!preset) {
|
||||
console.error('未找到资产库配置:', library);
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置当前选中项
|
||||
config.currentItem = node.properties?.selectedAsset;
|
||||
const config: SelectorConfig = {
|
||||
...preset,
|
||||
currentItem: node.properties?.selectedAsset || null
|
||||
};
|
||||
|
||||
openGenericSelector(config, (selectedItem) => {
|
||||
lf.setProperties(node.id, {
|
||||
@@ -80,4 +80,4 @@ const handleOpenSelector = () => {
|
||||
color: #606266;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user