fix(site): 精简站点配置,移除名称/Banner/相关链接 (#15)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
608afb88ea
commit
460cfdc78a
8 files changed
+24
-238
No files matched your search
@@ -173,18 +173,10 @@ export interface AdminFileQuery extends PageQuery {
|
||||
q?: string
|
||||
}
|
||||
|
||||
export interface FriendLink {
|
||||
name: string
|
||||
url: string
|
||||
}
|
||||
|
||||
export interface SiteSettings {
|
||||
site_name?: string | null
|
||||
logo_file_id?: number | null
|
||||
banner_file_ids?: number[] | null
|
||||
icp_text?: string | null
|
||||
police_text?: string | null
|
||||
friend_links?: FriendLink[] | null
|
||||
link_cirea?: string | null
|
||||
link_housing?: string | null
|
||||
complaint_workdays?: number | null
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
<div>
|
||||
<ElCard v-loading="loading">
|
||||
<ElForm label-width="140px" class="max-w-3xl">
|
||||
<ElFormItem label="站点名称">
|
||||
<ElInput v-model="form.site_name" :disabled="!canEdit" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="LOGO">
|
||||
<div class="flex items-center gap-3">
|
||||
<ElImage
|
||||
@@ -24,62 +21,12 @@
|
||||
<ElProgress v-if="logoUploading" class="mt-2 max-w-xs" :percentage="logoPercent" />
|
||||
<input ref="logoInput" class="hidden" type="file" accept="image/*" @change="onLogo" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="Banner">
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<div v-for="item in banners" :key="item.id" class="relative">
|
||||
<ElImage :src="item.url" fit="cover" class="w-40 h-20 border border-g-300 rounded" />
|
||||
<ElButton
|
||||
v-if="canEdit"
|
||||
class="absolute top-1 right-1"
|
||||
circle
|
||||
size="small"
|
||||
type="danger"
|
||||
@click="removeBanner(item.id)"
|
||||
>
|
||||
×
|
||||
</ElButton>
|
||||
</div>
|
||||
<ElButton v-auth="'site:edit'" :loading="bannerUploading" @click="pickBanner"
|
||||
>上传</ElButton
|
||||
>
|
||||
</div>
|
||||
<ElProgress v-if="bannerUploading" class="mt-2 max-w-xs" :percentage="bannerPercent" />
|
||||
<input
|
||||
ref="bannerInput"
|
||||
class="hidden"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
@change="onBanner"
|
||||
/>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="ICP 备案号">
|
||||
<ElInput v-model="form.icp_text" :disabled="!canEdit" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="公安备案号">
|
||||
<ElInput v-model="form.police_text" :disabled="!canEdit" />
|
||||
</ElFormItem>
|
||||
<ElFormItem label="相关链接">
|
||||
<div class="w-full flex flex-col gap-2">
|
||||
<div v-for="(link, index) in form.friend_links" :key="index" class="flex gap-2">
|
||||
<ElInput v-model="link.name" placeholder="名称" :disabled="!canEdit" />
|
||||
<ElInput v-model="link.url" placeholder="地址" :disabled="!canEdit" />
|
||||
<ElButton
|
||||
v-if="canEdit"
|
||||
link
|
||||
type="danger"
|
||||
@click="form.friend_links.splice(index, 1)"
|
||||
>
|
||||
删除
|
||||
</ElButton>
|
||||
</div>
|
||||
<div>
|
||||
<ElButton v-if="canEdit" @click="form.friend_links.push({ name: '', url: '' })">
|
||||
添加链接
|
||||
</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
</ElFormItem>
|
||||
<ElFormItem label="中房学">
|
||||
<ElInput v-model="form.link_cirea" placeholder="外链地址" :disabled="!canEdit" />
|
||||
</ElFormItem>
|
||||
@@ -127,7 +74,7 @@
|
||||
fetchUpdateSiteSettings,
|
||||
uploadAdminFile
|
||||
} from '@/api/system-manage'
|
||||
import type { FriendLink, SiteSettings } from '@/types/admin'
|
||||
import type { SiteSettings } from '@/types/admin'
|
||||
|
||||
defineOptions({ name: 'SiteSetting' })
|
||||
|
||||
@@ -136,21 +83,14 @@
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const logoUploading = ref(false)
|
||||
const bannerUploading = ref(false)
|
||||
const logoPercent = ref(0)
|
||||
const bannerPercent = ref(0)
|
||||
const logoUrl = ref('')
|
||||
const banners = ref<{ id: number; url: string }[]>([])
|
||||
const logoInput = ref<HTMLInputElement>()
|
||||
const bannerInput = ref<HTMLInputElement>()
|
||||
|
||||
const form = reactive({
|
||||
site_name: '',
|
||||
logo_file_id: null as number | null,
|
||||
banner_file_ids: [] as number[],
|
||||
icp_text: '',
|
||||
police_text: '',
|
||||
friend_links: [] as FriendLink[],
|
||||
link_cirea: '',
|
||||
link_housing: '',
|
||||
complaint_workdays: null as number | null,
|
||||
@@ -166,38 +106,6 @@
|
||||
return null
|
||||
}
|
||||
|
||||
const asIdList = (value: unknown): number[] => {
|
||||
let source = value
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
try {
|
||||
source = JSON.parse(value)
|
||||
} catch {
|
||||
source = []
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(source)) return []
|
||||
return source.map((item) => asNumber(item)).filter((item): item is number => item !== null)
|
||||
}
|
||||
|
||||
const asLinks = (value: unknown): FriendLink[] => {
|
||||
let source = value
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
try {
|
||||
source = JSON.parse(value)
|
||||
} catch {
|
||||
source = []
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(source)) return []
|
||||
return source.map((item) => {
|
||||
const row = item && typeof item === 'object' ? (item as Record<string, unknown>) : {}
|
||||
return {
|
||||
name: asText(row.name),
|
||||
url: asText(row.url || row.address)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const asSettings = (payload: unknown): Record<string, unknown> => {
|
||||
if (Array.isArray(payload)) return listToMap(payload)
|
||||
if (!payload || typeof payload !== 'object') return {}
|
||||
@@ -232,29 +140,15 @@
|
||||
loading.value = true
|
||||
try {
|
||||
const raw = asSettings(await fetchGetSiteSettings())
|
||||
form.site_name = asText(raw.site_name)
|
||||
form.logo_file_id = asNumber(raw.logo_file_id)
|
||||
form.banner_file_ids = asIdList(raw.banner_file_ids)
|
||||
form.icp_text = asText(raw.icp_text)
|
||||
form.police_text = asText(raw.police_text)
|
||||
form.friend_links = asLinks(raw.friend_links)
|
||||
form.link_cirea = asText(raw.link_cirea)
|
||||
form.link_housing = asText(raw.link_housing)
|
||||
form.complaint_workdays = asNumber(raw.complaint_workdays)
|
||||
form.expert_reply_workdays = asNumber(raw.expert_reply_workdays)
|
||||
const directLogo = asText(raw.logoUrl)
|
||||
logoUrl.value = directLogo || (form.logo_file_id ? await fileUrl(form.logo_file_id) : '')
|
||||
const bannerUrls = Array.isArray(raw.bannerUrls)
|
||||
? raw.bannerUrls.map((item) => asText(item))
|
||||
: []
|
||||
if (bannerUrls.length === form.banner_file_ids.length) {
|
||||
banners.value = form.banner_file_ids.map((id, index) => ({ id, url: bannerUrls[index] }))
|
||||
} else {
|
||||
banners.value = []
|
||||
for (const id of form.banner_file_ids) {
|
||||
banners.value.push({ id, url: await fileUrl(id) })
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -263,7 +157,6 @@
|
||||
onMounted(load)
|
||||
|
||||
const pickLogo = () => logoInput.value?.click()
|
||||
const pickBanner = () => bannerInput.value?.click()
|
||||
|
||||
const onLogo = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement
|
||||
@@ -285,54 +178,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
const onBanner = async (event: Event) => {
|
||||
const input = event.target as HTMLInputElement
|
||||
const files = input.files ? Array.from(input.files) : []
|
||||
input.value = ''
|
||||
if (!files.length) return
|
||||
bannerUploading.value = true
|
||||
try {
|
||||
for (const file of files) {
|
||||
bannerPercent.value = 0
|
||||
const saved = await uploadAdminFile(file, 'public', (percent) => {
|
||||
bannerPercent.value = percent
|
||||
})
|
||||
form.banner_file_ids.push(saved.id)
|
||||
banners.value.push({ id: saved.id, url: saved.url || '' })
|
||||
}
|
||||
} catch {
|
||||
// 失败文案由接口层展示
|
||||
} finally {
|
||||
bannerUploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const clearLogo = () => {
|
||||
form.logo_file_id = null
|
||||
logoUrl.value = ''
|
||||
}
|
||||
|
||||
const removeBanner = (id: number) => {
|
||||
form.banner_file_ids = form.banner_file_ids.filter((item) => item !== id)
|
||||
banners.value = banners.value.filter((item) => item.id !== id)
|
||||
}
|
||||
|
||||
const save = async () => {
|
||||
const links = form.friend_links.map((item) => ({
|
||||
name: item.name.trim(),
|
||||
url: item.url.trim()
|
||||
}))
|
||||
if (links.some((item) => (item.name && !item.url) || (!item.name && item.url))) {
|
||||
ElMessage.warning('相关链接需要同时填写名称和地址')
|
||||
return
|
||||
}
|
||||
const payload: Partial<SiteSettings> = {
|
||||
site_name: form.site_name,
|
||||
logo_file_id: form.logo_file_id,
|
||||
banner_file_ids: form.banner_file_ids,
|
||||
icp_text: form.icp_text,
|
||||
police_text: form.police_text,
|
||||
friend_links: links.filter((item) => item.name && item.url),
|
||||
link_cirea: form.link_cirea.trim(),
|
||||
link_housing: form.link_housing.trim(),
|
||||
complaint_workdays: form.complaint_workdays,
|
||||
|
||||
Reference in new issue
Block a user