feat: 管理后台更新(love 页配置、about/upload 接口、profile 页)
This commit is contained in:
Generated
+882
-1
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,9 @@
|
||||
"axios": "^1.7.9",
|
||||
"echarts": "^5.6.0",
|
||||
"gsap": "^3.15.0",
|
||||
"katex": "^0.18.9",
|
||||
"leaflet": "^1.9.4",
|
||||
"md-editor-v3": "^7.0.0",
|
||||
"naive-ui": "^2.41.0",
|
||||
"pinia": "^2.3.0",
|
||||
"vue": "^3.5.38",
|
||||
|
||||
+6
-5
@@ -17,7 +17,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import { darkTheme, NConfigProvider, NDialogProvider, NLoadingBarProvider, NMessageProvider } from 'naive-ui'
|
||||
import type { GlobalThemeOverrides } from 'naive-ui'
|
||||
import { getPublicConfig } from '@/api/config'
|
||||
import { getBootstrap } from '@/api/config'
|
||||
|
||||
type ThemeMode = 'light' | 'dark'
|
||||
|
||||
@@ -179,12 +179,13 @@ const applyTheme = (mode: ThemeMode) => {
|
||||
|
||||
const loadAndApplyTheme = async () => {
|
||||
try {
|
||||
const response = await getPublicConfig()
|
||||
const response = await getBootstrap()
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
// 后台仅消费主题域,逐项摊平为 page.theme.* 便于下方统一取值
|
||||
const theme = response.data.data?.theme || {}
|
||||
const configMap: Record<string, string> = {}
|
||||
list.forEach((item: any) => {
|
||||
configMap[item.configKey] = item.configValue
|
||||
Object.entries(theme).forEach(([key, value]) => {
|
||||
configMap[`page.theme.${key}`] = value === null || value === undefined ? '' : String(value)
|
||||
})
|
||||
|
||||
// 检查是否启用了自定义主题
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import request from './request'
|
||||
|
||||
export interface IdentityPayload {
|
||||
name: string
|
||||
role: string
|
||||
tags: string[]
|
||||
avatar: string
|
||||
}
|
||||
|
||||
export function getAboutView() {
|
||||
return request.get('/about/view')
|
||||
}
|
||||
|
||||
export function saveAboutProfile(payload: any) {
|
||||
return request.post('/about/save', payload)
|
||||
}
|
||||
|
||||
export function saveAboutIdentity(payload: IdentityPayload) {
|
||||
return request.post('/about/save-identity', payload)
|
||||
}
|
||||
@@ -5,3 +5,13 @@ export function login(formData: URLSearchParams | any) {
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
|
||||
})
|
||||
}
|
||||
|
||||
/** 修改管理员账号:password 留空表示不改密码 */
|
||||
export function updateAccount(payload: { username: string; password: string }) {
|
||||
return request.post('/auth/account', payload)
|
||||
}
|
||||
|
||||
/** 当前登录态与账号信息(username / nickname) */
|
||||
export function getAuthStatus() {
|
||||
return request.get('/auth/status')
|
||||
}
|
||||
|
||||
+90
-6
@@ -1,13 +1,97 @@
|
||||
import request from './request'
|
||||
|
||||
export function getPublicConfig() {
|
||||
return request.get('/config/public')
|
||||
// ---- 前台引导聚合(公开) ----
|
||||
|
||||
export function getBootstrap() {
|
||||
return request.get('/config/bootstrap')
|
||||
}
|
||||
|
||||
export function getConfigList() {
|
||||
return request.get('/config/list')
|
||||
// ---- 主题 ----
|
||||
|
||||
export function getThemeConfig() {
|
||||
return request.get('/config/theme')
|
||||
}
|
||||
|
||||
export function updateConfigBatch(payload: any) {
|
||||
return request.post('/config/update-batch', payload)
|
||||
export function saveThemeConfig(payload: any) {
|
||||
return request.put('/config/theme', payload)
|
||||
}
|
||||
|
||||
// ---- 品牌与全局文案 ----
|
||||
|
||||
export function getSiteConfig() {
|
||||
return request.get('/config/site')
|
||||
}
|
||||
|
||||
export function saveSiteConfig(payload: any) {
|
||||
return request.put('/config/site', payload)
|
||||
}
|
||||
|
||||
// ---- 备案 ----
|
||||
|
||||
export function getBeianConfig() {
|
||||
return request.get('/config/beian')
|
||||
}
|
||||
|
||||
export function saveBeianConfig(payload: any) {
|
||||
return request.put('/config/beian', payload)
|
||||
}
|
||||
|
||||
// ---- 高德地图 ----
|
||||
|
||||
export function getAmapConfig() {
|
||||
return request.get('/config/amap')
|
||||
}
|
||||
|
||||
export function saveAmapConfig(payload: any) {
|
||||
return request.put('/config/amap', payload)
|
||||
}
|
||||
|
||||
// ---- 页面可见性与全站口令 ----
|
||||
|
||||
export function getVisibilityConfig() {
|
||||
return request.get('/config/visibility')
|
||||
}
|
||||
|
||||
export function saveVisibilityConfig(payload: any) {
|
||||
return request.put('/config/visibility', payload)
|
||||
}
|
||||
|
||||
// ---- 对象存储 ----
|
||||
|
||||
export function getStorageConfig() {
|
||||
return request.get('/config/storage')
|
||||
}
|
||||
|
||||
export function saveStorageConfig(payload: any) {
|
||||
return request.put('/config/storage', payload)
|
||||
}
|
||||
|
||||
// ---- AI 能力 ----
|
||||
|
||||
export function getAiConfig() {
|
||||
return request.get('/config/ai')
|
||||
}
|
||||
|
||||
export function saveAiConfig(payload: any) {
|
||||
return request.put('/config/ai', payload)
|
||||
}
|
||||
|
||||
// ---- 数据库信息(只读) ----
|
||||
|
||||
export function getDatabaseConfig() {
|
||||
return request.get('/config/database')
|
||||
}
|
||||
|
||||
export function updateDatabaseConfig(payload: any) {
|
||||
return request.post('/config/database', payload)
|
||||
}
|
||||
|
||||
// ---- 关于作者 / 此时此刻(聚合结构) ----
|
||||
|
||||
export function getNowView() {
|
||||
return request.get('/now/view')
|
||||
}
|
||||
|
||||
export function saveNowView(payload: any) {
|
||||
return request.post('/now/save', payload)
|
||||
}
|
||||
@@ -1,5 +1,28 @@
|
||||
import request from './request'
|
||||
|
||||
// 恋爱域公开聚合配置(伴侣信息 / 数据指标 / 开屏氛围)
|
||||
export function getLoveConfig() {
|
||||
return request.get('/love/config')
|
||||
}
|
||||
|
||||
export function saveLoveCouple(payload: { name: string; avatar: string }) {
|
||||
return request.put('/love/couple', payload)
|
||||
}
|
||||
|
||||
export function saveLoveStats(payload: {
|
||||
startDate: string
|
||||
citiesCount: number
|
||||
flightDistance: number
|
||||
movieCount: number
|
||||
mealCount: number
|
||||
}) {
|
||||
return request.put('/love/stats', payload)
|
||||
}
|
||||
|
||||
export function saveLoveHero(payload: { heroBgUrl: string; atmospheres: any[] }) {
|
||||
return request.put('/love/hero', payload)
|
||||
}
|
||||
|
||||
export function getLoveList() {
|
||||
return request.get('/love/list')
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import request from './request'
|
||||
import { useMessage } from 'naive-ui'
|
||||
import type { UploadCustomRequestOptions } from 'naive-ui'
|
||||
|
||||
/**
|
||||
* 统一上传入口:n-upload 通过 :custom-request 接入。
|
||||
* 走 axios 实例以复用全局拦截器(每次请求现读 localStorage 注入 satoken、
|
||||
* 401 统一清除 token 并跳转登录页),成功/失败提示全站一致。
|
||||
*
|
||||
* @param onSuccess 上传成功后的回调,参数为后端返回的媒体 URL
|
||||
* @param type 存储子目录(about / blog / love / now / ...),对应 /blogs/upload 的 type 参数
|
||||
*/
|
||||
export function createUploader(onSuccess: (url: string) => void, type: string) {
|
||||
const message = useMessage()
|
||||
|
||||
return async (option: UploadCustomRequestOptions) => {
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('file', option.file.file as File)
|
||||
// 上传(尤其视频)可能耗时较长,单独放宽超时
|
||||
const response = await request.post('/blogs/upload', formData, {
|
||||
params: { type },
|
||||
timeout: 300000
|
||||
})
|
||||
const body = response.data
|
||||
if (body && body.code === 200 && body.data) {
|
||||
option.onFinish()
|
||||
onSuccess(body.data as string)
|
||||
message.success('媒体上传成功')
|
||||
} else {
|
||||
option.onError()
|
||||
message.error(body?.msg || '上传失败')
|
||||
}
|
||||
} catch (err: any) {
|
||||
option.onError()
|
||||
// 401 由 request.ts 响应拦截器统一处理(清 token + 跳登录),此处不重复提示
|
||||
if (err?.response?.status === 401) return
|
||||
const status = err?.response?.status
|
||||
message.error(status ? `上传失败(HTTP ${status})` : err?.message || '上传失败,请检查网络')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,12 @@ const routes: RouteRecordRaw[] = [
|
||||
component: () => import('@/views/about/index.vue'),
|
||||
meta: { title: '关于作者配置 - 个人博客', requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: 'profile',
|
||||
name: 'Profile',
|
||||
component: () => import('@/views/profile/index.vue'),
|
||||
meta: { title: '个人中心 - 个人博客', requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: 'config',
|
||||
name: 'Config',
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
:class="[isCollapsed ? 'justify-center px-0' : 'px-2']" aria-label="返回后台首页">
|
||||
<span
|
||||
class="relative h-10 w-10 shrink-0 overflow-hidden rounded-full border border-white/40 bg-white/60 shadow-sm flex items-center justify-center">
|
||||
<img src="/life-assets/avatar.jpg" alt="RRTiamo 头像" class="life-image w-full h-full object-cover" />
|
||||
<img :src="authorAvatar" :alt="`${authorName} 头像`" class="life-image w-full h-full object-cover" />
|
||||
</span>
|
||||
<div v-if="!isCollapsed" class="flex flex-col text-left transition-opacity duration-300">
|
||||
<span class="text-[14px] font-750 leading-tight tracking-tight">春风不解别离</span>
|
||||
@@ -92,7 +92,7 @@
|
||||
:class="[isCollapsed ? 'justify-center' : 'gap-3']">
|
||||
<span class="online-dot shrink-0"></span>
|
||||
<div v-if="!isCollapsed" class="flex flex-col text-left">
|
||||
<span class="text-[11px] font-700 leading-tight">RRTiamo 在线</span>
|
||||
<span class="text-[11px] font-700 leading-tight">{{ authorName }} 在线</span>
|
||||
<span class="text-[9px] leading-tight tone-muted mt-0.5">安全连接已接通</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -179,6 +179,8 @@
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router'
|
||||
import { NTooltip, useDialog, useMessage } from 'naive-ui'
|
||||
import { getAuthStatus } from '@/api/auth'
|
||||
import { getAboutView } from '@/api/about'
|
||||
|
||||
type ThemeMode = 'light' | 'dark'
|
||||
|
||||
@@ -191,6 +193,10 @@ const theme = ref<ThemeMode>('light')
|
||||
const isCollapsed = ref(false)
|
||||
const isMobileCollapsed = ref(true)
|
||||
|
||||
// 博主身份(从 /about/view 动态拉取,保持 fallback 防接口离线)
|
||||
const authorAvatar = ref('/life-assets/avatar.jpg')
|
||||
const authorName = ref('RRTiamo')
|
||||
|
||||
const menuItems = [
|
||||
{
|
||||
name: 'Dashboard',
|
||||
@@ -242,6 +248,11 @@ const menuItems = [
|
||||
label: '成就管理',
|
||||
icon: 'i-mdi-trophy-outline'
|
||||
},
|
||||
{
|
||||
name: 'Profile',
|
||||
label: '个人中心',
|
||||
icon: 'i-mdi-account-circle-outline'
|
||||
},
|
||||
{
|
||||
name: 'Config',
|
||||
label: '系统配置',
|
||||
@@ -388,6 +399,28 @@ const handleLogout = () => {
|
||||
onMounted(() => {
|
||||
theme.value = document.documentElement.classList.contains('dark') ? 'dark' : 'light'
|
||||
|
||||
// 启动即校验登录态:token 字符串还留着但后端会话已失效(如后端重启)时,
|
||||
// 页面加载的请求多为白名单公开接口不会 401,必须主动查 /auth/status 踢回登录页
|
||||
getAuthStatus()
|
||||
.then((res) => {
|
||||
if (res.data?.data?.isLogin === false) {
|
||||
localStorage.removeItem('satoken')
|
||||
router.replace('/login')
|
||||
}
|
||||
})
|
||||
.catch(() => { /* 后端离线等网络异常不误杀,交给具体接口的 401 拦截 */ })
|
||||
|
||||
// 拉取博主身份档案(公开接口,离线时保持 fallback 值)
|
||||
getAboutView()
|
||||
.then((res) => {
|
||||
const profile = res.data?.data
|
||||
if (profile) {
|
||||
if (profile.name) authorName.value = profile.name
|
||||
if (profile.avatar) authorAvatar.value = profile.avatar
|
||||
}
|
||||
})
|
||||
.catch(() => { /* 保持默认 fallback,不阻塞界面 */ })
|
||||
|
||||
// 恢复之前的侧边栏折叠状态
|
||||
const savedCollapsed = localStorage.getItem('admin_sidebar_collapsed')
|
||||
if (savedCollapsed !== null) {
|
||||
|
||||
+73
-194
@@ -9,7 +9,7 @@
|
||||
<div class="flex flex-col text-left">
|
||||
<h3 class="text-lg font-bold text-(--archive-text) tracking-wide">关于作者 (About) 个人档案管理</h3>
|
||||
<p class="text-xs text-(--archive-text)/60 mt-1 leading-relaxed max-w-[48rem]">
|
||||
在此处个性化定制您的个人姓名、头衔、简历切片、信念以及前台 <code>/about</code> 页面的探索导航。所有配置都将直接存入数据库,前台已同步。
|
||||
在此处维护前台 /about 页面的介绍文案、现状坐标、作品切片、信念信条与探索导航;作者姓名、头像等身份档案请前往「个人中心」维护。所有配置直接存入数据库,前台已同步。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -39,15 +39,6 @@
|
||||
<!-- 1. 基本信息 -->
|
||||
<n-tab-pane name="basic" tab="基本资料 (Basic)">
|
||||
<div class="space-y-4 pt-4">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<n-form-item label="作者姓名 (Name)" required>
|
||||
<n-input v-model:value="profile.name" placeholder="请输入姓名,例如: RRTiamo" class="archive-input" />
|
||||
</n-form-item>
|
||||
<n-form-item label="身份角色 (Role / 标题文字)" required>
|
||||
<n-input v-model:value="profile.role" placeholder="前台大字标题,例如: 此间主人" class="archive-input" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<n-form-item label="一句话介绍 (Headline)" required>
|
||||
<n-input v-model:value="profile.headline" placeholder="请输入简短的一句话介绍..." class="archive-input" />
|
||||
</n-form-item>
|
||||
@@ -62,45 +53,11 @@
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<!-- 静态标签流 -->
|
||||
<n-form-item label="个人标签流 (Tags - 回车或点击添加)">
|
||||
<n-dynamic-tags v-model:value="profile.tags" />
|
||||
</n-form-item>
|
||||
|
||||
<!-- 动态旋转身份标签 -->
|
||||
<n-form-item label="轮播旋转标签 (Rotating Texts - 顶端卡片旁滚动显示)">
|
||||
<n-dynamic-tags v-model:value="profile.rotatingTexts" />
|
||||
</n-form-item>
|
||||
|
||||
<!-- 头像配置 (本地上传 + 相册选择) -->
|
||||
<n-form-item label="个人头像媒体 (Avatar URL)">
|
||||
<div class="space-y-3 w-full">
|
||||
<div class="flex gap-2">
|
||||
<n-input v-model:value="profile.avatar" placeholder="输入外部头像链接,或点击右侧上传/选择..." class="font-mono flex-1 archive-input" clearable />
|
||||
<n-button secondary @click="openAvatarGallerySelect">从照片墙选择</n-button>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=about"
|
||||
:headers="uploadHeaders"
|
||||
:show-file-list="false"
|
||||
@finish="handleAvatarUploadFinish"
|
||||
@error="handleAvatarUploadError"
|
||||
>
|
||||
<n-button secondary size="small" type="primary">
|
||||
<template #icon><span class="i-mdi-upload"></span></template>
|
||||
本地上传头像
|
||||
</n-button>
|
||||
</n-upload>
|
||||
<span class="text-[10px] tone-muted">推荐 1:1 比例头像图片,支持 mp4/webm 视频文件</span>
|
||||
</div>
|
||||
<!-- 头像预览 -->
|
||||
<div v-if="profile.avatar" class="mt-2 relative h-28 w-28 rounded-2xl overflow-hidden border border-(--archive-border)/40 bg-black/5 flex items-center justify-center">
|
||||
<video v-if="isMediaVideo(profile.avatar)" :src="profile.avatar" autoplay muted loop playsinline class="w-full h-full object-cover"></video>
|
||||
<img v-else :src="profile.avatar" class="w-full h-full object-cover" />
|
||||
</div>
|
||||
</div>
|
||||
</n-form-item>
|
||||
</div>
|
||||
</n-tab-pane>
|
||||
|
||||
@@ -161,11 +118,8 @@
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=about"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="coordinateUploader(Number(idx))"
|
||||
:show-file-list="false"
|
||||
@finish="(event) => handleCoordinateUploadFinish(Number(idx), event)"
|
||||
@error="handleCoordinateUploadError"
|
||||
>
|
||||
<n-button secondary size="tiny" type="primary">
|
||||
<template #icon><span class="i-mdi-upload"></span></template>
|
||||
@@ -255,11 +209,8 @@
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=about"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="fragmentUploader(Number(idx))"
|
||||
:show-file-list="false"
|
||||
@finish="(event) => handleFragmentUploadFinish(Number(idx), event)"
|
||||
@error="handleFragmentUploadError"
|
||||
>
|
||||
<n-button secondary size="tiny" type="primary">
|
||||
<template #icon><span class="i-mdi-upload"></span></template>
|
||||
@@ -384,7 +335,7 @@
|
||||
<n-modal
|
||||
v-model:show="showGallerySelectModal"
|
||||
preset="card"
|
||||
title="从相册选择头像图片/视频"
|
||||
title="从相册选择图片/视频"
|
||||
class="w-[95vw] max-w-[700px] rounded-2xl"
|
||||
>
|
||||
<div v-if="loadingGallery" class="py-12 flex justify-center">
|
||||
@@ -447,10 +398,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useMessage, NTabs, NTabPane, NFormItem, NInput, NButton, NDynamicTags, NDynamicInput, NUpload, NModal, NSpin, NSelect } from 'naive-ui'
|
||||
import { getConfigList, updateConfigBatch } from '@/api/config'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NTabs, NTabPane, NFormItem, NInput, NButton, NDynamicTags, NDynamicInput, NUpload, NModal, NSpin, NSelect, NSwitch } from 'naive-ui'
|
||||
import { getAboutView, saveAboutProfile } from '@/api/about'
|
||||
import { getFileList } from '@/api/files'
|
||||
import { createUploader } from '@/api/upload'
|
||||
import { defaultProfile } from '@/mock/about'
|
||||
import { aboutIconOptions } from '@/icon/about'
|
||||
import type { AboutProfile } from '@/interface/about'
|
||||
@@ -473,10 +425,25 @@ const availableRouteOptions = [
|
||||
|
||||
const profile = ref<AboutProfile>(JSON.parse(JSON.stringify(defaultProfile)))
|
||||
|
||||
// 上传凭证
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器);v-for 列表项按 idx 缓存 uploader,避免每次渲染重建
|
||||
const coordinateUploaderCache = new Map<number, ReturnType<typeof createUploader>>()
|
||||
const coordinateUploader = (idx: number) => {
|
||||
let handler = coordinateUploaderCache.get(idx)
|
||||
if (!handler) {
|
||||
handler = createUploader((url) => { profile.value.coordinates.items[idx].image = url }, 'about')
|
||||
coordinateUploaderCache.set(idx, handler)
|
||||
}
|
||||
return handler
|
||||
}
|
||||
const fragmentUploaderCache = new Map<number, ReturnType<typeof createUploader>>()
|
||||
const fragmentUploader = (idx: number) => {
|
||||
let handler = fragmentUploaderCache.get(idx)
|
||||
if (!handler) {
|
||||
handler = createUploader((url) => { profile.value.fragments.items[idx].image = url }, 'about')
|
||||
fragmentUploaderCache.set(idx, handler)
|
||||
}
|
||||
return handler
|
||||
}
|
||||
|
||||
// 照片墙弹窗相关
|
||||
const showGallerySelectModal = ref(false)
|
||||
@@ -484,8 +451,8 @@ const loadingGallery = ref(false)
|
||||
const galleryPhotos = ref<any[]>([])
|
||||
const selectedPhotoUrl = ref('')
|
||||
|
||||
// 选相册的目标,可以是 'avatar'、'coordinate' 或者是 'fragment'
|
||||
const gallerySelectTarget = ref<'avatar' | 'coordinate' | 'fragment'>('avatar')
|
||||
// 选相册的目标,可以是 'coordinate' 或者是 'fragment'
|
||||
const gallerySelectTarget = ref<'coordinate' | 'fragment'>('coordinate')
|
||||
const currentCoordinateIndex = ref<number | null>(null)
|
||||
const currentFragmentIndex = ref<number | null>(null)
|
||||
|
||||
@@ -530,56 +497,52 @@ const handleDeleteLink = (idx: number) => {
|
||||
profile.value.explore.links.splice(idx, 1)
|
||||
}
|
||||
|
||||
// 读取系统配置
|
||||
// 读取作者档案(about_* 关系表聚合)
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
const response = await getConfigList()
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const item = list.find((c: any) => c.configKey === 'page.about.profile')
|
||||
if (item && item.configValue) {
|
||||
try {
|
||||
const parsed = JSON.parse(item.configValue)
|
||||
|
||||
// 对历史版本或缺失字段进行深度防空兼容性初始化
|
||||
if (!parsed.avatar) parsed.avatar = defaultProfile.avatar
|
||||
if (!parsed.tags) parsed.tags = []
|
||||
if (!parsed.rotatingTexts) parsed.rotatingTexts = []
|
||||
if (!parsed.currentStatus) parsed.currentStatus = { ...defaultProfile.currentStatus }
|
||||
if (!parsed.currentStatus.items) parsed.currentStatus.items = []
|
||||
if (!parsed.coordinates) parsed.coordinates = { ...defaultProfile.coordinates }
|
||||
|
||||
if (!parsed.coordinates.items) {
|
||||
parsed.coordinates.items = JSON.parse(JSON.stringify(defaultProfile.coordinates.items))
|
||||
} else {
|
||||
// 确保坐标中每一项都具有默认的图片以防开天窗
|
||||
parsed.coordinates.items.forEach((cItem: any, idx: number) => {
|
||||
if (!cItem.image && defaultProfile.coordinates.items[idx]) {
|
||||
cItem.image = defaultProfile.coordinates.items[idx].image
|
||||
}
|
||||
})
|
||||
}
|
||||
const response = await getAboutView()
|
||||
|
||||
if (!parsed.fragments) parsed.fragments = { ...defaultProfile.fragments }
|
||||
if (!parsed.fragments.items) {
|
||||
parsed.fragments.items = JSON.parse(JSON.stringify(defaultProfile.fragments.items))
|
||||
} else {
|
||||
parsed.fragments.items.forEach((fItem: any, idx: number) => {
|
||||
if (fItem.image === undefined) {
|
||||
fItem.image = defaultProfile.fragments.items[idx]?.image || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
if (!parsed.beliefs) parsed.beliefs = { ...defaultProfile.beliefs }
|
||||
if (!parsed.beliefs.items) parsed.beliefs.items = []
|
||||
if (!parsed.explore) parsed.explore = { ...defaultProfile.explore }
|
||||
if (!parsed.explore.links) parsed.explore.links = []
|
||||
|
||||
profile.value = parsed
|
||||
} catch (e) {
|
||||
console.error('Failed to parse page.about.profile JSON', e)
|
||||
if (response.data && response.data.code === 200 && response.data.data) {
|
||||
try {
|
||||
const parsed = response.data.data
|
||||
|
||||
// 对历史版本或缺失字段进行深度防空兼容性初始化
|
||||
if (!parsed.avatar) parsed.avatar = defaultProfile.avatar
|
||||
if (!parsed.tags) parsed.tags = []
|
||||
if (!parsed.rotatingTexts) parsed.rotatingTexts = []
|
||||
if (!parsed.currentStatus) parsed.currentStatus = { ...defaultProfile.currentStatus }
|
||||
if (!parsed.currentStatus.items) parsed.currentStatus.items = []
|
||||
if (!parsed.coordinates) parsed.coordinates = { ...defaultProfile.coordinates }
|
||||
|
||||
if (!parsed.coordinates.items) {
|
||||
parsed.coordinates.items = JSON.parse(JSON.stringify(defaultProfile.coordinates.items))
|
||||
} else {
|
||||
// 确保坐标中每一项都具有默认的图片以防开天窗
|
||||
parsed.coordinates.items.forEach((cItem: any, idx: number) => {
|
||||
if (!cItem.image && defaultProfile.coordinates.items[idx]) {
|
||||
cItem.image = defaultProfile.coordinates.items[idx].image
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (!parsed.fragments) parsed.fragments = { ...defaultProfile.fragments }
|
||||
if (!parsed.fragments.items) {
|
||||
parsed.fragments.items = JSON.parse(JSON.stringify(defaultProfile.fragments.items))
|
||||
} else {
|
||||
parsed.fragments.items.forEach((fItem: any, idx: number) => {
|
||||
if (fItem.image === undefined) {
|
||||
fItem.image = defaultProfile.fragments.items[idx]?.image || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
if (!parsed.beliefs) parsed.beliefs = { ...defaultProfile.beliefs }
|
||||
if (!parsed.beliefs.items) parsed.beliefs.items = []
|
||||
if (!parsed.explore) parsed.explore = { ...defaultProfile.explore }
|
||||
if (!parsed.explore.links) parsed.explore.links = []
|
||||
|
||||
profile.value = parsed
|
||||
} catch (e) {
|
||||
console.error('Failed to read about profile payload', e)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -591,17 +554,9 @@ const fetchConfigs = async () => {
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
|
||||
const payload = [
|
||||
{
|
||||
configKey: 'page.about.profile',
|
||||
configValue: JSON.stringify(profile.value),
|
||||
description: '关于作者页面自定义配置数据'
|
||||
}
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await updateConfigBatch(payload)
|
||||
|
||||
const response = await saveAboutProfile(profile.value)
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('关于作者(About)个人档案保存成功,前台已同步!')
|
||||
await fetchConfigs()
|
||||
@@ -621,79 +576,6 @@ const handleResetDefault = () => {
|
||||
message.success('已重置为默认作者数据,请点击右上角保存以应用!')
|
||||
}
|
||||
|
||||
// 头像本地上传回调
|
||||
const handleAvatarUploadFinish = ({ event }: any) => {
|
||||
try {
|
||||
const responseText = (event?.target as any)?.response
|
||||
if (responseText) {
|
||||
const res = JSON.parse(responseText)
|
||||
if (res && res.code === 200 && res.data) {
|
||||
profile.value.avatar = res.data
|
||||
message.success('头像媒体上传成功 📸')
|
||||
} else {
|
||||
throw new Error(res?.msg || '上传接口返回错误')
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(`头像上传失败: ${err.message || '解析错误'}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleAvatarUploadError = () => {
|
||||
message.error('图片上传失败,请检查网络或后端接口是否在线 ⚠️')
|
||||
}
|
||||
|
||||
// 坐标媒体本地上传回调
|
||||
const handleCoordinateUploadFinish = (idx: number, { event }: any) => {
|
||||
try {
|
||||
const responseText = (event?.target as any)?.response
|
||||
if (responseText) {
|
||||
const res = JSON.parse(responseText)
|
||||
if (res && res.code === 200 && res.data) {
|
||||
profile.value.coordinates.items[idx].image = res.data
|
||||
message.success(`坐标项 [${profile.value.coordinates.items[idx].label}] 媒体上传成功 🎨`)
|
||||
} else {
|
||||
throw new Error(res?.msg || '上传接口返回错误')
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(`坐标媒体上传失败: ${err.message || '解析错误'}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCoordinateUploadError = () => {
|
||||
message.error('媒体文件上传失败,请检查后端网络接口 ⚠️')
|
||||
}
|
||||
|
||||
const handleFragmentUploadFinish = (idx: number, { event }: any) => {
|
||||
try {
|
||||
const responseText = (event?.target as any)?.response
|
||||
if (responseText) {
|
||||
const res = JSON.parse(responseText)
|
||||
if (res && res.code === 200 && res.data) {
|
||||
profile.value.fragments.items[idx].image = res.data
|
||||
message.success(`自我切片 [${profile.value.fragments.items[idx].category}] 图片上传成功 🎨`)
|
||||
} else {
|
||||
throw new Error(res?.msg || '上传接口返回错误')
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(`自我切片图片上传失败: ${err.message || '解析错误'}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleFragmentUploadError = () => {
|
||||
message.error('自我切片图片上传失败,请检查后端网络接口 ⚠️')
|
||||
}
|
||||
|
||||
// 照片墙弹框交互:头像选择
|
||||
const openAvatarGallerySelect = () => {
|
||||
gallerySelectTarget.value = 'avatar'
|
||||
currentCoordinateIndex.value = null
|
||||
currentFragmentIndex.value = null
|
||||
triggerGalleryFetch(profile.value.avatar || '')
|
||||
}
|
||||
|
||||
// 照片墙弹框交互:坐标选择
|
||||
const openCoordinateGallerySelect = (idx: number) => {
|
||||
gallerySelectTarget.value = 'coordinate'
|
||||
@@ -751,9 +633,6 @@ const confirmGallerySelect = () => {
|
||||
} else if (gallerySelectTarget.value === 'fragment' && currentFragmentIndex.value !== null) {
|
||||
profile.value.fragments.items[currentFragmentIndex.value].image = selectedPhotoUrl.value
|
||||
message.success(`已从照片墙选中并应用到自我切片项 [${profile.value.fragments.items[currentFragmentIndex.value].category}]`)
|
||||
} else {
|
||||
profile.value.avatar = selectedPhotoUrl.value
|
||||
message.success('已从照片墙选中并应用头像媒体')
|
||||
}
|
||||
showGallerySelectModal.value = false
|
||||
}
|
||||
|
||||
@@ -47,11 +47,8 @@
|
||||
class="flex-1"
|
||||
/>
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=achieve"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="achievementCoverUploader"
|
||||
:show-file-list="false"
|
||||
@finish="handleUploadFinish"
|
||||
@error="handleUploadError"
|
||||
@before-upload="beforeUpload"
|
||||
accept="image/*"
|
||||
class="w-auto shrink-0"
|
||||
@@ -104,6 +101,7 @@ import {
|
||||
NButton,
|
||||
useMessage
|
||||
} from 'naive-ui'
|
||||
import { createUploader } from '@/api/upload'
|
||||
|
||||
const props = defineProps<{
|
||||
showModal: boolean
|
||||
@@ -114,7 +112,6 @@ const props = defineProps<{
|
||||
levelOptions: any[]
|
||||
iconOptions: any[]
|
||||
rules: any
|
||||
uploadHeaders: any
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -162,23 +159,8 @@ const beforeUpload = (data: { file: { file: File | null } }) => {
|
||||
return true
|
||||
}
|
||||
|
||||
const handleUploadFinish = ({ event }: { event?: ProgressEvent }) => {
|
||||
const target = event?.target as XMLHttpRequest
|
||||
if (target && target.status === 200) {
|
||||
const response = JSON.parse(target.response)
|
||||
if (response.code === 200) {
|
||||
const model = { ...props.formModel, cover: response.data }
|
||||
emit('update:formModel', model)
|
||||
message.success('配图上传成功!')
|
||||
} else {
|
||||
message.error('配图上传失败:' + (response.msg || '未知错误'))
|
||||
}
|
||||
} else {
|
||||
message.error('网络上传失败,请检查后端状态')
|
||||
}
|
||||
}
|
||||
|
||||
const handleUploadError = () => {
|
||||
message.error('配图上传出错,已自动切换为手动文本输入链接。')
|
||||
}
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器)
|
||||
const achievementCoverUploader = createUploader((url) => {
|
||||
emit('update:formModel', { ...props.formModel, cover: url })
|
||||
}, 'achieve')
|
||||
</script>
|
||||
|
||||
@@ -75,7 +75,6 @@
|
||||
:level-options="levelOptions"
|
||||
:icon-options="iconOptions"
|
||||
:rules="formRules"
|
||||
:upload-headers="uploadHeaders"
|
||||
@save="handleSave"
|
||||
/>
|
||||
|
||||
@@ -194,10 +193,6 @@ const formRules: FormRules = {
|
||||
description: { required: true, message: '请简短叙述此项里程碑的发生始末', trigger: 'blur' }
|
||||
}
|
||||
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
|
||||
const iconOptions = [
|
||||
{ label: '荣誉奖杯 (Trophy)', value: 'i-mdi-trophy-outline', icon: 'i-mdi-trophy-outline' },
|
||||
{ label: '爱心印记 (Heart)', value: 'i-mdi-heart-outline', icon: 'i-mdi-heart-outline' },
|
||||
|
||||
@@ -87,11 +87,8 @@
|
||||
</n-button>
|
||||
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=blog"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="articleCoverUploader"
|
||||
:show-file-list="false"
|
||||
@finish="handleUploadFinish"
|
||||
@error="handleUploadError"
|
||||
@before-upload="beforeUpload"
|
||||
accept="image/*"
|
||||
class="w-auto shrink-0"
|
||||
@@ -136,13 +133,18 @@
|
||||
</div>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="随笔正文 (支持 Markdown)" path="content">
|
||||
<n-input
|
||||
v-model:value="formModel.content"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 16, maxRows: 32 }"
|
||||
placeholder="在此倾注您的文字思考与情感体验,直接以 Markdown 编写。全屏大文本输入框让创作体验更稳定..."
|
||||
class="font-mono text-sm leading-relaxed"
|
||||
<n-form-item label="随笔正文 (Markdown 编辑器 · 支持工具栏与实时预览)" path="content">
|
||||
<MdEditor
|
||||
v-model="formModel.content"
|
||||
:theme="editorTheme"
|
||||
preview-theme="github"
|
||||
:toolbars="editorToolbars"
|
||||
:editor-extensions="{ katex: { instance: katex } }"
|
||||
:footers="['markdownTotal', '=', 'scrollSwitch']"
|
||||
:style="{ height: '480px' }"
|
||||
class="w-full"
|
||||
placeholder="在此倾注您的文字思考与情感体验,支持 Markdown 语法;上方工具栏可快速插入格式,右侧实时预览排版效果..."
|
||||
@on-upload-img="handleEditorUploadImg"
|
||||
/>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
@@ -156,8 +158,15 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, onMounted, onBeforeUnmount } from 'vue'
|
||||
import { NButton, NForm, NFormItem, NInput, NSelect, NCascader, NDynamicTags, NUpload, useMessage } from 'naive-ui'
|
||||
import { MdEditor } from 'md-editor-v3'
|
||||
import type { ToolbarNames } from 'md-editor-v3'
|
||||
import 'md-editor-v3/lib/style.css'
|
||||
import katex from 'katex'
|
||||
import 'katex/dist/katex.min.css'
|
||||
import request from '@/api/request'
|
||||
import { createUploader } from '@/api/upload'
|
||||
|
||||
const props = defineProps<{
|
||||
isEdit: boolean
|
||||
@@ -168,7 +177,6 @@ const props = defineProps<{
|
||||
moodOptions: any[]
|
||||
visibilityOptions: any[]
|
||||
formRules: any
|
||||
uploadHeaders: any
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -184,6 +192,54 @@ const message = useMessage()
|
||||
const formRef = ref<any>(null)
|
||||
const fileInputRef = ref<HTMLInputElement | null>(null)
|
||||
|
||||
// ===== Markdown 编辑器配置 =====
|
||||
// 编辑器主题跟随管理台明暗模式(applyTheme 切换的是 documentElement 的 dark class)
|
||||
const editorTheme = ref<'light' | 'dark'>(
|
||||
document.documentElement.classList.contains('dark') ? 'dark' : 'light'
|
||||
)
|
||||
const themeObserver = new MutationObserver(() => {
|
||||
editorTheme.value = document.documentElement.classList.contains('dark') ? 'dark' : 'light'
|
||||
})
|
||||
onMounted(() => {
|
||||
themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] })
|
||||
})
|
||||
onBeforeUnmount(() => themeObserver.disconnect())
|
||||
|
||||
// 工具栏:保留日常写作所需项,剔除前台渲染器不支持的 mermaid/HTML 预览等;katex 公式两端均可渲染
|
||||
const editorToolbars: ToolbarNames[] = [
|
||||
'bold', 'underline', 'italic', '-', 'strikeThrough', 'sub', 'sup', 'quote', 'unorderedList', 'orderedList', 'task', '-',
|
||||
'codeRow', 'code', 'link', 'image', 'table', 'katex', '-',
|
||||
'revoke', 'next', '=',
|
||||
'pageFullscreen', 'fullscreen', 'preview', 'catalog'
|
||||
]
|
||||
|
||||
// 编辑器内图片上传(点工具栏/直接粘贴)复用 /blogs/upload 接口
|
||||
const handleEditorUploadImg = async (files: File[], callback: (urls: string[]) => void) => {
|
||||
const urls: string[] = []
|
||||
for (const file of files) {
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
const response = await request.post('/blogs/upload', formData, {
|
||||
params: { type: 'blog' },
|
||||
timeout: 300000
|
||||
})
|
||||
const body = response.data
|
||||
if (body && body.code === 200 && body.data) {
|
||||
urls.push(body.data as string)
|
||||
} else {
|
||||
message.error(body?.msg || `图片「${file.name}」上传失败`)
|
||||
}
|
||||
} catch (err: any) {
|
||||
// 401 由 request.ts 响应拦截器统一处理,此处不重复提示
|
||||
if (err?.response?.status !== 401) {
|
||||
message.error(`图片「${file.name}」上传失败:${err?.message || '请检查网络'}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(urls)
|
||||
}
|
||||
|
||||
const triggerFileInput = () => {
|
||||
fileInputRef.value?.click()
|
||||
}
|
||||
@@ -227,23 +283,8 @@ const beforeUpload = (data: { file: { file: File | null } }) => {
|
||||
return true
|
||||
}
|
||||
|
||||
const handleUploadFinish = ({ event }: { event?: ProgressEvent }) => {
|
||||
const target = event?.target as XMLHttpRequest
|
||||
if (target && target.status === 200) {
|
||||
const response = JSON.parse(target.response)
|
||||
if (response.code === 200) {
|
||||
const model = { ...props.formModel, cover: response.data }
|
||||
emit('update:formModel', model)
|
||||
message.success('封面图片上传成功!')
|
||||
} else {
|
||||
message.error('封面上传失败:' + (response.msg || '未知错误'))
|
||||
}
|
||||
} else {
|
||||
message.error('网络上传失败,请检查后端状态')
|
||||
}
|
||||
}
|
||||
|
||||
const handleUploadError = () => {
|
||||
message.error('文件上传失败,请检查网络或后端服务。')
|
||||
}
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器)
|
||||
const articleCoverUploader = createUploader((url) => {
|
||||
emit('update:formModel', { ...props.formModel, cover: url })
|
||||
}, 'blog')
|
||||
</script>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<template>
|
||||
<template>
|
||||
<div class="grid gap-3">
|
||||
<article
|
||||
v-for="(blog, index) in paginatedBlogs"
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
:mood-options="moodOptions"
|
||||
:visibility-options="visibilityOptions"
|
||||
:form-rules="formRules"
|
||||
:upload-headers="uploadHeaders"
|
||||
@close="closeEditor"
|
||||
@save="handleSubmit"
|
||||
@open-gallery="openGallerySelector"
|
||||
@@ -214,11 +213,6 @@ const categoryTreeOptions = computed(() => {
|
||||
return roots
|
||||
})
|
||||
|
||||
// 文件上传 Headers
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
|
||||
// 数据过滤和分页
|
||||
const filteredBlogs = computed(() => {
|
||||
const query = searchQuery.value.trim().toLowerCase()
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NButton } from 'naive-ui'
|
||||
import request from '@/api/request'
|
||||
import { getAiConfig, saveAiConfig } from '@/api/config'
|
||||
|
||||
const message = useMessage()
|
||||
const saving = ref(false)
|
||||
@@ -64,21 +64,13 @@ const aiConfig = ref({
|
||||
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('satoken')
|
||||
const response = await request.get('/config/list', {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
const response = await getAiConfig()
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
}
|
||||
|
||||
aiConfig.value.apiKey = getValue('deepseek.api-key', '')
|
||||
aiConfig.value.baseUrl = getValue('deepseek.base-url', 'https://ark.cn-beijing.volces.com/api/v3')
|
||||
aiConfig.value.modelName = getValue('deepseek.model-name', 'deepseek-v3-2-251201')
|
||||
const data = response.data.data || {}
|
||||
aiConfig.value.apiKey = data.apiKey || ''
|
||||
aiConfig.value.baseUrl = data.baseUrl || 'https://ark.cn-beijing.volces.com/api/v3'
|
||||
aiConfig.value.modelName = data.modelName || 'deepseek-v3-2-251201'
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load AI config', err)
|
||||
@@ -87,19 +79,16 @@ const fetchConfigs = async () => {
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
const token = localStorage.getItem('satoken')
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'deepseek.api-key', configValue: aiConfig.value.apiKey || '', description: 'DeepSeek API 密钥' },
|
||||
{ configKey: 'deepseek.base-url', configValue: aiConfig.value.baseUrl || 'https://ark.cn-beijing.volces.com/api/v3', description: 'DeepSeek API 基础地址' },
|
||||
{ configKey: 'deepseek.model-name', configValue: aiConfig.value.modelName || 'deepseek-v3-2-251201', description: 'DeepSeek 模型名称' }
|
||||
]
|
||||
|
||||
|
||||
const payload = {
|
||||
apiKey: aiConfig.value.apiKey || '',
|
||||
baseUrl: aiConfig.value.baseUrl || 'https://ark.cn-beijing.volces.com/api/v3',
|
||||
modelName: aiConfig.value.modelName || 'deepseek-v3-2-251201'
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await request.post('/config/update-batch', payload, {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
const response = await saveAiConfig(payload)
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('AI 服务配置应用成功!')
|
||||
window.dispatchEvent(new CustomEvent('atlas-config-changed'))
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NButton } from 'naive-ui'
|
||||
import request from '@/api/request'
|
||||
import { getAmapConfig, saveAmapConfig } from '@/api/config'
|
||||
|
||||
const getBlogUrl = (path: string) => {
|
||||
const protocol = window.location.protocol
|
||||
@@ -107,20 +107,13 @@ const encryptKey = (str: string): string => {
|
||||
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('satoken')
|
||||
const response = await request.get('/config/list', {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
}
|
||||
const response = await getAmapConfig()
|
||||
|
||||
rawAmapKey.value = getValue('page.footprint.amap.key', '')
|
||||
rawAmapSecurityJsCode.value = getValue('page.footprint.amap.securityJsCode', '')
|
||||
if (response.data && response.data.code === 200) {
|
||||
const data = response.data.data || {}
|
||||
|
||||
rawAmapKey.value = data.amapKey || ''
|
||||
rawAmapSecurityJsCode.value = data.amapSecurityJsCode || ''
|
||||
|
||||
amap.value.key = rawAmapKey.value ? '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●' : ''
|
||||
amap.value.securityJsCode = rawAmapSecurityJsCode.value ? '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●' : ''
|
||||
@@ -132,7 +125,6 @@ const fetchConfigs = async () => {
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
const token = localStorage.getItem('satoken')
|
||||
|
||||
let finalKey = amap.value.key
|
||||
if (finalKey === '●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●') {
|
||||
@@ -148,16 +140,14 @@ const handleSave = async () => {
|
||||
finalCode = encryptKey(finalCode)
|
||||
}
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'page.footprint.amap.key', configValue: finalKey, description: '高德地图 API Key (JS端)' },
|
||||
{ configKey: 'page.footprint.amap.securityJsCode', configValue: finalCode, description: '高德地图 API 安全密钥 (SecurityJsCode)' }
|
||||
]
|
||||
const payload = {
|
||||
amapKey: finalKey,
|
||||
amapSecurityJsCode: finalCode
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await request.post('/config/update-batch', payload, {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
const response = await saveAmapConfig(payload)
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('地图服务配置已成功保存')
|
||||
await fetchConfigs()
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NButton } from 'naive-ui'
|
||||
import request from '@/api/request'
|
||||
import { getBeianConfig, saveBeianConfig } from '@/api/config'
|
||||
|
||||
const message = useMessage()
|
||||
const saving = ref(false)
|
||||
@@ -52,22 +52,14 @@ const beian = ref({
|
||||
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('satoken')
|
||||
const response = await request.get('/config/list', {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
const response = await getBeianConfig()
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
}
|
||||
|
||||
beian.value.icp = getValue('site.beian.icp', '')
|
||||
beian.value.icpUrl = getValue('site.beian.icpUrl', 'https://beian.miit.gov.cn/')
|
||||
beian.value.police = getValue('site.beian.police', '')
|
||||
beian.value.policeUrl = getValue('site.beian.policeUrl', '')
|
||||
const data = response.data.data || {}
|
||||
beian.value.icp = data.icp || ''
|
||||
beian.value.icpUrl = data.icpUrl || 'https://beian.miit.gov.cn/'
|
||||
beian.value.police = data.police || ''
|
||||
beian.value.policeUrl = data.policeUrl || ''
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load beian config', err)
|
||||
@@ -76,20 +68,17 @@ const fetchConfigs = async () => {
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
const token = localStorage.getItem('satoken')
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'site.beian.icp', configValue: beian.value.icp || '', description: '工信部ICP备案号' },
|
||||
{ configKey: 'site.beian.icpUrl', configValue: beian.value.icpUrl || 'https://beian.miit.gov.cn/', description: '工信部ICP备案跳转链接' },
|
||||
{ configKey: 'site.beian.police', configValue: beian.value.police || '', description: '公安联网备案号' },
|
||||
{ configKey: 'site.beian.policeUrl', configValue: beian.value.policeUrl || '', description: '公安联网备案跳转链接' }
|
||||
]
|
||||
|
||||
|
||||
const payload = {
|
||||
icp: beian.value.icp || '',
|
||||
icpUrl: beian.value.icpUrl || 'https://beian.miit.gov.cn/',
|
||||
police: beian.value.police || '',
|
||||
policeUrl: beian.value.policeUrl || ''
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await request.post('/config/update-batch', payload, {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
const response = await saveBeianConfig(payload)
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('备案信息配置应用成功!')
|
||||
window.dispatchEvent(new CustomEvent('atlas-config-changed'))
|
||||
|
||||
@@ -31,12 +31,9 @@
|
||||
<div class="flex items-center gap-2 shrink-0 justify-end sm:justify-start">
|
||||
<n-button secondary size="small" class="shrink-0" @click="openGallerySelect('logoUrl')">相册选择</n-button>
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=brand"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="brandLogoUploader"
|
||||
:show-file-list="false"
|
||||
class="flex shrink-0"
|
||||
@finish="(res) => handleUploadFinish('logoUrl', res)"
|
||||
@error="handleUploadError"
|
||||
>
|
||||
<n-button secondary size="small" type="primary">
|
||||
上传
|
||||
@@ -62,12 +59,9 @@
|
||||
<div class="flex items-center gap-2 shrink-0 justify-end sm:justify-start">
|
||||
<n-button secondary size="small" class="shrink-0" @click="openGallerySelect('faviconUrl')">相册选择</n-button>
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=brand"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="brandFaviconUploader"
|
||||
:show-file-list="false"
|
||||
class="flex shrink-0"
|
||||
@finish="(res) => handleUploadFinish('faviconUrl', res)"
|
||||
@error="handleUploadError"
|
||||
>
|
||||
<n-button secondary size="small" type="primary">
|
||||
上传
|
||||
@@ -96,26 +90,39 @@
|
||||
<p class="m-0 text-xs font-bold border-b border-(--archive-border)/40 pb-2 mb-3 text-(--archive-text)">主页开屏文本与定制媒体背景 (Welcome Hero)</p>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
<n-form-item label="开屏品牌英文/拼音大字 (Welcome Large Text)" required>
|
||||
<n-input v-model:value="brand.welcomeText" placeholder="例如: spring" class="archive-input font-mono" />
|
||||
<n-form-item label="开屏眉题英文小标 (Eyebrow Tag)" required>
|
||||
<n-input v-model:value="brand.eyebrowTag" placeholder="例如: Welcome" class="archive-input font-mono" />
|
||||
</n-form-item>
|
||||
<n-form-item label="开屏打字机底部小字 (Welcome Subtitle)" required>
|
||||
<n-input v-model:value="brand.welcomeSubtitle" placeholder="例如: 此间主人" class="archive-input" />
|
||||
<n-form-item label="开屏巨字 (Hero Title)" required>
|
||||
<n-input v-model:value="brand.heroTitle" placeholder="例如: Awakening" class="archive-input font-mono" />
|
||||
</n-form-item>
|
||||
<n-form-item label="开屏描边巨行 (Outline Text)" required>
|
||||
<n-input v-model:value="brand.welcomeText" placeholder="例如: Spring Breeze" class="archive-input font-mono" />
|
||||
</n-form-item>
|
||||
<n-form-item label="开屏眉题中文 / 博客名 (Subtitle)" required>
|
||||
<n-input v-model:value="brand.welcomeSubtitle" placeholder="例如: 那些年风吹过的地方" class="archive-input" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<n-form-item label="开屏描述行 (Description)">
|
||||
<n-input
|
||||
v-model:value="brand.heroDescription"
|
||||
type="textarea"
|
||||
:rows="2"
|
||||
placeholder="写一点代码,拍一些照片,记下那些普通但值得被留下的日子。"
|
||||
class="archive-input"
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="开屏背景展示媒体 (大图/视频 URL)">
|
||||
<div class="flex flex-col sm:flex-row items-stretch sm:items-center gap-2 w-full overflow-hidden">
|
||||
<n-input v-model:value="brand.heroBgUrl" placeholder="输入外部图片或视频链接..." class="font-mono flex-1 archive-input" clearable />
|
||||
<div class="flex items-center gap-2 shrink-0 justify-end sm:justify-start">
|
||||
<n-button secondary size="small" class="shrink-0" @click="openGallerySelect('heroBgUrl')">相册选择</n-button>
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=brand"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="brandHeroBgUploader"
|
||||
:show-file-list="false"
|
||||
class="flex shrink-0"
|
||||
@finish="(res) => handleUploadFinish('heroBgUrl', res)"
|
||||
@error="handleUploadError"
|
||||
>
|
||||
<n-button secondary size="small" type="primary">
|
||||
上传
|
||||
@@ -206,10 +213,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NUpload, NButton, NModal, NSpin } from 'naive-ui'
|
||||
import { getConfigList, updateConfigBatch } from '@/api/config'
|
||||
import { getSiteConfig, saveSiteConfig } from '@/api/config'
|
||||
import { getFileList } from '@/api/files'
|
||||
import { createUploader } from '@/api/upload'
|
||||
|
||||
const message = useMessage()
|
||||
const saving = ref(false)
|
||||
@@ -220,8 +228,11 @@ const defaultBrand = {
|
||||
faviconUrl: '',
|
||||
titleDefault: '此间主人 | RRTiamo',
|
||||
titleAbout: '春风不解别离意,今日方知我是春。',
|
||||
welcomeText: 'spring',
|
||||
welcomeSubtitle: '此间主人',
|
||||
eyebrowTag: 'Welcome',
|
||||
heroTitle: 'Awakening',
|
||||
welcomeText: 'Spring Breeze',
|
||||
welcomeSubtitle: '那些年风吹过的地方',
|
||||
heroDescription: '写一点代码,拍一些照片,记下那些普通但值得被留下的日子。',
|
||||
heroBgUrl: '/assets/bg-video.mp4'
|
||||
}
|
||||
|
||||
@@ -234,9 +245,10 @@ const galleryPhotos = ref<any[]>([])
|
||||
const selectedPhotoUrl = ref('')
|
||||
const gallerySelectTarget = ref<'logoUrl' | 'faviconUrl' | 'heroBgUrl'>('logoUrl')
|
||||
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器)
|
||||
const brandLogoUploader = createUploader((url) => { brand.value.logoUrl = url }, 'brand')
|
||||
const brandFaviconUploader = createUploader((url) => { brand.value.faviconUrl = url }, 'brand')
|
||||
const brandHeroBgUploader = createUploader((url) => { brand.value.heroBgUrl = url }, 'brand')
|
||||
|
||||
const isMediaVideo = (url: string) => {
|
||||
if (!url) return false
|
||||
@@ -245,22 +257,23 @@ const isMediaVideo = (url: string) => {
|
||||
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
const response = await getConfigList()
|
||||
const response = await getSiteConfig()
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
const data = response.data.data || {}
|
||||
brand.value = {
|
||||
...defaultBrand,
|
||||
logoUrl: data.logoUrl || '',
|
||||
logoText: data.logoText || defaultBrand.logoText,
|
||||
faviconUrl: data.faviconUrl || '',
|
||||
titleDefault: data.titleDefault || defaultBrand.titleDefault,
|
||||
titleAbout: data.titleAbout || defaultBrand.titleAbout,
|
||||
welcomeText: data.welcomeText || defaultBrand.welcomeText,
|
||||
welcomeSubtitle: data.welcomeSubtitle || defaultBrand.welcomeSubtitle,
|
||||
heroTitle: data.heroTitle || defaultBrand.heroTitle,
|
||||
eyebrowTag: data.eyebrowTag || defaultBrand.eyebrowTag,
|
||||
heroDescription: data.heroDescription || defaultBrand.heroDescription,
|
||||
heroBgUrl: data.heroBgUrl || defaultBrand.heroBgUrl
|
||||
}
|
||||
|
||||
brand.value.logoUrl = getValue('site.logo.url', '')
|
||||
brand.value.logoText = getValue('site.logo.text', 'RRTiamo')
|
||||
brand.value.faviconUrl = getValue('site.favicon.url', '')
|
||||
brand.value.titleDefault = getValue('site.title.default', '此间主人 | RRTiamo')
|
||||
brand.value.titleAbout = getValue('site.title.about', '春风不解别离意,今日方知我是春。')
|
||||
brand.value.welcomeText = getValue('page.home.welcomeText', 'spring')
|
||||
brand.value.welcomeSubtitle = getValue('page.home.welcomeSubtitle', '此间主人')
|
||||
brand.value.heroBgUrl = getValue('page.home.heroBgUrl', '/assets/bg-video.mp4')
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load brand config', err)
|
||||
@@ -270,19 +283,22 @@ const fetchConfigs = async () => {
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'site.logo.url', configValue: brand.value.logoUrl, description: '全站 LOGO 自定义图片链接' },
|
||||
{ configKey: 'site.logo.text', configValue: brand.value.logoText, description: '网站 LOGO 旁边的展示文字' },
|
||||
{ configKey: 'site.favicon.url', configValue: brand.value.faviconUrl, description: '浏览器 Tab 标签 Favicon 图片链接' },
|
||||
{ configKey: 'site.title.default', configValue: brand.value.titleDefault, description: '全站默认网页 Title 标题' },
|
||||
{ configKey: 'site.title.about', configValue: brand.value.titleAbout, description: '关于作者页专属网页 Title 标题' },
|
||||
{ configKey: 'page.home.welcomeText', configValue: brand.value.welcomeText, description: '主页开屏大字文案' },
|
||||
{ configKey: 'page.home.welcomeSubtitle', configValue: brand.value.welcomeSubtitle, description: '主页开屏副标题/打字机小字' },
|
||||
{ configKey: 'page.home.heroBgUrl', configValue: brand.value.heroBgUrl, description: '主页开屏背景图/视频 URL' }
|
||||
]
|
||||
const payload = {
|
||||
logoUrl: brand.value.logoUrl,
|
||||
logoText: brand.value.logoText,
|
||||
faviconUrl: brand.value.faviconUrl,
|
||||
titleDefault: brand.value.titleDefault,
|
||||
titleAbout: brand.value.titleAbout,
|
||||
welcomeText: brand.value.welcomeText,
|
||||
welcomeSubtitle: brand.value.welcomeSubtitle,
|
||||
heroTitle: brand.value.heroTitle,
|
||||
eyebrowTag: brand.value.eyebrowTag,
|
||||
heroDescription: brand.value.heroDescription,
|
||||
heroBgUrl: brand.value.heroBgUrl
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await updateConfigBatch(payload)
|
||||
const response = await saveSiteConfig(payload)
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('全站品牌与开屏配置应用成功,前台已实时生效!')
|
||||
window.dispatchEvent(new CustomEvent('atlas-config-changed'))
|
||||
@@ -302,28 +318,6 @@ const handleResetDefault = () => {
|
||||
message.success('已重置为默认品牌配置,请点击右下角应用生效')
|
||||
}
|
||||
|
||||
// 统一本地上传回调
|
||||
const handleUploadFinish = (target: 'logoUrl' | 'faviconUrl' | 'heroBgUrl', { event }: any) => {
|
||||
try {
|
||||
const responseText = (event?.target as any)?.response
|
||||
if (responseText) {
|
||||
const res = JSON.parse(responseText)
|
||||
if (res && res.code === 200 && res.data) {
|
||||
brand.value[target] = res.data
|
||||
message.success('多媒体文件上传成功 🎨')
|
||||
} else {
|
||||
throw new Error(res?.msg || '上传接口错误')
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(`文件上传失败: ${err.message || '解析错误'}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleUploadError = () => {
|
||||
message.error('文件上传失败,请确认后端服务连接状态 ⚠️')
|
||||
}
|
||||
|
||||
// 照片墙弹窗选择交互
|
||||
const openGallerySelect = async (target: 'logoUrl' | 'faviconUrl' | 'heroBgUrl') => {
|
||||
gallerySelectTarget.value = target
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<span class="i-mdi-database-outline text-lg tone-accent"></span>
|
||||
数据库连接属性设置
|
||||
</h3>
|
||||
<p class="tone-muted text-xs mt-1">博主可以直接在这里修改服务端 PostgreSQL 连接属性,完成平滑的物理库重连迁移。</p>
|
||||
<p class="tone-muted text-xs mt-1">数据库连接为服务端启动配置,此处仅作只读展示;如需变更请在 application-dev.yml 中配置后重启服务。</p>
|
||||
</div>
|
||||
<n-button
|
||||
secondary
|
||||
@@ -27,40 +27,33 @@
|
||||
<n-form label-placement="top" class="mt-5 space-y-4">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<n-form-item label="主机地址 (Host)" required>
|
||||
<n-input v-model:value="dbConfig.host" placeholder="如: localhost 或 127.0.0.1" />
|
||||
<n-input v-model:value="dbConfig.host" disabled placeholder="如: localhost 或 127.0.0.1" />
|
||||
</n-form-item>
|
||||
<n-form-item label="端口号 (Port)" required>
|
||||
<n-input v-model:value="dbConfig.port" placeholder="如: 5432" />
|
||||
<n-input v-model:value="dbConfig.port" disabled placeholder="如: 5432" />
|
||||
</n-form-item>
|
||||
<n-form-item label="数据库库名 (Database)" required>
|
||||
<n-input v-model:value="dbConfig.databaseName" placeholder="如: my_house" />
|
||||
<n-input v-model:value="dbConfig.databaseName" disabled placeholder="如: my_house" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<n-form-item label="数据库账号用户名 (Username)" required>
|
||||
<n-input v-model:value="dbConfig.username" placeholder="如: postgres" />
|
||||
<n-input v-model:value="dbConfig.username" disabled :input-props="{ autocomplete: 'off' }" placeholder="如: postgres" />
|
||||
</n-form-item>
|
||||
<n-form-item label="数据库账号密码 (Password)" required>
|
||||
<n-input v-model:value="dbConfig.password" type="password" show-password-on="click" placeholder="输入对应数据库密码" />
|
||||
<n-input v-model:value="dbConfig.password" type="password" disabled show-password-on="click" :input-props="{ autocomplete: 'new-password' }" placeholder="输入对应数据库密码" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div class="soft-panel p-3.5 bg-red-500/5 border border-red-500/10 rounded-2xl flex items-start gap-3">
|
||||
<span class="i-mdi-flash-outline text-red-500 mt-0.5 text-base"></span>
|
||||
<div class="soft-panel p-3.5 bg-sky-500/5 border border-sky-500/10 rounded-2xl flex items-start gap-3">
|
||||
<span class="i-mdi-information-outline text-sky-500 mt-0.5 text-base"></span>
|
||||
<div>
|
||||
<p class="m-0 text-xs font-700 text-red-500">高危操作提示</p>
|
||||
<p class="m-0 mt-0.5 text-[11px] leading-relaxed text-red-500/70">
|
||||
更改数据库配置可能会导致服务端与当前数据库失去连接并发生自动重连。如果填写的账号或者主机密码错误,会导致整个系统中断无法服务。
|
||||
<p class="m-0 text-xs font-700 text-sky-500">只读信息</p>
|
||||
<p class="m-0 mt-0.5 text-[11px] leading-relaxed text-sky-500/70">
|
||||
数据库连接信息(含密码)由服务端启动配置注入,出于安全考虑密码不会回显。修改连接需在 application-dev.yml 中配置 SPRING_DATASOURCE_* 环境变量后重启服务。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-(--archive-border)/40 pt-4 mt-2 flex justify-end">
|
||||
<n-button type="primary" :loading="saving" @click="handleSave">
|
||||
<template #icon><span class="i-mdi-content-save-outline"></span></template>
|
||||
测试并更新数据库连接
|
||||
</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -68,8 +61,8 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NButton } from 'naive-ui'
|
||||
import request from '@/api/request'
|
||||
import { NForm, NFormItem, NInput, NButton } from 'naive-ui'
|
||||
import { getDatabaseConfig } from '@/api/config'
|
||||
|
||||
const getBlogUrl = (path: string) => {
|
||||
const protocol = window.location.protocol
|
||||
@@ -84,9 +77,6 @@ const getBlogUrl = (path: string) => {
|
||||
return `${protocol}//${hostname}${path}`
|
||||
}
|
||||
|
||||
const message = useMessage()
|
||||
const saving = ref(false)
|
||||
|
||||
const dbConfig = ref({
|
||||
host: '',
|
||||
port: '',
|
||||
@@ -97,38 +87,22 @@ const dbConfig = ref({
|
||||
|
||||
const fetchDbConfig = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('satoken')
|
||||
const response = await request.get('/config/database', {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
const response = await getDatabaseConfig()
|
||||
if (response.data && response.data.code === 200) {
|
||||
dbConfig.value = response.data.data || { host: '', port: '', databaseName: '', username: '', password: '' }
|
||||
const data = response.data.data || {}
|
||||
dbConfig.value = {
|
||||
host: data.host || '',
|
||||
port: data.port || '',
|
||||
databaseName: data.databaseName || '',
|
||||
username: data.username || '',
|
||||
password: data.password || ''
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch database configuration', err)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
const token = localStorage.getItem('satoken')
|
||||
try {
|
||||
const response = await request.post('/config/database', dbConfig.value, {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success(response.data.msg || '数据库配置已成功保存')
|
||||
await fetchDbConfig()
|
||||
} else {
|
||||
throw new Error(response.data?.msg || '保存失败')
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(err.message || '网络连接失败,数据库配置保存失败。')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchDbConfig()
|
||||
})
|
||||
|
||||
@@ -99,7 +99,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NSelect, NInput, NButton } from 'naive-ui'
|
||||
import request from '@/api/request'
|
||||
import { getStorageConfig, saveStorageConfig } from '@/api/config'
|
||||
|
||||
const getBlogUrl = (path: string) => {
|
||||
const protocol = window.location.protocol
|
||||
@@ -158,28 +158,23 @@ const activeStorageLabel = computed(() => {
|
||||
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('satoken')
|
||||
const response = await request.get('/config/list', {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
}
|
||||
const response = await getStorageConfig()
|
||||
|
||||
formModel.value.storageType = getValue('storage.type', 'local')
|
||||
formModel.value.minio.endpoint = getValue('storage.minio.endpoint', '')
|
||||
formModel.value.minio.accessKey = getValue('storage.minio.accessKey', '')
|
||||
formModel.value.minio.secretKey = getValue('storage.minio.secretKey', '')
|
||||
formModel.value.minio.bucketName = getValue('storage.minio.bucketName', '')
|
||||
|
||||
formModel.value.qiniu.accessKey = getValue('storage.qiniu.accessKey', '')
|
||||
formModel.value.qiniu.secretKey = getValue('storage.qiniu.secretKey', '')
|
||||
formModel.value.qiniu.bucketName = getValue('storage.qiniu.bucketName', '')
|
||||
formModel.value.qiniu.domain = getValue('storage.qiniu.domain', '')
|
||||
if (response.data && response.data.code === 200) {
|
||||
const data = response.data.data || {}
|
||||
const minio = data.minio || {}
|
||||
const qiniu = data.qiniu || {}
|
||||
|
||||
formModel.value.storageType = data.storageType || 'local'
|
||||
formModel.value.minio.endpoint = minio.endpoint || ''
|
||||
formModel.value.minio.accessKey = minio.accessKey || ''
|
||||
formModel.value.minio.secretKey = minio.secretKey || ''
|
||||
formModel.value.minio.bucketName = minio.bucketName || ''
|
||||
|
||||
formModel.value.qiniu.accessKey = qiniu.accessKey || ''
|
||||
formModel.value.qiniu.secretKey = qiniu.secretKey || ''
|
||||
formModel.value.qiniu.bucketName = qiniu.bucketName || ''
|
||||
formModel.value.qiniu.domain = qiniu.domain || ''
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch storage configs', err)
|
||||
@@ -188,25 +183,16 @@ const fetchConfigs = async () => {
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
const token = localStorage.getItem('satoken')
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'storage.type', configValue: formModel.value.storageType, description: '存储方式: local, minio, qiniu' },
|
||||
{ configKey: 'storage.minio.endpoint', configValue: formModel.value.minio.endpoint, description: 'MinIO服务访问端点' },
|
||||
{ configKey: 'storage.minio.accessKey', configValue: formModel.value.minio.accessKey, description: 'MinIO Access Key' },
|
||||
{ configKey: 'storage.minio.secretKey', configValue: formModel.value.minio.secretKey, description: 'MinIO Secret Key' },
|
||||
{ configKey: 'storage.minio.bucketName', configValue: formModel.value.minio.bucketName, description: 'MinIO 存储空间桶名' },
|
||||
{ configKey: 'storage.qiniu.accessKey', configValue: formModel.value.qiniu.accessKey, description: '七牛云 Access Key' },
|
||||
{ configKey: 'storage.qiniu.secretKey', configValue: formModel.value.qiniu.secretKey, description: '七牛云 Secret Key' },
|
||||
{ configKey: 'storage.qiniu.bucketName', configValue: formModel.value.qiniu.bucketName, description: '七牛云 存储空间名' },
|
||||
{ configKey: 'storage.qiniu.domain', configValue: formModel.value.qiniu.domain, description: '七牛云加速域名' }
|
||||
]
|
||||
|
||||
const payload = {
|
||||
storageType: formModel.value.storageType,
|
||||
minio: { ...formModel.value.minio },
|
||||
qiniu: { ...formModel.value.qiniu }
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await request.post('/config/update-batch', payload, {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
const response = await saveStorageConfig(payload)
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('存储与图床配置已成功保存')
|
||||
await fetchConfigs()
|
||||
|
||||
@@ -153,11 +153,8 @@
|
||||
|
||||
<div class="flex flex-wrap items-center gap-2 mb-2">
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=theme"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="themeBgUploader"
|
||||
:show-file-list="false"
|
||||
@finish="handleBgUploadFinish"
|
||||
@error="handleBgUploadError"
|
||||
>
|
||||
<n-button secondary size="small" type="primary">
|
||||
<template #icon><span class="i-mdi-upload"></span></template>
|
||||
@@ -258,9 +255,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NInputNumber, NSwitch, NUpload, NButton, NModal, NSpin } from 'naive-ui'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NInputNumber, NSwitch, NUpload, NButton, NModal, NSpin, NSelect } from 'naive-ui'
|
||||
import request from '@/api/request'
|
||||
import { getThemeConfig, saveThemeConfig } from '@/api/config'
|
||||
import { createUploader } from '@/api/upload'
|
||||
|
||||
const message = useMessage()
|
||||
const saving = ref(false)
|
||||
@@ -293,44 +292,21 @@ const loadingGallery = ref(false)
|
||||
const galleryPhotos = ref<any[]>([])
|
||||
const selectedPhotoUrl = ref('')
|
||||
|
||||
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器)
|
||||
const themeBgUploader = createUploader((url) => { theme.value.bgImageUrl = url }, 'theme')
|
||||
|
||||
|
||||
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('satoken')
|
||||
const response = await request.get('/config/list', {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
}
|
||||
const response = await getThemeConfig()
|
||||
|
||||
theme.value.enabled = getValue('page.theme.enabled', 'false') === 'true'
|
||||
theme.value.accentColor = getValue('page.theme.accentColor', '#D9865F')
|
||||
theme.value.accentSoftColor = getValue('page.theme.accentSoftColor', '#F1B894')
|
||||
theme.value.bgColor = getValue('page.theme.bgColor', '#F7F8F1')
|
||||
theme.value.bgSoftColor = getValue('page.theme.bgSoftColor', '#EAF0E5')
|
||||
theme.value.darkAccentColor = getValue('page.theme.darkAccentColor', '#F1A77C')
|
||||
theme.value.darkAccentSoftColor = getValue('page.theme.darkAccentSoftColor', '#F5C6A8')
|
||||
theme.value.darkBgColor = getValue('page.theme.darkBgColor', '#17211B')
|
||||
theme.value.darkBgSoftColor = getValue('page.theme.darkBgSoftColor', '#203027')
|
||||
theme.value.grainOpacity = Number(getValue('page.theme.grainOpacity', '3.8'))
|
||||
theme.value.glowsEnabled = getValue('page.theme.glowsEnabled', 'false') === 'true'
|
||||
theme.value.bgImageUrl = getValue('page.theme.bgImageUrl', '')
|
||||
theme.value.bgImageStyle = getValue('page.theme.bgImageStyle', 'cover')
|
||||
theme.value.bgImageBlur = Number(getValue('page.theme.bgImageBlur', '0'))
|
||||
theme.value.bgImageOpacity = Number(getValue('page.theme.bgImageOpacity', '10'))
|
||||
theme.value.darkBgImageOpacity = Number(getValue('page.theme.darkBgImageOpacity', '5'))
|
||||
theme.value.customCss = getValue('page.theme.customCss', '')
|
||||
if (response.data && response.data.code === 200) {
|
||||
const data = response.data.data || {}
|
||||
const merged = { ...JSON.parse(JSON.stringify(defaultTheme)), ...data }
|
||||
delete merged.id
|
||||
delete merged.updatedAt
|
||||
theme.value = merged
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load theme config', err)
|
||||
@@ -339,33 +315,10 @@ const fetchConfigs = async () => {
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
const token = localStorage.getItem('satoken')
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'page.theme.enabled', configValue: String(theme.value.enabled), description: '是否启用系统自定义外观主题' },
|
||||
{ configKey: 'page.theme.accentColor', configValue: theme.value.accentColor, description: '自定义主题-亮色模式主色' },
|
||||
{ configKey: 'page.theme.accentSoftColor', configValue: theme.value.accentSoftColor, description: '自定义主题-亮色模式柔和主色' },
|
||||
{ configKey: 'page.theme.bgColor', configValue: theme.value.bgColor, description: '自定义主题-亮色模式背景色' },
|
||||
{ configKey: 'page.theme.bgSoftColor', configValue: theme.value.bgSoftColor, description: '自定义主题-亮色模式次级背景色' },
|
||||
{ configKey: 'page.theme.darkAccentColor', configValue: theme.value.darkAccentColor, description: '自定义主题-暗色模式主色' },
|
||||
{ configKey: 'page.theme.darkAccentSoftColor', configValue: theme.value.darkAccentSoftColor, description: '自定义主题-暗色模式柔和主色' },
|
||||
{ configKey: 'page.theme.darkBgColor', configValue: theme.value.darkBgColor, description: '自定义主题-暗色模式背景色' },
|
||||
{ configKey: 'page.theme.darkBgSoftColor', configValue: theme.value.darkBgSoftColor, description: '自定义主题-暗色模式次级背景色' },
|
||||
{ configKey: 'page.theme.grainOpacity', configValue: String(theme.value.grainOpacity), description: '自定义主题-电影噪点不透明度(0-100)' },
|
||||
{ configKey: 'page.theme.glowsEnabled', configValue: String(theme.value.glowsEnabled), description: '自定义主题-是否开启霓虹背景灯效' },
|
||||
{ configKey: 'page.theme.bgImageUrl', configValue: theme.value.bgImageUrl, description: '自定义主题-全局背景图片URL' },
|
||||
{ configKey: 'page.theme.bgImageStyle', configValue: theme.value.bgImageStyle || 'cover', description: '自定义主题-背景图展示样式(cover/contain/tile)' },
|
||||
{ configKey: 'page.theme.bgImageBlur', configValue: String(theme.value.bgImageBlur || 0), description: '自定义主题-背景图模糊度(0-40px)' },
|
||||
{ configKey: 'page.theme.bgImageOpacity', configValue: String(theme.value.bgImageOpacity || 10), description: '自定义主题-亮色模式背景图透明度(0-100)' },
|
||||
{ configKey: 'page.theme.darkBgImageOpacity', configValue: String(theme.value.darkBgImageOpacity || 5), description: '自定义主题-暗色模式背景图透明度(0-100)' },
|
||||
{ configKey: 'page.theme.customCss', configValue: theme.value.customCss, description: '自定义主题-附加自定义CSS样式代码' }
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await request.post('/config/update-batch', payload, {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
const response = await saveThemeConfig(theme.value)
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('外观色彩配置应用成功,刷新后将同步展现!')
|
||||
window.dispatchEvent(new CustomEvent('atlas-config-changed'))
|
||||
@@ -380,27 +333,6 @@ const handleSave = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleBgUploadFinish = ({ event }: any) => {
|
||||
try {
|
||||
const responseText = (event?.target as any)?.response
|
||||
if (responseText) {
|
||||
const res = JSON.parse(responseText)
|
||||
if (res && res.code === 200 && res.data) {
|
||||
theme.value.bgImageUrl = res.data
|
||||
message.success('自定义背景图片上传成功 🖼️')
|
||||
} else {
|
||||
throw new Error(res?.msg || '上传接口返回错误')
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(`背景图上传失败: ${err.message || '解析错误'}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleBgUploadError = () => {
|
||||
message.error('图片上传失败,请检查网络或后端接口是否在线 ⚠️')
|
||||
}
|
||||
|
||||
const handleRemoveBgImage = () => {
|
||||
theme.value.bgImageUrl = ''
|
||||
message.success('已恢复默认背景')
|
||||
|
||||
@@ -108,7 +108,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NSwitch, NButton, NInput, NFormItem } from 'naive-ui'
|
||||
import request from '@/api/request'
|
||||
import { getVisibilityConfig, saveVisibilityConfig } from '@/api/config'
|
||||
|
||||
const message = useMessage()
|
||||
const saving = ref(false)
|
||||
@@ -126,25 +126,17 @@ const passcode = ref('2026')
|
||||
|
||||
const fetchConfigs = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem('satoken')
|
||||
const response = await request.get('/config/list', {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
}
|
||||
const response = await getVisibilityConfig()
|
||||
|
||||
page.value.loveEnable = getValue('page.love.enable', 'true') === 'true'
|
||||
page.value.letterEnable = getValue('page.letter.enable', 'true') === 'true'
|
||||
page.value.nowEnable = getValue('page.now.enable', 'true') === 'true'
|
||||
page.value.aboutEnable = getValue('page.about.enable', 'true') === 'true'
|
||||
page.value.footprintsEnable = getValue('page.footprints.enable', 'true') === 'true'
|
||||
page.value.pondEnable = getValue('page.pond.enable', 'true') === 'true'
|
||||
passcode.value = getValue('site.access.passcode', '2026')
|
||||
if (response.data && response.data.code === 200) {
|
||||
const data = response.data.data || {}
|
||||
page.value.loveEnable = data.loveEnabled !== false
|
||||
page.value.letterEnable = data.letterEnabled !== false
|
||||
page.value.nowEnable = data.nowEnabled !== false
|
||||
page.value.aboutEnable = data.aboutEnabled !== false
|
||||
page.value.footprintsEnable = data.footprintsEnabled !== false
|
||||
page.value.pondEnable = data.pondEnabled !== false
|
||||
passcode.value = data.accessPasscode ?? '2026'
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load visibility configs', err)
|
||||
@@ -153,23 +145,20 @@ const fetchConfigs = async () => {
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
const token = localStorage.getItem('satoken')
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'page.love.enable', configValue: String(page.value.loveEnable), description: '是否开启“恋爱纪实”页面及导航入口' },
|
||||
{ configKey: 'page.letter.enable', configValue: String(page.value.letterEnable), description: '是否开启“岁月信件”页面及导航入口' },
|
||||
{ configKey: 'page.now.enable', configValue: String(page.value.nowEnable), description: '是否开启“目前状态”页面及导航入口' },
|
||||
{ configKey: 'page.about.enable', configValue: String(page.value.aboutEnable), description: '是否开启“关于作者”页面及导航入口' },
|
||||
{ configKey: 'page.footprints.enable', configValue: String(page.value.footprintsEnable), description: '是否开启“岁月足迹”页面及导航入口' },
|
||||
{ configKey: 'page.pond.enable', configValue: String(page.value.pondEnable), description: '是否开启“鱼塘反馈”页面及导航入口' },
|
||||
{ configKey: 'site.access.passcode', configValue: String(passcode.value), description: '全站随笔及恋爱私密档案全局访问口令' }
|
||||
]
|
||||
const payload = {
|
||||
loveEnabled: page.value.loveEnable,
|
||||
letterEnabled: page.value.letterEnable,
|
||||
nowEnabled: page.value.nowEnable,
|
||||
aboutEnabled: page.value.aboutEnable,
|
||||
footprintsEnabled: page.value.footprintsEnable,
|
||||
pondEnabled: page.value.pondEnable,
|
||||
accessPasscode: String(passcode.value)
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await request.post('/config/update-batch', payload, {
|
||||
headers: { satoken: token }
|
||||
})
|
||||
|
||||
const response = await saveVisibilityConfig(payload)
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('可见性配置已成功保存')
|
||||
await fetchConfigs()
|
||||
|
||||
@@ -288,7 +288,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { NInput, NSelect, NSpin, NImage, NTooltip, NPagination, useDialog, useMessage } from 'naive-ui'
|
||||
import { NInput, NSelect, NSpin, NImage, NTooltip, NPagination, NButton, useDialog, useMessage } from 'naive-ui'
|
||||
import { getStorageType, getFileList, deleteFile } from '@/api/files'
|
||||
import type { StorageInfo, FileItem } from '@/interface/files'
|
||||
|
||||
|
||||
@@ -83,11 +83,8 @@
|
||||
/>
|
||||
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=gallery"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="photoMediaUploader"
|
||||
:show-file-list="false"
|
||||
@finish="handleUploadFinish"
|
||||
@error="handleUploadError"
|
||||
@before-upload="beforeUpload"
|
||||
accept="image/*,video/*"
|
||||
class="w-auto shrink-0"
|
||||
@@ -130,6 +127,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { NButton, NForm, NFormItem, NInput, NSelect, NDatePicker, NUpload, NInputNumber, useMessage } from 'naive-ui'
|
||||
import { createUploader } from '@/api/upload'
|
||||
|
||||
const props = defineProps<{
|
||||
isEdit: boolean
|
||||
@@ -138,7 +136,6 @@ const props = defineProps<{
|
||||
typeOptions: any[]
|
||||
footprintTypeOptions: any[]
|
||||
formRules: any
|
||||
uploadHeaders: any
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -177,24 +174,9 @@ const beforeUpload = (data: { file: { file: File | null } }) => {
|
||||
return true
|
||||
}
|
||||
|
||||
const handleUploadFinish = ({ event }: { event?: ProgressEvent }) => {
|
||||
const target = event?.target as XMLHttpRequest
|
||||
if (target && target.status === 200) {
|
||||
const response = JSON.parse(target.response)
|
||||
if (response.code === 200) {
|
||||
const type = response.data.endsWith('.mp4') || response.data.endsWith('.mov') ? 'video' : 'image'
|
||||
const model = { ...props.formModel, src: response.data, type }
|
||||
emit('update:formModel', model)
|
||||
message.success('媒体上传并识别完成!')
|
||||
} else {
|
||||
message.error('媒体上传失败:' + (response.msg || '未知错误'))
|
||||
}
|
||||
} else {
|
||||
message.error('网络上传失败,请检查后端状态')
|
||||
}
|
||||
}
|
||||
|
||||
const handleUploadError = () => {
|
||||
message.error('文件上传失败,请检查网络或后端服务。')
|
||||
}
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器),上传后按扩展名自动识别媒体类型
|
||||
const photoMediaUploader = createUploader((url) => {
|
||||
const type = url.endsWith('.mp4') || url.endsWith('.mov') ? 'video' : 'image'
|
||||
emit('update:formModel', { ...props.formModel, src: url, type })
|
||||
}, 'gallery')
|
||||
</script>
|
||||
|
||||
@@ -80,7 +80,6 @@
|
||||
:type-options="typeOptions"
|
||||
:footprint-type-options="footprintTypeOptions"
|
||||
:form-rules="formRules"
|
||||
:upload-headers="uploadHeaders"
|
||||
@close="closeEditor"
|
||||
@save="handleSave"
|
||||
@gps="getDeviceLocation"
|
||||
@@ -181,10 +180,6 @@ const statusText = computed(() => {
|
||||
// 地图选点状态
|
||||
const showMapModal = ref(false)
|
||||
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
|
||||
// 检索过滤
|
||||
const filteredPhotos = computed(() => {
|
||||
const query = searchQuery.value.trim().toLowerCase()
|
||||
|
||||
@@ -101,11 +101,8 @@
|
||||
|
||||
<n-upload
|
||||
v-if="letterImagesList.length < 2"
|
||||
action="/api/blogs/upload?type=letter"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="letterPhotoUploader"
|
||||
:show-file-list="false"
|
||||
@finish="handleUploadFinish"
|
||||
@error="handleUploadError"
|
||||
accept="image/*"
|
||||
class="aspect-[4/3] border border-dashed border-(--archive-border) rounded-lg flex flex-center items-center justify-center cursor-pointer hover:border-(--archive-accent)"
|
||||
>
|
||||
@@ -154,6 +151,7 @@
|
||||
import { ref, onMounted, computed, watch } from 'vue'
|
||||
import { useMessage, useDialog, NButton, NTable, NSpace, NModal, NForm, NFormItem, NInput, NUpload, NDatePicker } from 'naive-ui'
|
||||
import { getTimeLetterList, createTimeLetter, updateTimeLetter, deleteTimeLetter } from '@/api/letter'
|
||||
import { createUploader } from '@/api/upload'
|
||||
import GallerySelectModal from '../articles/components/GallerySelectModal.vue'
|
||||
import { getFileList } from '@/api/files'
|
||||
|
||||
@@ -285,9 +283,12 @@ const handleSaveLetter = async () => {
|
||||
// 辅助方法和图片上传
|
||||
const onlyAllowNumber = (value: string) => !value || /^\d+$/.test(value)
|
||||
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器)
|
||||
const letterPhotoUploader = createUploader((url) => {
|
||||
const list = [...letterImagesList.value]
|
||||
list.push(url)
|
||||
letterForm.value.images = list.join(',')
|
||||
}, 'letter')
|
||||
|
||||
const letterImagesList = computed(() => {
|
||||
return letterForm.value.images ? letterForm.value.images.split(',').map(s => s.trim()).filter(Boolean) : []
|
||||
@@ -341,27 +342,6 @@ const handleSelectGalleryPhoto = (src: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleUploadFinish = ({ event }: { event?: ProgressEvent }) => {
|
||||
const target = event?.target as XMLHttpRequest
|
||||
if (target && target.status === 200) {
|
||||
const response = JSON.parse(target.response)
|
||||
if (response.code === 200) {
|
||||
const list = [...letterImagesList.value]
|
||||
list.push(response.data)
|
||||
letterForm.value.images = list.join(',')
|
||||
message.success('照片上传成功!')
|
||||
} else {
|
||||
message.error('照片上传失败:' + (response.msg || '未知错误'))
|
||||
}
|
||||
} else {
|
||||
message.error('网络上传失败,请检查后端状态')
|
||||
}
|
||||
}
|
||||
|
||||
const handleUploadError = () => {
|
||||
message.error('照片上传失败,请检查网络或后端服务。')
|
||||
}
|
||||
|
||||
const handleDeleteLetter = (id: number) => {
|
||||
dialog.warning({
|
||||
title: '确认删除',
|
||||
|
||||
@@ -95,11 +95,8 @@
|
||||
|
||||
<div class="grid grid-cols-2 gap-2 mb-6">
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=love"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="atmosphereUploader"
|
||||
:show-file-list="false"
|
||||
@finish="handleAtmosphereUploadFinish"
|
||||
@error="handleLoveHeroUploadError"
|
||||
@before-upload="beforeLoveHeroUpload"
|
||||
class="w-full"
|
||||
>
|
||||
@@ -241,13 +238,25 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NUpload, NButton, NModal, NSpin, NSpace, NTable, NTag } from 'naive-ui'
|
||||
import { updateConfigBatch, getConfigList } from '@/api/config'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NUpload, NButton, NModal, NSpin, NSpace, NTable, NTag, NSelect } from 'naive-ui'
|
||||
import { getLoveConfig, saveLoveHero } from '@/api/love'
|
||||
import { getFileList } from '@/api/files'
|
||||
import { createUploader } from '@/api/upload'
|
||||
|
||||
const message = useMessage()
|
||||
|
||||
const DEFAULT_ATMOSPHERES: AtmosphereItem[] = [
|
||||
{ id: 'cherry', name: '樱落', src: '/assets/【哲风壁纸】樱花-樱花飘落.mp4', type: 'video' },
|
||||
{ id: 'island', name: '海风', src: '/assets/【哲风壁纸】户外-树枝-海岛.mp4', type: 'video' },
|
||||
{ id: 'snow', name: '雪杉', src: '/assets/【哲风壁纸】mc-下雪-云杉树.mp4', type: 'video' }
|
||||
]
|
||||
|
||||
// 恋爱开屏自定义背景 URL(本页无编辑入口,保存时原样回传避免被清空)
|
||||
const loveHeroBgUrl = ref('')
|
||||
// 是否已成功加载背景配置(防止加载完成前保存用空串覆盖)
|
||||
const loveHeroBgLoaded = ref(false)
|
||||
|
||||
// ==================== 恋爱开屏背景配置逻辑 ====================
|
||||
interface AtmosphereItem {
|
||||
id: string
|
||||
@@ -280,11 +289,7 @@ const atmosphereTypeOptions = [
|
||||
|
||||
// 重置默认氛围
|
||||
const handleResetDefaultAtmospheres = () => {
|
||||
loveAtmospheres.value = [
|
||||
{ id: 'cherry', name: '樱落', src: '/assets/【哲风壁纸】樱花-樱花飘落.mp4', type: 'video' },
|
||||
{ id: 'island', name: '海风', src: '/assets/【哲风壁纸】户外-树枝-海岛.mp4', type: 'video' },
|
||||
{ id: 'snow', name: '雪杉', src: '/assets/【哲风壁纸】mc-下雪-云杉树.mp4', type: 'video' }
|
||||
]
|
||||
loveAtmospheres.value = JSON.parse(JSON.stringify(DEFAULT_ATMOSPHERES))
|
||||
message.info('已重置默认氛围列表,应用后生效')
|
||||
}
|
||||
|
||||
@@ -334,6 +339,12 @@ const handleSaveAtmosphereItem = () => {
|
||||
|
||||
const savingLoveHero = ref(false)
|
||||
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器),上传后按扩展名自动设定资源类型
|
||||
const atmosphereUploader = createUploader((url) => {
|
||||
atmosphereForm.value.src = url
|
||||
atmosphereForm.value.type = url.match(/\.(mp4|webm|ogg|mov|m4v)($|\?)/i) ? 'video' : 'image'
|
||||
}, 'love')
|
||||
|
||||
const handleSetDefaultAtmosphere = (index: number) => {
|
||||
if (index <= 0 || index >= loveAtmospheres.value.length) return
|
||||
const arr = [...loveAtmospheres.value]
|
||||
@@ -344,15 +355,24 @@ const handleSetDefaultAtmosphere = (index: number) => {
|
||||
}
|
||||
|
||||
const handleSaveLoveHero = async () => {
|
||||
if (!loveHeroBgLoaded.value) {
|
||||
message.warning('开屏背景配置尚未加载完成,请稍后再试')
|
||||
return
|
||||
}
|
||||
savingLoveHero.value = true
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'page.love.heroBgUrl', configValue: '', description: '恋爱开屏自定义背景图片/视频URL' },
|
||||
{ configKey: 'page.love.atmospheres', configValue: JSON.stringify(loveAtmospheres.value), description: '恋爱开屏切换氛围配置列表' }
|
||||
]
|
||||
const payload = {
|
||||
heroBgUrl: loveHeroBgUrl.value || '',
|
||||
atmospheres: loveAtmospheres.value.map((a) => ({
|
||||
id: a.id,
|
||||
name: a.name,
|
||||
src: a.src,
|
||||
type: a.type
|
||||
}))
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await updateConfigBatch(payload)
|
||||
const response = await saveLoveHero(payload)
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('恋爱开屏背景及切换列表应用成功 💖')
|
||||
} else {
|
||||
@@ -366,10 +386,6 @@ const handleSaveLoveHero = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
|
||||
// 上传恋爱背景控制
|
||||
const beforeLoveHeroUpload = (data: { file: any }) => {
|
||||
const isImgOrVid = data.file.file?.type.startsWith('image/') || data.file.file?.type.startsWith('video/')
|
||||
@@ -385,28 +401,6 @@ const beforeLoveHeroUpload = (data: { file: any }) => {
|
||||
return true
|
||||
}
|
||||
|
||||
const handleAtmosphereUploadFinish = ({ event }: any) => {
|
||||
try {
|
||||
const responseText = (event?.target as any)?.response
|
||||
if (responseText) {
|
||||
const res = JSON.parse(responseText)
|
||||
if (res && res.code === 200 && res.data) {
|
||||
atmosphereForm.value.src = res.data
|
||||
atmosphereForm.value.type = res.data.match(/\.(mp4|webm|ogg|mov|m4v)($|\?)/i) ? 'video' : 'image'
|
||||
message.success('氛围资源上传成功 🎨')
|
||||
} else {
|
||||
throw new Error(res?.msg || '上传接口返回错误')
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(`资源上传失败: ${err.message || '解析错误'}`)
|
||||
}
|
||||
}
|
||||
|
||||
const handleLoveHeroUploadError = () => {
|
||||
message.error('背景上传失败,请检查网络或后端接口是否在线 ⚠️')
|
||||
}
|
||||
|
||||
// 从照片墙选择背景图
|
||||
const showLoveHeroGalleryModal = ref(false)
|
||||
const loadingLoveHeroGallery = ref(false)
|
||||
@@ -459,33 +453,23 @@ const confirmLoveHeroGallerySelect = () => {
|
||||
|
||||
const fetchHeroConfig = async () => {
|
||||
try {
|
||||
const response = await getConfigList()
|
||||
const response = await getLoveConfig()
|
||||
if (response.data && response.data.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
}
|
||||
const data = response.data.data || {}
|
||||
loveHeroBgUrl.value = data.heroBgUrl || ''
|
||||
loveHeroBgLoaded.value = true
|
||||
|
||||
const atmospheresStr = getValue('page.love.atmospheres', '[]')
|
||||
try {
|
||||
const parsed = JSON.parse(atmospheresStr)
|
||||
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||
loveAtmospheres.value = parsed
|
||||
} else {
|
||||
// 初始化默认的三个氛围配置,实现默认绑定到后台
|
||||
loveAtmospheres.value = [
|
||||
{ id: 'cherry', name: '樱落', src: '/assets/【哲风壁纸】樱花-樱花飘落.mp4', type: 'video' },
|
||||
{ id: 'island', name: '海风', src: '/assets/【哲风壁纸】户外-树枝-海岛.mp4', type: 'video' },
|
||||
{ id: 'snow', name: '雪杉', src: '/assets/【哲风壁纸】mc-下雪-云杉树.mp4', type: 'video' }
|
||||
]
|
||||
}
|
||||
} catch (e) {
|
||||
loveAtmospheres.value = [
|
||||
{ id: 'cherry', name: '樱落', src: '/assets/【哲风壁纸】樱花-樱花飘落.mp4', type: 'video' },
|
||||
{ id: 'island', name: '海风', src: '/assets/【哲风壁纸】户外-树枝-海岛.mp4', type: 'video' },
|
||||
{ id: 'snow', name: '雪杉', src: '/assets/【哲风壁纸】mc-下雪-云杉树.mp4', type: 'video' }
|
||||
]
|
||||
const parsed = data.atmospheres
|
||||
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||
loveAtmospheres.value = parsed.map((a: any) => ({
|
||||
id: a.id,
|
||||
name: a.name,
|
||||
src: a.src,
|
||||
type: a.type === 'image' ? 'image' : 'video'
|
||||
}))
|
||||
} else {
|
||||
// 初始化默认的三个氛围配置,实现默认绑定到后台
|
||||
loveAtmospheres.value = JSON.parse(JSON.stringify(DEFAULT_ATMOSPHERES))
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<template>
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<section class="archive-card p-4 sm:p-5">
|
||||
<h3 class="m-0 text-lg font-760 text-(--archive-text) flex items-center gap-1.5">
|
||||
@@ -46,7 +46,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NDatePicker, NInputNumber, NButton } from 'naive-ui'
|
||||
import { getConfigList, updateConfigBatch } from '@/api/config'
|
||||
import { getLoveConfig, saveLoveStats } from '@/api/love'
|
||||
|
||||
const message = useMessage()
|
||||
// statsModel conforms structure of LoveStats with startDate represented as timestamp locally
|
||||
@@ -61,20 +61,16 @@ const savingStats = ref(false)
|
||||
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
const response = await getConfigList()
|
||||
const response = await getLoveConfig()
|
||||
if (response.data?.code !== 200) return
|
||||
const list = response.data.data || []
|
||||
const getValue = (key: string, def: string) => {
|
||||
const item = list.find((c: any) => c.configKey === key)
|
||||
return item ? item.configValue : def
|
||||
}
|
||||
const stats = response.data.data?.stats || {}
|
||||
|
||||
const dateStr = getValue('love.stats.startDate', '2023-05-20')
|
||||
const dateStr = stats.startDate || '2023-05-20'
|
||||
statsModel.value.startDate = new Date(dateStr).getTime()
|
||||
statsModel.value.citiesCount = Number(getValue('love.stats.citiesCount', '0'))
|
||||
statsModel.value.flightDistance = Number(getValue('love.stats.flightDistance', '0'))
|
||||
statsModel.value.movieCount = Number(getValue('love.stats.movieCount', '0'))
|
||||
statsModel.value.mealCount = Number(getValue('love.stats.mealCount', '0'))
|
||||
statsModel.value.citiesCount = Number(stats.citiesCount ?? 0)
|
||||
statsModel.value.flightDistance = Number(stats.flightDistance ?? 0)
|
||||
statsModel.value.movieCount = Number(stats.movieCount ?? 0)
|
||||
statsModel.value.mealCount = Number(stats.mealCount ?? 0)
|
||||
} catch (err) {
|
||||
console.error('Failed to load stats', err)
|
||||
}
|
||||
@@ -83,17 +79,17 @@ const fetchStats = async () => {
|
||||
const handleSaveStats = async () => {
|
||||
savingStats.value = true
|
||||
const dateStr = new Date(statsModel.value.startDate).toISOString().split('T')[0]
|
||||
|
||||
const payload = [
|
||||
{ configKey: 'love.stats.startDate', configValue: dateStr },
|
||||
{ configKey: 'love.stats.citiesCount', configValue: String(statsModel.value.citiesCount) },
|
||||
{ configKey: 'love.stats.flightDistance', configValue: String(statsModel.value.flightDistance) },
|
||||
{ configKey: 'love.stats.movieCount', configValue: String(statsModel.value.movieCount) },
|
||||
{ configKey: 'love.stats.mealCount', configValue: String(statsModel.value.mealCount) }
|
||||
]
|
||||
|
||||
const payload = {
|
||||
startDate: dateStr,
|
||||
citiesCount: statsModel.value.citiesCount,
|
||||
flightDistance: statsModel.value.flightDistance,
|
||||
movieCount: statsModel.value.movieCount,
|
||||
mealCount: statsModel.value.mealCount
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await updateConfigBatch(payload)
|
||||
const response = await saveLoveStats(payload)
|
||||
if (response.data?.code !== 200) {
|
||||
throw new Error(response.data?.msg || '保存失败')
|
||||
}
|
||||
|
||||
@@ -252,11 +252,8 @@
|
||||
<div class="flex gap-2 items-center">
|
||||
<n-input v-model:value="formModel.reading.coverUrl" placeholder="输入外部路径,或点击上传" class="archive-input flex-1" />
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=now"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="readingCoverUploader"
|
||||
:show-file-list="false"
|
||||
@finish="handleUploadFinish"
|
||||
@error="handleUploadError"
|
||||
@before-upload="beforeUpload"
|
||||
class="flex-shrink-0"
|
||||
>
|
||||
@@ -489,11 +486,8 @@
|
||||
<div class="flex gap-2 w-full">
|
||||
<n-input v-model:value="bgm.src" placeholder="例如: /assets/music/mr-lawrence.mp3" class="archive-input font-mono flex-1" />
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=now"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="audioUploader(bgm)"
|
||||
:show-file-list="false"
|
||||
@finish="(options: any) => handleAudioUploadFinish(options, bgm)"
|
||||
@error="handleUploadError"
|
||||
@before-upload="beforeAudioUpload"
|
||||
class="flex-shrink-0"
|
||||
>
|
||||
@@ -543,11 +537,8 @@
|
||||
<div class="flex gap-2 w-full">
|
||||
<n-input v-model:value="noise.src" placeholder="例如: /assets/music/rain.mp3" class="archive-input font-mono flex-1" />
|
||||
<n-upload
|
||||
action="/api/blogs/upload?type=now"
|
||||
:headers="uploadHeaders"
|
||||
:custom-request="audioUploader(noise)"
|
||||
:show-file-list="false"
|
||||
@finish="(options: any) => handleAudioUploadFinish(options, noise)"
|
||||
@error="handleUploadError"
|
||||
@before-upload="beforeAudioUpload"
|
||||
class="flex-shrink-0"
|
||||
>
|
||||
@@ -584,12 +575,12 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, h } from 'vue'
|
||||
import { NFormItem, NInput, NSlider, NGrid, NGi, NDivider, NButton, NSpace, NSelect, NUpload, NDropdown, useMessage } from 'naive-ui'
|
||||
import { NFormItem, NInput, NSlider, NGrid, NGi, NDivider, NButton, NSpace, NSelect, NUpload, NDropdown, NRadio, NRadioGroup, useMessage } from 'naive-ui'
|
||||
import { createUploader } from '@/api/upload'
|
||||
|
||||
const props = defineProps<{
|
||||
formModel: any
|
||||
saving: boolean
|
||||
uploadHeaders: any
|
||||
lightColorOptions: any[]
|
||||
}>()
|
||||
|
||||
@@ -647,27 +638,25 @@ const beforeUpload = (data: { file: any }) => {
|
||||
return true
|
||||
}
|
||||
|
||||
const handleUploadFinish = ({ event }: any) => {
|
||||
try {
|
||||
const responseText = (event?.target as any)?.response
|
||||
if (responseText) {
|
||||
const res = JSON.parse(responseText)
|
||||
if (res && res.code === 200 && res.data) {
|
||||
const model = { ...props.formModel }
|
||||
model.reading.coverUrl = res.data
|
||||
emit('update:formModel', model)
|
||||
message.success('书籍封面图片上传成功 🖼️')
|
||||
} else {
|
||||
throw new Error(res?.msg || '上传接口返回错误')
|
||||
}
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(`封面上传失败: ${err.message || '解析错误'}`)
|
||||
}
|
||||
}
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器)
|
||||
const readingCoverUploader = createUploader((url) => {
|
||||
const model = { ...props.formModel }
|
||||
model.reading.coverUrl = url
|
||||
emit('update:formModel', model)
|
||||
}, 'now')
|
||||
|
||||
const handleUploadError = () => {
|
||||
message.error('图片上传失败,请检查网络或后端接口是否在线 ⚠️')
|
||||
// 音频上传目标为 v-for 列表项,按项缓存 uploader(避免每次渲染重建闭包/重复调用 useMessage)
|
||||
const audioUploaderCache = new Map<any, ReturnType<typeof createUploader>>()
|
||||
const audioUploader = (target: any) => {
|
||||
let handler = audioUploaderCache.get(target)
|
||||
if (!handler) {
|
||||
handler = createUploader((url) => {
|
||||
target.src = url
|
||||
emit('update:formModel', { ...props.formModel })
|
||||
}, 'now')
|
||||
audioUploaderCache.set(target, handler)
|
||||
}
|
||||
return handler
|
||||
}
|
||||
|
||||
const handleRemoveCover = () => {
|
||||
@@ -748,21 +737,6 @@ const beforeAudioUpload = (data: { file: any }) => {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
const handleAudioUploadFinish = ({ event }: any, target: any) => {
|
||||
try {
|
||||
const res = JSON.parse(event.target.response)
|
||||
if (res && res.code === 200 && res.data) {
|
||||
target.src = res.data
|
||||
emit('update:formModel', { ...props.formModel })
|
||||
message.success('音频文件上传成功 🎵')
|
||||
} else {
|
||||
message.error(res.msg || '音频上传被拒绝')
|
||||
}
|
||||
} catch (e) {
|
||||
message.error('解析服务器响应失败')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
+35
-57
@@ -34,7 +34,6 @@
|
||||
<NowStatusForm
|
||||
v-model:formModel="formModel"
|
||||
:saving="saving"
|
||||
:upload-headers="uploadHeaders"
|
||||
:light-color-options="lightColorOptions"
|
||||
@save-module="handleSaveCurrentModule"
|
||||
/>
|
||||
@@ -42,9 +41,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage } from 'naive-ui'
|
||||
import { getConfigList, updateConfigBatch } from '@/api/config'
|
||||
import { getNowView, saveNowView } from '@/api/config'
|
||||
|
||||
// 导入子组件
|
||||
import NowStatusForm from './components/NowStatusForm.vue'
|
||||
@@ -136,10 +135,6 @@ const defaultData = {
|
||||
|
||||
const formModel = ref(JSON.parse(JSON.stringify(defaultData)))
|
||||
|
||||
const uploadHeaders = computed(() => ({
|
||||
satoken: localStorage.getItem('satoken') || ''
|
||||
}))
|
||||
|
||||
const lightColorOptions = [
|
||||
{ label: '翡翠绿 (Active)', value: 'bg-emerald-500 shadow-emerald-500/50' },
|
||||
{ label: '绯红赤 (Romantic/Film)', value: 'bg-red-500 shadow-red-500/50' },
|
||||
@@ -155,41 +150,38 @@ const handleResetDefault = () => {
|
||||
|
||||
const loadNowConfig = async () => {
|
||||
try {
|
||||
const response = await getConfigList()
|
||||
if (response.data?.code === 200) {
|
||||
const list = response.data.data || []
|
||||
const item = list.find((c: any) => c.configKey === 'now.content.json')
|
||||
if (item && item.configValue) {
|
||||
try {
|
||||
const parsed = JSON.parse(item.configValue)
|
||||
|
||||
// 深度防空兼容性初始化
|
||||
if (!parsed.location) parsed.location = { ...defaultData.location }
|
||||
if (!parsed.mood) parsed.mood = { ...defaultData.mood }
|
||||
if (!parsed.mood.stats) {
|
||||
parsed.mood.stats = { ...defaultData.mood.stats }
|
||||
} else {
|
||||
parsed.mood.stats.focus = parsed.mood.stats.focus ?? 85
|
||||
parsed.mood.stats.creative = parsed.mood.stats.creative ?? 75
|
||||
parsed.mood.stats.calm = parsed.mood.stats.calm ?? 90
|
||||
parsed.mood.stats.energy = parsed.mood.stats.energy ?? 60
|
||||
parsed.mood.stats.social = parsed.mood.stats.social ?? 40
|
||||
parsed.mood.stats.physical = parsed.mood.stats.physical ?? 70
|
||||
}
|
||||
if (!parsed.reading) parsed.reading = { ...defaultData.reading }
|
||||
if (parsed.reading.progress === undefined) parsed.reading.progress = 68
|
||||
if (parsed.reading.coverUrl === undefined) parsed.reading.coverUrl = ''
|
||||
if (!parsed.listening) parsed.listening = { ...defaultData.listening }
|
||||
if (!parsed.setup) parsed.setup = { ...defaultData.setup }
|
||||
if (!parsed.setup.devices) parsed.setup.devices = []
|
||||
if (!parsed.radio) parsed.radio = { ...defaultData.radio }
|
||||
if (!parsed.radio.bgmList) parsed.radio.bgmList = []
|
||||
if (!parsed.radio.noiseList) parsed.radio.noiseList = []
|
||||
|
||||
formModel.value = parsed
|
||||
} catch (e) {
|
||||
console.error('Failed to parse now.content.json', e)
|
||||
const response = await getNowView()
|
||||
if (response.data?.code === 200 && response.data.data) {
|
||||
try {
|
||||
const parsed = response.data.data
|
||||
|
||||
// 深度防空兼容性初始化
|
||||
if (!parsed.location) parsed.location = { ...defaultData.location }
|
||||
if (!parsed.mood) parsed.mood = { ...defaultData.mood }
|
||||
if (!parsed.mood.stats) {
|
||||
parsed.mood.stats = { ...defaultData.mood.stats }
|
||||
} else {
|
||||
parsed.mood.stats.focus = parsed.mood.stats.focus ?? 85
|
||||
parsed.mood.stats.creative = parsed.mood.stats.creative ?? 75
|
||||
parsed.mood.stats.calm = parsed.mood.stats.calm ?? 90
|
||||
parsed.mood.stats.energy = parsed.mood.stats.energy ?? 60
|
||||
parsed.mood.stats.social = parsed.mood.stats.social ?? 40
|
||||
parsed.mood.stats.physical = parsed.mood.stats.physical ?? 70
|
||||
}
|
||||
if (!parsed.focus) parsed.focus = { ...defaultData.focus }
|
||||
if (!parsed.reading) parsed.reading = { ...defaultData.reading }
|
||||
if (parsed.reading.progress === undefined) parsed.reading.progress = 68
|
||||
if (parsed.reading.coverUrl === undefined) parsed.reading.coverUrl = ''
|
||||
if (!parsed.listening) parsed.listening = { ...defaultData.listening }
|
||||
if (!parsed.setup) parsed.setup = { ...defaultData.setup }
|
||||
if (!parsed.setup.devices) parsed.setup.devices = []
|
||||
if (!parsed.radio) parsed.radio = { ...defaultData.radio }
|
||||
if (!parsed.radio.bgmList) parsed.radio.bgmList = []
|
||||
if (!parsed.radio.noiseList) parsed.radio.noiseList = []
|
||||
|
||||
formModel.value = parsed
|
||||
} catch (e) {
|
||||
console.error('Failed to read now content payload', e)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -199,16 +191,9 @@ const loadNowConfig = async () => {
|
||||
|
||||
const handleSave = async () => {
|
||||
saving.value = true
|
||||
const payload = [
|
||||
{
|
||||
configKey: 'now.content.json',
|
||||
configValue: JSON.stringify(formModel.value),
|
||||
description: '前台此时此刻(Now)页面内容数据配置JSON'
|
||||
}
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await updateConfigBatch(payload)
|
||||
const response = await saveNowView(formModel.value)
|
||||
if (response.data?.code === 200) {
|
||||
message.success('“此时此刻”全部配置保存成功,前台已同步')
|
||||
await loadNowConfig()
|
||||
@@ -224,16 +209,9 @@ const handleSave = async () => {
|
||||
|
||||
const handleSaveCurrentModule = async (moduleLabel: string) => {
|
||||
saving.value = true
|
||||
const payload = [
|
||||
{
|
||||
configKey: 'now.content.json',
|
||||
configValue: JSON.stringify(formModel.value),
|
||||
description: '前台此时此刻(Now)页面内容数据配置JSON'
|
||||
}
|
||||
]
|
||||
|
||||
try {
|
||||
const response = await updateConfigBatch(payload)
|
||||
const response = await saveNowView(formModel.value)
|
||||
if (response.data?.code === 200) {
|
||||
message.success(`“${moduleLabel}”配置保存成功,前台已同步`)
|
||||
await loadNowConfig()
|
||||
|
||||
@@ -0,0 +1,330 @@
|
||||
<template>
|
||||
<div class="space-y-6">
|
||||
<!-- 卡片 A:管理员账户 -->
|
||||
<div class="border border-(--archive-border) rounded-2xl bg-(--archive-bg-card) p-6 md:p-8 shadow-sm transition-all hover:shadow-md text-left">
|
||||
<div class="flex items-start gap-3.5 pb-4 border-b border-(--archive-border)/40">
|
||||
<div class="h-12 w-12 rounded-2xl bg-(--archive-accent)/10 text-(--archive-accent) flex items-center justify-center shrink-0">
|
||||
<span class="i-mdi-shield-account-outline text-2xl"></span>
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<h3 class="m-0 text-base font-760 text-(--archive-text) tracking-wide">管理员账户</h3>
|
||||
<p class="text-xs text-(--archive-text)/60 mt-1 leading-relaxed max-w-[48rem]">
|
||||
管理员账号与密码用于后台登录验证,密码保存时由服务端自动加密,修改保存后立即生效,请务必妥善保管。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<n-form label-placement="top" class="mt-5 space-y-4">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<n-form-item label="管理员账号" required>
|
||||
<n-input v-model:value="accountForm.username" :input-props="{ autocomplete: 'off' }" placeholder="请输入管理员登录账号" class="archive-input" />
|
||||
</n-form-item>
|
||||
<n-form-item label="管理员密码" required>
|
||||
<n-input
|
||||
v-model:value="accountForm.password"
|
||||
type="password"
|
||||
show-password-on="click"
|
||||
:input-props="{ autocomplete: 'new-password' }"
|
||||
placeholder="请输入管理员登录密码"
|
||||
class="archive-input"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div class="border-t border-(--archive-border)/40 pt-4 mt-2 flex justify-end">
|
||||
<n-button type="primary" :loading="savingAccount" @click="handleSaveAccount">
|
||||
<template #icon><span class="i-mdi-content-save-outline"></span></template>
|
||||
保存账户信息
|
||||
</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
</div>
|
||||
|
||||
<!-- 卡片 B:作者身份档案 -->
|
||||
<div class="border border-(--archive-border) rounded-2xl bg-(--archive-bg-card) p-6 md:p-8 shadow-sm transition-all hover:shadow-md text-left">
|
||||
<div class="flex items-start gap-3.5 pb-4 border-b border-(--archive-border)/40">
|
||||
<div class="h-12 w-12 rounded-2xl bg-(--archive-accent)/10 text-(--archive-accent) flex items-center justify-center shrink-0">
|
||||
<span class="i-mdi-card-account-details-outline text-2xl"></span>
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<h3 class="m-0 text-base font-760 text-(--archive-text) tracking-wide">作者身份档案(前台关于作者页头像与标签)</h3>
|
||||
<p class="text-xs text-(--archive-text)/60 mt-1 leading-relaxed max-w-[48rem]">
|
||||
仅维护前台 /about 页面的作者姓名、身份角色、个人标签流与头像媒体;保存时只合并这四个字段,不会影响「关于作者」页维护的其余内容。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<n-form label-placement="top" class="mt-5 space-y-4">
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<n-form-item label="作者姓名 (Name)" required>
|
||||
<n-input v-model:value="profileForm.name" placeholder="请输入姓名,例如: RRTiamo" class="archive-input" />
|
||||
</n-form-item>
|
||||
<n-form-item label="身份角色 (Role / 标题文字)" required>
|
||||
<n-input v-model:value="profileForm.role" placeholder="前台大字标题,例如: 此间主人" class="archive-input" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<n-form-item label="个人标签流 (Tags - 回车或点击添加)">
|
||||
<n-dynamic-tags v-model:value="profileForm.tags" />
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="个人头像媒体 (Avatar URL)">
|
||||
<div class="space-y-3 w-full">
|
||||
<n-input v-model:value="profileForm.avatar" placeholder="输入外部头像链接,或点击下方本地上传..." class="font-mono archive-input" clearable />
|
||||
<div class="flex items-center gap-3">
|
||||
<n-upload
|
||||
:custom-request="authorUploader"
|
||||
:show-file-list="false"
|
||||
>
|
||||
<n-button secondary size="small" type="primary">
|
||||
<template #icon><span class="i-mdi-upload"></span></template>
|
||||
本地上传头像
|
||||
</n-button>
|
||||
</n-upload>
|
||||
<span class="text-[10px] tone-muted">推荐 1:1 比例头像图片,支持 mp4/webm 视频文件</span>
|
||||
</div>
|
||||
<!-- 头像媒体预览 -->
|
||||
<div v-if="profileForm.avatar" class="relative h-28 w-28 rounded-2xl overflow-hidden border border-(--archive-border)/40 bg-black/5 flex items-center justify-center">
|
||||
<video v-if="isMediaVideo(profileForm.avatar)" :src="profileForm.avatar" autoplay muted loop playsinline class="w-full h-full object-cover"></video>
|
||||
<img v-else :src="profileForm.avatar" class="w-full h-full object-cover" />
|
||||
</div>
|
||||
</div>
|
||||
</n-form-item>
|
||||
|
||||
<div class="border-t border-(--archive-border)/40 pt-4 mt-2 flex justify-end">
|
||||
<n-button type="primary" :loading="savingProfile" @click="handleSaveProfile">
|
||||
<template #icon><span class="i-mdi-content-save-outline"></span></template>
|
||||
保存身份档案
|
||||
</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
</div>
|
||||
|
||||
<!-- 卡片 C:伴侣信息 -->
|
||||
<div class="border border-(--archive-border) rounded-2xl bg-(--archive-bg-card) p-6 md:p-8 shadow-sm transition-all hover:shadow-md text-left">
|
||||
<div class="flex items-start gap-3.5 pb-4 border-b border-(--archive-border)/40">
|
||||
<div class="h-12 w-12 rounded-2xl bg-rose-500/10 text-rose-500 flex items-center justify-center shrink-0">
|
||||
<span class="i-mdi-heart-outline text-2xl"></span>
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<h3 class="m-0 text-base font-760 text-(--archive-text) tracking-wide">伴侣信息</h3>
|
||||
<p class="text-xs text-(--archive-text)/60 mt-1 leading-relaxed max-w-[48rem]">
|
||||
维护恋爱记首页女方身份、足迹页甜蜜点标记与信件落款中的伴侣昵称与头像(love.couple.info),保存后前台即时生效。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<n-form label-placement="top" class="mt-5 space-y-4">
|
||||
<n-form-item label="伴侣昵称 (Name)" required>
|
||||
<n-input v-model:value="coupleForm.name" placeholder="请输入伴侣昵称,例如: Sweetheart" class="archive-input" />
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="伴侣头像媒体 (Avatar URL)">
|
||||
<div class="space-y-3 w-full">
|
||||
<n-input v-model:value="coupleForm.avatar" placeholder="输入外部头像链接,或点击下方本地上传..." class="font-mono archive-input" clearable />
|
||||
<div class="flex items-center gap-3">
|
||||
<n-upload
|
||||
:custom-request="coupleUploader"
|
||||
:show-file-list="false"
|
||||
>
|
||||
<n-button secondary size="small" type="primary">
|
||||
<template #icon><span class="i-mdi-upload"></span></template>
|
||||
本地上传头像
|
||||
</n-button>
|
||||
</n-upload>
|
||||
<span class="text-[10px] tone-muted">推荐 1:1 比例头像图片,支持 mp4/webm 视频文件</span>
|
||||
</div>
|
||||
<!-- 头像媒体预览 -->
|
||||
<div v-if="coupleForm.avatar" class="relative h-28 w-28 rounded-2xl overflow-hidden border border-(--archive-border)/40 bg-black/5 flex items-center justify-center">
|
||||
<video v-if="isMediaVideo(coupleForm.avatar)" :src="coupleForm.avatar" autoplay muted loop playsinline class="w-full h-full object-cover"></video>
|
||||
<img v-else :src="coupleForm.avatar" class="w-full h-full object-cover" />
|
||||
</div>
|
||||
</div>
|
||||
</n-form-item>
|
||||
|
||||
<div class="border-t border-(--archive-border)/40 pt-4 mt-2 flex justify-end">
|
||||
<n-button type="primary" :loading="savingCouple" @click="handleSaveCouple">
|
||||
<template #icon><span class="i-mdi-content-save-outline"></span></template>
|
||||
保存伴侣信息
|
||||
</n-button>
|
||||
</div>
|
||||
</n-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useMessage, NForm, NFormItem, NInput, NButton, NDynamicTags, NUpload } from 'naive-ui'
|
||||
import { getAuthStatus, updateAccount } from '@/api/auth'
|
||||
import { getAboutView, saveAboutIdentity } from '@/api/about'
|
||||
import { getLoveConfig, saveLoveCouple } from '@/api/love'
|
||||
import { createUploader } from '@/api/upload'
|
||||
import { defaultProfile } from '@/mock/about'
|
||||
import type { AboutProfile } from '@/interface/about'
|
||||
|
||||
const message = useMessage()
|
||||
const savingAccount = ref(false)
|
||||
const savingProfile = ref(false)
|
||||
const savingCouple = ref(false)
|
||||
|
||||
// 上传统一走 api/upload.ts(axios 实例 + 全局拦截器),不再直传
|
||||
const authorUploader = createUploader((url) => { profileForm.value.avatar = url }, 'about')
|
||||
const coupleUploader = createUploader((url) => { coupleForm.value.avatar = url }, 'about')
|
||||
|
||||
// 卡片 A:管理员账户
|
||||
const accountForm = ref({
|
||||
username: 'admin',
|
||||
password: ''
|
||||
})
|
||||
|
||||
// 卡片 B:作者身份档案(仅编辑 name / role / tags / avatar 四个字段)
|
||||
const profileForm = ref({
|
||||
name: '',
|
||||
role: '',
|
||||
tags: [] as string[],
|
||||
avatar: ''
|
||||
})
|
||||
|
||||
// 卡片 C:伴侣信息(love.couple.info,JSON 序列化存储)
|
||||
const coupleForm = ref({
|
||||
name: '',
|
||||
avatar: ''
|
||||
})
|
||||
|
||||
// 页面加载时获取到的完整档案,作为保存合并失败时的兜底数据
|
||||
const loadedProfile = ref<AboutProfile>(JSON.parse(JSON.stringify(defaultProfile)))
|
||||
|
||||
const isMediaVideo = (url: string) => {
|
||||
if (!url) return false
|
||||
return /\.(mp4|webm|ogg|mov|m4v)($|\?)/i.test(url)
|
||||
}
|
||||
|
||||
const applyProfileToForm = (profile: AboutProfile) => {
|
||||
loadedProfile.value = profile
|
||||
profileForm.value.name = profile.name || ''
|
||||
profileForm.value.role = profile.role || ''
|
||||
profileForm.value.tags = Array.isArray(profile.tags) ? [...profile.tags] : []
|
||||
profileForm.value.avatar = profile.avatar || ''
|
||||
}
|
||||
|
||||
// 读取管理员账号与作者身份档案,填充三张卡片表单
|
||||
const fetchConfigs = async () => {
|
||||
// 管理员账户:以 sys_user 表为唯一权威,密码不回显(留空表示不修改)
|
||||
try {
|
||||
const response = await getAuthStatus()
|
||||
if (response.data && response.data.code === 200 && response.data.data) {
|
||||
accountForm.value.username = response.data.data.username || 'admin'
|
||||
accountForm.value.password = ''
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load admin account info', err)
|
||||
}
|
||||
|
||||
// 伴侣信息:love_* 关系表
|
||||
try {
|
||||
const response = await getLoveConfig()
|
||||
if (response.data && response.data.code === 200) {
|
||||
const couple = response.data.data?.couple || {}
|
||||
coupleForm.value.name = couple.name || ''
|
||||
coupleForm.value.avatar = couple.avatar || ''
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load couple info', err)
|
||||
}
|
||||
|
||||
// 作者身份档案:统一走 about_* 关系表聚合接口
|
||||
await reloadProfile()
|
||||
}
|
||||
|
||||
// 从聚合接口加载身份档案(与「关于作者」页同源)
|
||||
const reloadProfile = async () => {
|
||||
try {
|
||||
const response = await getAboutView()
|
||||
if (response.data && response.data.code === 200 && response.data.data) {
|
||||
applyProfileToForm({ ...JSON.parse(JSON.stringify(defaultProfile)), ...response.data.data })
|
||||
return
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to load about identity', err)
|
||||
}
|
||||
applyProfileToForm(JSON.parse(JSON.stringify(defaultProfile)))
|
||||
}
|
||||
|
||||
// 保存管理员账户
|
||||
const handleSaveAccount = async () => {
|
||||
savingAccount.value = true
|
||||
|
||||
try {
|
||||
const response = await updateAccount({
|
||||
username: accountForm.value.username,
|
||||
password: accountForm.value.password
|
||||
})
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success(response.data.msg || '账户信息已保存')
|
||||
await fetchConfigs()
|
||||
} else {
|
||||
throw new Error(response.data?.msg || '保存失败')
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(err.message || '配置提交失败,网络连接异常。')
|
||||
} finally {
|
||||
savingAccount.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 保存作者身份档案(只更新 name / role / tags / avatar,不触碰其余内容)
|
||||
const handleSaveProfile = async () => {
|
||||
savingProfile.value = true
|
||||
try {
|
||||
const response = await saveAboutIdentity({
|
||||
name: profileForm.value.name,
|
||||
role: profileForm.value.role,
|
||||
tags: [...profileForm.value.tags],
|
||||
avatar: profileForm.value.avatar
|
||||
})
|
||||
|
||||
if (response.data && response.data.code === 200) {
|
||||
loadedProfile.value = JSON.parse(JSON.stringify(profileForm.value))
|
||||
message.success('作者身份档案已保存,前台关于页已同步!')
|
||||
} else {
|
||||
throw new Error(response.data?.msg || '保存失败')
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(err.message || '配置提交失败,网络连接异常。')
|
||||
} finally {
|
||||
savingProfile.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 保存伴侣信息(love_couple + love_stats 关系域)
|
||||
const handleSaveCouple = async () => {
|
||||
savingCouple.value = true
|
||||
|
||||
try {
|
||||
const response = await saveLoveCouple({
|
||||
name: coupleForm.value.name,
|
||||
avatar: coupleForm.value.avatar
|
||||
})
|
||||
if (response.data && response.data.code === 200) {
|
||||
message.success('伴侣信息已保存,前台恋爱页/足迹页已同步!')
|
||||
} else {
|
||||
throw new Error(response.data?.msg || '保存失败')
|
||||
}
|
||||
} catch (err: any) {
|
||||
message.error(err.message || '配置提交失败,网络连接异常。')
|
||||
} finally {
|
||||
savingCouple.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchConfigs()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.archive-input :deep(.n-input-wrapper) {
|
||||
border-radius: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -3,11 +3,9 @@
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"types": ["vite/client"],
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
},
|
||||
"ignoreDeprecations": "6.0",
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { defineConfig, loadEnv } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import UnoCSS from 'unocss/vite'
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import mdiIcons from '@iconify-json/mdi/icons.json' with { type: 'json' }
|
||||
import {
|
||||
extractorSplit,
|
||||
presetAttributify,
|
||||
@@ -57,6 +58,11 @@ export default defineConfig(({ mode }) => {
|
||||
presetIcons({
|
||||
scale: 1.2,
|
||||
warn: true,
|
||||
// 显式绑定本地 mdi 图标集(静态导入避免运行时动态 import JSON 报 ERR_IMPORT_ATTRIBUTE_MISSING),
|
||||
// 不再依赖编辑器环境探测(此前用 delete process.env.VSCODE_CWD 规避)
|
||||
collections: {
|
||||
mdi: () => mdiIcons,
|
||||
},
|
||||
}),
|
||||
],
|
||||
transformers: [
|
||||
|
||||
Reference in New Issue
Block a user