refactor: 统一所有页面按钮文案,合并上传逻辑到保存
1. Sites.vue: '保存' → '保存预览版' 2. SitePages.vue: '保存' → '保存预览版',移除上传按钮和uploadPages函数 3. AccessResultCheck.vue: 两处'保存' → '保存预览版' 4. SitePagesController: savePages/saveDefaultPages 直接包含CDN上传,移除 /upload 端点
This commit is contained in:
@@ -73,6 +73,15 @@ public class SitePagesController {
|
|||||||
String authType = (String) payload.get("authType");
|
String authType = (String) payload.get("authType");
|
||||||
String authValue = (String) payload.get("authValue");
|
String authValue = (String) payload.get("authValue");
|
||||||
sitePagesService.savePages(siteId, entries, authType, authValue);
|
sitePagesService.savePages(siteId, entries, authType, authValue);
|
||||||
|
try {
|
||||||
|
Map<String, Object> config = new LinkedHashMap<>();
|
||||||
|
config.put("siteId", siteId);
|
||||||
|
if (authType != null) config.put("authType", authType);
|
||||||
|
if (authValue != null) config.put("authValue", authValue);
|
||||||
|
config.put("entries", entries);
|
||||||
|
storageService.store("pages/site/" + siteId + ".json",
|
||||||
|
new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(config));
|
||||||
|
} catch (Exception ignored) {}
|
||||||
return ApiResponse.success();
|
return ApiResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,47 +279,13 @@ public class SitePagesController {
|
|||||||
var entries = (List<Map<String, Object>>) payload.get("entries");
|
var entries = (List<Map<String, Object>>) payload.get("entries");
|
||||||
String authType = (String) payload.get("authType");
|
String authType = (String) payload.get("authType");
|
||||||
String authValue = (String) payload.get("authValue");
|
String authValue = (String) payload.get("authValue");
|
||||||
sitePagesService.savePages("default:" + type, entries != null ? entries : List.of(), authType, authValue);
|
if (entries == null) entries = List.of();
|
||||||
|
sitePagesService.savePages("default:" + type, entries, authType, authValue);
|
||||||
|
try { storageService.store("pages/default/" + type + ".json",
|
||||||
|
new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(entries)); } catch (Exception ignored) {}
|
||||||
return ApiResponse.success();
|
return ApiResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 发布默认页面模板到云存储 */
|
|
||||||
@PutMapping("/api/v1/admin/default-pages/{type}/upload")
|
|
||||||
public ApiResponse<Void> uploadDefaultPages(
|
|
||||||
@PathVariable String type, @RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
|
||||||
checkAdmin(request);
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
var entries = (List<Map<String, Object>>) payload.get("entries");
|
|
||||||
sitePagesService.savePages("default:" + type, entries != null ? entries : List.of());
|
|
||||||
try {
|
|
||||||
String json = entries != null
|
|
||||||
? new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(entries) : "[]";
|
|
||||||
storageService.store("pages/default/" + type + ".json", json);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
return ApiResponse.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 发布普通站点页面配置到云存储 */
|
|
||||||
@PutMapping("/api/v1/admin/site-pages/{siteId}/upload")
|
|
||||||
public ApiResponse<Void> uploadSitePages(
|
|
||||||
@PathVariable String siteId, @RequestBody Map<String, Object> payload, HttpServletRequest request) {
|
|
||||||
checkAdmin(request);
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
var entries = (List<Map<String, Object>>) payload.get("entries");
|
|
||||||
String authType = (String) payload.get("authType");
|
|
||||||
String authValue = (String) payload.get("authValue");
|
|
||||||
sitePagesService.savePages(siteId, entries != null ? entries : List.of(), authType, authValue);
|
|
||||||
try {
|
|
||||||
Map<String, Object> config = new LinkedHashMap<>();
|
|
||||||
config.put("siteId", siteId);
|
|
||||||
if (authType != null) config.put("authType", authType);
|
|
||||||
if (authValue != null) config.put("authValue", authValue);
|
|
||||||
config.put("entries", entries != null ? entries : List.of());
|
|
||||||
String json = objectMapper.writeValueAsString(config);
|
|
||||||
storageService.store("pages/site/" + siteId + ".json", json);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
return ApiResponse.success();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkAdmin(HttpServletRequest request) {
|
private void checkAdmin(HttpServletRequest request) {
|
||||||
var level = request.getAttribute("trustLevel");
|
var level = request.getAttribute("trustLevel");
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
</el-select>
|
</el-select>
|
||||||
<el-button size="small" @click="revertScript">回滚</el-button>
|
<el-button size="small" @click="revertScript">回滚</el-button>
|
||||||
<el-button v-if="hasUnsavedChanges" size="small" @click="resetScript" type="warning">重置</el-button>
|
<el-button v-if="hasUnsavedChanges" size="small" @click="resetScript" type="warning">重置</el-button>
|
||||||
<el-button size="small" type="primary" @click="savePreview" :loading="savingPreview" v-if="snapshotStatus">保存</el-button>
|
<el-button size="small" type="primary" @click="savePreview" :loading="savingPreview" v-if="snapshotStatus">保存预览版</el-button>
|
||||||
<el-button size="small" type="danger" @click="deleteScript" :loading="deleting">删除</el-button>
|
<el-button size="small" type="danger" @click="deleteScript" :loading="deleting">删除</el-button>
|
||||||
<template v-if="selectedConfig?.status==='pending'">
|
<template v-if="selectedConfig?.status==='pending'">
|
||||||
<el-button size="small" type="success" @click="approveConfig" :loading="approving">通过</el-button>
|
<el-button size="small" type="success" @click="approveConfig" :loading="approving">通过</el-button>
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
<el-button size="small" type="danger" @click="discardDraftSnapshot" :loading="discardingDraft" v-if="snapshotStatus?.draft.exists">丢弃预览版</el-button>
|
<el-button size="small" type="danger" @click="discardDraftSnapshot" :loading="discardingDraft" v-if="snapshotStatus?.draft.exists">丢弃预览版</el-button>
|
||||||
<el-tag v-if="hasUnsavedChanges" size="small" type="danger" effect="dark">未保存</el-tag>
|
<el-tag v-if="hasUnsavedChanges" size="small" type="danger" effect="dark">未保存</el-tag>
|
||||||
</template>
|
</template>
|
||||||
<el-button v-if="!scriptExpanded && selectedConfigId" size="small" type="primary" @click="savePreview" :loading="savingPreview">保存</el-button>
|
<el-button v-if="!scriptExpanded && selectedConfigId" size="small" type="primary" @click="savePreview" :loading="savingPreview">保存预览版</el-button>
|
||||||
</div>
|
</div>
|
||||||
<template v-if="scriptExpanded">
|
<template v-if="scriptExpanded">
|
||||||
<div style="flex:1;min-height:0;border-radius:4px;overflow:hidden">
|
<div style="flex:1;min-height:0;border-radius:4px;overflow:hidden">
|
||||||
|
|||||||
@@ -52,9 +52,10 @@
|
|||||||
<el-tag v-if="hasUnsavedChanges" size="small" type="danger" effect="dark">未保存</el-tag>
|
<el-tag v-if="hasUnsavedChanges" size="small" type="danger" effect="dark">未保存</el-tag>
|
||||||
</div>
|
</div>
|
||||||
<div style="display:flex;gap:8px">
|
<div style="display:flex;gap:8px">
|
||||||
<el-button v-if="!isDefaultEditor && snapshotStatus" size="small" type="primary" @click="savePreview" :loading="savingPreview">保存</el-button>
|
<el-button v-if="!isDefaultEditor && snapshotStatus" size="small" type="primary" @click="savePreview" :loading="savingPreview">保存预览版</el-button>
|
||||||
<el-button v-if="hasUnsavedChanges" size="small" @click="resetEditor" type="warning">重置</el-button>
|
<el-button v-if="hasUnsavedChanges" size="small" @click="resetEditor" type="warning">重置</el-button>
|
||||||
<el-button size="small" @click="uploadPages" :loading="uploading">上传</el-button>
|
|
||||||
|
|
||||||
<el-button v-if="!isDefaultEditor && snapshotStatus?.draft.exists" size="small" type="success" @click="publishSnapshot" :loading="publishing">发布正式版</el-button>
|
<el-button v-if="!isDefaultEditor && snapshotStatus?.draft.exists" size="small" type="success" @click="publishSnapshot" :loading="publishing">发布正式版</el-button>
|
||||||
<el-button v-if="!isDefaultEditor && snapshotStatus?.draft.exists" size="small" type="danger" @click="discardDraft" :loading="discardingDraft">丢弃预览版</el-button>
|
<el-button v-if="!isDefaultEditor && snapshotStatus?.draft.exists" size="small" type="danger" @click="discardDraft" :loading="discardingDraft">丢弃预览版</el-button>
|
||||||
<el-button size="small" type="danger" @click="deletePages" :loading="deleting">删除</el-button>
|
<el-button size="small" type="danger" @click="deletePages" :loading="deleting">删除</el-button>
|
||||||
@@ -123,7 +124,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import api from '../api'; import { Refresh } from '@element-plus/icons-vue'
|
import api from '../api'; import { Refresh } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
const loading = ref(false), saving = ref(false), uploading = ref(false), deleting = ref(false), savingPreview = ref(false), publishing = ref(false), discardingDraft = ref(false)
|
const loading = ref(false), saving = ref(false), deleting = ref(false), savingPreview = ref(false), publishing = ref(false), discardingDraft = ref(false)
|
||||||
const sites = ref([]), pagesMap = ref({}), sitesList = ref([])
|
const sites = ref([]), pagesMap = ref({}), sitesList = ref([])
|
||||||
const editSiteId = ref(''), editorJson = ref('{}'), originalJson = ref('')
|
const editSiteId = ref(''), editorJson = ref('{}'), originalJson = ref('')
|
||||||
const snapshotStatus = ref(null)
|
const snapshotStatus = ref(null)
|
||||||
@@ -282,20 +283,6 @@ const deletePages = async () => {
|
|||||||
finally { deleting.value = false }
|
finally { deleting.value = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadPages = async () => {
|
|
||||||
uploading.value = true
|
|
||||||
try {
|
|
||||||
if (editSiteId.value.startsWith('default:')) {
|
|
||||||
const type = editSiteId.value.replace('default:','')
|
|
||||||
await api.raw.put('/admin/default-pages/'+type+'/upload', { entries: parsed.value })
|
|
||||||
} else {
|
|
||||||
await api.raw.put('/admin/site-pages/'+editSiteId.value+'/upload', { entries: parsed.value, authType: authType.value })
|
|
||||||
}
|
|
||||||
ElMessage.success('已上传到云存储')
|
|
||||||
} catch { ElMessage.error('上传失败') }
|
|
||||||
finally { uploading.value = false }
|
|
||||||
}
|
|
||||||
|
|
||||||
const savePages = async () => {
|
const savePages = async () => {
|
||||||
saving.value = true
|
saving.value = true
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
<div style="display:flex;gap:8px">
|
<div style="display:flex;gap:8px">
|
||||||
<el-button size="small" @click="resetEditor" v-if="hasUnsavedChanges" type="warning">重置</el-button>
|
<el-button size="small" @click="resetEditor" v-if="hasUnsavedChanges" type="warning">重置</el-button>
|
||||||
<el-button size="small" @click="editSiteId=''">返回列表</el-button>
|
<el-button size="small" @click="editSiteId=''">返回列表</el-button>
|
||||||
<el-button size="small" type="primary" @click="savePreview" :loading="savingPreview">保存</el-button>
|
<el-button size="small" type="primary" @click="savePreview" :loading="savingPreview">保存预览版</el-button>
|
||||||
<el-button size="small" @click="discardDraft" :loading="discarding" v-if="snapshotStatus?.draft.exists" type="danger">丢弃预览版</el-button>
|
<el-button size="small" @click="discardDraft" :loading="discarding" v-if="snapshotStatus?.draft.exists" type="danger">丢弃预览版</el-button>
|
||||||
<el-button size="small" type="success" @click="publishSite" :loading="publishing">发布正式版</el-button>
|
<el-button size="small" type="success" @click="publishSite" :loading="publishing">发布正式版</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user