Compare commits

..

11 commits
v0.6.1 ... main

Author SHA1 Message Date
fcdaa529cd 代码重构:使用统一消息组件封装替代原始调用 2025-07-14 00:56:12 +08:00
717df6588a 界面优化:将镜像源选择器从单选按钮改为下拉菜单 2025-07-07 20:39:35 +08:00
fb8ab18fc5 功能扩展:PyPI新增中国科学技术大学镜像源选项 2025-07-07 20:38:51 +08:00
06fab427aa 界面优化
1.启动程序界面字体对齐
2.编辑实例名称时保持行高和实例名称位置不变
3.修改实例名称输入框添加可清除选项
4.打开配置路径按钮移到右侧按钮处
2025-03-22 20:39:56 +08:00
e3c2627fc5 发布v0.7.1版本 2025-03-10 01:00:49 +08:00
e4b93b94b1 新增功能:启动实例后自动打开网页面板 2025-03-10 00:59:58 +08:00
6e235a28c1 功能修复:更新源码时没有指定为远程分支 2025-03-10 00:04:46 +08:00
e3457c1081 发布v0.7.0版本 2025-03-09 22:26:54 +08:00
5576f8de39 新增功能:使用cli控制实例启停、在浏览器中打开网页面板 2025-03-09 21:29:33 +08:00
de2c2af2bd 新增功能:添加zhaozuohong.vip镜像选项 2025-03-08 11:28:22 +08:00
501259b420 发布v0.6.1版本 2025-02-23 21:00:43 +08:00
16 changed files with 374 additions and 159 deletions

View file

@ -1,4 +1,4 @@
from typing import List
from typing import List, Literal, get_args, get_origin
from pydantic import BaseModel, model_validator
from pydantic_core import PydanticUndefined
@ -15,6 +15,18 @@ class ConfModel(BaseModel):
data[name] = expected_type
else:
data[name] = field.default
value = data[name]
# 检查 Literal 类型并修正
if get_origin(expected_type) is Literal:
valid_literals = get_args(expected_type)
if value not in valid_literals:
# 修正为默认值
data[name] = (
field.default
if field.default is not PydanticUndefined
else None
)
return data
@ -55,9 +67,17 @@ class LaunchPart(ConfModel):
is_show_log: bool = False
class OtherPart(ConfModel):
"""其他配置"""
# xx.zhaozuohong.vip镜像 (访问xx.zhaozuohong.vip url时,0=原路径 1=在.zhaozuohong.vip前添加-cf前缀)
base_mirror: Literal["0", "1"] = "0"
class Conf(
Total,
UpdatePart,
LaunchPart,
OtherPart,
):
pass

View file

@ -8,25 +8,41 @@ constants.py
update_tmp_folder = "download_tmp"
# 更新脚本名
upgrade_script_name = "upgrade.bat"
# 下载新版本压缩包名
file_name = "launcher.7z"
# 获取最新版本发布信息
get_new_version_url = (
"https://git-cf.zhaozuohong.vip/api/v1/repos/mower-ng/launcher/releases/latest"
)
# 下载新版本压缩包名
file_name = "launcher.7z"
# 下载地址
download_git_url = "https://list.zhaozuohong.vip/mower-ng/git.7z"
download_python_url = "https://list.zhaozuohong.vip/mower-ng/python.7z"
# mower-ng git链接
mower_ng_git_url = "https://git-cf.zhaozuohong.vip/mower-ng/mower-ng.git"
# pip镜像地址
mirror_list = {
"pypi": "https://pypi.org/simple",
"aliyun": "https://mirrors.aliyun.com/pypi/simple/",
"tuna": "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple",
"sjtu": "https://mirror.sjtu.edu.cn/pypi/web/simple",
"ustc": "https://mirrors.ustc.edu.cn/pypi/simple",
}
# 实例文件夹名
instances_folder_name = "instances"
# cli命令
cli_command = {
"status": "获取mower-ng实例状态",
"launch": "启动mower-ng进程",
"exit": "停止mower-ng进程",
"kill": "强制退出mower-ng进程",
"start": "开始运行调度器",
"stop": "停止运行调度器",
"webui": "在浏览器中打开网页面板",
"log": "通过WebSocket获取日志",
}

