feat: add configurable association education links

This commit is contained in:
wuzilong committed 2026-11-02 11:54:25 +08:00
1 parent d3c5461de5
commit 740d00880a
14 files changed
+490 -4

No files matched your search

+13
View File
@@ -75,3 +75,16 @@ export function saveRelatedLinks(data: Record<string, unknown>) {
export function saveCompliance(data: Record<string, unknown>) {
return request.put({ url: '/api/admin/home/compliance', data })
}
export interface AssociationEducationLinks {
webUrl: string
mobileUrl: string
}
export function fetchAssociationEducation() {
return request.get<AssociationEducationLinks>({ url: '/api/admin/edu/association' })
}
export function saveAssociationEducation(data: AssociationEducationLinks) {
return request.put({ url: '/api/admin/edu/association', data })
}
@@ -0,0 +1,102 @@
<template>
<div v-loading="loading" class="min-h-40">
<ElAlert v-if="failed" title="暂时无法读取协会教育配置" type="error" :closable="false">
<ElButton link type="primary" @click="load">重试</ElButton>
</ElAlert>
<template v-else-if="ready">
<div class="flex flex-wrap items-center justify-between gap-3 mb-4">
<p class="m-0 text-sm text-g-600">配置协会教育平台入口,门户点击后在新窗口打开。</p>
<ElButton v-if="canEdit" type="primary" :loading="saving" @click="save">保存</ElButton>
</div>
<ElForm
ref="formRef"
:model="links"
:rules="rules"
label-position="top"
:disabled="!canEdit || saving"
class="association-form"
>
<ElFormItem label="Web 端地址" prop="webUrl">
<ElInput v-model="links.webUrl" placeholder="https://" maxlength="2048" clearable />
</ElFormItem>
<ElFormItem label="移动端地址" prop="mobileUrl">
<ElInput v-model="links.mobileUrl" placeholder="https://" maxlength="2048" clearable />
</ElFormItem>
</ElForm>
<p class="m-0 text-sm text-g-600">留空时,门户对应入口显示“暂未开放”。</p>
</template>
</div>
</template>
<script setup lang="ts">
import type { FormInstance, FormRules } from 'element-plus'
import { fetchAssociationEducation, saveAssociationEducation } from '@/api/home'
import { useAuth } from '@/hooks/core/useAuth'
const { hasAuth } = useAuth()
const canEdit = computed(() => hasAuth('edu:edit'))
const formRef = ref<FormInstance>()
const links = reactive({ webUrl: '', mobileUrl: '' })
const loading = ref(false)
const saving = ref(false)
const ready = ref(false)
const failed = ref(false)
const validateUrl = (_rule: unknown, value: string, callback: (error?: Error) => void) => {
const text = value.trim()
if (!text) return callback()
try {
const url = new URL(text)
if (
!/^https?:\/\//i.test(text) ||
!url.hostname ||
url.username ||
url.password ||
/[\s\\]/u.test(text) ||
Array.from(text).some((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127) ||
url.port === '0'
)
throw new Error()
callback()
} catch {
callback(new Error('请填写完整的 http:// 或 https:// 网址,不包含账号密码'))
}
}
const rules: FormRules = {
webUrl: [{ validator: validateUrl, trigger: 'blur' }],
mobileUrl: [{ validator: validateUrl, trigger: 'blur' }]
}
const load = async () => {
loading.value = true
failed.value = false
try {
Object.assign(links, await fetchAssociationEducation())
ready.value = true
} catch {
failed.value = true
} finally {
loading.value = false
}
}
const save = async () => {
if (!canEdit.value || saving.value || !(await formRef.value?.validate().catch(() => false)))
return
saving.value = true
try {
const data = { webUrl: links.webUrl.trim(), mobileUrl: links.mobileUrl.trim() }
await saveAssociationEducation(data)
Object.assign(links, data)
ElMessage.success('已保存')
} finally {
saving.value = false
}
}
onMounted(load)
</script>
<style scoped>
.association-form {
max-width: 600px;
}
</style>
+19 -4
View File
@@ -3,8 +3,12 @@
<ElTabs v-if="ready" v-model="activeTab" type="border-card">
<ElTabPane label="在线教育" name="platforms">
<div class="flex flex-wrap items-center justify-between gap-3 mb-4">
<p class="m-0 text-sm text-g-600">每张卡片一张图,图下是教育网站名称。门户点击后在新窗口打开网址。</p>
<ElButton v-auth="'edu:edit'" type="primary" :loading="saving" @click="save">保存</ElButton>
<p class="m-0 text-sm text-g-600"
>每张卡片一张图,图下是教育网站名称。门户点击后在新窗口打开网址。</p
>
<ElButton v-auth="'edu:edit'" type="primary" :loading="saving" @click="save"
>保存</ElButton
>
</div>
<div class="media-grid">
<article v-for="(item, index) in items" :key="index" class="media-card">
@@ -14,7 +18,12 @@
@pick="(payload) => assignImage(item, payload)"
@clear="clearImage(item)"
/>
<ElInput v-model="item.name" class="mt-3" :disabled="!canEdit" placeholder="教育网站名称" />
<ElInput
v-model="item.name"
class="mt-3"
:disabled="!canEdit"
placeholder="教育网站名称"
/>
<ElInput v-model="item.url" class="mt-2" :disabled="!canEdit" placeholder="https://" />
<div class="mt-3 flex items-center justify-between gap-2">
<div class="flex items-center gap-2">
@@ -26,7 +35,9 @@
controls-position="right"
/>
</div>
<ElButton v-if="canEdit" link type="danger" @click="items.splice(index, 1)">删除</ElButton>
<ElButton v-if="canEdit" link type="danger" @click="items.splice(index, 1)"
>删除</ElButton
>
</div>
</article>
<button v-if="canEdit" type="button" class="media-add" @click="addItem">
@@ -43,11 +54,15 @@
enable-cover
/>
</ElTabPane>
<ElTabPane label="协会教育" name="association">
<AssociationEducation v-if="activeTab === 'association'" />
</ElTabPane>
</ElTabs>
</div>
</template>
<script setup lang="ts">
import AssociationEducation from './components/AssociationEducation.vue'
import AboutColumnEditor from '@/views/about/components/AboutColumnEditor.vue'
import { fetchEduPlatforms, saveEduPlatforms } from '@/api/home'
import { useAuth } from '@/hooks/core/useAuth'