feat: 页面配置key改为枚举下拉框+自动填method
This commit is contained in:
@@ -91,6 +91,15 @@ public class SitePagesController {
|
|||||||
return ApiResponse.success(Map.of("siteId", siteId, "version", version, "content", content));
|
return ApiResponse.success(Map.of("siteId", siteId, "version", version, "content", content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 获取页面入口 key 枚举列表 */
|
||||||
|
@GetMapping("/api/v1/admin/page-keys")
|
||||||
|
public ApiResponse<List<Map<String, String>>> pageKeys() {
|
||||||
|
var list = java.util.Arrays.stream(com.par.core.enums.PageKey.values())
|
||||||
|
.map(pk -> Map.of("key", pk.getKey(), "label", pk.getLabel(), "defaultMethod", pk.getDefaultMethod()))
|
||||||
|
.toList();
|
||||||
|
return ApiResponse.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/api/v1/admin/default-pages/{type}")
|
@GetMapping("/api/v1/admin/default-pages/{type}")
|
||||||
public ApiResponse<Map<String, Object>> getDefaultPages(@PathVariable String type, HttpServletRequest request) {
|
public ApiResponse<Map<String, Object>> getDefaultPages(@PathVariable String type, HttpServletRequest request) {
|
||||||
checkAdmin(request);
|
checkAdmin(request);
|
||||||
|
|||||||
41
par-core/src/main/java/com/par/core/enums/PageKey.java
Normal file
41
par-core/src/main/java/com/par/core/enums/PageKey.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package com.par.core.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 站点页面入口 key 枚举 — 统一命名,脚本据此分发解析逻辑
|
||||||
|
*/
|
||||||
|
public enum PageKey {
|
||||||
|
SYNC("sync", "同步", "GET"),
|
||||||
|
SIGN_IN("signIn", "签到", "POST"),
|
||||||
|
SEARCH("search", "搜索", "GET"),
|
||||||
|
DETAIL("detail", "资源详情", "GET"),
|
||||||
|
DOWNLOAD("download", "下载", "GET"),
|
||||||
|
USER("user", "用户信息", "GET"),
|
||||||
|
HOME("home", "首页", "GET"),
|
||||||
|
TORRENTS("torrents", "种子列表", "GET"),
|
||||||
|
BONUS("bonus", "魔力值", "GET"),
|
||||||
|
MESSAGES("messages", "消息", "GET");
|
||||||
|
|
||||||
|
private final String key;
|
||||||
|
private final String label;
|
||||||
|
private final String defaultMethod;
|
||||||
|
|
||||||
|
PageKey(String key, String label, String defaultMethod) {
|
||||||
|
this.key = key;
|
||||||
|
this.label = label;
|
||||||
|
this.defaultMethod = defaultMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonValue
|
||||||
|
public String getKey() { return key; }
|
||||||
|
public String getLabel() { return label; }
|
||||||
|
public String getDefaultMethod() { return defaultMethod; }
|
||||||
|
|
||||||
|
public static PageKey fromKey(String key) {
|
||||||
|
for (var pk : values()) {
|
||||||
|
if (pk.key.equalsIgnoreCase(key)) return pk;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,8 +61,12 @@
|
|||||||
<div style="flex:1;overflow:auto;min-height:0">
|
<div style="flex:1;overflow:auto;min-height:0">
|
||||||
<div style="font-size:13px;font-weight:500;margin-bottom:4px">双向可视化</div>
|
<div style="font-size:13px;font-weight:500;margin-bottom:4px">双向可视化</div>
|
||||||
<el-table :data="parsed" stripe border style="font-size:13px" :row-style="{height:'42px'}" v-if="parsed.length">
|
<el-table :data="parsed" stripe border style="font-size:13px" :row-style="{height:'42px'}" v-if="parsed.length">
|
||||||
<el-table-column prop="key" label="key" width="100">
|
<el-table-column prop="key" label="key" width="120">
|
||||||
<template #default="s"><el-input v-model="s.row.key" size="small" @input="syncToJson"/></template>
|
<template #default="s">
|
||||||
|
<el-select v-model="s.row.key" size="small" @change="onKeyChange(s.row)" filterable>
|
||||||
|
<el-option v-for="k in pageKeys" :key="k.key" :label="k.key+' - '+k.label" :value="k.key" />
|
||||||
|
</el-select>
|
||||||
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="label" label="名称" width="110">
|
<el-table-column prop="label" label="名称" width="110">
|
||||||
<template #default="s"><el-input v-model="s.row.label" size="small" @input="syncToJson"/></template>
|
<template #default="s"><el-input v-model="s.row.label" size="small" @input="syncToJson"/></template>
|
||||||
@@ -91,6 +95,18 @@ const loading = ref(false), saving = ref(false), uploading = ref(false), deletin
|
|||||||
const editSiteId = ref(''), editorJson = ref('[]')
|
const editSiteId = ref(''), editorJson = ref('[]')
|
||||||
const defaultTypes = ['nexusphp','mtorrent','gazelle','unit3d']
|
const defaultTypes = ['nexusphp','mtorrent','gazelle','unit3d']
|
||||||
const isDefaultEditor = computed(() => editSiteId.value.startsWith('default:'))
|
const isDefaultEditor = computed(() => editSiteId.value.startsWith('default:'))
|
||||||
|
const pageKeys = ref([])
|
||||||
|
|
||||||
|
const loadPageKeys = async () => {
|
||||||
|
try { const r = await api.raw.get('/admin/page-keys'); pageKeys.value = r?.data || r || [] }
|
||||||
|
catch {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onKeyChange = (row) => {
|
||||||
|
const pk = pageKeys.value.find(k => k.key === row.key)
|
||||||
|
if (pk?.defaultMethod) row.method = pk.defaultMethod
|
||||||
|
syncToJson()
|
||||||
|
}
|
||||||
const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-'
|
const fmt = (t) => t ? (t.substring(0,19)||'').replace('T',' ') : '-'
|
||||||
const parsed = computed(() => { try { return JSON.parse(editorJson.value) } catch { return [] } })
|
const parsed = computed(() => { try { return JSON.parse(editorJson.value) } catch { return [] } })
|
||||||
const resolveUrl = (url) => url?.replace('{base}', sitesList.value.find(s=>s.siteId===editSiteId.value)?.urls?.[0] || '{base}') || ''
|
const resolveUrl = (url) => url?.replace('{base}', sitesList.value.find(s=>s.siteId===editSiteId.value)?.urls?.[0] || '{base}') || ''
|
||||||
@@ -157,5 +173,5 @@ const savePages = async () => {
|
|||||||
} catch { ElMessage.error('保存失败') }
|
} catch { ElMessage.error('保存失败') }
|
||||||
finally { saving.value = false }
|
finally { saving.value = false }
|
||||||
}
|
}
|
||||||
onMounted(fetchAll)
|
onMounted(() => { fetchAll(); loadPageKeys() })
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user