View file

@ -1,5 +1,5 @@
{
"version": "v0.6",
"version": "v0.7.1",
"url": "ui/dist/index.html",
"log_level": "INFO",
"debug": false

12
launcher/utils.py Normal file
View file

@ -0,0 +1,12 @@
from launcher import config
def build_base_url(url: str) -> str:
"""
构建xx.zhaozuohong.vip如果配置base_mirror是1.zhaozuohong.vip前添加-cf前缀
:param url: 带有xx.zhaozuohong.vip的url字符串
:return: 构建完成的url
"""
if config.conf.base_mirror == "1":
url = url.replace(".zhaozuohong.vip", "-cf.zhaozuohong.vip")
return url

View file

@ -2,7 +2,7 @@ import io
import os
import shutil
import subprocess
import threading
import time
from _winapi import CREATE_NO_WINDOW
from pathlib import Path
from shutil import rmtree
@ -11,7 +11,6 @@ from subprocess import Popen
import requests
from launcher import config
from launcher.config.conf import LaunchPart
from launcher.constants import (
download_git_url,
download_python_url,
@ -20,6 +19,8 @@ from launcher.constants import (
mirror_list,
file_name,
instances_folder_name,
mower_ng_git_url,
cli_command,
)
from launcher.file.download import init_download, download_file
from launcher.file.extract import extract_7z_file
@ -27,22 +28,29 @@ from launcher.file.utils import ensure_directory_exists, check_command_path
from launcher.instances import manager
from launcher.log import logger
from launcher.sys_config import sys_config
from launcher.utils import build_base_url
from launcher.webview.events import custom_event, LogType
command_list = {
"download_git": lambda: init_download("git", download_git_url, os.getcwd()),
"download_git": lambda: init_download(
"git", build_base_url(download_git_url), os.getcwd()
),
"download_python": lambda: init_download(
"python", download_python_url, os.getcwd()
"python", build_base_url(download_python_url), os.getcwd()
),
"lfs": "git\\bin\\git lfs install",
"ensurepip": "python\\python -m ensurepip --default-pip",
"clone": "git\\bin\\git -c lfs.concurrenttransfers=100 clone https://git-cf.zhaozuohong.vip/mower-ng/mower-ng.git --branch slow",
"clone": lambda: f"git\\bin\\git -c lfs.concurrenttransfers=100 clone {build_base_url(mower_ng_git_url)} --branch slow",
"set_remote": lambda: f"..\\git\\bin\\git remote set-url origin {build_base_url(mower_ng_git_url)}",
"set_lfs": lambda: f"..\\git\\bin\\git config lfs.url {build_base_url(mower_ng_git_url)}/info/lfs",
"fetch": lambda: f"..\\git\\bin\\git fetch origin {config.conf.branch} --progress",
"switch": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=100 switch -f {config.conf.branch} --progress",
"reset": lambda: f"..\\git\\bin\\git -c lfs.concurrenttransfers=200 reset --hard origin/{config.conf.branch}",
"pip_tools_install": lambda: f"..\\python\\Scripts\\pip install --no-cache-dir -i {mirror_list[config.conf.mirror]} pip-tools --no-warn-script-location",
"pip_sync": lambda: f"..\\python\\Scripts\\pip-sync -i {mirror_list[config.conf.mirror]} requirements.txt",
"webview": lambda instance_path="": f'..\\python\\pythonw -X utf8 webview_ui.py "{instance_path}"',
"cli": lambda path,
command: f'..\\python\\pythonw -X utf8 cli.py -p "{path}" {command}',
}
@ -86,11 +94,12 @@ class Api:
def get_new_version(self):
logger.info("获取最新版本号")
response = requests.get(get_new_version_url)
response = requests.get(build_base_url(get_new_version_url))
return response.json()
# 更新启动器本身
def update_self(self, download_url):
download_url = build_base_url(download_url)
logger.info(f"开始更新启动器 {download_url}")
current_path = os.getcwd()
download_tmp_folder = os.path.join(current_path, "download_tmp")
@ -221,28 +230,6 @@ class Api:
) == instances_dir and os.path.exists(abs_path):
shutil.rmtree(abs_path)
def start_checked_instance(self):
checked_instances = [
instance for instance in config.conf.instances if instance.checked
]
if not checked_instances:
custom_event(LogType.warning, "没有选中的实例")
return [{"status": False, "message": "No checked instances"}]
def _run_instance(instance: LaunchPart.Instance):
self.run(
"webview",
"mower-ng",
{"instance_path": instance.path},
)
# 创建并启动线程 目前进程依然有阻塞,待优化
for instance in checked_instances:
thread = threading.Thread(
target=_run_instance, args=(instance,), daemon=True
)
thread.start()
def migrate_default_instance(self):
"""迁移默认实例文件到新实例"""
source_path = os.path.join(os.getcwd(), "mower-ng")
@ -258,3 +245,63 @@ class Api:
else:
os.startfile(path)
custom_event(LogType.info, f"成功打开文件夹:{path}")
def test_base_url_connect(self):
url = build_base_url(get_new_version_url)
custom_event(LogType.info, f"开始测试URL连接:{url}")
try:
start_time = time.time()
response = requests.get(url)
end_time = time.time()
if response.status_code == 200:
elapsed_time_ms = (end_time - start_time) * 1000
custom_event(
LogType.info, f"测试成功,响应时间为 {elapsed_time_ms:.2f} 毫秒"
)
else:
custom_event(
LogType.error, f"测试失败: HTTP状态码 {response.status_code}"
)
except requests.exceptions.RequestException as e:
custom_event(LogType.error, f"发生错误: {e}")
def cli_control(self, command: str, path: str):
"""
统一的CLI控制接口用于执行指定命令并可选地指定工作目录
:param command_str: 要执行的命令字符串或命令键 "status", "launch"
:param path: 实例路径
"""
if command not in cli_command:
custom_event(
LogType.error,
f"无效的命令字符串或命令键:{command},请检查输入。",
)
return
try:
ret = self.run("cli", "mower-ng", {"command": command, "path": path})
if command == "launch" and ret == "success":
self.run("cli", "mower-ng", {"command": "webui", "path": path})
except Exception as e:
custom_event(LogType.error, f"{cli_command[command]} 失败 {repr(e)}")
def batch_cli_control(self, command):
checked_instances = [
instance for instance in config.conf.instances if instance.checked
]
if not checked_instances:
custom_event(LogType.warning, "没有选中的实例")
return [{"status": False, "message": "No checked instances"}]
for instance in checked_instances:
try:
custom_event(LogType.info, f"{instance.name} {cli_command[command]}")
self.cli_control(command, instance.path)
custom_event(
LogType.info, f"{instance.name} {cli_command[command]} 完成"
)
except Exception as e:
custom_event(
LogType.error,
f"{instance.name} {cli_command[command]} 失败 {repr(e)}",
)

View file

@ -89,35 +89,34 @@ provide('new_version', new_version)
<n-spin v-if="loading" class="container">
<template #description>加载中</template>
</n-spin>
<n-notification-provider v-else>
<n-tabs
type="card"
placement="left"
class="container"
v-model:value="conf.page"
@update:value="set_page"
justify-content="center"
>
<n-tab-pane :disabled="running" name="init" tab="初始化"><init /></n-tab-pane>
<n-tab-pane :disabled="running" name="update" tab="更新代码"><update /></n-tab-pane>
<n-tab-pane :disabled="running" name="launch" tab="启动程序"><launch /></n-tab-pane>
<n-tab-pane :disabled="running" name="fix" tab="依赖修复"><fix /></n-tab-pane>
<n-tab-pane :disabled="running" name="settings">
<template #tab>
<div class="tab-content">
<span>设置</span>
<n-tag v-if="update_able" class="tag" round type="success"></n-tag>
</div>
</template>
<settings />
</n-tab-pane>
<template #suffix>
<div class="suffix-container">
<n-button type="primary" secondary size="small" @click="show_doc">帮助文档</n-button>
<n-tabs
type="card"
placement="left"
class="container"
v-model:value="conf.page"
@update:value="set_page"
justify-content="center"
v-else
>
<n-tab-pane :disabled="running" name="init" tab="初始化"><init /></n-tab-pane>
<n-tab-pane :disabled="running" name="update" tab="更新代码"><update /></n-tab-pane>
<n-tab-pane :disabled="running" name="launch" tab="启动程序"><launch /></n-tab-pane>
<n-tab-pane :disabled="running" name="fix" tab="依赖修复"><fix /></n-tab-pane>
<n-tab-pane :disabled="running" name="settings">
<template #tab>
<div class="tab-content">
<span>设置</span>
<n-tag v-if="update_able" class="tag" round type="success"></n-tag>
</div>
</template>
</n-tabs>
</n-notification-provider>
<settings />
</n-tab-pane>
<template #suffix>
<div class="suffix-container">
<n-button type="primary" secondary size="small" @click="show_doc">帮助文档</n-button>
</div>
</template>
</n-tabs>
<n-global-style />
</n-config-provider>
</template>

View file

@ -0,0 +1,30 @@
<script setup>
import { form_item_label_style } from '@/styles/styles.js'
import { useConfigStore } from '@/stores/config.js'
const conf = useConfigStore().config
const running = inject('running')
async function test_connect() {
running.value = true
await pywebview.api.test_base_url_connect()
running.value = false
}
</script>
<template>
<n-form-item label="镜像模式" :label-style="form_item_label_style">
<n-radio-group v-model:value="conf.base_mirror" :disabled="running">
<n-flex>
<n-radio value="0">默认模式</n-radio>
<n-radio value="1">镜像模式-cf后缀</n-radio>
</n-flex>
</n-radio-group>
<n-button strong secondary type="primary" size="small" @click="test_connect" :disabled="running"
>测试连接</n-button
>
</n-form-item>
</template>
<style scoped></style>

View file

@ -1,6 +1,7 @@
<script setup>
import PlayIcon from '@vicons/ionicons5/Play'
import { inject } from 'vue'
import { notify } from '@/utils/naiveDiscrete.js'
const running = inject('running')
const log = inject('log')
@ -8,8 +9,6 @@ const steps = inject('steps')
const current_step = inject('current_step')
const current_state = inject('current_state')
const notification = useNotification()
async function start() {
log.value = []
running.value = true
@ -20,22 +19,14 @@ async function start() {
if ((await pywebview.api.run(cmd, step.cwd)) == 'failed') {
current_state.value = 'error'
running.value = false
notification['error']({
content: '错误',
meta: '命令运行失败',
duration: 3000
})
notify.error('命令运行失败')
return
}
}
}
current_state.value = 'finish'
running.value = false
notification['info']({
content: '提示',
meta: '命令运行完成',
duration: 3000
})
notify.info('命令运行完成')
}
</script>

