feat: 迁移自定义功能至 1.5.9.9 版本

包含音乐源限制、CI 防 OOM 优化、数据库连接池优化、管理端权限及 UI 细节定制等功能
This commit is contained in:
2026-09-12 19:26:42 +08:00
parent 34f0679117
commit 1106aeea6c
161 changed files with 18963 additions and 27900 deletions
+190 -313
View File
@@ -2,82 +2,45 @@
<div class="max-w-[1400px] mx-auto space-y-8 pb-20">
<div class="flex flex-col md:flex-row md:items-end justify-between gap-6">
<div>
<h2 class="text-2xl font-black text-text-primary tracking-tight">{{ locale.title }}</h2>
<p class="text-xs text-text-tertiary mt-1">{{ locale.desc }}</p>
<h2 class="text-2xl font-black text-zinc-100 tracking-tight">向用户发送通知</h2>
<p class="text-xs text-zinc-500 mt-1">即时推送系统公告、活动信息或重要提醒至指定群体</p>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-12 gap-8 items-start">
<!-- 左侧:编辑区 -->
<div class="lg:col-span-7 space-y-6">
<div class="bg-bg-secondary-30 border border-border-secondary rounded-[2rem] p-8 shadow-xl">
<div class="bg-zinc-900/30 border border-zinc-800 rounded-[2rem] p-8 shadow-xl">
<div class="space-y-6">
<!-- 标题 -->
<div class="space-y-2">
<label class="text-[10px] font-black text-text-disabled uppercase tracking-[0.2em] px-1"
>{{ locale.notificationTitle }}</label
<label class="text-[10px] font-black text-zinc-600 uppercase tracking-[0.2em] px-1"
>通知标题</label
>
<input
v-model="form.title"
type="text"
:placeholder="locale.titlePlaceholder"
class="w-full bg-bg-primary border border-border-secondary rounded-2xl px-5 py-3.5 text-sm focus:outline-none focus:border-primary-30 transition-all text-text-primary placeholder:text-text-primary"
placeholder="请输入通知标题"
class="w-full bg-zinc-950 border border-zinc-800 rounded-2xl px-5 py-3.5 text-sm focus:outline-none focus:border-blue-500/30 transition-all text-zinc-200 placeholder:text-zinc-800"
>
</div>
<!-- 内容 -->
<div class="space-y-2">
<label class="text-[10px] font-black text-text-disabled uppercase tracking-[0.2em] px-1"
>{{ locale.notificationContent }}</label
<label class="text-[10px] font-black text-zinc-600 uppercase tracking-[0.2em] px-1"
>通知内容</label
>
<textarea
v-model="form.content"
:placeholder="locale.contentPlaceholder"
class="w-full bg-bg-primary border border-border-secondary rounded-2xl px-5 py-4 text-sm focus:outline-none focus:border-primary-30 transition-all text-text-primary placeholder:text-text-primary min-h-[160px] resize-none"
placeholder="请输入通知详情内容..."
class="w-full bg-zinc-950 border border-zinc-800 rounded-2xl px-5 py-4 text-sm focus:outline-none focus:border-blue-500/30 transition-all text-zinc-200 placeholder:text-zinc-800 min-h-[160px] resize-none"
/>
<p class="px-1 text-[10px] font-medium text-text-disabled">
{{ locale.markdownHint }}
</p>
</div>
<!-- 重要通知开关 -->
<label
class="flex cursor-pointer items-start gap-4 rounded-2xl border p-4 shadow-sm transition-colors"
:class="
form.important
? 'border-primary-300 bg-primary-10'
: 'border-border-tertiary bg-bg-primary hover:border-border-quaternary hover:bg-bg-secondary'
"
>
<span
class="relative mt-0.5 inline-block h-6 w-11 shrink-0"
>
<input v-model="form.important" type="checkbox" class="peer sr-only">
<span
class="absolute inset-0 rounded-full bg-border-tertiary transition-colors peer-checked:bg-primary peer-focus-visible:ring-2 peer-focus-visible:ring-primary-300"
/>
<span
class="absolute left-1 top-1 h-4 w-4 rounded-full bg-white shadow-sm transition-transform peer-checked:translate-x-5"
/>
</span>
<span class="min-w-0">
<span class="flex items-center gap-2 text-sm font-black text-text-primary">
<AlertTriangle
:size="16"
:class="form.important ? 'text-primary' : 'text-text-tertiary'"
/>
{{ locale.importantToggleTitle }}
</span>
<span class="mt-1 block text-xs leading-relaxed text-text-secondary">
{{ locale.importantToggleDescription }}
</span>
</span>
</label>
<!-- 范围选择 -->
<div class="space-y-3 pt-4 border-t border-border-secondary-50">
<label class="text-[10px] font-black text-text-disabled uppercase tracking-[0.2em] px-1"
>{{ locale.scope }}</label
<div class="space-y-3 pt-4 border-t border-zinc-800/50">
<label class="text-[10px] font-black text-zinc-600 uppercase tracking-[0.2em] px-1"
>通知范围</label
>
<div class="flex flex-wrap gap-2">
<button
@@ -86,8 +49,8 @@
:class="[
'flex items-center gap-2 px-4 py-2.5 rounded-xl text-[11px] font-black transition-all border',
form.scope === opt.id
? 'bg-primary-hover border-primary text-text-primary shadow-lg shadow-[var(--primary-glow)]'
: 'bg-bg-primary border-border-secondary text-text-tertiary hover:border-border-tertiary hover:text-text-secondary'
? 'bg-blue-600 border-blue-500 text-white shadow-lg shadow-blue-900/20'
: 'bg-zinc-950 border-zinc-800 text-zinc-500 hover:border-zinc-700 hover:text-zinc-300'
]"
@click="form.scope = opt.id"
>
@@ -103,26 +66,24 @@
<div
v-if="form.scope === 'ALL'"
key="all"
class="p-4 bg-primary-5 border border-primary-10 rounded-2xl flex items-center gap-4"
class="p-4 bg-blue-500/5 border border-blue-500/10 rounded-2xl flex items-center gap-4"
>
<Info class="text-primary shrink-0" :size="18" />
<p class="text-[11px] font-bold text-text-tertiary">
{{ locale.allUsersHint }}
<Info class="text-blue-500 shrink-0" :size="18" />
<p class="text-[11px] font-bold text-zinc-400">
将向系统中所有已注册的活跃用户发送此通知。
</p>
</div>
<div v-else-if="form.scope === 'GRADE'" key="grade" class="space-y-4">
<div class="space-y-1.5">
<span class="text-[9px] font-black text-text-disabled uppercase tracking-widest px-1"
>{{ locale.selectGrade }}</span
<span class="text-[9px] font-black text-zinc-600 uppercase tracking-widest px-1"
>选择年级</span
>
<CustomSelect
v-model="form.grade"
:options="gradeOptions"
label-key="label"
value-key="value"
:placeholder="locale.selectGradePlaceholder"
class-name="w-full md:w-64"
:options="['高一', '高二', '高三', '教师']"
placeholder="请选择年级"
class="w-full md:w-64"
/>
</div>
</div>
@@ -133,61 +94,55 @@
class="grid grid-cols-1 md:grid-cols-2 gap-4"
>
<div class="space-y-1.5">
<span class="text-[9px] font-black text-text-disabled uppercase tracking-widest px-1"
>{{ locale.grade }}</span
<span class="text-[9px] font-black text-zinc-600 uppercase tracking-widest px-1"
>年级</span
>
<CustomSelect
v-model="form.classGrade"
:options="gradeOptions"
label-key="label"
value-key="value"
:placeholder="locale.selectGradePlaceholder"
class-name="w-full"
:options="['高一', '高二', '高三', '教师']"
placeholder="请选择年级"
class="w-full"
/>
</div>
<div class="space-y-1.5">
<span class="text-[9px] font-black text-text-disabled uppercase tracking-widest px-1"
>{{ locale.className }}</span
<span class="text-[9px] font-black text-zinc-600 uppercase tracking-widest px-1"
>班级</span
>
<CustomSelect
v-model="form.className"
:options="classOptionsForClassScope"
:options="classNumberOptions"
label-key="label"
value-key="value"
:placeholder="locale.selectClassPlaceholder"
placeholder="请选择班级"
class-name="w-full"
:disabled="!form.classGrade"
/>
</div>
</div>
<div v-else-if="form.scope === 'MULTI_CLASS'" key="multi" class="space-y-4">
<div class="p-6 bg-bg-primary-50 border border-border-secondary border-dashed rounded-2xl">
<div class="p-6 bg-zinc-950/50 border border-zinc-800 border-dashed rounded-2xl">
<div class="grid grid-cols-1 md:grid-cols-2 gap-3 mb-4">
<CustomSelect
v-model="multiClassForm.grade"
:options="gradeOptions"
label-key="label"
value-key="value"
:placeholder="locale.selectGradePlaceholder"
class-name="w-full"
:options="['高一', '高二', '高三', '教师']"
placeholder="请选择年级"
class="w-full"
/>
<div class="flex gap-2">
<CustomSelect
v-model="multiClassForm.class"
:options="classOptionsForMultiClassScope"
:options="classNumberOptions"
label-key="label"
value-key="value"
:placeholder="locale.selectClassPlaceholder"
placeholder="请选择班级"
class-name="flex-1"
:disabled="!multiClassForm.grade"
/>
<button
:disabled="!canAddClass"
class="px-4 bg-bg-tertiary hover:bg-bg-quaternary disabled:opacity-50 disabled:cursor-not-allowed text-text-tertiary font-bold rounded-xl text-xs transition-all"
class="px-4 bg-zinc-800 hover:bg-zinc-700 disabled:opacity-50 disabled:cursor-not-allowed text-zinc-400 font-bold rounded-xl text-xs transition-all"
@click="addClassToSelection"
>
{{ locale.add }}
添加
</button>
</div>
</div>
@@ -196,13 +151,13 @@
<div
v-for="(cls, index) in form.selectedClasses"
:key="index"
class="flex items-center gap-2 px-3 py-1.5 bg-bg-secondary border border-border-secondary rounded-lg group"
class="flex items-center gap-2 px-3 py-1.5 bg-zinc-900 border border-zinc-800 rounded-lg group"
>
<span class="text-[10px] font-bold text-text-tertiary"
<span class="text-[10px] font-bold text-zinc-400"
>{{ cls.grade }} {{ cls.class }}</span
>
<button
class="text-text-disabled hover:text-error transition-colors"
class="text-zinc-600 hover:text-red-400 transition-colors"
@click="removeClassFromSelection(index)"
>
<X :size="12" />
@@ -210,8 +165,8 @@
</div>
</div>
<div v-else class="text-center py-4">
<p class="text-[10px] font-black text-text-secondary uppercase tracking-widest">
{{ locale.noClassSelected }}
<p class="text-[10px] font-black text-zinc-700 uppercase tracking-widest">
未选择任何班级
</p>
</div>
</div>
@@ -221,19 +176,19 @@
<div class="relative flex items-center">
<Search
v-if="!userSearchLoading"
class="absolute left-4 text-text-secondary pointer-events-none"
class="absolute left-4 text-zinc-700 pointer-events-none"
:size="16"
/>
<Loader2
v-else
class="absolute left-4 text-primary animate-spin pointer-events-none"
class="absolute left-4 text-blue-500 animate-spin pointer-events-none"
:size="16"
/>
<input
v-model="userSearchQuery"
type="text"
:placeholder="locale.userSearchPlaceholder"
class="w-full bg-bg-primary border border-border-secondary rounded-2xl pl-12 pr-4 py-3 text-sm focus:outline-none focus:border-primary-30 transition-all text-text-primary"
placeholder="搜索并选择用户 (姓名、用户名或ID)..."
class="w-full bg-zinc-950 border border-zinc-800 rounded-2xl pl-12 pr-4 py-3 text-sm focus:outline-none focus:border-blue-500/30 transition-all text-zinc-200"
@input="onUserSearchInput"
>
</div>
@@ -241,42 +196,42 @@
<!-- 搜索结果 -->
<div
v-if="showUserSearchResults && userSearchResults.length > 0"
class="bg-bg-primary border border-border-secondary rounded-2xl overflow-hidden max-h-[300px] overflow-y-auto custom-scrollbar"
class="bg-zinc-950 border border-zinc-800 rounded-2xl overflow-hidden max-h-[300px] overflow-y-auto custom-scrollbar"
>
<div class="px-4 py-2 border-b border-border-secondary-60 bg-bg-secondary-40">
<span class="text-[9px] font-black text-text-disabled uppercase tracking-widest"
>{{ getLocaleMessage('searchResults', userSearchResults.length) }}</span
<div class="px-4 py-2 border-b border-zinc-800/60 bg-zinc-900/40">
<span class="text-[9px] font-black text-zinc-600 uppercase tracking-widest"
>搜索结果 ({{ userSearchResults.length }})</span
>
</div>
<div
v-for="user in userSearchResults"
:key="user.id"
class="flex items-center justify-between p-4 border-b border-border-secondary-30 last:border-0 hover:bg-bg-tertiary-30 transition-all"
class="flex items-center justify-between p-4 border-b border-zinc-800/30 last:border-0 hover:bg-zinc-800/30 transition-all"
>
<div>
<h5 class="text-sm font-bold text-text-primary">
<h5 class="text-sm font-bold text-zinc-200">
{{ user.name || user.username }}
</h5>
<div class="flex items-center gap-2 mt-0.5">
<span class="text-[10px] text-primary font-black"
<span class="text-[10px] text-blue-500 font-black"
>@{{ user.username }}</span
>
<span
v-if="user.grade && user.class"
class="text-[10px] text-text-disabled font-bold uppercase tracking-widest"
class="text-[10px] text-zinc-600 font-bold uppercase tracking-widest"
>{{ user.grade }} {{ user.class }}</span
>
<span class="text-[10px] text-text-secondary font-black">{{
<span class="text-[10px] text-zinc-700 font-black">{{
getRoleText(user.role)
}}</span>
</div>
</div>
<button
:disabled="isUserSelected(user.id)"
class="px-3 py-1.5 bg-bg-tertiary hover:bg-primary-hover hover:text-text-primary disabled:opacity-50 disabled:cursor-not-allowed text-text-tertiary text-[10px] font-black rounded-lg transition-all uppercase"
class="px-3 py-1.5 bg-zinc-800 hover:bg-blue-600 hover:text-white disabled:opacity-50 disabled:cursor-not-allowed text-zinc-400 text-[10px] font-black rounded-lg transition-all uppercase"
@click="addUserToSelection(user)"
>
{{ isUserSelected(user.id) ? locale.selected : locale.select }}
{{ isUserSelected(user.id) ? '已选择' : '选择' }}
</button>
</div>
</div>
@@ -284,30 +239,30 @@
<!-- 已选择的用户 -->
<div v-if="form.selectedUsers.length > 0" class="space-y-3">
<div class="flex items-center justify-between px-1">
<span class="text-[9px] font-black text-text-disabled uppercase tracking-widest"
>{{ getLocaleMessage('selectedUsers', form.selectedUsers.length) }}</span
<span class="text-[9px] font-black text-zinc-600 uppercase tracking-widest"
>已选择用户 ({{ form.selectedUsers.length }})</span
>
<button
class="text-[9px] font-black text-error-70 hover:text-error uppercase tracking-widest transition-colors"
class="text-[9px] font-black text-red-500/70 hover:text-red-500 uppercase tracking-widest transition-colors"
@click="clearAllSelectedUsers"
>
{{ locale.clearAll }}
清空全部
</button>
</div>
<div class="flex flex-wrap gap-2">
<div
v-for="(user, index) in form.selectedUsers"
:key="user.id"
class="flex items-center gap-2 px-3 py-1.5 bg-bg-secondary border border-border-secondary rounded-lg group"
class="flex items-center gap-2 px-3 py-1.5 bg-zinc-900 border border-zinc-800 rounded-lg group"
>
<div class="flex flex-col">
<span class="text-[10px] font-bold text-text-secondary leading-none">{{
<span class="text-[10px] font-bold text-zinc-300 leading-none">{{
user.name || user.username
}}</span>
<span class="text-[8px] text-text-disabled">@{{ user.username }}</span>
<span class="text-[8px] text-zinc-600">@{{ user.username }}</span>
</div>
<button
class="text-text-disabled hover:text-error transition-colors"
class="text-zinc-600 hover:text-red-400 transition-colors"
@click="removeUserFromSelection(index)"
>
<X :size="12" />
@@ -316,8 +271,8 @@
</div>
</div>
<div v-else class="text-center py-4">
<p class="text-[10px] font-black text-text-secondary uppercase tracking-widest">
{{ locale.noUsersSelected }}
<p class="text-[10px] font-black text-zinc-700 uppercase tracking-widest">
未选择任何用户
</p>
</div>
</div>
@@ -329,17 +284,17 @@
<div v-if="error || success" class="mt-6">
<div
v-if="error"
class="p-4 bg-error-5 border border-error-10 rounded-2xl flex items-center gap-3"
class="p-4 bg-red-500/5 border border-red-500/10 rounded-2xl flex items-center gap-3"
>
<AlertCircle class="text-error shrink-0" :size="18" />
<p class="text-xs font-bold text-error">{{ error }}</p>
<AlertCircle class="text-red-500 shrink-0" :size="18" />
<p class="text-xs font-bold text-red-400">{{ error }}</p>
</div>
<div
v-if="success"
class="p-4 bg-success-5 border border-success-10 rounded-2xl flex items-center gap-3"
class="p-4 bg-green-500/5 border border-green-500/10 rounded-2xl flex items-center gap-3"
>
<Check class="text-success shrink-0" :size="18" />
<p class="text-xs font-bold text-success">{{ success }}</p>
<Check class="text-green-500 shrink-0" :size="18" />
<p class="text-xs font-bold text-green-400">{{ success }}</p>
</div>
</div>
@@ -347,16 +302,16 @@
<button
:disabled="loading || !isFormValid"
:class="[
'flex items-center gap-2 px-10 py-4 bg-bg-primary border border-border-secondary text-xs font-black rounded-2xl transition-all uppercase tracking-[0.2em] shadow-lg',
'flex items-center gap-2 px-10 py-4 bg-zinc-950 border border-zinc-800 text-xs font-black rounded-2xl transition-all uppercase tracking-[0.2em] shadow-lg',
loading || !isFormValid
? 'text-text-primary cursor-not-allowed'
: 'text-text-tertiary hover:text-text-primary hover:border-border-tertiary hover:bg-bg-secondary'
? 'text-zinc-800 cursor-not-allowed'
: 'text-zinc-400 hover:text-zinc-100 hover:border-zinc-600 hover:bg-zinc-900'
]"
@click="sendNotification"
>
<Loader2 v-if="loading" class="animate-spin" :size="16" />
<Send v-else :size="16" />
{{ loading ? locale.sending : locale.send }}
{{ loading ? '发送中...' : '发送通知' }}
</button>
</div>
</div>
@@ -365,130 +320,97 @@
<!-- 右侧:预览区 -->
<div class="lg:col-span-5 space-y-6 lg:sticky lg:top-8">
<div
class="bg-bg-secondary-30 border border-border-secondary rounded-[2rem] p-8 shadow-xl flex flex-col h-full"
class="bg-zinc-900/30 border border-zinc-800 rounded-[2rem] p-8 shadow-xl flex flex-col h-full"
>
<h3
class="text-sm font-black text-text-primary uppercase tracking-widest mb-6 flex items-center gap-2"
class="text-sm font-black text-zinc-100 uppercase tracking-widest mb-6 flex items-center gap-2"
>
<Eye :size="16" class="text-primary" /> {{ locale.previewTitle }}
<Eye :size="16" class="text-blue-500" /> 通知预览
</h3>
<div class="flex flex-1 flex-col items-center justify-center p-1 sm:p-4">
<!-- 重要通知预览 -->
<section
v-if="form.important"
class="w-full max-w-[320px] overflow-hidden rounded-2xl border border-primary-300 bg-bg-primary shadow-2xl"
>
<div class="h-1.5 w-full bg-warning" />
<div class="p-5 space-y-5">
<header class="flex items-start gap-3">
<div
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-warning-300 bg-warning-10 text-warning"
aria-hidden="true"
>
<Icon name="bell-ring" :size="17" />
</div>
<div class="min-w-0 flex-1">
<h4
class="break-words text-sm font-black"
:class="form.title ? 'text-text-primary' : 'italic text-text-disabled'"
>
{{ form.title || locale.previewTitlePlaceholder }}
</h4>
<p class="mt-1 truncate text-[11px] font-black text-text-disabled">
{{ locale.senderLabel }}:{{ previewSenderName }}
</p>
</div>
</header>
<div
v-if="form.content"
class="markdown-body max-h-64 overflow-y-auto text-sm leading-relaxed text-text-tertiary"
v-html="previewContent"
/>
<p v-else class="text-sm italic leading-relaxed text-text-disabled">
{{ locale.previewContentPlaceholder }}
</p>
<footer class="flex items-center justify-between gap-4 border-t border-border-secondary-50 pt-4">
<div class="flex min-w-0 items-center gap-1.5 text-text-secondary">
<Users :size="13" class="shrink-0" aria-hidden="true" />
<span class="truncate text-[10px] font-black text-text-disabled">
{{ getLocaleMessage('previewScope', scopeDescription) }}
</span>
</div>
<MessageSquare :size="17" class="shrink-0 text-warning" aria-hidden="true" />
</footer>
</div>
</section>
<!-- 普通通知预览 -->
<article
v-else
class="w-full max-w-[320px] overflow-hidden rounded-2xl border border-border-secondary bg-bg-primary shadow-2xl"
>
<div class="h-1.5 w-full bg-primary" />
<div class="p-5 space-y-5">
<header class="flex items-start gap-3">
<div
class="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-primary-20 bg-primary-hover-10 text-primary"
aria-hidden="true"
>
<Icon name="bell" :size="17" />
</div>
<div class="min-w-0 flex-1">
<h4
class="break-words text-sm font-black"
:class="form.title ? 'text-text-primary' : 'italic text-text-disabled'"
>
{{ form.title || locale.previewTitlePlaceholder }}
</h4>
<p class="mt-1 truncate text-[11px] font-black text-text-disabled">
{{ locale.senderLabel }}:{{ previewSenderName }}
</p>
</div>
</header>
<div
v-if="form.content"
class="markdown-body max-h-64 overflow-y-auto text-sm leading-relaxed text-text-tertiary"
v-html="previewContent"
/>
<p v-else class="text-sm italic leading-relaxed text-text-disabled">
{{ locale.previewContentPlaceholder }}
</p>
<footer class="flex items-center justify-between gap-4 border-t border-border-secondary-50 pt-4">
<div class="flex min-w-0 items-center gap-1.5 text-text-secondary">
<Users :size="13" class="shrink-0" aria-hidden="true" />
<span class="truncate text-[10px] font-black text-text-disabled">
{{ getLocaleMessage('previewScope', scopeDescription) }}
</span>
</div>
<MessageSquare :size="17" class="shrink-0 text-primary" aria-hidden="true" />
</footer>
</div>
</article>
<div class="flex-1 flex flex-col items-center justify-center p-4">
<div
class="mt-6 flex w-full max-w-[320px] items-start gap-3 rounded-lg border border-warning-10 bg-warning-5 p-3"
class="w-full max-w-[320px] bg-[#0c0c0e] border border-zinc-800 rounded-3xl overflow-hidden shadow-2xl relative"
>
<AlertCircle :size="14" class="mt-0.5 shrink-0 text-warning" />
<p class="text-[10px] font-black text-text-tertiary leading-normal">
{{ locale.previewHint }}
</p>
<!-- 顶部装饰 -->
<div class="h-1.5 bg-blue-600 w-full" />
<div class="p-6 space-y-4">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<div
class="w-8 h-8 rounded-xl bg-blue-600/10 text-blue-500 flex items-center justify-center border border-blue-500/20"
>
<Bell :size="14" />
</div>
<span class="text-[10px] font-black text-zinc-600 uppercase tracking-widest"
>VoiceHub 系统</span
>
</div>
<span class="text-[9px] text-zinc-700 font-bold uppercase tracking-wider"
>刚刚</span
>
</div>
<div class="space-y-2">
<h4
:class="[
'text-sm font-black transition-colors',
form.title ? 'text-zinc-100' : 'text-zinc-800 italic'
]"
>
{{ form.title || '通知标题' }}
</h4>
<p
:class="[
'text-[11px] leading-relaxed transition-colors',
form.content ? 'text-zinc-400' : 'text-zinc-800 italic line-clamp-3'
]"
>
{{ form.content || '这里将显示通知的详细内容预览...' }}
</p>
</div>
<div class="pt-4 border-t border-zinc-800/50 flex items-center justify-between">
<div class="flex items-center gap-1.5">
<Users :size="12" class="text-zinc-700" />
<span class="text-[9px] font-black text-zinc-600 uppercase tracking-wider">
发送范围: {{ scopeDescription }}
</span>
</div>
<button
class="p-1.5 text-blue-500 hover:bg-blue-600/10 rounded-lg transition-all"
>
<MessageSquare :size="14" />
</button>
</div>
</div>
<!-- 背景光晕 -->
<div
class="absolute top-0 right-0 w-32 h-32 bg-blue-600/5 blur-[50px] -z-10 rounded-full"
/>
</div>
<div class="mt-8 space-y-3 w-full max-w-[320px]">
<div
class="flex items-start gap-3 p-3 bg-amber-500/5 border border-amber-500/10 rounded-2xl"
>
<AlertCircle class="text-amber-500 shrink-0 mt-0.5" :size="14" />
<p class="text-[10px] font-bold text-zinc-500 leading-normal">
预览图仅供参考布局,实际发送效果可能会根据用户设备显示语言和屏幕尺寸有所不同。
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<NotificationHistory :refresh-key="historyRefreshKey" />
</div>
</template>
<script setup>
import { computed, ref, onUnmounted, onMounted, watch } from 'vue'
import { computed, ref, onUnmounted } from 'vue'
import {
Send,
Users,
@@ -496,51 +418,27 @@ import {
LayoutGrid,
User,
Search,
Bell,
Info,
X,
Check,
Plus,
AlertCircle,
AlertTriangle,
Eye,
MessageSquare,
Loader2
} from '@lucide/vue'
import CustomSelect from '~/components/UI/Common/CustomSelect.vue'
import Icon from '~/components/UI/Icon.vue'
import NotificationHistory from '~/components/Admin/NotificationHistory.vue'
import { useAuth } from '~/composables/useAuth'
import { useAdmin } from '~/composables/useAdmin'
import { useUserFilters } from '~/composables/useUserFilters'
import { useLocale } from '~/utils/locale'
import { renderMarkdown } from '~/utils/markdown'
const { user: authUser, isAdmin, getAuthConfig } = useAuth()
const { isAdmin } = useAuth()
const { sendAdminNotification } = useAdmin()
const userFilters = useUserFilters()
const { admin } = useLocale()
const locale = computed(() => admin.value?.notificationSender || {})
const { msg: getLocaleMessage, nested: getNestedMessage } = useLocaleText(locale)
const previewSenderName = computed(
() =>
authUser.value?.name?.trim() ||
authUser.value?.username?.trim() ||
locale.value.previewSender
)
onMounted(() => {
userFilters.fetchOptions()
})
const gradeOptions = computed(() => {
return userFilters.getAvailableGrades().map(g => ({ label: g, value: g }))
})
// 表单数据
const form = ref({
title: '',
content: '',
important: false,
scope: 'ALL', // 'ALL', 'GRADE', 'CLASS', 'MULTI_CLASS', 'SPECIFIC_USERS'
grade: '',
classGrade: '',
@@ -555,29 +453,9 @@ const multiClassForm = ref({
class: ''
})
const classOptionsForClassScope = computed(() => {
const classes = userFilters.getAvailableClasses(undefined, form.value.classGrade)
return classes.map(c => ({ label: c, value: c }))
})
const classOptionsForMultiClassScope = computed(() => {
const classes = userFilters.getAvailableClasses(undefined, multiClassForm.value.grade)
return classes.map(c => ({ label: c, value: c }))
})
watch(() => form.value.classGrade, () => {
form.value.className = ''
})
watch(() => multiClassForm.value.grade, () => {
multiClassForm.value.class = ''
})
const loading = ref(false)
const error = ref('')
const success = ref('')
const historyRefreshKey = ref(0)
const previewContent = computed(() => renderMarkdown(form.value.content))
// 用户搜索相关
const userSearchQuery = ref('')
@@ -586,13 +464,18 @@ const showUserSearchResults = ref(false)
const userSearchLoading = ref(false)
let userSearchTimeout = null
const targetOptions = computed(() => [
{ id: 'ALL', label: getNestedMessage('targets', 'all'), icon: Users },
{ id: 'GRADE', label: getNestedMessage('targets', 'grade'), icon: GraduationCap },
{ id: 'CLASS', label: getNestedMessage('targets', 'class'), icon: LayoutGrid },
{ id: 'MULTI_CLASS', label: getNestedMessage('targets', 'multiClass'), icon: Plus },
{ id: 'SPECIFIC_USERS', label: getNestedMessage('targets', 'specificUsers'), icon: User }
])
const targetOptions = [
{ id: 'ALL', label: '全体用户', icon: Users },
{ id: 'GRADE', label: '按年级选择', icon: GraduationCap },
{ id: 'CLASS', label: '按班级选择', icon: LayoutGrid },
{ id: 'MULTI_CLASS', label: '多班级选择', icon: Plus },
{ id: 'SPECIFIC_USERS', label: '指定用户', icon: User }
]
const classNumberOptions = Array.from({ length: 16 }, (_, i) => ({
label: `${i + 1}班`,
value: (i + 1).toString()
}))
// 判断是否可以添加班级
const canAddClass = computed(() => {
@@ -650,8 +533,7 @@ const searchUsers = async (query) => {
query: {
search: query,
limit: 20
},
...getAuthConfig()
}
})
if (response.success) {
@@ -704,9 +586,9 @@ const clearAllSelectedUsers = () => {
// 获取角色文本
const getRoleText = (role) => {
const roleMap = {
admin: getNestedMessage('roles', 'admin'),
teacher: getNestedMessage('roles', 'teacher'),
student: getNestedMessage('roles', 'student')
admin: '管理员',
teacher: '教师',
student: '学生'
}
return roleMap[role] || role
}
@@ -740,23 +622,21 @@ const isFormValid = computed(() => {
const scopeDescription = computed(() => {
switch (form.value.scope) {
case 'ALL':
return getNestedMessage('scopeDescriptions', 'all')
return '全体用户'
case 'GRADE':
return form.value.grade
? getNestedMessage('scopeDescriptions', 'grade', form.value.grade)
: getNestedMessage('scopeDescriptions', 'selectGrade')
return form.value.grade ? `${form.value.grade}年级` : '请选择年级'
case 'CLASS':
return form.value.classGrade && form.value.className
? getNestedMessage('scopeDescriptions', 'class', form.value.classGrade, form.value.className)
: getNestedMessage('scopeDescriptions', 'selectClass')
? `${form.value.classGrade}年级${form.value.className}班`
: '请选择班级'
case 'MULTI_CLASS':
return form.value.selectedClasses.length > 0
? getNestedMessage('scopeDescriptions', 'multiClass', form.value.selectedClasses.length)
: getNestedMessage('scopeDescriptions', 'selectClass')
? `${form.value.selectedClasses.length}个班级`
: '请选择班级'
case 'SPECIFIC_USERS':
return form.value.selectedUsers.length > 0
? getNestedMessage('scopeDescriptions', 'specificUsers', form.value.selectedUsers.length)
: getNestedMessage('scopeDescriptions', 'selectUsers')
? `已选择${form.value.selectedUsers.length}个用户`
: '请选择用户'
default:
return ''
}
@@ -765,12 +645,12 @@ const scopeDescription = computed(() => {
// 发送通知
const sendNotification = async () => {
if (!isAdmin.value) {
error.value = getNestedMessage('errors', 'adminOnly')
error.value = '只有管理员可以发送系统通知'
return
}
if (!isFormValid.value) {
error.value = getNestedMessage('errors', 'incomplete')
error.value = '请填写完整信息'
return
}
@@ -783,7 +663,6 @@ const sendNotification = async () => {
const notificationData = {
title: form.value.title,
content: form.value.content,
important: form.value.important,
scope: form.value.scope,
filter: {}
}
@@ -804,8 +683,7 @@ const sendNotification = async () => {
const result = await sendAdminNotification(notificationData)
if (result && result.success) {
success.value = getNestedMessage('messages', 'sendSuccess', result.sentCount)
historyRefreshKey.value += 1
success.value = `成功发送通知给 ${result.sentCount} 名用户`
// 3秒后自动隐藏成功提示
setTimeout(() => {
@@ -816,7 +694,6 @@ const sendNotification = async () => {
form.value = {
title: '',
content: '',
important: false,
scope: 'ALL',
grade: '',
classGrade: '',
@@ -835,10 +712,10 @@ const sendNotification = async () => {
userSearchLoading.value = false
clearTimeout(userSearchTimeout)
} else {
throw new Error(result?.message || getNestedMessage('errors', 'sendFailed'))
throw new Error(result?.message || '发送通知失败')
}
} catch (err) {
error.value = err.message || getNestedMessage('errors', 'sendError')
error.value = err.message || '发送通知时发生错误'
console.error('发送通知错误:', err)
// 3秒后自动隐藏错误提示
@@ -865,11 +742,11 @@ onUnmounted(() => {
background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: var(--panel-bg-alt);
background: var(--bg-tertiary, #27272a);
border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: var(--panel-bg-hover);
background: #3f3f46;
}
.fade-enter-active,