diff --git a/app.go b/app.go index a0b3cc9..cc95936 100644 --- a/app.go +++ b/app.go @@ -35,6 +35,14 @@ func (a *App) startup(ctx context.Context) { } }() + // 后台 goroutine 持续推送运行状态 + go func() { + for { + time.Sleep(500 * time.Millisecond) + runtime.EventsEmit(a.ctx, "is-run", a.isRun) + } + }() + //在程序启动时运行上传程序 a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx) if config.APPConfig.IsRunOnStart { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index ecd675c..241ec98 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -12,11 +12,13 @@ const token = ref('') const checkDir = ref('') const concurrentFiles = ref(1) const uploadThreads = ref(1) +const autoStart = ref(false) const progress = ref(0) const isRunning = ref(false) const logOutput = ref([]) const logContentRef = ref() +const logRoll = ref(true) interface FileProgress { name: string @@ -32,7 +34,7 @@ const progressList = ref([ const addLog = (msg: string) => { logOutput.value.push(`[${new Date().toLocaleString()}]` + msg) nextTick(() => { - if (logContentRef.value) { + if (logContentRef.value && logRoll.value){ logContentRef.value.scrollTop = logContentRef.value.scrollHeight } }) @@ -60,13 +62,6 @@ const startRun = () => { } isRunning.value = true progress.value = 0 - addLog("===============================================") - // addLog(`开始运行...`) - addLog(`服务器: ${serverUrl.value}`) - addLog(`检测目录: ${checkDir.value}`) - addLog(`同时处理文件数: ${concurrentFiles.value}`) - addLog(`单文件上传线程: ${uploadThreads.value}`) - addLog("===============================================") StartUpload() } @@ -100,6 +95,7 @@ try { checkDir.value = config.check_dir concurrentFiles.value = config.handle_file_count uploadThreads.value = config.thread_count + autoStart.value = config.is_run_on_start LogPrint(`[${new Date().toLocaleString()}] 配置已加载`) }) @@ -122,6 +118,9 @@ watch(concurrentFiles, () => { watch(uploadThreads, () => { WriteConfig("thread-count", uploadThreads.value) }) +watch(autoStart, () => { + WriteConfig("is-run-on-start", autoStart.value) +}) EventsOn("log", (msg) => { addLog(msg) @@ -129,6 +128,9 @@ EventsOn("log", (msg) => { EventsOn("progress", (progress) => { progressList.value = progress }) +EventsOn("is-run", (run) => { + isRunning.value = run +})