完成大量美化

This commit is contained in:
2026-05-01 14:44:18 +08:00
parent 1d0f0ae0ef
commit 6b65b24b0f
49 changed files with 2487 additions and 9019 deletions

View File

@@ -77,68 +77,49 @@ const useWorldBookStore = create((set, get) => ({
currentEntry: null
}),
// 异步操作:切换世界书的全局状态
// 异步操作:切换世界书的全局状态(纯前端操作,使用 LocalStorage
toggleGlobalWorldBook: async (name, isGlobal) => {
set({ loading: true, error: null, success: false });
try {
const formData = new FormData();
formData.append('is_global', isGlobal);
const response = await fetch(`/api/worldbooks/${name}`, {
method: 'PUT',
body: formData
});
const data = await handleResponse(response);
set(state => {
const updatedWorldBooks = state.worldBooks.map(wb =>
wb.name === data.name ? data : wb
);
// 更新全局世界书列表
let updatedGlobalBooks = [...state.globalWorldBooks];
const globalIndex = updatedGlobalBooks.findIndex(wb => wb.name === data.name);
if (isGlobal) {
// 如果是世界书被标记为全局
if (globalIndex === -1) {
// 如果不在全局列表中,添加它
updatedGlobalBooks = [...updatedGlobalBooks, data];
} else {
// 如果已经在全局列表中,更新它
updatedGlobalBooks[globalIndex] = data;
}
} else {
// 如果世界书不再全局,从全局列表中移除
if (globalIndex !== -1) {
updatedGlobalBooks = updatedGlobalBooks.filter(wb => wb.name !== data.name);
}
}
// 保存到 LocalStorage
saveGlobalWorldBooks(updatedGlobalBooks);
set(state => {
// 查找世界书
const worldBook = state.worldBooks.find(wb => wb.name === name);
if (!worldBook) {
return {
loading: false,
worldBooks: updatedWorldBooks,
globalWorldBooks: updatedGlobalBooks,
currentWorldBook: state.currentWorldBook?.name === data.name
? data
: state.currentWorldBook,
success: true,
error: `Worldbook '${name}' not found`,
success: false
};
});
}
return data;
} catch (error) {
set({
// 更新全局世界书列表
let updatedGlobalBooks = [...state.globalWorldBooks];
const globalIndex = updatedGlobalBooks.findIndex(wb => wb.name === name);
if (isGlobal) {
// 如果世界书被标记为全局
if (globalIndex === -1) {
// 如果不在全局列表中,添加它
updatedGlobalBooks = [...updatedGlobalBooks, worldBook];
} else {
// 如果已经在全局列表中,更新它
updatedGlobalBooks[globalIndex] = worldBook;
}
} else {
// 如果世界书不再全局,从全局列表中移除
if (globalIndex !== -1) {
updatedGlobalBooks = updatedGlobalBooks.filter(wb => wb.name !== name);
}
}
// 保存到 LocalStorage
saveGlobalWorldBooks(updatedGlobalBooks);
return {
loading: false,
error: error.message,
success: false
});
throw error;
}
globalWorldBooks: updatedGlobalBooks,
success: true,
message: isGlobal ? `已将 "${name}" 设为全局世界书` : `已取消 "${name}" 的全局状态`
};
});
},
// 异步操作:获取所有世界书

View File

@@ -3,3 +3,4 @@ export { default as useSideBarLeftStore } from './SideBarLeftSlice';
export { default as useApiConfigStore } from './ApiConfigSlice';
export { default as usePresetStore } from './PresetSlice';
export { default as useWorldBookStore } from './WorldBookSlice';
export { default as useCharacterStore } from './CharacterSlice';