refactor(题目): 提交状态挪进 store——手机上切页签、桌面切分栏,判题结果和点评不再丢
提交按钮那个组件(SubmitCode)在编辑器的工具栏里,而提交的全部状态和判完之后的 反应都长在它身上:手机上交完切到「描述」页签(Naive 的页签切走即卸载)、桌面切到 「题目 / 自测」模式,编辑器一卸载,判题结果、AI 提示、失败计数、通过后的点评、 题单里的回题单全丢了。 - oj/store/submission.ts:这次提交、判题跟踪、语法检查报错、结果面板开合、冷却、 AI 提示(useSubmissionHint) - SubmissionEffects.vue:挂在题目页这一层,失败计数、标成已解决、烟花、强制点评 (连同「先点评再换题」的导航拦截)、回题单 - SubmitCode 只剩按钮和结果面板 - WebSocket 通道和判题监控的收尾改成 onScopeDispose:onUnmounted 在 store 里挂不上 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a8b83ba762
commit
26e22e2542
8 files changed
+556
-419
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { createDiscreteApi } from "naive-ui"
|
||||
import { ref, onUnmounted, type Ref } from "vue"
|
||||
import { ref, getCurrentScope, onScopeDispose, type Ref } from "vue"
|
||||
|
||||
import { useAuthModalStore } from "shared/store/authModal"
|
||||
import { useUserStore } from "shared/store/user"
|
||||
@@ -467,7 +467,9 @@ export interface SubmissionUpdate extends WebSocketMessage {
|
||||
* 带二十五行示例注释的 `createWebSocketComposable` 工厂,示例里那条通知通道并不
|
||||
* 存在,三个真实的 composable 一个都没用它。现在只剩这一个。
|
||||
*
|
||||
* 每次调用都新建一条连接(和原来一致,不是单例),并在组件卸载时摘掉 handler、断开。
|
||||
* 每次调用都新建一条连接(和原来一致,不是单例),并在作用域销毁时摘掉 handler、断开。
|
||||
* 用的是 onScopeDispose 而不是 onUnmounted:组件卸载时它照样触发,而在 Pinia store
|
||||
* 里调用时 onUnmounted 根本挂不上(没有组件实例,只报一条警告),连接就永远断不掉。
|
||||
*/
|
||||
function useChannel<T extends WebSocketMessage>(path: string, handler?: MessageHandler<T>) {
|
||||
const ws = new BaseWebSocket<T>(path)
|
||||
@@ -476,10 +478,12 @@ function useChannel<T extends WebSocketMessage>(path: string, handler?: MessageH
|
||||
// 中间那段窗口收到的广播没有任何 handler 接。窗口极小,但没有理由留着它。
|
||||
if (handler) ws.addHandler(handler)
|
||||
|
||||
onUnmounted(() => {
|
||||
if (handler) ws.removeHandler(handler)
|
||||
ws.disconnect()
|
||||
})
|
||||
if (getCurrentScope()) {
|
||||
onScopeDispose(() => {
|
||||
if (handler) ws.removeHandler(handler)
|
||||
ws.disconnect()
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
connect: () => ws.connect(),
|
||||
|
||||
Reference in new issue
Block a user