Skip to content

Commit

Permalink
移除“排班表路径”选项
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoZuohong committed Jul 28, 2024
1 parent e9b602d commit 01773ed
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 57 deletions.
20 changes: 14 additions & 6 deletions arknights_mower/utils/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from arknights_mower.utils.path import get_path

conf_path = get_path("@app/conf.yml")
plan_path = get_path("@app/plan.json")


def save_conf():
Expand All @@ -33,6 +34,7 @@ def load_conf():
conf_path.parent.mkdir(exist_ok=True)
conf = Conf()
save_conf()
return
with conf_path.open("r", encoding="utf-8") as f:
conf = Conf(**yaml.load(f, Loader=CoreLoader))

Expand All @@ -41,20 +43,26 @@ def load_conf():
load_conf()


def save_plan():
with plan_path.open("w", encoding="utf-8") as f:
json.dump(plan.model_dump(exclude_none=True), f, ensure_ascii=False, indent=2)


def load_plan():
global plan
with open(conf.planFile, "r", encoding="utf-8") as f:
if not plan_path.is_file():
plan_path.parent.mkdir(exist_ok=True)
plan = PlanModel()
save_plan()
return
with plan_path.open("r", encoding="utf-8") as f:
plan = PlanModel(**json.load(f))


def save_plan():
with open(conf.planFile, "w", encoding="utf-8") as f:
json.dump(plan.model_dump(exclude_none=True), f, ensure_ascii=False, indent=2)


plan: PlanModel
load_plan()


stop_mower = Event()

# 日志
Expand Down
2 changes: 0 additions & 2 deletions arknights_mower/utils/config/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,6 @@ class RunOrderGrandetModeConf(ConfModel):
"无人机加速间隔"
free_blacklist: str = ""
"宿舍黑名单"
planFile: str = "./plan.json"
"排班表路径"
reload_room: str = ""
"搓玉补货房间"
run_order_delay: float = 3
Expand Down
4 changes: 2 additions & 2 deletions arknights_mower/utils/config/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ class BackupPlan(BaseModel):

class PlanModel(BaseModel):
default: str = "plan1"
plan1: Plan1 = {}
conf: PlanConf = {}
plan1: Plan1 = Plan1()
conf: PlanConf = PlanConf()
backup_plans: list[BackupPlan] = []
9 changes: 2 additions & 7 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,12 @@ def load_config():
@require_token
def load_plan_from_json():
if request.method == "GET":
try:
config.load_plan()
except Exception as e:
logger.exception(f"排班表文件路径错误{e},重置为plan.json")
config.conf.planFile = "./plan.json"
config.load_plan()
config.load_plan()
return config.plan.model_dump(exclude_none=True)
else:
config.plan = config.PlanModel(**request.json)
config.save_plan()
return f"New plan saved at {config.conf.planFile}"
return "New plan saved"


