UPDATE: VERSION-20260317

This commit is contained in:
libertyspy
2026-03-17 10:21:00 +08:00
parent 185e490560
commit c724a7acf7
3 changed files with 75 additions and 42 deletions

View File

@@ -35,9 +35,9 @@
</template>
<script lang="ts">
import { computed, defineComponent, onMounted, type PropType, ref, watch } from 'vue';
import type { Platform, PlatformComponent, PlatformComponentPayload, PlatformWithComponents, PlatformWithComponentsResponse } from '../types';
import { findAllPlatformWithComponents } from './api';
import { computed, defineComponent, type PropType, ref, watch } from 'vue';
import type { PlatformComponentPayload } from '../types';
import { usePlatformComponents } from './store';
export default defineComponent({
name: 'PlatformSelect',
@@ -57,45 +57,16 @@ export default defineComponent({
change: (payload: PlatformComponentPayload) => true,
},
setup(props, { emit }) {
const loading = ref<boolean>(true);
const platforms = ref<PlatformWithComponents[]>([]);
const platformMap = ref<Map<number, Platform>>(new Map());
const componentMap = ref<Map<number, PlatformComponent>>(new Map());
const { loading, platforms, platformMap, componentMap } = usePlatformComponents();
const innerPlatformId = ref<number | null>(null);
const innerComponentId = ref<number | null>(null);
const innerPlatformId = ref<number | null>(props.platformId);
const innerComponentId = ref<number | null>(props.componentId);
const selectedPlatformComponents = computed(() => {
const platform = platforms.value.find(p => p.id === innerPlatformId.value);
return platform?.components || [];
});
const loadData = async () => {
try {
loading.value = true;
const res: PlatformWithComponentsResponse = await findAllPlatformWithComponents();
const data = res.data || [];
platforms.value = data;
platformMap.value.clear();
componentMap.value.clear();
data.forEach(platform => {
platformMap.value.set(platform.id, platform);
platform.components?.forEach(component => {
componentMap.value.set(component.id, component);
});
});
innerPlatformId.value = props.platformId;
innerComponentId.value = props.componentId;
} catch (err) {
console.error('加载平台组件失败:', err);
} finally {
loading.value = false;
}
};
const emitChange = () => {
// 根据ID获取完整对象
const platform = platformMap.value.get(innerPlatformId.value || -1) || null;
@@ -135,10 +106,6 @@ export default defineComponent({
watch(innerComponentId, emitChange);
onMounted(() => {
loadData();
});
return {
loading,
platforms,