feat: 添加新遠程頁面

This commit is contained in:
bmy
2024-07-16 17:36:48 +08:00
parent de8012a590
commit 211b4767c1
4 changed files with 173 additions and 10 deletions

22
app.py
View File

@@ -23,6 +23,8 @@ processes = []
time_record = None time_record = None
task_run_flag = False
# 日志队列 # 日志队列
queue = Queue() queue = Queue()
# 跳过任务 干预任务调度 # 跳过任务 干预任务调度
@@ -54,6 +56,10 @@ fileOptions_list = ['cfg_args.toml','cfg_main.toml', 'cfg_subtask.toml']
def index(): def index():
return render_template('index.html') return render_template('index.html')
@app.route('/run')
def run():
return render_template('index1.html')
@app.route('/csdn') @app.route('/csdn')
def csdn(): def csdn():
return render_template('csdn.html') return render_template('csdn.html')
@@ -64,6 +70,7 @@ def operate_handle(data):
global task_process global task_process
global processes global processes
global time_record global time_record
global task_run_flag
if data['type'] == 'save_config': if data['type'] == 'save_config':
f = open(os.path.join(fileOptions_path,data['file_name']), 'w') f = open(os.path.join(fileOptions_path,data['file_name']), 'w')
ret = toml.dump(data['content'], f) ret = toml.dump(data['content'], f)
@@ -99,6 +106,7 @@ def operate_handle(data):
elif data['type'] == 'operate_task': elif data['type'] == 'operate_task':
# 任务函数 # 任务函数
if data['content'] == 'run': if data['content'] == 'run':
task_run_flag = True
if task_process != None: if task_process != None:
task_process.terminate() task_process.terminate()
time_record = time.perf_counter() time_record = time.perf_counter()
@@ -106,6 +114,7 @@ def operate_handle(data):
task_process.start() task_process.start()
logger.info("开启 task") logger.info("开启 task")
elif data['content'] == 'stop': elif data['content'] == 'stop':
task_run_flag = False
task_process.terminate() task_process.terminate()
logger.info(f"任务结束 用时{time.perf_counter() - time_record}s") logger.info(f"任务结束 用时{time.perf_counter() - time_record}s")
logger.info("关闭 task") logger.info("关闭 task")
@@ -125,6 +134,12 @@ def operate_handle(data):
elif data['type'] == 'skip_task': elif data['type'] == 'skip_task':
logger.info(data) logger.info(data)
skip_task_queue.put(1) skip_task_queue.put(1)
elif data['type'] == 'save_target_person':
config_path = os.path.join(fileOptions_path, 'cfg_args.toml')
config_args = toml.load(config_path)
config_args['lane_mode']['mode_index'] = int(data['content'])
with open(config_path, 'w') as config_file:
toml.dump(config_args, config_file)
@socketio.on('connect') @socketio.on('connect')
def test_connect(): def test_connect():
@@ -134,6 +149,7 @@ def test_connect():
for item in fileOptions_list: for item in fileOptions_list:
config_data[item] = toml.load(os.path.join(fileOptions_path,item)) config_data[item] = toml.load(os.path.join(fileOptions_path,item))
socketio.emit('config_data', {'type': 'config_data', 'content': config_data}) socketio.emit('config_data', {'type': 'config_data', 'content': config_data})
socketio.emit('task_status', {'type': 'task_status', 'content': int(task_run_flag)})
def thread_function(): def thread_function():
global queue global queue
while True: while True:
@@ -146,6 +162,12 @@ def thread_function():
if __name__ == '__main__': if __name__ == '__main__':
config_path = os.path.join(fileOptions_path, 'cfg_args.toml')
config_args = toml.load(config_path)
config_args['lane_mode']['mode_index'] = 1
with open(config_path, 'w') as config_file:
toml.dump(config_args, config_file)
log_file = "server_processes.log" log_file = "server_processes.log"
log = open(log_file, "w") log = open(log_file, "w")
time.sleep(2) time.sleep(2)

View File

@@ -40,6 +40,7 @@ def main_func(_queue, _skip_queue):
# 配置日志输出 # 配置日志输出
logger.add(cfg_main['debug']['logger_filename'], format=cfg_main['debug']['logger_format'], retention = 5, level="INFO") logger.add(cfg_main['debug']['logger_filename'], format=cfg_main['debug']['logger_format'], retention = 5, level="INFO")
logger.info(cfg_args)
act.axis.camera(0) act.axis.camera(0)
act.axis.x2(140) act.axis.x2(140)

View File