@app.route("/operator")
Expand Down
57 changes: 21 additions & 36 deletions ui/src/pages/Plan.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup>
import { storeToRefs } from 'pinia'
import { useConfigStore } from '@/stores/config'
import { usePlanStore } from '@/stores/plan'
import { deepcopy } from '@/utils/deepcopy'
import { storeToRefs } from 'pinia'
const config_store = useConfigStore()
const { plan_file, free_blacklist, theme } = storeToRefs(config_store)
const { free_blacklist, theme } = storeToRefs(config_store)
const { build_config } = config_store
const plan_store = usePlanStore()
Expand All @@ -22,24 +22,12 @@ const {
} = storeToRefs(plan_store)
const { load_plan, fill_empty } = plan_store
import { inject, ref, computed, provide, watchEffect } from 'vue'
import { computed, inject, provide, ref, watchEffect } from 'vue'
const axios = inject('axios')
const facility = ref('')
provide('facility', facility)
import { file_dialog } from '@/utils/dialog'
async function open_plan_file() {
const file_path = await file_dialog()
if (file_path) {
plan_file.value = file_path
await axios.post(`${import.meta.env.VITE_HTTP_URL}/conf`, build_config())
await load_plan()
sub_plan.value = 'main'
}
}
import { useMessage } from 'naive-ui'
const plan_editor = ref(null)
Expand All @@ -48,8 +36,8 @@ const generating_image = ref(false)
const message = useMessage()
import { toBlob } from 'html-to-image'
import { sleep } from '@/utils/sleep'
import { toBlob } from 'html-to-image'
import { useLoadingBar } from 'naive-ui'
const loading_bar = useLoadingBar()
Expand Down Expand Up @@ -176,14 +164,14 @@ const add_task = ref(false)
provide('show_task', show_task)
provide('add_task', add_task)
import DocumentExport from '@vicons/carbon/DocumentExport'
import DocumentImport from '@vicons/carbon/DocumentImport'
import IosArrowBack from '@vicons/ionicons4/IosArrowBack'
import IosArrowForward from '@vicons/ionicons4/IosArrowForward'
import TrashOutline from '@vicons/ionicons5/TrashOutline'
import CodeSlash from '@vicons/ionicons5/CodeSlash'
import PlusRound from '@vicons/material/PlusRound'
import TrashOutline from '@vicons/ionicons5/TrashOutline'
import AddTaskRound from '@vicons/material/AddTaskRound'
import DocumentImport from '@vicons/carbon/DocumentImport'
import DocumentExport from '@vicons/carbon/DocumentExport'
import PlusRound from '@vicons/material/PlusRound'
async function import_plan() {
const response = await axios.get(`${import.meta.env.VITE_HTTP_URL}/import`)
Expand All @@ -201,22 +189,6 @@ async function import_plan() {
<trigger-dialog />
<task-dialog />
<div class="plan-bar w-980 mx-auto mt-12 mw-980">
<n-input type="textarea" :autosize="true" v-model:value="plan_file" />
<n-button @click="open_plan_file">...</n-button>
<n-button @click="import_plan">
<template #icon>
<n-icon><document-import /></n-icon>
</template>
从图片导入(覆盖当前排班)
</n-button>
<n-button @click="save" :loading="generating_image" :disabled="generating_image">
<template #icon>
<n-icon><document-export /></n-icon>
</template>
导出图片
</n-button>
</div>
<div class="plan-bar w-980 mx-auto mw-980">
<n-button
:disabled="sub_plan == 'main'"
@click="sub_plan = sub_plan == 0 ? 'main' : sub_plan - 1"
Expand Down Expand Up @@ -258,6 +230,19 @@ async function import_plan() {
</template>
删除此副表
</n-button>
<n-divider vertical />
<n-button @click="import_plan">
<template #icon>
<n-icon><document-import /></n-icon>
</template>
导入排班
</n-button>
<n-button @click="save" :loading="generating_image" :disabled="generating_image">
<template #icon>
<n-icon><document-export /></n-icon>
</template>
导出排班
</n-button>
</div>
<plan-editor ref="plan_editor" class="w-980 mx-auto mw-980 px-12" />
<n-form
Expand Down
4 changes: 0 additions & 4 deletions ui/src/stores/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const useConfigStore = defineStore('config', () => {
const recipient = ref('')
const custom_smtp_server = ref({})
const package_type = ref('official')
const plan_file = ref('')
const reload_room = ref('')
const run_order_delay = ref(10)
const start_automatically = ref(false)
Expand Down Expand Up @@ -116,7 +115,6 @@ export const useConfigStore = defineStore('config', () => {
recipient.value = response.data.recipient
custom_smtp_server.value = response.data.custom_smtp_server
package_type.value = response.data.package_type == 1 ? 'official' : 'bilibili'
plan_file.value = response.data.planFile
reload_room.value = response.data.reload_room == '' ? [] : response.data.reload_room.split(',')
run_order_delay.value = response.data.run_order_delay
start_automatically.value = response.data.start_automatically
Expand Down Expand Up @@ -200,7 +198,6 @@ export const useConfigStore = defineStore('config', () => {
pass_code: pass_code.value,
recipient: recipient.value,
custom_smtp_server: custom_smtp_server.value,
planFile: plan_file.value,
reload_room: reload_room.value.join(','),
run_order_delay: run_order_delay.value,
start_automatically: start_automatically.value,
Expand Down Expand Up @@ -297,7 +294,6 @@ export const useConfigStore = defineStore('config', () => {
recipient,
custom_smtp_server,
package_type,
plan_file,
reload_room,
run_order_delay,
start_automatically,
Expand Down

0 comments on commit 01773ed

Please sign in to comment.