feat: 页面配置增加authType认证方式(NONE/COOKIE/TOKEN/BASIC/API_KEY)
This commit is contained in:
@@ -51,9 +51,11 @@ public class SitePagesController {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
var entries = (List<Map<String, Object>>) payload.get("entries");
|
var entries = (List<Map<String, Object>>) payload.get("entries");
|
||||||
if (entries == null || entries.isEmpty()) return ApiResponse.error(400, "entries is required");
|
if (entries == null || entries.isEmpty()) return ApiResponse.error(400, "entries is required");
|
||||||
sitePagesService.savePages(siteId, entries);
|
String authType = (String) payload.get("authType");
|
||||||
|
String authValue = (String) payload.get("authValue");
|
||||||
|
sitePagesService.savePages(siteId, entries, authType, authValue);
|
||||||
return ApiResponse.success();
|
return ApiResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/api/v1/admin/site-pages")
|
@GetMapping("/api/v1/admin/site-pages")
|
||||||
public ApiResponse<List<Map<String, Object>>> adminList(HttpServletRequest request) {
|
public ApiResponse<List<Map<String, Object>>> adminList(HttpServletRequest request) {
|
||||||
@@ -115,7 +117,9 @@ public class SitePagesController {
|
|||||||
checkAdmin(request);
|
checkAdmin(request);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
var entries = (List<Map<String, Object>>) payload.get("entries");
|
var entries = (List<Map<String, Object>>) payload.get("entries");
|
||||||
sitePagesService.savePages("default:" + type, entries != null ? entries : List.of());
|
String authType = (String) payload.get("authType");
|
||||||
|
String authValue = (String) payload.get("authValue");
|
||||||
|
sitePagesService.savePages("default:" + type, entries != null ? entries : List.of(), authType, authValue);
|
||||||
return ApiResponse.success();
|
return ApiResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public interface SitePagesService {
|
|||||||
String getVersion(String siteId);
|
String getVersion(String siteId);
|
||||||
/** 保存/更新页面配置 */
|
/** 保存/更新页面配置 */
|
||||||
void savePages(String siteId, List<Map<String, Object>> entries);
|
void savePages(String siteId, List<Map<String, Object>> entries);
|
||||||
|
/** 保存/更新页面配置(含认证方式) */
|
||||||
|
void savePages(String siteId, List<Map<String, Object>> entries, String authType, String authValue);
|
||||||
/** 获取所有站点页面配置列表(管理员) */
|
/** 获取所有站点页面配置列表(管理员) */
|
||||||
List<Map<String, Object>> listAll();
|
List<Map<String, Object>> listAll();
|
||||||
/** 删除站点页面配置 */
|
/** 删除站点页面配置 */
|
||||||
|
|||||||
@@ -53,8 +53,17 @@ public class SitePagesServiceImpl implements SitePagesService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void savePages(String siteId, List<Map<String, Object>> entries) {
|
public void savePages(String siteId, List<Map<String, Object>> entries) {
|
||||||
|
savePages(siteId, entries, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void savePages(String siteId, List<Map<String, Object>> entries, String authType, String authValue) {
|
||||||
try {
|
try {
|
||||||
String json = om.writerWithDefaultPrettyPrinter().writeValueAsString(entries);
|
Map<String, Object> full = new LinkedHashMap<>();
|
||||||
|
full.put("entries", entries);
|
||||||
|
if (authType != null && !"NONE".equals(authType)) full.put("authType", authType);
|
||||||
|
if (authValue != null && !authValue.isBlank()) full.put("authValue", authValue);
|
||||||
|
String json = om.writerWithDefaultPrettyPrinter().writeValueAsString(full);
|
||||||
// 版本号递增
|
// 版本号递增
|
||||||
String currentVer = getVersion(siteId);
|
String currentVer = getVersion(siteId);
|
||||||
int nextVer = 1;
|
int nextVer = 1;
|
||||||
|
|||||||
@@ -59,8 +59,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="flex:1;overflow:auto;min-height:0">
|
<div style="flex:1;overflow:auto;min-height:0">
|
||||||
|
<!-- 认证方式 -->
|
||||||
|
<div style="margin-bottom:12px;padding:10px 12px;border:1px solid #e6a23c;border-radius:4px;background:#fdf6ec">
|
||||||
|
<div style="font-weight:500;margin-bottom:6px;font-size:13px">认证方式</div>
|
||||||
|
<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center">
|
||||||
|
<el-select v-model="authType" size="small" @change="syncAuth" style="width:120px">
|
||||||
|
<el-option label="无" value="NONE"/>
|
||||||
|
<el-option label="Cookie" value="COOKIE"/>
|
||||||
|
<el-option label="Token" value="TOKEN"/>
|
||||||
|
<el-option label="Basic" value="BASIC"/>
|
||||||
|
<el-option label="API Key" value="API_KEY"/>
|
||||||
|
</el-select>
|
||||||
|
<el-input v-if="authType!=='NONE'" v-model="authValue" size="small" placeholder="cookie/token值或占位符" @input="syncAuth" style="flex:1;max-width:300px"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 页面入口 -->
|
||||||
<div style="font-size:13px;font-weight:500;margin-bottom:8px;display:flex;justify-content:space-between;align-items:center">
|
<div style="font-size:13px;font-weight:500;margin-bottom:8px;display:flex;justify-content:space-between;align-items:center">
|
||||||
<span>页面入口编辑</span>
|
<span>页面入口</span>
|
||||||
<el-button size="small" @click="addEntry">+ 添加</el-button>
|
<el-button size="small" @click="addEntry">+ 添加</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!parsed.length" style="text-align:center;padding:40px;color:#909399">暂无,点击添加</div>
|
<div v-if="!parsed.length" style="text-align:center;padding:40px;color:#909399">暂无,点击添加</div>
|
||||||
@@ -88,7 +104,8 @@
|
|||||||
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), sites = ref([]), pagesMap = ref({}), sitesList = ref([])
|
const loading = ref(false), saving = ref(false), uploading = ref(false), deleting = ref(false), sites = ref([]), pagesMap = ref({}), sitesList = ref([])
|
||||||
const editSiteId = ref(''), editorJson = ref('[]')
|
const editSiteId = ref(''), editorJson = ref('{}')
|
||||||
|
const authType = ref('NONE'), authValue = 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 pageKeys = ref([])
|
||||||
@@ -104,7 +121,20 @@ const onKeyChange = (row) => {
|
|||||||
syncToJson()
|
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).entries || [] } catch { return [] } })
|
||||||
|
const syncAuth = () => {
|
||||||
|
const obj = (() => { try { return JSON.parse(editorJson.value) } catch { return {} } })()
|
||||||
|
obj.authType = authType.value
|
||||||
|
if (authType.value !== 'NONE') obj.authValue = authValue.value
|
||||||
|
else delete obj.authValue
|
||||||
|
obj.entries = parsed.value
|
||||||
|
editorJson.value = JSON.stringify(obj, null, 2)
|
||||||
|
}
|
||||||
|
const syncToJson = () => {
|
||||||
|
const obj = { authType: authType.value, entries: parsed.value }
|
||||||
|
if (authType.value !== 'NONE') obj.authValue = authValue.value
|
||||||
|
editorJson.value = JSON.stringify(obj, null, 2)
|
||||||
|
}
|
||||||
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}') || ''
|
||||||
const merged = computed(() => (Array.isArray(sitesList.value)?sitesList.value:[]).map(s => ({
|
const merged = computed(() => (Array.isArray(sitesList.value)?sitesList.value:[]).map(s => ({
|
||||||
siteId: s.siteId, names: s.names,
|
siteId: s.siteId, names: s.names,
|
||||||
@@ -133,8 +163,13 @@ const editPage = async (row) => {
|
|||||||
const url = row.siteId.startsWith('default:')
|
const url = row.siteId.startsWith('default:')
|
||||||
? '/admin/default-pages/' + row.siteId.replace('default:','')
|
? '/admin/default-pages/' + row.siteId.replace('default:','')
|
||||||
: '/admin/site-pages/' + row.siteId
|
: '/admin/site-pages/' + row.siteId
|
||||||
try { const r = await api.raw.get(url); editorJson.value = (r?.data||r)?.entries ? JSON.stringify((r.data||r).entries, null, 2) : '[]' }
|
try {
|
||||||
catch { editorJson.value = '[]' }
|
const r = await api.raw.get(url)
|
||||||
|
const data = r?.data || r
|
||||||
|
authType.value = data?.authType || 'NONE'
|
||||||
|
authValue.value = data?.authValue || ''
|
||||||
|
editorJson.value = JSON.stringify({ authType: authType.value, authValue: authValue.value || undefined, entries: data?.entries || [] }, null, 2)
|
||||||
|
} catch { editorJson.value = JSON.stringify({ authType:'NONE', entries:[] }, null, 2) }
|
||||||
}
|
}
|
||||||
|
|
||||||
const syncToJson = () => { editorJson.value = JSON.stringify(parsed.value, null, 2) }
|
const syncToJson = () => { editorJson.value = JSON.stringify(parsed.value, null, 2) }
|
||||||
@@ -164,7 +199,7 @@ const savePages = async () => {
|
|||||||
const url = editSiteId.value.startsWith('default:')
|
const url = editSiteId.value.startsWith('default:')
|
||||||
? '/admin/default-pages/' + editSiteId.value.replace('default:','')
|
? '/admin/default-pages/' + editSiteId.value.replace('default:','')
|
||||||
: '/sites/' + editSiteId.value + '/pages'
|
: '/sites/' + editSiteId.value + '/pages'
|
||||||
await api.raw.put(url, { entries: parsed.value })
|
await api.raw.put(url, { entries: parsed.value, authType: authType.value, authValue: authType.value!=='NONE'?authValue.value:null })
|
||||||
ElMessage.success('已保存'); editSiteId.value=''; fetchAll()
|
ElMessage.success('已保存'); editSiteId.value=''; fetchAll()
|
||||||
} catch { ElMessage.error('保存失败') }
|
} catch { ElMessage.error('保存失败') }
|
||||||
finally { saving.value = false }
|
finally { saving.value = false }
|
||||||
|
|||||||
Reference in New Issue
Block a user