feat: 删除站点自定义脚本回退默认模板
This commit is contained in:
@@ -27,6 +27,7 @@ public class ScriptController {
|
||||
private final ConfigService configService;
|
||||
private final CachedStorageService storageService;
|
||||
private final SiteMapper siteMapper;
|
||||
private final com.par.core.mapper.SiteConfigMapper siteConfigMapper;
|
||||
|
||||
/** 下载最新 Groovy 脚本 */
|
||||
@GetMapping("/api/v1/scripts/{siteId}")
|
||||
@@ -57,6 +58,19 @@ public class ScriptController {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
/** 删除站点自定义脚本(回退到默认模板) */
|
||||
@DeleteMapping("/api/v1/admin/configs/{siteId}/script")
|
||||
public ApiResponse<Void> deleteScript(@PathVariable String siteId, HttpServletRequest request) {
|
||||
checkAdmin(request);
|
||||
SiteConfig latest = configService.getLatestConfig(siteId);
|
||||
if (latest == null) return ApiResponse.success();
|
||||
latest.setScriptStoragePath(null);
|
||||
latest.setIsLatest(false);
|
||||
siteConfigMapper.updateById(latest);
|
||||
log.info("Custom script deleted for siteId={}, fallback to default", siteId);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
|
||||
/** 获取脚本版本(自定义脚本优先,否则返回默认模板版本) */
|
||||
@GetMapping("/api/v1/scripts/{siteId}/version")
|
||||
public ApiResponse<Map<String, String>> getVersion(@PathVariable String siteId) {
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
</el-select>
|
||||
<el-button size="small" @click="revertScript">回滚</el-button>
|
||||
<el-button size="small" type="primary" @click="saveScript" :loading="saving">保存</el-button>
|
||||
<el-button size="small" type="danger" @click="deleteScript" :loading="deleting">删除</el-button>
|
||||
<template v-if="selectedConfig?.status==='pending'">
|
||||
<el-button size="small" type="success" @click="approveConfig" :loading="approving">通过</el-button>
|
||||
<el-button size="small" type="danger" @click="rejectConfig" :loading="rejecting">拒绝</el-button>
|
||||
@@ -147,7 +148,7 @@ import { Loading } from '@element-plus/icons-vue'
|
||||
const route = useRoute()
|
||||
const siteId = route.params.siteId
|
||||
|
||||
const loading = ref(false), parseLoading = ref(false), scriptExpanded = ref(true), historyVersion = ref(null), urlFilter = ref('')
|
||||
const loading = ref(false), parseLoading = ref(false), scriptExpanded = ref(true), historyVersion = ref(null), urlFilter = ref(''), deleting = ref(false)
|
||||
const selectedConfigId = ref(null), selectedConfig = ref(null)
|
||||
const scriptContent = ref(''), saving = ref(false), approving = ref(false), rejecting = ref(false)
|
||||
const allConfigVersions = ref([]), allResults = ref([])
|
||||
@@ -297,6 +298,14 @@ const deleteResult = async (page) => {
|
||||
catch { ElMessage.error('删除失败') }
|
||||
}
|
||||
|
||||
const deleteScript = async () => {
|
||||
try { await ElMessageBox.confirm('确认删除自定义脚本?删除后站点将使用默认模板','确认',{type:'warning',confirmButtonText:'确认删除'}) } catch { return }
|
||||
deleting.value = true
|
||||
try { await api.raw.delete('/admin/configs/'+siteId+'/script'); ElMessage.success('已删除,将使用默认模板'); loadConfigs() }
|
||||
catch(e) { ElMessage.error(e.response?.data?.message||'删除失败') }
|
||||
finally { deleting.value = false }
|
||||
}
|
||||
|
||||
const approveConfig = async () => {
|
||||
if (!selectedConfig.value) return
|
||||
const label = selectedConfig.value.status==='pending' ? '确认审批?版本号将自动+1' : '确认发布脚本?版本号将+1'
|
||||
|
||||
Reference in New Issue
Block a user