Compare commits
2 Commits
6952c33f16
...
03e4e6f45b
| Author | SHA1 | Date | |
|---|---|---|---|
| 03e4e6f45b | |||
| 6bd82024d9 |
@@ -45,12 +45,12 @@ func (a *App) startup(ctx context.Context) {
|
||||
}()
|
||||
|
||||
//在程序启动时运行上传程序
|
||||
if config.APPConfig.IsRunOnStart {
|
||||
time.Sleep(time.Second)
|
||||
a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx)
|
||||
go uploader.StartUpload(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir)
|
||||
a.isRun = true
|
||||
}
|
||||
//if config.APPConfig.IsRunOnStart {
|
||||
// time.Sleep(time.Second)
|
||||
// a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx)
|
||||
// go uploader.StartUpload(a.uploaderCTX, &a.logChan)
|
||||
// a.isRun = true
|
||||
//}
|
||||
}
|
||||
|
||||
// SelectPath 打开选择路径弹框
|
||||
@@ -74,7 +74,7 @@ func (a *App) StartUpload() {
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
+32
-29
@@ -7,12 +7,12 @@ import {config} from "../wailsjs/go/models.ts";
|
||||
import Config = config.Config;
|
||||
import {EventsOn, LogPrint} from "../wailsjs/runtime";
|
||||
|
||||
const serverUrl = ref('')
|
||||
// const serverUrl = ref('')
|
||||
const token = ref('')
|
||||
const checkDir = ref('')
|
||||
const concurrentFiles = ref(1)
|
||||
const uploadThreads = ref(1)
|
||||
const autoStart = ref(false)
|
||||
// const autoStart = ref(false)
|
||||
|
||||
const isRunning = ref(false)
|
||||
const logOutput = ref<string[]>([])
|
||||
@@ -26,9 +26,8 @@ interface FileProgress {
|
||||
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(() => {
|
||||
return [...progressList.value].sort((a, b) => {
|
||||
@@ -53,21 +52,25 @@ const addLog = (msg: string) => {
|
||||
const selectDirectory = () => {
|
||||
// ElMessage.info('请手动输入检测目录路径')
|
||||
SelectPath().then((path) => {
|
||||
checkDir.value = path
|
||||
if (path){
|
||||
checkDir.value = path
|
||||
}else {
|
||||
ElMessage.warning('未选择目录,不更改配置')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const startRun = () => {
|
||||
if (!serverUrl.value) {
|
||||
ElMessage.warning('请输入服务器地址')
|
||||
return
|
||||
}
|
||||
// if (!serverUrl.value) {
|
||||
// ElMessage.warning('请输入服务器地址')
|
||||
// return
|
||||
// }
|
||||
if (!token.value) {
|
||||
ElMessage.warning('请输入Token')
|
||||
ElMessage.error('请输入Token')
|
||||
return
|
||||
}
|
||||
if (!checkDir.value) {
|
||||
ElMessage.warning('请选择检测目录')
|
||||
ElMessage.error('请选择检测目录')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -77,7 +80,7 @@ const startRun = () => {
|
||||
const stopRun = () => {
|
||||
addLog(`正在停止运行`)
|
||||
StopUpload().then(() => {
|
||||
ElMessage.info('已停止运行')
|
||||
ElMessage.success('已停止运行')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -93,9 +96,9 @@ const clearLog = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const writeServerUrl =() => {
|
||||
WriteConfig("url", serverUrl.value)
|
||||
}
|
||||
// const writeServerUrl =() => {
|
||||
// WriteConfig("url", serverUrl.value)
|
||||
// }
|
||||
const writeToken =() => {
|
||||
WriteConfig("token", token.value)
|
||||
}
|
||||
@@ -108,19 +111,19 @@ const writeConcurrentFiles = () => {
|
||||
const writeUploadThreads =() => {
|
||||
WriteConfig("thread-count", uploadThreads.value)
|
||||
}
|
||||
const writeAutoStart = () => {
|
||||
WriteConfig("is-run-on-start", autoStart.value)
|
||||
}
|
||||
// const writeAutoStart = () => {
|
||||
// WriteConfig("is-run-on-start", autoStart.value)
|
||||
// }
|
||||
|
||||
// 加载配置
|
||||
try {
|
||||
GetConfig().then((config: Config) => {
|
||||
serverUrl.value = config.url
|
||||
// serverUrl.value = config.url
|
||||
token.value = config.token
|
||||
checkDir.value = config.check_dir
|
||||
concurrentFiles.value = config.handle_file_count
|
||||
uploadThreads.value = config.thread_count
|
||||
autoStart.value = config.is_run_on_start
|
||||
// autoStart.value = config.is_run_on_start
|
||||
|
||||
LogPrint(`[${new Date().toLocaleString()}] 配置已加载`)
|
||||
})
|
||||
@@ -142,10 +145,10 @@ EventsOn("log", (msg) => {
|
||||
<template>
|
||||
<div class="container">
|
||||
<div class="left-panel">
|
||||
<div class="form-item">
|
||||
<label>服务器地址</label>
|
||||
<el-input v-model="serverUrl" placeholder="请输入服务器地址" :disabled="isRunning" @change="writeServerUrl()"/>
|
||||
</div>
|
||||
<!-- <div class="form-item">-->
|
||||
<!-- <label>服务器地址</label>-->
|
||||
<!-- <el-input v-model="serverUrl" placeholder="请输入服务器地址" :disabled="isRunning" @change="writeServerUrl()"/>-->
|
||||
<!-- </div>-->
|
||||
|
||||
<div class="form-item">
|
||||
<label>Token</label>
|
||||
@@ -170,9 +173,9 @@ EventsOn("log", (msg) => {
|
||||
<el-input-number v-model="uploadThreads" :min="1" :max="100" :disabled="isRunning" @change="writeUploadThreads()"/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<el-checkbox v-model="autoStart" label="运行时自动启动上传" size="large" :disabled="isRunning" @change="writeAutoStart()"/>
|
||||
</div>
|
||||
<!-- <div class="form-item">-->
|
||||
<!-- <el-checkbox v-model="autoStart" label="运行时自动启动上传" size="large" :disabled="isRunning" @change="writeAutoStart()"/>-->
|
||||
<!-- </div>-->
|
||||
|
||||
<div class="form-item">
|
||||
<label>上传进度</label>
|
||||
@@ -253,7 +256,7 @@ EventsOn("log", (msg) => {
|
||||
|
||||
.progress-list {
|
||||
margin-top: 12px;
|
||||
max-height: 160px;
|
||||
max-height: 250px;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -20,8 +20,6 @@ import (
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
var progress sync.Map
|
||||
|
||||
type Task struct {
|
||||
FilePath string
|
||||
FileLines int
|
||||
@@ -34,7 +32,9 @@ type Progress struct {
|
||||
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, `服务器: `+config.APPConfig.Url)
|
||||
AddLog(logChan, `Token: `+config.APPConfig.Token)
|
||||
@@ -70,20 +70,20 @@ func StartUpload(ctx context.Context, logChan *chan string, lookingPath string)
|
||||
|
||||
//开启上传程序
|
||||
for {
|
||||
uploadData(ctx, logChan, lookingPath)
|
||||
uploadData(ctx, logChan)
|
||||
select {
|
||||
case <-time.After(time.Minute):
|
||||
case <-ctx.Done():
|
||||
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 = "./"
|
||||
if lookingPath != "" {
|
||||
path = lookingPath
|
||||
if config.APPConfig.CheckDir != "" {
|
||||
path = config.APPConfig.CheckDir
|
||||
}
|
||||
|
||||
//获取文件列表
|
||||
@@ -97,6 +97,7 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
||||
//检测到文件
|
||||
//统计文件行数
|
||||
fileLines := make(map[string]int)
|
||||
@@ -111,6 +112,7 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
|
||||
if err != nil {
|
||||
AddLog(logChan, "打开文件失败:"+err.Error())
|
||||
}
|
||||
|
||||
// 使用 bufio.Scanner 逐行读取
|
||||
scanner := bufio.NewScanner(file)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
if isAllEmpty {
|
||||
AddLog(logChan, "所有文件都为空,不进行上传")
|
||||
return
|
||||
}
|
||||
|
||||
progress.Clear()
|
||||
|
||||
//添加文件上传任务参数(文件路径,文件行数)
|
||||
var tasks []Task
|
||||
for fileName, lines := range fileLines {
|
||||
@@ -179,12 +183,9 @@ func uploadData(ctx context.Context, logChan *chan string, lookingPath string) {
|
||||
return
|
||||
default:
|
||||
// 等待所有任务完成
|
||||
if err := g.Wait(); err != nil {
|
||||
AddLog(logChan, fmt.Sprintf("任务执行出错: %v", err))
|
||||
} else {
|
||||
AddLog(logChan, "所有任务执行完成!")
|
||||
}
|
||||
g.Wait()
|
||||
|
||||
AddLog(logChan, "所有任务执行完成!")
|
||||
AddLog(logChan, fmt.Sprintf("上传完成,耗时:%s", time.Since(start).String()))
|
||||
}
|
||||
}
|
||||
@@ -196,7 +197,7 @@ func getTxtFiles(dir string) (txtFiles []string, err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// 只处理普通文件,跳过目录
|
||||
// 跳过目录,只处理普通文件
|
||||
if !info.Mode().IsRegular() {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user