Compare commits

...

2 Commits

Author SHA1 Message Date
ygxbnet 03e4e6f45b fix(uploader): 修复上传器逻辑和UI提示问题
构建上传工具 / build (push) Successful in 1m23s
- 修复目录选择为空时不更改配置的逻辑
- 将警告提示改为错误提示以提高用户体验
- 优化停止运行时的成功提示
- 增加进度列表的最大高度以显示更多内容
- 调整定时器逻辑顺序避免提前退出
- 移除重复的任务等待错误处理
- 优化代码结构和空行格式
2026-04-30 21:24:30 +08:00
ygxbnet 6bd82024d9 refactor(App): 移除服务器地址和自动启动配置功能
- 注释掉 serverUrl 相关的响应式变量定义
- 注释掉 autoStart 相关的响应式变量定义
- 移除进度列表中的测试数据注释
- 注释掉服务器地址验证逻辑
- 注释掉服务器地址和自动启动的写入配置函数
- 注释掉配置加载中的相关字段赋值
- 在模板中隐藏服务器地址输入框和自动启动复选框组件
2026-04-30 20:39:08 +08:00
3 changed files with 55 additions and 51 deletions
+7 -7
View File
@@ -45,12 +45,12 @@ func (a *App) startup(ctx context.Context) {
}() }()
//在程序启动时运行上传程序 //在程序启动时运行上传程序
if config.APPConfig.IsRunOnStart { //if config.APPConfig.IsRunOnStart {
time.Sleep(time.Second) // time.Sleep(time.Second)
a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx) // a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx)
go uploader.StartUpload(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir) // go uploader.StartUpload(a.uploaderCTX, &a.logChan)
a.isRun = true // a.isRun = true
} //}
} }
// SelectPath 打开选择路径弹框 // SelectPath 打开选择路径弹框
@@ -74,7 +74,7 @@ func (a *App) StartUpload() {
return return
} }
a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx) a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx)
go uploader.StartUpload(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir) go uploader.StartUpload(a.uploaderCTX, &a.logChan)
a.isRun = true a.isRun = true
} }
+32 -29
View File
@@ -7,12 +7,12 @@ import {config} from "../wailsjs/go/models.ts";
import Config = config.Config; import Config = config.Config;
import {EventsOn, LogPrint} from "../wailsjs/runtime"; import {EventsOn, LogPrint} from "../wailsjs/runtime";
const serverUrl = ref('') // const serverUrl = ref('')
const token = ref('') const token = ref('')
const checkDir = ref('') const checkDir = ref('')
const concurrentFiles = ref(1) const concurrentFiles = ref(1)
const uploadThreads = ref(1) const uploadThreads = ref(1)
const autoStart = ref(false) // const autoStart = ref(false)
const isRunning = ref(false) const isRunning = ref(false)
const logOutput = ref<string[]>([]) const logOutput = ref<string[]>([])
@@ -26,9 +26,8 @@ interface FileProgress {
percentage: number percentage: number
} }
const progressList = ref<FileProgress[]>([ // {name: '测试文件1.txt', uploaded: 100, total: 500, percentage: 20},
// {name: '测试文件1.txt', uploaded: 100, total: 500, percentage: 20}, const progressList = ref<FileProgress[]>([])
])
const sortedProgressList = computed(() => { const sortedProgressList = computed(() => {
return [...progressList.value].sort((a, b) => { return [...progressList.value].sort((a, b) => {
@@ -53,21 +52,25 @@ const addLog = (msg: string) => {
const selectDirectory = () => { const selectDirectory = () => {
// ElMessage.info('请手动输入检测目录路径') // ElMessage.info('请手动输入检测目录路径')
SelectPath().then((path) => { SelectPath().then((path) => {
checkDir.value = path if (path){
checkDir.value = path
}else {
ElMessage.warning('未选择目录,不更改配置')
}
}) })
} }
const startRun = () => { const startRun = () => {
if (!serverUrl.value) { // if (!serverUrl.value) {
ElMessage.warning('请输入服务器地址') // ElMessage.warning('请输入服务器地址')
return // return
} // }
if (!token.value) { if (!token.value) {
ElMessage.warning('请输入Token') ElMessage.error('请输入Token')
return return
} }
if (!checkDir.value) { if (!checkDir.value) {
ElMessage.warning('请选择检测目录') ElMessage.error('请选择检测目录')
return return
} }
@@ -77,7 +80,7 @@ const startRun = () => {
const stopRun = () => { const stopRun = () => {
addLog(`正在停止运行`) addLog(`正在停止运行`)
StopUpload().then(() => { StopUpload().then(() => {
ElMessage.info('已停止运行') ElMessage.success('已停止运行')
}) })
} }
@@ -93,9 +96,9 @@ const clearLog = () => {
}) })
} }
const writeServerUrl =() => { // const writeServerUrl =() => {
WriteConfig("url", serverUrl.value) // WriteConfig("url", serverUrl.value)
} // }
const writeToken =() => { const writeToken =() => {
WriteConfig("token", token.value) WriteConfig("token", token.value)
} }
@@ -108,19 +111,19 @@ const writeConcurrentFiles = () => {
const writeUploadThreads =() => { const writeUploadThreads =() => {
WriteConfig("thread-count", uploadThreads.value) WriteConfig("thread-count", uploadThreads.value)
} }
const writeAutoStart = () => { // const writeAutoStart = () => {
WriteConfig("is-run-on-start", autoStart.value) // WriteConfig("is-run-on-start", autoStart.value)
} // }
// 加载配置 // 加载配置
try { try {
GetConfig().then((config: Config) => { GetConfig().then((config: Config) => {
serverUrl.value = config.url // serverUrl.value = config.url
token.value = config.token token.value = config.token
checkDir.value = config.check_dir checkDir.value = config.check_dir
concurrentFiles.value = config.handle_file_count concurrentFiles.value = config.handle_file_count
uploadThreads.value = config.thread_count uploadThreads.value = config.thread_count
autoStart.value = config.is_run_on_start // autoStart.value = config.is_run_on_start
LogPrint(`[${new Date().toLocaleString()}] 配置已加载`) LogPrint(`[${new Date().toLocaleString()}] 配置已加载`)
}) })
@@ -142,10 +145,10 @@ EventsOn("log", (msg) => {
<template> <template>
<div class="container"> <div class="container">
<div class="left-panel"> <div class="left-panel">
<div class="form-item"> <!-- <div class="form-item">-->
<label>服务器地址</label> <!-- <label>服务器地址</label>-->
<el-input v-model="serverUrl" placeholder="请输入服务器地址" :disabled="isRunning" @change="writeServerUrl()"/> <!-- <el-input v-model="serverUrl" placeholder="请输入服务器地址" :disabled="isRunning" @change="writeServerUrl()"/>-->
</div> <!-- </div>-->
<div class="form-item"> <div class="form-item">
<label>Token</label> <label>Token</label>
@@ -170,9 +173,9 @@ EventsOn("log", (msg) => {
<el-input-number v-model="uploadThreads" :min="1" :max="100" :disabled="isRunning" @change="writeUploadThreads()"/> <el-input-number v-model="uploadThreads" :min="1" :max="100" :disabled="isRunning" @change="writeUploadThreads()"/>
</div> </div>
<div class="form-item"> <!-- <div class="form-item">-->
<el-checkbox v-model="autoStart" label="运行时自动启动上传" size="large" :disabled="isRunning" @change="writeAutoStart()"/> <!-- <el-checkbox v-model="autoStart" label="运行时自动启动上传" size="large" :disabled="isRunning" @change="writeAutoStart()"/>-->
</div> <!-- </div>-->
<div class="form-item"> <div class="form-item">
<label>上传进度</label> <label>上传进度</label>
@@ -253,7 +256,7 @@ EventsOn("log", (msg) => {
.progress-list { .progress-list {
margin-top: 12px; margin-top: 12px;
max-height: 160px; max-height: 250px;
overflow-y: auto; overflow-y: auto;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
+16 -15
View File
@@ -20,8 +20,6 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
var progress sync.Map
type Task struct { type Task struct {
FilePath string FilePath string
FileLines int FileLines int
@@ -34,7 +32,9 @@ type Progress struct {
Percentage int `json:"percentage"` Percentage int `json:"percentage"`
} }
func StartUpload(ctx context.Context, logChan *chan string, lookingPath string) { var progress sync.Map
func StartUpload(ctx context.Context, logChan *chan string) {
AddLog(logChan, "===============================================") AddLog(logChan, "===============================================")
AddLog(logChan, `服务器: `+config.APPConfig.Url) AddLog(logChan, `服务器: `+config.APPConfig.Url)
AddLog(logChan, `Token: `+config.APPConfig.Token) AddLog(logChan, `Token: `+config.APPConfig.Token)
@@ -70,20 +70,20 @@ func StartUpload(ctx context.Context, logChan *chan string, lookingPath string)
//开启上传程序 //开启上传程序
for { for {
uploadData(ctx, logChan, lookingPath) uploadData(ctx, logChan)
select { select {
case <-time.After(time.Minute):
case <-ctx.Done(): case <-ctx.Done():
return return
case <-time.After(time.Minute):
} }
} }
} }
func uploadData(ctx context.Context, logChan *chan string, lookingPath string) { func uploadData(ctx context.Context, logChan *chan string) {
// 获取检测目录
var path = "./" var path = "./"
if lookingPath != "" { if config.APPConfig.CheckDir != "" {
path = lookingPath path = config.APPConfig.CheckDir
} }
//获取文件列表 //获取文件列表
@@ -97,6 +97,7 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
} }
start := time.Now() start := time.Now()
//检测到文件 //检测到文件
//统计文件行数 //统计文件行数
fileLines := make(map[string]int) fileLines := make(map[string]int)
@@ -111,6 +112,7 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
if err != nil { if err != nil {
AddLog(logChan, "打开文件失败:"+err.Error()) AddLog(logChan, "打开文件失败:"+err.Error())
} }
// 使用 bufio.Scanner 逐行读取 // 使用 bufio.Scanner 逐行读取
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
lineCount := 0 lineCount := 0
@@ -127,12 +129,14 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
AddLog(logChan, fmt.Sprintf("%s 文件行数:%v", filepath.Base(filePath), lineCount)) AddLog(logChan, fmt.Sprintf("%s 文件行数:%v", filepath.Base(filePath), lineCount))
} }
} }
if isAllEmpty { if isAllEmpty {
AddLog(logChan, "所有文件都为空,不进行上传") AddLog(logChan, "所有文件都为空,不进行上传")
return return
} }
progress.Clear() progress.Clear()
//添加文件上传任务参数(文件路径,文件行数) //添加文件上传任务参数(文件路径,文件行数)
var tasks []Task var tasks []Task
for fileName, lines := range fileLines { for fileName, lines := range fileLines {
@@ -179,12 +183,9 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
return return
default: default:
// 等待所有任务完成 // 等待所有任务完成
if err := g.Wait(); err != nil { g.Wait()
AddLog(logChan, fmt.Sprintf("任务执行出错: %v", err))
} else {
AddLog(logChan, "所有任务执行完成!")
}
AddLog(logChan, "所有任务执行完成!")
AddLog(logChan, fmt.Sprintf("上传完成,耗时:%s", time.Since(start).String())) AddLog(logChan, fmt.Sprintf("上传完成,耗时:%s", time.Since(start).String()))
} }
} }
@@ -196,7 +197,7 @@ func getTxtFiles(dir string) (txtFiles []string, err error) {
return err return err
} }
// 只处理普通文件,跳过目录 // 跳过目录,只处理普通文件
if !info.Mode().IsRegular() { if !info.Mode().IsRegular() {
return nil return nil
} }