feat: 初步完成调度台适配
This commit is contained in:
@@ -37,24 +37,24 @@
|
||||
type="primary"
|
||||
ghost
|
||||
size="middle"
|
||||
@click="handleMAAConfig(script)"
|
||||
@click="handleStartMAAConfig(script)"
|
||||
>
|
||||
<template #icon>
|
||||
<SettingOutlined />
|
||||
</template>
|
||||
设置MAA全局配置
|
||||
配置MAA
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="script.type === 'MAA' && props.activeConnections.has(script.id)"
|
||||
type="primary"
|
||||
danger
|
||||
size="middle"
|
||||
@click="handleDisconnectMAA(script)"
|
||||
style="background: #52c41a; border-color: #52c41a;"
|
||||
@click="handleSaveMAAConfig(script)"
|
||||
>
|
||||
<template #icon>
|
||||
<StopOutlined />
|
||||
<SaveOutlined />
|
||||
</template>
|
||||
断开配置连接
|
||||
保存配置
|
||||
</a-button>
|
||||
<a-button type="default" size="middle" @click="handleEdit(script)">
|
||||
<template #icon>
|
||||
@@ -291,8 +291,8 @@ import type { Script, User } from '../types/script'
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
SaveOutlined,
|
||||
SettingOutlined,
|
||||
StopOutlined,
|
||||
UserAddOutlined,
|
||||
} from '@ant-design/icons-vue'
|
||||
|
||||
@@ -312,9 +312,9 @@ interface Emits {
|
||||
|
||||
(e: 'deleteUser', user: User): void
|
||||
|
||||
(e: 'maaConfig', script: Script): void
|
||||
(e: 'startMaaConfig', script: Script): void
|
||||
|
||||
(e: 'disconnectMaa', script: Script): void
|
||||
(e: 'saveMaaConfig', script: Script): void
|
||||
|
||||
(e: 'toggleUserStatus', user: User): void
|
||||
}
|
||||
@@ -350,12 +350,12 @@ const handleDeleteUser = (user: User) => {
|
||||
emit('deleteUser', user)
|
||||
}
|
||||
|
||||
const handleMAAConfig = (script: Script) => {
|
||||
emit('maaConfig', script)
|
||||
const handleStartMAAConfig = (script: Script) => {
|
||||
emit('startMaaConfig', script)
|
||||
}
|
||||
|
||||
const handleDisconnectMAA = (script: Script) => {
|
||||
emit('disconnectMaa', script)
|
||||
const handleSaveMAAConfig = (script: Script) => {
|
||||
emit('saveMaaConfig', script)
|
||||
}
|
||||
|
||||
const handleToggleUserStatus = (user: User) => {
|
||||
|
||||
@@ -17,18 +17,32 @@
|
||||
</div>
|
||||
|
||||
<a-space size="middle">
|
||||
<!-- MAA配置按钮组 -->
|
||||
<a-button
|
||||
v-if="formData.Info.Mode !== '简洁'"
|
||||
v-if="formData.Info.Mode !== '简洁' && !maaWebsocketId"
|
||||
type="primary"
|
||||
ghost
|
||||
size="large"
|
||||
@click="handleMAAConfig"
|
||||
@click="handleStartMAAConfig"
|
||||
:loading="maaConfigLoading"
|
||||
>
|
||||
<template #icon>
|
||||
<SettingOutlined />
|
||||
</template>
|
||||
MAA配置
|
||||
配置MAA
|
||||
</a-button>
|
||||
<a-button
|
||||
v-if="formData.Info.Mode !== '简洁' && maaWebsocketId"
|
||||
type="primary"
|
||||
size="large"
|
||||
@click="handleSaveMAAConfig"
|
||||
:loading="maaConfigLoading"
|
||||
style="background: #52c41a; border-color: #52c41a;"
|
||||
>
|
||||
<template #icon>
|
||||
<SaveOutlined />
|
||||
</template>
|
||||
保存配置
|
||||
</a-button>
|
||||
<a-button size="large" @click="handleCancel" class="cancel-button">
|
||||
<template #icon>
|
||||
@@ -973,6 +987,7 @@ import { usePlanApi } from '@/composables/usePlanApi'
|
||||
import { useWebSocket } from '@/composables/useWebSocket'
|
||||
import { Service } from '@/api'
|
||||
import { GetStageIn } from '@/api/models/GetStageIn'
|
||||
import { TaskCreateIn } from '@/api/models/TaskCreateIn'
|
||||
import { defineComponent } from 'vue'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -1235,9 +1250,9 @@ const getDefaultMAAUserData = () => ({
|
||||
Data: {
|
||||
CustomInfrastPlanIndex: '',
|
||||
IfPassCheck: false,
|
||||
LastAnnihilationDate: '',
|
||||
LastProxyDate: '',
|
||||
LastSklandDate: '',
|
||||
LastAnnihilationDate: '2000-01-01',
|
||||
LastProxyDate: '2000-01-01',
|
||||
LastSklandDate: '2000-01-01',
|
||||
ProxyTimes: 0,
|
||||
},
|
||||
})
|
||||
@@ -1532,36 +1547,95 @@ const handleSubmit = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleMAAConfig = async () => {
|
||||
const handleStartMAAConfig = async () => {
|
||||
if (!isEdit.value) {
|
||||
message.warning('请先保存用户后再进行MAA配置')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
maaConfigLoading.value = true
|
||||
|
||||
// 如果已有连接,先断开
|
||||
// 检查是否已有连接
|
||||
if (maaWebsocketId.value) {
|
||||
unsubscribe(maaWebsocketId.value)
|
||||
maaWebsocketId.value = null
|
||||
message.warning('该用户MAA配置已在进行中,请先保存配置')
|
||||
return
|
||||
}
|
||||
|
||||
// 直接订阅(旧 connect 参数移除)
|
||||
const subId = userId
|
||||
subscribe(subId, {
|
||||
onError: error => {
|
||||
console.error(`用户 ${formData.userName} MAA配置错误:`, error)
|
||||
message.error(`MAA配置连接失败: ${error}`)
|
||||
maaWebsocketId.value = null
|
||||
}
|
||||
maaConfigLoading.value = true
|
||||
|
||||
// 调用启动配置任务API
|
||||
const response = await Service.addTaskApiDispatchStartPost({
|
||||
taskId: userId,
|
||||
mode: TaskCreateIn.mode.SettingScriptMode
|
||||
})
|
||||
|
||||
maaWebsocketId.value = subId
|
||||
message.success(`已开始配置用户 ${formData.userName} 的MAA设置`)
|
||||
if (response.code === 200) {
|
||||
// 订阅WebSocket消息
|
||||
subscribe(response.websocketId, {
|
||||
onError: error => {
|
||||
console.error(`用户 ${formData.userName} MAA配置错误:`, error)
|
||||
message.error(`MAA配置连接失败: ${error}`)
|
||||
maaWebsocketId.value = null
|
||||
},
|
||||
onResult: (data: any) => {
|
||||
// 处理配置完成消息(兼容任何结构)
|
||||
if (data.Accomplish) {
|
||||
message.success(`用户 ${formData.userName} MAA配置已完成`)
|
||||
maaWebsocketId.value = null
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 记录连接和websocketId
|
||||
maaWebsocketId.value = response.websocketId
|
||||
message.success(`已启动用户 ${formData.userName} 的MAA配置`)
|
||||
|
||||
// 设置自动断开连接的定时器(30分钟后)
|
||||
setTimeout(
|
||||
() => {
|
||||
if (maaWebsocketId.value) {
|
||||
unsubscribe(maaWebsocketId.value)
|
||||
maaWebsocketId.value = null
|
||||
message.info(`用户 ${formData.userName} MAA配置会话已超时断开`)
|
||||
}
|
||||
},
|
||||
30 * 60 * 1000
|
||||
) // 30分钟
|
||||
} else {
|
||||
message.error(response.message || '启动MAA配置失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('MAA配置失败:', error)
|
||||
message.error('MAA配置失败')
|
||||
console.error('启动MAA配置失败:', error)
|
||||
message.error('启动MAA配置失败')
|
||||
} finally {
|
||||
maaConfigLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleSaveMAAConfig = async () => {
|
||||
try {
|
||||
if (!maaWebsocketId.value) {
|
||||
message.error('未找到活动的配置会话')
|
||||
return
|
||||
}
|
||||
|
||||
maaConfigLoading.value = true
|
||||
|
||||
// 调用停止配置任务API
|
||||
const response = await Service.stopTaskApiDispatchStopPost({
|
||||
taskId: maaWebsocketId.value
|
||||
})
|
||||
|
||||
if (response.code === 200) {
|
||||
// 取消订阅
|
||||
unsubscribe(maaWebsocketId.value)
|
||||
maaWebsocketId.value = null
|
||||
message.success(`用户 ${formData.userName} 的MAA配置已保存`)
|
||||
} else {
|
||||
message.error(response.message || '保存配置失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存MAA配置失败:', error)
|
||||
message.error('保存MAA配置失败')
|
||||
} finally {
|
||||
maaConfigLoading.value = false
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,8 +40,8 @@
|
||||
@add-user="handleAddUser"
|
||||
@edit-user="handleEditUser"
|
||||
@delete-user="handleDeleteUser"
|
||||
@maa-config="handleMAAConfig"
|
||||
@disconnect-maa="handleDisconnectMAA"
|
||||
@start-maa-config="handleStartMAAConfig"
|
||||
@save-maa-config="handleSaveMAAConfig"
|
||||
@toggle-user-status="handleToggleUserStatus"
|
||||
/>
|
||||
|
||||
@@ -232,6 +232,8 @@ import { useScriptApi } from '@/composables/useScriptApi'
|
||||
import { useUserApi } from '@/composables/useUserApi'
|
||||
import { useWebSocket } from '@/composables/useWebSocket'
|
||||
import { useTemplateApi, type WebConfigTemplate } from '@/composables/useTemplateApi'
|
||||
import { Service } from '@/api/services/Service'
|
||||
import { TaskCreateIn } from '@/api/models/TaskCreateIn'
|
||||
import MarkdownIt from 'markdown-it'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -494,51 +496,89 @@ const handleDeleteUser = async (user: User) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleMAAConfig = async (script: Script) => {
|
||||
const handleStartMAAConfig = async (script: Script) => {
|
||||
try {
|
||||
// 检查是否已有连接
|
||||
const existingConnection = activeConnections.value.get(script.id)
|
||||
if (existingConnection) {
|
||||
message.warning('该脚本已在配置中,请先断开连接')
|
||||
message.warning('该脚本已在配置中,请先保存配置')
|
||||
return
|
||||
}
|
||||
|
||||
// 新订阅
|
||||
subscribe(script.id, {
|
||||
onError: error => {
|
||||
console.error(`脚本 ${script.name} 连接错误:`, error)
|
||||
message.error(`MAA配置连接失败: ${error}`)
|
||||
activeConnections.value.delete(script.id)
|
||||
},
|
||||
// 调用启动配置任务API
|
||||
const response = await Service.addTaskApiDispatchStartPost({
|
||||
taskId: script.id,
|
||||
mode: TaskCreateIn.mode.SettingScriptMode
|
||||
})
|
||||
|
||||
// 记录连接
|
||||
activeConnections.value.set(script.id, script.id)
|
||||
message.success(`已开始配置 ${script.name}`)
|
||||
|
||||
// 可选:设置自动断开连接的定时器(比如30分钟后)
|
||||
setTimeout(
|
||||
() => {
|
||||
if (activeConnections.value.has(script.id)) {
|
||||
unsubscribe(script.id)
|
||||
if (response.code === 200) {
|
||||
// 订阅WebSocket消息
|
||||
subscribe(response.websocketId, {
|
||||
onError: error => {
|
||||
console.error(`脚本 ${script.name} 连接错误:`, error)
|
||||
message.error(`MAA配置连接失败: ${error}`)
|
||||
activeConnections.value.delete(script.id)
|
||||
message.info(`${script.name} 配置会话已超时断开`)
|
||||
},
|
||||
onResult: (data: any) => {
|
||||
// 处理配置完成消息(兼容任何结构)
|
||||
if (data.Accomplish) {
|
||||
message.success(`${script.name} 配置已完成`)
|
||||
activeConnections.value.delete(script.id)
|
||||
}
|
||||
}
|
||||
},
|
||||
30 * 60 * 1000
|
||||
) // 30分钟
|
||||
})
|
||||
|
||||
// 记录连接和websocketId
|
||||
activeConnections.value.set(script.id, response.websocketId)
|
||||
message.success(`已启动 ${script.name} 的MAA配置`)
|
||||
|
||||
// 设置自动断开连接的定时器(30分钟后)
|
||||
setTimeout(
|
||||
() => {
|
||||
if (activeConnections.value.has(script.id)) {
|
||||
const wsId = activeConnections.value.get(script.id)
|
||||
if (wsId) {
|
||||
unsubscribe(wsId)
|
||||
}
|
||||
activeConnections.value.delete(script.id)
|
||||
message.info(`${script.name} 配置会话已超时断开`)
|
||||
}
|
||||
},
|
||||
30 * 60 * 1000
|
||||
) // 30分钟
|
||||
} else {
|
||||
message.error(response.message || '启动MAA配置失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('MAA配置失败:', error)
|
||||
message.error('MAA配置失败')
|
||||
console.error('启动MAA配置失败:', error)
|
||||
message.error('启动MAA配置失败')
|
||||
}
|
||||
}
|
||||
|
||||
const handleDisconnectMAA = (script: Script) => {
|
||||
const connectionId = activeConnections.value.get(script.id)
|
||||
if (connectionId) {
|
||||
unsubscribe(script.id)
|
||||
activeConnections.value.delete(script.id)
|
||||
message.success(`已断开 ${script.name} 的配置连接`)
|
||||
const handleSaveMAAConfig = async (script: Script) => {
|
||||
try {
|
||||
const websocketId = activeConnections.value.get(script.id)
|
||||
if (!websocketId) {
|
||||
message.error('未找到活动的配置会话')
|
||||
return
|
||||
}
|
||||
|
||||
// 调用停止配置任务API
|
||||
const response = await Service.stopTaskApiDispatchStopPost({
|
||||
taskId: websocketId
|
||||
})
|
||||
|
||||
if (response.code === 200) {
|
||||
// 取消订阅
|
||||
unsubscribe(websocketId)
|
||||
activeConnections.value.delete(script.id)
|
||||
message.success(`${script.name} 的配置已保存`)
|
||||
} else {
|
||||
message.error(response.message || '保存配置失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存MAA配置失败:', error)
|
||||
message.error('保存MAA配置失败')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user