Skip to content

Commit

Permalink
一条龙保存
Browse files Browse the repository at this point in the history
  • Loading branch information
tignioj committed Oct 11, 2024
1 parent cc94119 commit 51fb89c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const activateClass = (link) => {
route.fullPath.includes(link)
}
const keepAlive = ['ConfigEditorPage', 'ScriptManagerPage']
const keepAlive = ['ScriptManagerPage']
</script>
<template>
<p>
Expand Down
4 changes: 4 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const leyLineOutcropGetConfigURL = `${serverURL}/leyline_outcrop/get_config`;
// 一条龙
const oneDragonRunURL= `${serverURL}/one_dragon/run`;
const oneDragonStopURL= `${serverURL}/one_dragon/stop`;
const oneDragonGetURL= `${serverURL}/one_dragon/get`; // 获取配置
const oneDragonSaveURL= `${serverURL}/one_dragon/save`; // 保存一条龙配置

export {
serverURL,
Expand Down Expand Up @@ -128,4 +130,6 @@ export {
// 一条龙
oneDragonRunURL,
oneDragonStopURL,
oneDragonGetURL,
oneDragonSaveURL
};
20 changes: 12 additions & 8 deletions src/page/ConfigEditorPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ const isDuplicate = (name) => {
<table>
<thead>
<tr>
<th class="narrow-column">当前</th>
<th class="narrow-column">启用</th>
<th class="narrow-column">名称</th>
<th class="narrow-column">服务器</th>
Expand All @@ -182,11 +181,11 @@ const isDuplicate = (name) => {
@dragover="dragOverInstance"
@drop="dropInstances(item)">

<td class="narrow-column">
<input name="instance" type="radio" v-model="currentInstance"
@change="setInstance(item.name)"
:checked="currentInstance===item.name">
</td>
<!-- <td class="narrow-column">-->
<!-- <input name="instance" type="radio" v-model="currentInstance"-->
<!-- @change="setInstance(item.name)"-->
<!-- :checked="currentInstance===item.name">-->
<!-- </td>-->
<td class="narrow-column"> <input type="checkbox" v-model="item.enable"> </td>
<td class="narrow-column">
<!-- 动态设置输入框的class,当name重复时变红 -->
Expand All @@ -195,8 +194,13 @@ const isDuplicate = (name) => {
<td class="narrow-column"> <input type="text" v-model="item.server"> </td>
<td> <input v-model="item.account" type="text" /> </td>
<td> <input v-model="item.password" type="password"/> </td>
<td><button @click="deleteInstance(item.name)">删除实例</button></td>
<td><button @click="login(item.name)">登录</button></td>
<td>
<button :disabled="currentInstance===item.name" @click="setInstance(item.name)">
{{ currentInstance === item.name ? "当前选中": "切换实例" }}
</button>
<button @click="deleteInstance(item.name)">删除实例</button>
<button @click="login(item.name)">登录</button>
</td>
</tr>
</tbody>
</table>
Expand Down
82 changes: 66 additions & 16 deletions src/page/OneDragonPage.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<script setup>
import {computed, inject, onMounted, ref} from 'vue';
import {oneDragonRunURL, oneDragonStopURL, socketURL} from "@/api.js";
import {
oneDragonGetURL,
oneDragonRunURL,
oneDragonSaveURL,
oneDragonStopURL,
socketURL
} from "@/api.js";
import {store} from "@/store.js";
import {
SOCKET_EVENT_DAILY_MISSION_END,
Expand Down Expand Up @@ -32,13 +38,14 @@ function errorMsg(msg) {
const todoList = ref([
const oneDragonList = ref([
{ name: '清单', value: 'todo' , checked: false },
{ name: '战斗委托', value: 'dailyMission' , checked: true},
{ name: '地脉', value: 'leyLine' , checked: true},
{ name: '领取奖励', value: 'claimReward' , checked: true}
]);
const afterOneDragon = ref('')
Expand All @@ -48,14 +55,14 @@ function dragStart(item) { dragItem.value = item; }
function dragOver(e) { e.preventDefault(); }
function drop(item) {
const fromIndex = todoList.value.indexOf(dragItem.value);
const toIndex = todoList.value.indexOf(item);
todoList.value.splice(fromIndex, 1);
todoList.value.splice(toIndex, 0, dragItem.value);
const fromIndex = oneDragonList.value.indexOf(dragItem.value);
const toIndex = oneDragonList.value.indexOf(item);
oneDragonList.value.splice(fromIndex, 1);
oneDragonList.value.splice(toIndex, 0, dragItem.value);
}
const checkedItems = computed(() => {
return todoList.value.filter(item => item.checked);
return oneDragonList.value.filter(item => item.checked);
});
function logCheckedItems() {
Expand All @@ -64,8 +71,8 @@ function logCheckedItems() {
function runAll() {
logCheckedItems()
const jsonString = JSON.stringify(todoList.value)
const count = todoList.value.filter(item => item.checked).length;
const jsonString = JSON.stringify(oneDragonList.value)
const count = oneDragonList.value.filter(item => item.checked).length;
if(count === 0) {
errorMsg('未勾选任何清单,无法执行')
return
Expand Down Expand Up @@ -127,9 +134,51 @@ onMounted(()=> {
const gameFolder = ref('');
function save() {
logCheckedItems()
const jsonString = JSON.stringify(oneDragonList.value)
fetch(oneDragonSaveURL, {
method: 'POST', // 请求方法
headers: {
'Content-Type': 'application/json' // 指定发送的数据格式为 JSON
},
body: jsonString // 将 JavaScript 对象转换为 JSON 字符串
}).then(response => {
if (!response.ok) throw new Error('Network response was not ok ' + response.statusText);
return response.json(); // 解析响应为 JSON
})
.then(data => {
if (data.success === true) {
info(data.message)
} else {
errorMsg(data.message)
}
}).catch(error => {
console.error('Error:', error); // 处理错误
errorMsg(error)
});
}
function getOneDragonList() {
fetch(oneDragonGetURL).then(response => {
if (!response.ok) throw new Error('Network response was not ok ' + response.statusText);
return response.json(); // 解析响应为 JSON
})
.then(data => {
if (data.success === true) {
const result = data.data
console.log(result)
oneDragonList.value = result
} else {
errorMsg(data.message)
}
}).catch(error => {
console.error('Error:', error); // 处理错误
errorMsg(error)
});
}
getOneDragonList();
</script>


Expand All @@ -145,7 +194,7 @@ function save() {
</tr>
</thead>
<tbody>
<tr v-for="item in todoList" :key="item.value"
<tr v-for="item in oneDragonList" :key="item.value"
draggable="true"
@dragstart="dragStart(item)"
@dragover="dragOver"
Expand All @@ -159,23 +208,24 @@ function save() {
</tbody>
</table>
<br/>
<button @click="save">保存设置</button>
<button @click="runAll" :disabled="checkedItems.length < 1">一键运行</button>
<button @click="stop" >停止运行</button>
<div>
<h2>一条龙设置(保存后生效)</h2>
<div>
游戏目录:
<input type="text" v-model="gameFolder" />
<p v-if="gameFolder">{{ gameFolder }}</p>
</div> 结束后:
<!-- <div>-->
<!-- 游戏目录:-->
<!-- <input type="text" v-model="gameFolder" />-->
<!-- <p v-if="gameFolder">{{ gameFolder }}</p>-->
<!-- </div> -->
结束后:
<select v-model="afterOneDragon">
<option value="">无</option>
<option value="close">关闭游戏</option>
<option value="sleep">休眠</option>
<option value="shutdown">关机</option>
</select>
<br/>
<button @click="save">保存设置</button>
</div>
</template>
<style scoped>
Expand Down

0 comments on commit 51fb89c

Please sign in to comment.