refactor frontend (not done)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
|
||||
import { gameApi, type InitStatusDTO } from '../api/game'
|
||||
import { systemApi, type InitStatusDTO } from '../api'
|
||||
|
||||
const props = defineProps<{
|
||||
status: InitStatusDTO | null
|
||||
@@ -105,7 +105,7 @@ async function handleRetry() {
|
||||
localElapsed.value = 0
|
||||
displayProgress.value = 0
|
||||
try {
|
||||
await gameApi.reinitGame()
|
||||
await systemApi.reinitGame()
|
||||
} catch (e: any) {
|
||||
console.error('Reinit failed:', e)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ref } from 'vue'
|
||||
import { Assets, Texture, TextureStyle } from 'pixi.js'
|
||||
import { gameApi } from '@/api/game'
|
||||
import { avatarApi } from '@/api'
|
||||
import { getClusteredTileVariant } from '@/utils/procedural'
|
||||
|
||||
// 设置全局纹理缩放模式为 nearest (像素风)
|
||||
@@ -35,7 +35,7 @@ export function useTextures() {
|
||||
// 1. 获取最新的 Avatar Meta 并检查是否有变化
|
||||
let metaChanged = false
|
||||
try {
|
||||
const meta = await gameApi.fetchAvatarMeta()
|
||||
const meta = await avatarApi.fetchAvatarMeta()
|
||||
|
||||
// 对比当前缓存的列表和新获取的列表
|
||||
const newMalesStr = JSON.stringify(meta.males || [])
|
||||
|
||||
@@ -7,7 +7,7 @@ import EntityRow from './components/EntityRow.vue';
|
||||
import RelationRow from './components/RelationRow.vue';
|
||||
import TagList from './components/TagList.vue';
|
||||
import SecondaryPopup from './components/SecondaryPopup.vue';
|
||||
import { gameApi } from '@/api/game';
|
||||
import { avatarApi } from '@/api';
|
||||
import { useUiStore } from '@/stores/ui';
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -38,7 +38,7 @@ function jumpToSect(id: string) {
|
||||
async function handleSetObjective() {
|
||||
if (!objectiveContent.value.trim()) return;
|
||||
try {
|
||||
await gameApi.setLongTermObjective(props.data.id, objectiveContent.value);
|
||||
await avatarApi.setLongTermObjective(props.data.id, objectiveContent.value);
|
||||
showObjectiveModal.value = false;
|
||||
objectiveContent.value = '';
|
||||
uiStore.refreshDetail();
|
||||
@@ -51,7 +51,7 @@ async function handleSetObjective() {
|
||||
async function handleClearObjective() {
|
||||
if (!confirm('确定要清空该角色的长期目标吗?')) return;
|
||||
try {
|
||||
await gameApi.clearLongTermObjective(props.data.id);
|
||||
await avatarApi.clearLongTermObjective(props.data.id);
|
||||
uiStore.refreshDetail();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { gameApi, type GameDataDTO, type CreateAvatarParams, type SimpleAvatarDTO } from '../../../../api/game'
|
||||
import { avatarApi, type GameDataDTO, type CreateAvatarParams, type SimpleAvatarDTO } from '../../../../api'
|
||||
import { useWorldStore } from '../../../../stores/world'
|
||||
import { useMessage, NInput, NSelect, NSlider, NRadioGroup, NRadioButton, NForm, NFormItem, NButton } from 'naive-ui'
|
||||
|
||||
@@ -120,13 +120,13 @@ async function fetchData() {
|
||||
loading.value = true
|
||||
try {
|
||||
if (!gameData.value) {
|
||||
gameData.value = await gameApi.fetchGameData()
|
||||
gameData.value = await avatarApi.fetchGameData()
|
||||
}
|
||||
if (!avatarMeta.value) {
|
||||
avatarMeta.value = await gameApi.fetchAvatarMeta()
|
||||
avatarMeta.value = await avatarApi.fetchAvatarMeta()
|
||||
}
|
||||
// 获取角色列表用于关系选择
|
||||
const res = await gameApi.fetchAvatarList()
|
||||
const res = await avatarApi.fetchAvatarList()
|
||||
avatarList.value = res.avatars
|
||||
} catch (e) {
|
||||
message.error('获取游戏数据失败')
|
||||
@@ -153,7 +153,7 @@ async function handleCreateAvatar() {
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
await gameApi.createAvatar(createForm.value)
|
||||
await avatarApi.createAvatar(createForm.value)
|
||||
message.success('角色创建成功')
|
||||
await worldStore.fetchState?.()
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { gameApi, type SimpleAvatarDTO } from '../../../../api/game'
|
||||
import { avatarApi, type SimpleAvatarDTO } from '../../../../api'
|
||||
import { useWorldStore } from '../../../../stores/world'
|
||||
import { useMessage, NInput, NButton } from 'naive-ui'
|
||||
|
||||
@@ -21,7 +21,7 @@ const filteredAvatars = computed(() => {
|
||||
async function fetchAvatarList() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await gameApi.fetchAvatarList()
|
||||
const res = await avatarApi.fetchAvatarList()
|
||||
avatarList.value = res.avatars
|
||||
} catch (e) {
|
||||
message.error('获取角色列表失败')
|
||||
@@ -35,7 +35,7 @@ async function handleDeleteAvatar(id: string, name: string) {
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
await gameApi.deleteAvatar(id)
|
||||
await avatarApi.deleteAvatar(id)
|
||||
message.success('删除成功')
|
||||
await Promise.all([
|
||||
fetchAvatarList(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { NForm, NFormItem, NInputNumber, NSelect, NButton, useMessage } from 'naive-ui'
|
||||
import { gameApi } from '../../../../api/game'
|
||||
import { systemApi } from '../../../../api'
|
||||
|
||||
const props = defineProps<{
|
||||
readonly: boolean
|
||||
@@ -29,7 +29,7 @@ const protagonistOptions = [
|
||||
async function fetchConfig() {
|
||||
try {
|
||||
loading.value = true
|
||||
const res = await gameApi.fetchCurrentConfig()
|
||||
const res = await systemApi.fetchCurrentConfig()
|
||||
config.value = {
|
||||
init_npc_num: res.game.init_npc_num,
|
||||
sect_num: res.game.sect_num,
|
||||
@@ -47,7 +47,7 @@ async function fetchConfig() {
|
||||
async function startGame() {
|
||||
try {
|
||||
loading.value = true
|
||||
await gameApi.startGame(config.value)
|
||||
await systemApi.startGame(config.value)
|
||||
message.success('配置已保存,正在初始化世界...')
|
||||
// 父组件会通过 polling 检测到状态变化,从而自动关闭菜单并显示 loading
|
||||
} catch (e) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { gameApi, type LLMConfigDTO } from '../../../../api/game'
|
||||
import { llmApi, type LLMConfigDTO } from '../../../../api'
|
||||
import { useMessage } from 'naive-ui'
|
||||
|
||||
const message = useMessage()
|
||||
@@ -52,7 +52,7 @@ const presets = [
|
||||
async function fetchConfig() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await gameApi.fetchLLMConfig()
|
||||
const res = await llmApi.fetchConfig()
|
||||
// 确保 API Key 在前端展示为空,增加安全性提示
|
||||
config.value = { ...res, api_key: '' }
|
||||
} catch (e) {
|
||||
@@ -86,11 +86,11 @@ async function handleTestAndSave() {
|
||||
testing.value = true
|
||||
try {
|
||||
// 1. 测试连接
|
||||
await gameApi.testLLMConnection(config.value)
|
||||
await llmApi.testConnection(config.value)
|
||||
message.success('连接测试成功')
|
||||
|
||||
// 2. 保存配置
|
||||
await gameApi.saveLLMConfig(config.value)
|
||||
await llmApi.saveConfig(config.value)
|
||||
message.success('配置已保存')
|
||||
emit('config-saved')
|
||||
} catch (e: any) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, watch } from 'vue'
|
||||
import { gameApi, type SaveFileDTO } from '../../../../api/game'
|
||||
import { systemApi, type SaveFileDTO } from '../../../../api'
|
||||
import { useWorldStore } from '../../../../stores/world'
|
||||
import { useUiStore } from '../../../../stores/ui'
|
||||
import { useMessage } from 'naive-ui'
|
||||
@@ -22,7 +22,7 @@ const saves = ref<SaveFileDTO[]>([])
|
||||
async function fetchSaves() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await gameApi.fetchSaves()
|
||||
const res = await systemApi.fetchSaves()
|
||||
saves.value = res.saves
|
||||
} catch (e) {
|
||||
message.error('获取存档列表失败')
|
||||
@@ -34,7 +34,7 @@ async function fetchSaves() {
|
||||
async function handleSave() {
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await gameApi.saveGame()
|
||||
const res = await systemApi.saveGame()
|
||||
message.success(`存档成功: ${res.filename}`)
|
||||
await fetchSaves()
|
||||
} catch (e) {
|
||||
@@ -49,7 +49,7 @@ async function handleLoad(filename: string) {
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
await gameApi.loadGame(filename)
|
||||
await systemApi.loadGame(filename)
|
||||
worldStore.reset()
|
||||
uiStore.clearSelection()
|
||||
await worldStore.initialize()
|
||||
|
||||
Reference in New Issue
Block a user