style(code): 格式化代码缩进和布局样式

- 统一调整 admin.ts 文件中的接口定义缩进格式
- 优化 animated-theme-toggler.tsx 组件的代码结构和缩进
- 规范 app-config-modal.tsx 中 JSX 元素的嵌套格式
- 整理 app-providers.tsx 中的组件层级缩进
- 标准化 app-theme.ts 中的对象属性缩进格式
This commit is contained in:
HouYunFei
2026-05-22 23:19:25 +08:00
parent cee08cb5a8
commit e319481976
93 changed files with 11406 additions and 10424 deletions
+5 -5
View File
@@ -4,10 +4,10 @@ import { App } from "antd";
import copy from "copy-to-clipboard";
export function useCopyText() {
const { message } = App.useApp();
const { message } = App.useApp();
return (value: string, successText = "已复制") => {
copy(value);
message.success(successText);
};
return (value: string, successText = "已复制") => {
copy(value);
message.success(successText);
};
}
+70 -70
View File
@@ -7,88 +7,88 @@ const latestVersionUrl = "https://raw.githubusercontent.com/basketikun/infinite-
const latestChangelogUrl = "https://raw.githubusercontent.com/basketikun/infinite-canvas/main/CHANGELOG.md";
function readLocalReleases(): ReleaseInfo[] {
try {
return JSON.parse(process.env.NEXT_PUBLIC_APP_RELEASES || "[]");
} catch {
return [];
}
try {
return JSON.parse(process.env.NEXT_PUBLIC_APP_RELEASES || "[]");
} catch {
return [];
}
}
function toVersionParts(version: string) {
const match = version.trim().match(/^v?(\d+)\.(\d+)\.(\d+)/);
return match ? match.slice(1).map(Number) : null;
const match = version.trim().match(/^v?(\d+)\.(\d+)\.(\d+)/);
return match ? match.slice(1).map(Number) : null;
}
function isNewerVersion(latestVersion: string, currentVersion: string) {
const latest = toVersionParts(latestVersion);
const current = toVersionParts(currentVersion);
if (!latest || !current) return false;
return latest.some((value, index) => value > current[index] && latest.slice(0, index).every((part, prevIndex) => part === current[prevIndex]));
const latest = toVersionParts(latestVersion);
const current = toVersionParts(currentVersion);
if (!latest || !current) return false;
return latest.some((value, index) => value > current[index] && latest.slice(0, index).every((part, prevIndex) => part === current[prevIndex]));
}
export function useVersionCheck() {
const currentVersion = APP_VERSION;
const { message } = App.useApp();
const localReleases = useMemo(readLocalReleases, []);
const [latestVersion, setLatestVersion] = useState(currentVersion);
const [releases, setReleases] = useState<ReleaseInfo[]>(localReleases);
const [checking, setChecking] = useState(false);
const [open, setOpen] = useState(false);
const hasNewVersion = isNewerVersion(latestVersion, currentVersion);
const currentVersion = APP_VERSION;
const { message } = App.useApp();
const localReleases = useMemo(readLocalReleases, []);
const [latestVersion, setLatestVersion] = useState(currentVersion);
const [releases, setReleases] = useState<ReleaseInfo[]>(localReleases);
const [checking, setChecking] = useState(false);
const [open, setOpen] = useState(false);
const hasNewVersion = isNewerVersion(latestVersion, currentVersion);
const checkLatestVersion = useCallback(async () => {
try {
const response = await fetch(latestVersionUrl);
if (!response.ok) return false;
const version = await response.text();
setLatestVersion(version.trim() || currentVersion);
return true;
} catch {
return false;
}
}, [currentVersion]);
const checkLatestVersion = useCallback(async () => {
try {
const response = await fetch(latestVersionUrl);
if (!response.ok) return false;
const version = await response.text();
setLatestVersion(version.trim() || currentVersion);
return true;
} catch {
return false;
}
}, [currentVersion]);
const checkLatestRelease = useCallback(async (showMessage = false) => {
setChecking(true);
try {
const [versionResponse, changelogResponse] = await Promise.all([
fetch(latestVersionUrl),
fetch(latestChangelogUrl),
]);
if (!versionResponse.ok) throw new Error("版本读取失败");
if (!changelogResponse.ok) throw new Error("更新日志读取失败");
const [version, changelog] = await Promise.all([versionResponse.text(), changelogResponse.text()]);
setLatestVersion(version.trim() || currentVersion);
if (changelog.trim()) setReleases(parseChangelog(changelog));
if (showMessage) message.success("已获取最新版本信息");
return true;
} catch {
setLatestVersion(currentVersion);
setReleases(localReleases);
if (showMessage) message.error("获取最新版本信息失败");
return false;
} finally {
setChecking(false);
}
}, [currentVersion, localReleases, message]);
const checkLatestRelease = useCallback(
async (showMessage = false) => {
setChecking(true);
try {
const [versionResponse, changelogResponse] = await Promise.all([fetch(latestVersionUrl), fetch(latestChangelogUrl)]);
if (!versionResponse.ok) throw new Error("版本读取失败");
if (!changelogResponse.ok) throw new Error("更新日志读取失败");
const [version, changelog] = await Promise.all([versionResponse.text(), changelogResponse.text()]);
setLatestVersion(version.trim() || currentVersion);
if (changelog.trim()) setReleases(parseChangelog(changelog));
if (showMessage) message.success("已获取最新版本信息");
return true;
} catch {
setLatestVersion(currentVersion);
setReleases(localReleases);
if (showMessage) message.error("获取最新版本信息失败");
return false;
} finally {
setChecking(false);
}
},
[currentVersion, localReleases, message],
);
useEffect(() => {
void checkLatestVersion();
}, [checkLatestVersion]);
useEffect(() => {
void checkLatestVersion();
}, [checkLatestVersion]);
const openReleaseModal = useCallback(() => {
setOpen(true);
void checkLatestRelease();
}, [checkLatestRelease]);
const openReleaseModal = useCallback(() => {
setOpen(true);
void checkLatestRelease();
}, [checkLatestRelease]);
return {
open,
setOpen,
openReleaseModal,
latestVersion,
releases,
checking,
hasNewVersion,
checkLatestRelease,
};
return {
open,
setOpen,
openReleaseModal,
latestVersion,
releases,
checking,
hasNewVersion,
checkLatestRelease,
};
}