@@ -109,7 +109,7 @@
</el-col> </el-col>
<el-col :xs="24" :sm="8"> <el-col :xs="24" :sm="8">
<el-button @click="skipTask" type="success" style="width: 100%"> <el-button @click="skipTask" type="success" style="width: 100%">
强制跳转 关闭
</el-button> </el-button>
</el-col> </el-col>
</el-row> </el-row>
@@ -128,12 +128,16 @@
</el-button> --> </el-button> -->
<el-form v-if="showConfigForm && config" class="config-form"> <el-form v-if="showConfigForm && config" class="config-form">
<el-button @click="saveConfig" type="primary" style="margin-top: 20px;">保存配置</el-button>
<el-button v-if="showConfigForm" @click="toggleConfigForm" type="primary" style="margin-bottom: 20px;">
{{ showConfigForm ? '关闭' : '打开' }} 配置
</el-button>
<div v-for="(section, sectionName) in config" :key="sectionName"> <div v-for="(section, sectionName) in config" :key="sectionName">
<h3>{{ sectionName }}</h3> <h3>{{ sectionName }}</h3>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col v-for="(value, key) in section" :key="key" :xs="24" :sm="12" :md="8" :lg="6"> <el-col v-for="(value, key) in section" :key="key" :xs="24" :sm="12" :md="8" :lg="6">
<el-form-item :label="key"> <el-form-item :label="key">
<el-select v-if="sectionName === 'kick_ass'" v-model="config[sectionName][key]"> <el-select v-if="sectionName === 'lane_mode'" v-model="config[sectionName][key]">
<el-option <el-option
v-for="item in target_person_options" v-for="item in target_person_options"
:key="item.value" :key="item.value"
@@ -162,10 +166,7 @@
</el-col> </el-col>
</el-row> </el-row>
</div> </div>
<el-button @click="saveConfig" type="primary" style="margin-top: 20px;">保存配置</el-button>
<el-button v-if="showConfigForm" @click="toggleConfigForm" type="primary" style="margin-bottom: 20px;">
{{ showConfigForm ? '关闭' : '打开' }} 配置
</el-button>
</el-form> </el-form>
<h2 class="section-title">Log Display</h2> <h2 class="section-title">Log Display</h2>
@@ -197,16 +198,16 @@
timer: null, timer: null,
target_person_options: [{ target_person_options: [{
value: 1, value: 1,
label: '模式 1' label: '6_9'
}, { }, {
value: 2, value: 2,
label: '模式 2' label: '7_10_2'
}, { }, {
value: 3, value: 3,
label: '模式 3' label: '7_14_2'
}, { }, {
value: 4, value: 4,
label: '模式 4' label: '7_15_4'
}], }],
}, },
methods: { methods: {

139
templates/index1.html Normal file
View File

@@ -0,0 +1,139 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>btl143</title>
<link rel="stylesheet" href="static/index.css">
<script src="static/vue.js"></script>
<script src="static/index.js"></script>
<script src="static/socket.io.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f7fa;
}
.app-container {
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
.button-group {
margin-bottom: 20px;
}
.full-screen-background {
background-color: #f0f0f0;
position: fixed;
top: 60px; /* Adjust based on button height and margin */
left: 0;
right: 0;
bottom: 0;
z-index: -1;
}
.counter-display {
padding: 20px;
text-align: center;
position: fixed;
top: 80px; /* Adjust based on your requirements */
left: 50%;
transform: translateX(-50%);
z-index: 1;
}
</style>
</head>
<body>
<div id="app">
<el-container class="app-container">
<el-main>
<h1 class="section-title">btl143 upper</h1>
<el-row :gutter="20" class="button-group">
<el-col :xs="24" :sm="8">
<el-button
@click="toggleTask"
:type="taskActive ? 'success' : 'danger'"
style="width: 100%">
{{ taskActive ? `开启 task ${counter}` : `关闭 task ${counter}` }}
</el-button>
</el-col>
</el-row>
<div class="full-screen-background" @click="incrementCounter">
<div class="counter-display">
</div>
</div>
</el-main>
</el-container>
</div>
<script>
new Vue({
el: '#app',
data: {
taskActive: true,
counter: 1
},
methods: {
toggleTask() {
if (this.taskActive) {
this.socket.emit('operate', {type: 'operate_task', content: 'run'});
}
else {
this.socket.emit('operate', {type: 'operate_task', content: 'stop'});
}
this.taskActive = !this.taskActive;
},
incrementCounter() {
this.counter += 1;
if (this.counter == 5) {
this.counter = 1;
}
this.socket.emit('operate', {type: 'save_target_person', content: this.counter});
},
startServer() {
this.socket.emit('operate', {type: 'operate_server', content: 'run'});
},
stopServer() {
this.socket.emit('operate', {type: 'operate_server', content: 'stop'});
},
restartServer() {
this.socket.emit('operate', {type: 'operate_server', content: 'restart'});
},
startTask() {
this.socket.emit('operate', {type: 'operate_task', content: 'run'});
},
stopTask() {
this.socket.emit('operate', {type: 'operate_task', content: 'stop'});
},
restartTask() {
this.socket.emit('operate', {type: 'operate_task', content: 'restart'});
},
skipTask() {
this.socket.emit('operate', { type: 'skip_task', content: '' });
}
},
mounted() {
this.socket = io('http://' + document.domain + ':5001');
this.socket.on('connect', () => {
console.log('Connected to server');
});
this.socket.on('task_status', (data) => {
if (data.content == 0) {
this.taskActive = true
} else {
this.taskActive = false
}
});
}
});
</script>
</body>
</html>