1 parent
3af1fc4147
commit
29cfebd620
36 files changed
+2838
-118
No files matched your search
+17
-7
@@ -42,9 +42,15 @@ function attachApiErrorDetails(error) {
|
||||
|
||||
return error
|
||||
}
|
||||
|
||||
function isSetupRequest(config) {
|
||||
const url = String(config?.url || '').split('?')[0]
|
||||
return url === '/api/setup' || url === '/api/v1/setup'
|
||||
}
|
||||
|
||||
http.interceptors.response.use(async (response) => {
|
||||
//响应成功
|
||||
if (response.data.errorNo === 403) {
|
||||
if (response.data.errorNo === 403 && !isSetupRequest(response.config)) {
|
||||
|
||||
await router.replace({
|
||||
path: '/login',
|
||||
@@ -75,12 +81,16 @@ http.interceptors.response.use(async (response) => {
|
||||
message = '请求错误';
|
||||
break;
|
||||
case 403:
|
||||
await router.replace({
|
||||
path: '/login',
|
||||
query: {
|
||||
redirect: router.currentRoute.fullPath
|
||||
}
|
||||
});
|
||||
if (isSetupRequest(error.config)) {
|
||||
message = lang.setup_failed
|
||||
} else {
|
||||
await router.replace({
|
||||
path: '/login',
|
||||
query: {
|
||||
redirect: router.currentRoute.fullPath
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 404:
|
||||
message = '请求地址出错';
|
||||
|
||||
@@ -239,4 +239,60 @@
|
||||
flex: 1;
|
||||
min-width: 120px;
|
||||
}
|
||||
}
|
||||
.panel-desc {
|
||||
margin: 14px 0 0;
|
||||
color: var(--pm-text-secondary);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.migration-source {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.migration-source > div {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
padding: 12px 14px;
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-primary);
|
||||
}
|
||||
.migration-source span {
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.migration-source strong {
|
||||
color: var(--pm-text-primary);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.migration-form {
|
||||
margin-top: 16px;
|
||||
}
|
||||
.migration-form :deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.migration-result-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
.migration-error {
|
||||
color: #b42318;
|
||||
}
|
||||
.restart-services {
|
||||
margin-top: 18px;
|
||||
}
|
||||
.restart-result {
|
||||
margin-top: 16px;
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.migration-source {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.migration-result-heading {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
@@ -53,11 +53,19 @@ export function usePage() {
|
||||
const rollbackConfirmed = ref(false)
|
||||
const rollbackPreview = ref(null)
|
||||
const auditItems = ref([])
|
||||
const databaseConfig = reactive({ type: '', name: '', localRef: '' })
|
||||
const migrationTargetName = ref('')
|
||||
const migrationPreview = ref(null)
|
||||
const migrationToken = ref('')
|
||||
const migrationRecord = ref(null)
|
||||
const restartPreview = ref(null)
|
||||
|
||||
const canWrite = computed(() => globalStatus.hasCapability('config.write_global'))
|
||||
const canRollback = computed(() => globalStatus.hasCapability('config.rollback'))
|
||||
const canAudit = computed(() => globalStatus.hasCapability('audit.read'))
|
||||
const canExportAudit = computed(() => globalStatus.hasCapability('audit.export'))
|
||||
const canMigrate = computed(() => globalStatus.hasCapability('database.migrate'))
|
||||
const canRestart = computed(() => globalStatus.hasCapability('service.restart'))
|
||||
const stateLabel = computed(() => ({ new: '未初始化', bootstrap: '初始化中', ready: '就绪', degraded: '降级' }[status.setupState] || status.setupState || '未知'))
|
||||
const stateTagType = computed(() => ({ ready: 'success', degraded: 'warning', bootstrap: 'info', new: 'danger' }[status.setupState] || 'info'))
|
||||
const secretField = computed(() => {
|
||||
@@ -81,7 +89,26 @@ export function usePage() {
|
||||
const serviceLabel = value => serviceLabels[value] || value
|
||||
const sectionLabel = value => sectionLabels[value] || value || '-'
|
||||
const operationLabel = value => operationLabels[value] || value || '-'
|
||||
|
||||
const migrationStatusLabels = {
|
||||
previewed: '已生成预览',
|
||||
created: '已创建',
|
||||
copying: '复制中',
|
||||
verifying: '校验中',
|
||||
switching: '切换中',
|
||||
succeeded: '已完成',
|
||||
failed: '失败'
|
||||
}
|
||||
const migrationStatusLabel = value => migrationStatusLabels[value] || value || '未知'
|
||||
const migrationStatusType = value => ({
|
||||
previewed: 'info',
|
||||
created: 'info',
|
||||
copying: 'warning',
|
||||
verifying: 'warning',
|
||||
switching: 'warning',
|
||||
succeeded: 'success',
|
||||
failed: 'danger'
|
||||
}[value] || 'info')
|
||||
const databaseTypeLabel = value => ({ mysql: 'MySQL', postgresql: 'PostgreSQL', sqlite: 'SQLite' }[value] || value || '-')
|
||||
const loadStatus = async () => {
|
||||
const response = await http.get('/api/v1/config/status')
|
||||
notifyResponseError(response, '配置状态读取失败')
|
||||
@@ -96,7 +123,12 @@ export function usePage() {
|
||||
try {
|
||||
const response = await http.get(`/api/v1/config/${selectedSection.value}`)
|
||||
notifyResponseError(response, '配置分区读取失败')
|
||||
editorText.value = JSON.stringify(response.data || {}, null, 2)
|
||||
const publicConfig = response.data || {}
|
||||
editorText.value = JSON.stringify(publicConfig, null, 2)
|
||||
if (selectedSection.value === 'base') {
|
||||
const database = publicConfig.database || {}
|
||||
Object.assign(databaseConfig, { type: database.type || '', name: database.name || '', localRef: database.localRef || '' })
|
||||
}
|
||||
} catch (error) {
|
||||
sectionError.value = error.message || '配置分区读取失败'
|
||||
editorText.value = ''
|
||||
@@ -131,6 +163,106 @@ export function usePage() {
|
||||
}
|
||||
}
|
||||
|
||||
const previewDatabaseMigration = async () => {
|
||||
if (!canMigrate.value || !migrationTargetName.value.trim()) return
|
||||
working.value = 'migration-preview'
|
||||
migrationPreview.value = null
|
||||
migrationRecord.value = null
|
||||
migrationToken.value = ''
|
||||
try {
|
||||
const response = await http.post('/api/v1/database/migrations/preview', {
|
||||
targetName: migrationTargetName.value.trim(),
|
||||
expectedGeneration: Number(status.activeGeneration)
|
||||
})
|
||||
notifyResponseError(response, '数据库迁移预览失败')
|
||||
migrationPreview.value = response.data?.migration || null
|
||||
migrationRecord.value = migrationPreview.value
|
||||
migrationToken.value = response.data?.token || ''
|
||||
ElMessage.success('数据库迁移预览已生成,请确认目标名称后执行')
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '数据库迁移预览失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const loadMigrationStatus = async () => {
|
||||
if (!migrationRecord.value?.id) return
|
||||
working.value = 'migration-status'
|
||||
try {
|
||||
const response = await http.get(`/api/v1/database/migrations/${migrationRecord.value.id}`)
|
||||
notifyResponseError(response, '数据库迁移状态读取失败')
|
||||
migrationRecord.value = response.data || migrationRecord.value
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '数据库迁移状态读取失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const executeDatabaseMigration = async () => {
|
||||
if (!migrationPreview.value?.id || !migrationToken.value) return
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'迁移将复制数据库内容并切换配置,旧数据库会保留。确认继续吗?',
|
||||
'确认执行数据库迁移',
|
||||
{ type: 'warning', confirmButtonText: '继续迁移', cancelButtonText: '取消' }
|
||||
)
|
||||
working.value = 'migration-execute'
|
||||
const response = await http.post('/api/v1/database/migrations', {
|
||||
id: migrationPreview.value.id,
|
||||
token: migrationToken.value
|
||||
})
|
||||
notifyResponseError(response, '数据库迁移执行失败')
|
||||
migrationRecord.value = response.data || migrationPreview.value
|
||||
migrationToken.value = ''
|
||||
migrationPreview.value = null
|
||||
await Promise.all([loadStatus(), loadSection()])
|
||||
if (migrationRecord.value.status === 'succeeded') {
|
||||
ElMessage.success('数据库迁移已完成,旧数据库仍然保留')
|
||||
} else {
|
||||
ElMessage.warning(`数据库迁移${migrationStatusLabel(migrationRecord.value.status)}`)
|
||||
}
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(error.message || '数据库迁移执行失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const previewRestart = async () => {
|
||||
if (!canRestart.value) return
|
||||
working.value = 'restart-preview'
|
||||
try {
|
||||
const response = await http.post('/api/v1/system/restart/preview', {})
|
||||
notifyResponseError(response, '重启预览读取失败')
|
||||
restartPreview.value = response.data || null
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '重启预览读取失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const requestRestart = async () => {
|
||||
if (!canRestart.value) return
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'服务将按固定服务管理器重启,当前页面可能会短暂断开。确认继续吗?',
|
||||
'确认重启 Smail',
|
||||
{ type: 'warning', confirmButtonText: '确认重启', cancelButtonText: '取消' }
|
||||
)
|
||||
working.value = 'restart'
|
||||
const response = await http.post('/api/v1/system/restart', {})
|
||||
notifyResponseError(response, '重启请求提交失败')
|
||||
ElMessage.success('重启请求已提交,请等待服务恢复')
|
||||
restartPreview.value = null
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(error.message || '重启请求提交失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
const loadAll = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -299,6 +431,9 @@ export function usePage() {
|
||||
backupsLoading, backups, rollbackGeneration, rollbackConfirmed, rollbackPreview,
|
||||
auditLoading, auditItems, loadAll, loadSection, validateConfig, saveConfig, applyConfig,
|
||||
loadBackups, previewRollback, executeRollback, loadAudit, exportAudit, formatTime,
|
||||
serviceLabel, sectionLabel, operationLabel
|
||||
serviceLabel, sectionLabel, operationLabel, databaseConfig, databaseTypeLabel, canMigrate,
|
||||
migrationTargetName, migrationPreview, migrationRecord, migrationStatusLabel, migrationStatusType,
|
||||
previewDatabaseMigration, loadMigrationStatus, executeDatabaseMigration, canRestart, restartPreview,
|
||||
previewRestart, requestRestart
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,78 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="canMigrate" class="migration-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<span class="section-eyebrow">数据库迁移</span>
|
||||
<h4>安全迁移数据库</h4>
|
||||
</div>
|
||||
<el-tag type="warning" effect="plain">仅允许修改数据库名称</el-tag>
|
||||
</div>
|
||||
<p class="panel-desc">系统会先生成一次性预览票据,再复制并校验数据。主机、端口、用户名和密码保持不变,旧数据库不会自动删除。</p>
|
||||
<div class="migration-source">
|
||||
<div>
|
||||
<span>当前数据库类型</span>
|
||||
<strong>{{ databaseTypeLabel(databaseConfig.type) }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>当前数据库</span>
|
||||
<strong>{{ databaseConfig.type === 'sqlite' ? databaseConfig.localRef || '-' : databaseConfig.name || '-' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<el-form label-position="top" class="migration-form">
|
||||
<el-form-item :label="databaseConfig.type === 'sqlite' ? '目标数据库文件引用' : '目标数据库名称'">
|
||||
<el-input
|
||||
v-model="migrationTargetName"
|
||||
:placeholder="databaseConfig.type === 'sqlite' ? '例如 smail-next.db' : '例如 smail_next'"
|
||||
maxlength="128"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="action-row">
|
||||
<el-button :loading="working === 'migration-preview'" @click="previewDatabaseMigration">生成迁移预览</el-button>
|
||||
<el-button type="primary" :loading="working === 'migration-execute'" :disabled="!migrationPreview || !migrationToken" @click="executeDatabaseMigration">
|
||||
执行迁移
|
||||
</el-button>
|
||||
<el-button v-if="migrationRecord?.id" plain :loading="working === 'migration-status'" @click="loadMigrationStatus">刷新迁移状态</el-button>
|
||||
</div>
|
||||
<div v-if="migrationRecord" class="preview-box migration-result">
|
||||
<div class="migration-result-heading">
|
||||
<strong>迁移状态</strong>
|
||||
<el-tag :type="migrationStatusType(migrationRecord.status)" effect="plain">{{ migrationStatusLabel(migrationRecord.status) }}</el-tag>
|
||||
</div>
|
||||
<span>迁移编号:{{ migrationRecord.id }}</span>
|
||||
<span>源数据库:{{ migrationRecord.source?.name || migrationRecord.source?.localRef || '-' }}</span>
|
||||
<span>目标数据库:{{ migrationRecord.target?.name || migrationRecord.target?.localRef || '-' }}</span>
|
||||
<span v-if="migrationRecord.errorCode" class="migration-error">错误代码:{{ migrationRecord.errorCode }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="canRestart && status.pendingRestart?.length" class="restart-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
<span class="section-eyebrow">受控重启</span>
|
||||
<h4>应用待重启服务</h4>
|
||||
</div>
|
||||
<el-tag type="warning" effect="plain">固定目标:Smail</el-tag>
|
||||
</div>
|
||||
<p class="panel-desc">配置变更需要重启时,只能通过固定的 Smail 服务管理器提交请求,不接受外部命令、服务名或参数。</p>
|
||||
<div class="tag-list restart-services">
|
||||
<el-tag v-for="service in status.pendingRestart" :key="service" type="warning">{{ serviceLabel(service) }}</el-tag>
|
||||
</div>
|
||||
<div class="action-row">
|
||||
<el-button :loading="working === 'restart-preview'" @click="previewRestart">查看重启预览</el-button>
|
||||
<el-button type="danger" :loading="working === 'restart'" :disabled="!restartPreview?.triggerAvailable" @click="requestRestart">提交重启请求</el-button>
|
||||
</div>
|
||||
<div v-if="restartPreview" class="preview-box restart-result">
|
||||
<strong>重启预览</strong>
|
||||
<span>目标:{{ restartPreview.target }} · 操作:{{ restartPreview.action }}</span>
|
||||
<span>服务管理器:{{ restartPreview.serviceManager }}</span>
|
||||
<span>{{ restartPreview.triggerAvailable ? '重启通道可用' : '重启通道暂不可用,请先检查服务部署' }}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-if="canRollback" class="rollback-panel">
|
||||
<div class="panel-heading">
|
||||
<div>
|
||||
@@ -218,12 +290,28 @@ const {
|
||||
rollbackPreview,
|
||||
auditLoading,
|
||||
auditItems,
|
||||
databaseConfig,
|
||||
migrationTargetName,
|
||||
migrationPreview,
|
||||
migrationToken,
|
||||
migrationRecord,
|
||||
migrationStatusLabel,
|
||||
migrationStatusType,
|
||||
databaseTypeLabel,
|
||||
canMigrate,
|
||||
canRestart,
|
||||
restartPreview,
|
||||
loadAll,
|
||||
loadSection,
|
||||
validateConfig,
|
||||
saveConfig,
|
||||
applyConfig,
|
||||
loadBackups,
|
||||
previewDatabaseMigration,
|
||||
loadMigrationStatus,
|
||||
executeDatabaseMigration,
|
||||
previewRestart,
|
||||
requestRestart,
|
||||
previewRollback,
|
||||
executeRollback,
|
||||
loadAudit,
|
||||
|
||||
Reference in new issue
Block a user