View file

@ -1,4 +1,3 @@
import 'vfonts/Lato.css'
import 'vfonts/FiraCode.css'
import './styles/global.css'

View file

@ -1,26 +1,15 @@
<script setup>
import { notify } from '@/utils/naiveDiscrete.js'
const running = inject('running')
const notification = useNotification()
async function rm_site_packages_and_python_scripts() {
running.value = true
notification['info']({
content: '提示',
meta: '开始移除site-packages和python/Script目录',
duration: 3000
})
notify.info('开始移除site-packages和python/Script目录')
const response = await pywebview.api.rm_site_packages()
notification['info']({
content: '提示',
meta: response,
duration: 3000
})
notify.info(response)
const response2 = await pywebview.api.rm_python_scripts()
notification['info']({
content: '提示',
meta: response2,
duration: 3000
})
notify.info(response2)
running.value = false
}
</script>

View file

@ -1,4 +1,6 @@
<script setup>
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
const steps = ref([
{
title: '下载 git、python',
@ -22,6 +24,9 @@ provide('current_state', current_state)
<template>
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
<base-mirror-option />
</n-form>
<n-alert title="以下步骤仅需运行一次" type="warning" />
<n-steps :current="current_step" :status="current_state" size="small">
<n-step v-for="step in steps" :title="step.title" />

View file

@ -1,9 +1,18 @@
<script setup>
import { useConfigStore } from '@/stores/config.js'
import { NButton } from 'naive-ui'
import { Add, Pencil, Play, Folder, TrashOutline, Archive } from '@vicons/ionicons5'
const notification = useNotification()
import {
Add,
Pencil,
Play,
Folder,
TrashOutline,
Archive,
Browsers,
Stop,
Search
} from '@vicons/ionicons5'
import { notify } from '@/utils/naiveDiscrete.js'
const config_store = useConfigStore()
const conf = config_store.config
@ -64,13 +73,11 @@ function end_update_instance_name() {
function open_folder(path) {
pywebview.api.open_folder(path)
}
function start_instance(instance) {
pywebview.api.run('webview', 'mower-ng', {
instance_path: instance.path
})
function cli(command, instance) {
pywebview.api.cli_control(command, instance.path)
}
function start_checked_instance() {
pywebview.api.start_checked_instance()
function batch_cli_control(command) {
pywebview.api.batch_cli_control(command)
}
async function handle_migrate(key) {
if (key == 'default') {
@ -82,17 +89,9 @@ async function handle_migrate(key) {
name: '默认实例',
path: response.data
})
notification['success']({
content: '信息',
meta: response.message,
duration: 3000
})
notify.success(response.message)
} else {
notification['error']({
content: '错误',
meta: response.message,
duration: 3000
})
notify.error(response.message)
}
} else {
const response = await pywebview.api.migrate_instances_config()
@ -102,17 +101,9 @@ async function handle_migrate(key) {
conf.instances = [...config_store.config.instances]
}
if (response.status) {
notification['info']({
title: '信息',
content: response.message,
duration: 3000
})
notify.info(response.message)
} else {
notification['error']({
title: '错误',
content: response.message,
duration: 3000
})
notify.error(response.message)
}
}
}
@ -132,7 +123,7 @@ async function handle_migrate(key) {
class="launch-btn"
type="primary"
secondary
@click="start_checked_instance"
@click="batch_cli_control('launch')"
:disabled="!check_all && !check_part"
>
<template #icon>
@ -140,6 +131,18 @@ async function handle_migrate(key) {
</template>
启动所选实例
</n-button>
<n-button
class="launch-btn"
type="error"
secondary
@click="batch_cli_control('exit')"
:disabled="!check_all && !check_part"
>
<template #icon>
<n-icon :component="Stop"></n-icon>
</template>
停止所选实例
</n-button>
<n-dropdown trigger="click" :options="migrate_options" @select="handle_migrate">
<n-button class="launch-btn" type="primary" secondary>
<template #icon>
@ -155,8 +158,8 @@ async function handle_migrate(key) {
显示日志
</div>
</n-space>
<n-list class="instance-list" bordered>
<n-list-item>
<n-list class="instance_list" bordered>
<n-list-item class="instance_list_item">
<template #prefix>
<n-checkbox
v-model:checked="check_all"
@ -167,38 +170,55 @@ async function handle_migrate(key) {
>
</template>
</n-list-item>
<n-list-item v-for="(item, index) in conf.instances" :key="index">
<n-list-item class="instance_list_item" v-for="(item, index) in conf.instances" :key="index">
<template #prefix>
<n-checkbox v-model:checked="item.checked"></n-checkbox>
</template>
<n-space vertical>
<n-space v-if="update_instance_name_index != index">
<n-text>{{ item.name }}</n-text>
<n-text class="instance_name">{{ item.name }}</n-text>
<n-button size="tiny" @click="start_update_instance_name(index)">
<template #icon>
<n-icon :component="Pencil"></n-icon>
</template>
</n-button>
<n-button @click="open_folder(item.path)" size="tiny">
<template #icon>
<n-icon :component="Folder"></n-icon>
</template>
</n-button>
</n-space>
<n-input
v-else
class="instance_name_input"
:ref="(el) => setInstanceNameInputRef(el, index)"
v-model:value="item.name"
@blur="end_update_instance_name"
clearable
></n-input>
</n-space>
<template #suffix>
<n-space :wrap="false">
<n-button type="primary" size="small" @click="start_instance(item)">
<n-button type="primary" ghost size="small" @click="cli('status', item)">
<template #icon>
<n-icon :component="Search"></n-icon>
</template>
</n-button>
<n-button type="primary" size="small" @click="cli('launch', item)">
<template #icon>
<n-icon :component="Play"></n-icon>
</template>
</n-button>
<n-button type="primary" ghost size="small" @click="cli('webui', item)">
<template #icon>
<n-icon :component="Browsers"></n-icon>
</template>
</n-button>
<n-button type="error" ghost size="small" @click="cli('exit', item)">
<template #icon>
<n-icon :component="Stop"></n-icon>
</template>
</n-button>
<n-button type="primary" ghost size="small" @click="open_folder(item.path)">
<template #icon>
<n-icon :component="Folder"></n-icon>
</template>
</n-button>
<n-popconfirm @positive-click="delete_instance(index, item.path)">
<template #trigger>
<n-button type="error" ghost size="small">
@ -221,9 +241,18 @@ async function handle_migrate(key) {
.launch-btn {
height: 38px;
}
.instance-list {
.instance_list {
overflow: auto;
}
.instance_list_item {
height: 50px;
}
.instance_name {
margin-left: 12px;
}
.instance_name_input {
height: 35px;
}
.log {
min-height: 40vh;
max-height: 40vh;
@ -234,5 +263,6 @@ async function handle_migrate(key) {
}
.is_show_log_switch {
margin-right: 20px;
text-align: center;
}
</style>

View file

@ -1,8 +1,8 @@
<script setup>
import { SyncCircle } from '@vicons/ionicons5'
import { Sync } from '@vicons/ionicons5'
import { form_item_label_style } from '@/styles/styles.js'
const notification = useNotification()
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
import { notify } from '@/utils/naiveDiscrete.js'
const update_able = inject('update_able')
const running = inject('running')
@ -18,11 +18,7 @@ async function update_self() {
const response = await pywebview.api.update_self(
new_version.value['assets'][0]['browser_download_url']
)
notification['error']({
content: '错误',
meta: response,
duration: 3000
})
notify.error(response)
update_self_running.value = false
running.value = false
}
@ -37,18 +33,10 @@ async function check_update() {
new_version.value = await pywebview.api.get_new_version()
if (new_version.value.tag_name > version.value) {
update_able.value = true
notification['info']({
content: '提示',
meta: '有新版本可更新',
duration: 3000
})
notify.info('有新版本可更新')
} else {
update_able.value = false
notification['info']({
content: '提示',
meta: '当前已是最新版本',
duration: 3000
})
notify.info('当前已是最新版本')
}
check_running.value = false
running.value = false
@ -58,17 +46,20 @@ async function check_update() {
<template>
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
<base-mirror-option />
<n-form-item label="版本" :label-style="form_item_label_style">
<n-space align="center">
{{ version }}
<n-button
type="success"
secondary
size="small"
:loading="check_running"
:disabled="running"
@click="check_update"
>
<template #icon>
<n-icon :component="SyncCircle"></n-icon>
<n-icon :component="Sync"></n-icon>
</template>
检查更新
</n-button>
@ -77,11 +68,14 @@ async function check_update() {
<n-alert style="margin: 8px 0" type="success" v-if="update_able">
<template #header>
最新版本{{ `${new_version.tag_name} ${new_version.name}` }}
<n-button style="float: right" @click="open_new_version_html">了解此版本</n-button>
<n-button type="success" secondary style="float: right" @click="open_new_version_html">
了解此版本
</n-button>
</template>
<n-space>
<n-button
type="success"
secondary
:loading="update_self_running"
:disabled="running"
@click="update_self"

View file

@ -1,15 +1,17 @@
<script setup>
import { useConfigStore } from '@/stores/config.js'
import { form_item_label_style } from '@/styles/styles.js'
import BaseMirrorOption from '@/components/BaseMirrorOption.vue'
const conf = useConfigStore().config
const branch = ref(null)
const mirror = ref(null)
const running = inject('running')
const steps = computed(() => [
{
title: '更新源码',
command: ['fetch', 'switch', 'reset'],
command: ['set_remote', 'set_lfs', 'fetch', 'switch', 'reset'],
cwd: 'mower-ng'
},
{
@ -18,6 +20,28 @@ const steps = computed(() => [
cwd: 'mower-ng'
}
])
const mirror_options = [
{
label: 'PyPI',
value: 'pypi'
},
{
label: '阿里云镜像源',
value: 'aliyun'
},
{
label: '上海交通大学镜像源',
value: 'sjtu'
},
{
label: '清华大学镜像源',
value: 'tuna'
},
{
label: '中国科学技术大学镜像源',
value: 'ustc'
}
]
provide('steps', steps)
const current_step = ref(1)
provide('current_step', current_step)
@ -28,8 +52,9 @@ provide('current_state', current_state)
<template>
<n-flex vertical style="gap: 16px; height: 100%; padding: 16px; box-sizing: border-box">
<n-form label-placement="left" :show-feedback="false" label-width="auto" label-align="left">
<base-mirror-option />
<n-form-item label="mower-ng 代码分支" :label-style="form_item_label_style">
<n-radio-group v-model:value="conf.branch">
<n-radio-group v-model:value="conf.branch" :disabled="running">
<n-flex>
<n-radio value="fast">测试版</n-radio>
<n-radio value="slow">稳定版</n-radio>
@ -37,14 +62,7 @@ provide('current_state', current_state)
</n-radio-group>
</n-form-item>
<n-form-item label="PyPI 仓库镜像" :label-style="form_item_label_style">
<n-radio-group v-model:value="conf.mirror">
<n-flex>
<n-radio value="pypi">PyPI</n-radio>
<n-radio value="aliyun">阿里云镜像站</n-radio>
<n-radio value="sjtu">上海交通大学镜像站</n-radio>
<n-radio value="tuna">清华大学镜像站</n-radio>
</n-flex>
</n-radio-group>
<n-select v-model:value="conf.mirror" :options="mirror_options" :disabled="running" />
</n-form-item>
</n-form>
<n-steps :current="current_step" :status="current_state" size="small">

View file

@ -20,6 +20,8 @@ export const useConfigStore = defineStore('config', () => {
// 启动程序 LaunchPart
this.instances = []
this.is_show_log = conf.is_show_log
// 其他部分 OtherPart
this.base_mirror = conf.base_mirror
Object.assign(this, conf)
}
}

View file

@ -0,0 +1,63 @@
import { createDiscreteApi, darkTheme, lightTheme } from 'naive-ui'
// 创建全局单例
const { message, dialog, notification, loadingBar } = createDiscreteApi(
['message', 'dialog', 'notification', 'loadingBar'],
{
configProviderProps: {
// 全局主题配置(示例使用系统主题)
theme: window.matchMedia('(prefers-color-scheme: dark)').matches ? darkTheme : lightTheme
}
}
)
// 创建统一的工厂函数
const createMessager =
(handler, defaults) =>
(content, options = {}) => {
const mergedOptions =
typeof content === 'string'
? { content, ...defaults, ...options }
: { ...defaults, ...content, ...options }
return handler(mergedOptions)
}
// 消息提示封装
export const toast = {
info: createMessager((opts) => message.info(opts.content, opts), { duration: 3000 }),
success: createMessager((opts) => message.success(opts.content, opts), { duration: 3000 }),
warning: createMessager((opts) => message.warning(opts.content, opts), { duration: 5000 }),
error: createMessager((opts) => message.error(opts.content, opts), { duration: 7000 })
}
// 通知封装
export const notify = {
info: createMessager(notification.info, { title: '提示', duration: 3000 }),
success: createMessager(notification.success, { title: '成功', duration: 3000 }),
warning: createMessager(notification.warning, { title: '警告', duration: 5000 }),
error: createMessager(notification.error, { title: '错误', duration: 7000 })
}
// 对话框封装
export const modal = {
info: (options) => dialog.info(options),
success: (options) => dialog.success(options),
warning: (options) => dialog.warning(options),
error: (options) => dialog.error(options),
confirm: (options) => dialog.confirm(options)
}
// 加载条控制器
export const loader = {
start: () => loadingBar.start(),
finish: () => loadingBar.finish(),
error: () => loadingBar.error(),
setProgress: (progress) => loadingBar.setProgress(progress)
}