Skip to content

Commit 2356548

Browse files
committed
更好的启动时错误提示
1 parent fc19f87 commit 2356548

File tree

5 files changed

+109
-0
lines changed

5 files changed

+109
-0
lines changed

MaiChartManager/Controllers/App/AppStatusController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace MaiChartManager.Controllers.App;
66
[Route("MaiChartManagerServlet/[action]Api")]
77
public class AppStatusController(StaticSettings settings, ILogger<AppStatusController> logger) : ControllerBase
88
{
9+
[HttpGet]
910
public IEnumerable<string> GetAppStartupErrors()
1011
{
1112
return StaticSettings.StartupErrorsList;

MaiChartManager/Front/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { dateZhCN, NConfigProvider, NDialogProvider, NMessageProvider, NNotifica
33
import FeedbackErrorDialog from "@/components/FeedbackErrorDialog";
44
import NeedPurchaseDialog from "@/components/NeedPurchaseDialog";
55
import Index from "@/views/Index";
6+
import StartupErrorDialog from "@/components/StartupErrorDialog";
67

78
export default defineComponent({
89
render() {
@@ -14,6 +15,7 @@ export default defineComponent({
1415
<Index/>
1516
<FeedbackErrorDialog/>
1617
<NeedPurchaseDialog/>
18+
<StartupErrorDialog/>
1719
</NMessageProvider>
1820
</NDialogProvider>
1921
</NNotificationProvider>

MaiChartManager/Front/src/client/apiGen.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,21 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
642642
...params,
643643
}),
644644

645+
/**
646+
* No description
647+
*
648+
* @tags AppStatus
649+
* @name GetAppStartupErrors
650+
* @request GET:/MaiChartManagerServlet/GetAppStartupErrorsApi
651+
*/
652+
GetAppStartupErrors: (params: RequestParams = {}) =>
653+
this.request<string[], any>({
654+
path: `/MaiChartManagerServlet/GetAppStartupErrorsApi`,
655+
method: "GET",
656+
format: "json",
657+
...params,
658+
}),
659+
645660
/**
646661
* No description
647662
*
@@ -1745,5 +1760,28 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
17451760
query: query,
17461761
...params,
17471762
}),
1763+
1764+
/**
1765+
* No description
1766+
*
1767+
* @tags VrcProcess
1768+
* @name GenAllMusicPreviewMp3ForVrc
1769+
* @request POST:/MaiChartManagerServlet/GenAllMusicPreviewMp3ForVrcApi
1770+
*/
1771+
GenAllMusicPreviewMp3ForVrc: (
1772+
data: {
1773+
targetDir?: string;
1774+
/** @format int32 */
1775+
maxConcurrency?: number;
1776+
},
1777+
params: RequestParams = {},
1778+
) =>
1779+
this.request<void, any>({
1780+
path: `/MaiChartManagerServlet/GenAllMusicPreviewMp3ForVrcApi`,
1781+
method: "POST",
1782+
body: data,
1783+
type: ContentType.FormData,
1784+
...params,
1785+
}),
17481786
};
17491787
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { defineComponent, PropType, ref, computed, watch } from 'vue';
2+
import { NFlex, NList, NListItem, NModal } from 'naive-ui';
3+
import useAsync from "@/hooks/useAsync";
4+
import api from "@/client/api";
5+
6+
export default defineComponent({
7+
// props: {
8+
// },
9+
setup(props, { emit }) {
10+
const errors = useAsync(() => api.GetAppStartupErrors())
11+
const show = ref(false)
12+
13+
watch(() => errors.data.value, value => {
14+
if (!value) return
15+
if (value.data?.length) {
16+
show.value = true
17+
}
18+
})
19+
20+
return () => <NModal
21+
preset="card"
22+
class="w-[min(50vw,60em)] bg-red-1!"
23+
title="启动过程中发生错误"
24+
v-model:show={show.value}
25+
>
26+
<NFlex vertical class="max-h-70vh overflow-y-auto">
27+
<NList showDivider={false}>
28+
{errors.data.value?.data?.map((error) => {
29+
return <NListItem>
30+
<div class="text-0.9em">
31+
{error}
32+
</div>
33+
</NListItem>
34+
})}
35+
</NList>
36+
请尽量修复这些问题,否则 MaiChartManager 可能无法按预期工作
37+
</NFlex>
38+
</NModal>;
39+
},
40+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { AsyncComputedOnCancel, computedAsync } from '@vueuse/core';
2+
import { ref } from 'vue';
3+
4+
export default <T>(evaluationCallback: (onCancel: AsyncComputedOnCancel) => T | Promise<T>, initialState: T | null = null, lazy = false) => {
5+
const loading = ref(false);
6+
const error = ref<Error | null>(null);
7+
const reloadFlip = ref(false);
8+
const data = computedAsync(async (onCancel: AsyncComputedOnCancel) => {
9+
error.value = null;
10+
void reloadFlip.value;
11+
try {
12+
return await evaluationCallback(onCancel);
13+
}
14+
catch (e: any) {
15+
console.log(e);
16+
error.value = e;
17+
}
18+
}, initialState, {
19+
evaluating: loading,
20+
lazy,
21+
});
22+
return {
23+
data, error, loading,
24+
refresh: () => {
25+
reloadFlip.value = !reloadFlip.value;
26+
},
27+
};
28+
}

0 commit comments

Comments
 (0)