重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,727 @@
<template>
<div class="system-messages admin-page">
<section class="message-page-head">
<a-page-header title="消息发布" sub-title="发布站内消息,支持文本和单张图片" />
</section>
<section class="message-composer-shell">
<div class="message-composer-grid">
<article class="message-editor-panel">
<div class="panel-heading">
<div class="panel-heading__icon">
<SendOutlined />
</div>
<div>
<p class="panel-eyebrow">站内消息</p>
<h2>发布消息</h2>
</div>
</div>
<a-form layout="vertical" :model="form" class="message-form">
<a-form-item label="标题" required>
<a-input v-model:value="form.title" :maxlength="100" placeholder="请输入消息标题" />
</a-form-item>
<a-form-item label="内容">
<a-textarea v-model:value="form.content" :rows="6" :maxlength="2000" placeholder="支持 HTML / Markdown,可配合图片展示" />
</a-form-item>
<a-form-item label="消息图片">
<div class="image-upload-row">
<a-upload accept="image/*" list-type="picture-card" :show-upload-list="false" :custom-request="handleImageUpload">
<div v-if="!imagePreviewUrl" class="upload-placeholder">
<PictureOutlined />
<span>上传图片</span>
</div>
<img v-else class="message-image-preview" :src="imagePreviewUrl" alt="消息图片预览" />
</a-upload>
<div class="image-upload-copy">
<div>每条消息最多上传一张图片。</div>
<small>建议使用 JPG/PNG/WebP,图片会在弹窗和通知详情中展示。</small>
<a-button v-if="form.imageFileId" type="link" danger size="small" @click="removeImage">移除图片</a-button>
</div>
</div>
</a-form-item>
<div class="scope-panel">
<a-row :gutter="16">
<a-col :xs="24" :md="10">
<a-form-item label="接收范围" required>
<a-select v-model:value="form.targetType" @change="handleTargetTypeChange">
<a-select-option v-for="item in targetTypes" :key="item.value" :value="item.value">
{{ item.label }}
</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col v-if="needsShopSelection" :xs="24" :md="14">
<a-form-item label="接收店铺" required>
<a-select v-model:value="form.shopIds" mode="multiple" :options="shopOptions" placeholder="请选择店铺" />
</a-form-item>
</a-col>
<a-col v-if="form.targetType === 'SELECTED_USERS'" :xs="24" :md="14">
<a-form-item label="接收用户" required>
<a-select
v-model:value="form.userIds"
mode="multiple"
show-search
option-filter-prop="label"
:options="userOptions"
placeholder="请选择用户"
/>
</a-form-item>
</a-col>
</a-row>
</div>
<div class="publish-footer">
<a-checkbox v-model:checked="popupEnabled" class="popup-checkbox">弹窗显示一次</a-checkbox>
<a-space>
<a-button @click="resetForm">清空</a-button>
<a-button type="primary" :loading="saving" @click="handlePublish">
<template #icon>
<SendOutlined />
</template>
发布
</a-button>
</a-space>
</div>
</a-form>
</article>
<aside class="message-preview-panel">
<SystemMessageCard
:title="previewTitle"
:content="previewContent"
:image-url="imagePreviewUrl"
:meta="previewMeta"
surface="preview"
footer-align="end"
>
<template #footer>
<button class="preview-read-button" type="button" tabindex="-1">
<CheckOutlined />
我知道了
</button>
</template>
</SystemMessageCard>
</aside>
</div>
</section>
<a-card :bordered="false" class="admin-section-card">
<template #title>发布记录</template>
<a-table :columns="columns" :data-source="messages" :loading="loading" row-key="id" :pagination="{ pageSize: 8 }" :scroll="{ x: 'max-content' }">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
<a-image v-if="record.imageUrl" :src="record.imageUrl" :width="54" :height="54" class="table-image" />
<span v-else class="muted">无</span>
</template>
<template v-else-if="column.key === 'status'">
<a-tag :color="record.status === 1 ? 'green' : 'default'">{{ record.status === 1 ? '已发布' : '已撤回' }}</a-tag>
</template>
<template v-else-if="column.key === 'popupEnabled'">
<a-tag :color="record.popupEnabled === 1 ? 'blue' : 'default'">{{ record.popupEnabled === 1 ? '弹窗' : '不弹窗' }}</a-tag>
</template>
<template v-else-if="column.key === 'action'">
<a-space>
<a-button type="link" size="small" @click="previewMessage(record as SystemMessageVO)">查看</a-button>
<a-popconfirm v-if="record.status === 1" title="确定撤回这条消息吗?" @confirm="handleRevoke(record.id)">
<a-button type="link" size="small" danger>撤回</a-button>
</a-popconfirm>
</a-space>
</template>
</template>
</a-table>
</a-card>
<a-modal v-model:open="previewVisible" :footer="null" width="560px" wrap-class-name="message-detail-modal-wrap" :mask-closable="false">
<SystemMessageCard
:title="currentMessage?.title || '消息详情'"
:content="currentMessage?.content || ''"
:image-url="currentMessage?.imageUrl || ''"
:meta="currentMessageMeta"
surface="modal"
footer-align="end"
>
<template #footer>
<a-button type="primary" class="message-detail-close-button" @click="previewVisible = false">
<template #icon>
<CheckOutlined />
</template>
我知道了
</a-button>
</template>
</SystemMessageCard>
</a-modal>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import {
CheckOutlined,
PictureOutlined,
SendOutlined
} from '@ant-design/icons-vue'
import SystemMessageCard from '@/components/SystemMessageCard.vue'
/**
* Purpose: SystemMessageCreateRequest supports SystemMessagesView.vue by holding or executing the system message create request page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminFileApi, adminSystemMessageApi, type SystemMessageCreateRequest, type SystemMessageVO } from '@/api/admin'
import type { IdType } from '@/utils/id'
/**
* Purpose: loading supports SystemMessagesView.vue by holding or executing the loading page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const loading = ref(false)
/**
* Purpose: saving supports SystemMessagesView.vue by holding or executing the saving page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const saving = ref(false)
/**
* Purpose: imageUploading supports SystemMessagesView.vue by holding or executing the image uploading page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const imageUploading = ref(false)
/**
* Purpose: messages supports SystemMessagesView.vue by holding or executing the messages page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const messages = ref<SystemMessageVO[]>([])
/**
* Purpose: targetOptions supports SystemMessagesView.vue by holding or executing the target options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const targetOptions = ref({ shops: [] as any[], users: [] as any[] })
/**
* Purpose: popupEnabled supports SystemMessagesView.vue by holding or executing the popup enabled page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const popupEnabled = ref(true)
/**
* Purpose: previewVisible supports SystemMessagesView.vue by holding or executing the preview visible page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const previewVisible = ref(false)
/**
* Purpose: currentMessage supports SystemMessagesView.vue by holding or executing the current message page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentMessage = ref<SystemMessageVO | null>(null)
/**
* Purpose: imagePreviewUrl supports SystemMessagesView.vue by holding or executing the image preview url page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const imagePreviewUrl = ref('')
/**
* Purpose: form supports SystemMessagesView.vue by holding or executing the form page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const form = reactive<SystemMessageCreateRequest>({
title: '',
content: '',
imageFileId: undefined,
targetType: 'CURRENT_SHOP_ALL',
shopIds: [],
userIds: [],
popupEnabled: 1
})
/**
* Purpose: currentAdminUser supports SystemMessagesView.vue by holding or executing the current admin user page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentAdminUser = computed(() => {
try {
const cache = localStorage.getItem('adminUserInfo') || sessionStorage.getItem('adminUserInfo')
return cache ? JSON.parse(cache) : null
} catch {
return null
}
})
/**
* Purpose: isPlatformAdmin supports SystemMessagesView.vue by holding or executing the is platform admin page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const isPlatformAdmin = computed(() => Number(currentAdminUser.value?.type) === 4)
/**
* Purpose: targetTypes supports SystemMessagesView.vue by holding or executing the target types page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const targetTypes = computed(() => [
...(isPlatformAdmin.value ? [{ label: '全平台', value: 'PLATFORM_ALL' }] : []),
{ label: isPlatformAdmin.value ? '指定店铺全员' : '本店全员', value: isPlatformAdmin.value ? 'SELECTED_SHOPS' : 'CURRENT_SHOP_ALL' },
{ label: '指定用户', value: 'SELECTED_USERS' }
])
/**
* Purpose: needsShopSelection supports SystemMessagesView.vue by holding or executing the needs shop selection page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const needsShopSelection = computed(() => form.targetType === 'SELECTED_SHOPS' || form.targetType === 'SHOP_ALL')
/**
* Purpose: shopOptions supports SystemMessagesView.vue by holding or executing the shop options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopOptions = computed(() => targetOptions.value.shops.map(shop => ({ label: shop.shopName, value: shop.id })))
/**
* Purpose: userOptions supports SystemMessagesView.vue by holding or executing the user options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userOptions = computed(() => targetOptions.value.users.map(user => ({
label: `${user.nickname || user.account} ${user.shopName ? `(${user.shopName})` : ''}`,
value: user.id
})))
/**
* Purpose: previewTitle supports SystemMessagesView.vue by holding or executing the preview title page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const previewTitle = computed(() => form.title.trim() || '消息标题预览')
/**
* Purpose: previewContent supports SystemMessagesView.vue by holding or executing the preview content page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const previewContent = computed(() => form.content.trim() || (imagePreviewUrl.value ? '' : '这里会显示消息正文。支持纯文本,也可以配合一张图片展示给用户。'))
/**
* Purpose: previewMeta supports SystemMessagesView.vue by holding or executing the preview meta page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const previewMeta = computed(() => `系统消息 · ${popupEnabled.value ? '弹窗预览' : '列表预览'}`)
/**
* Purpose: currentMessageMeta supports SystemMessagesView.vue by holding or executing the current message meta page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentMessageMeta = computed(() => {
if (!currentMessage.value) return ''
return [
currentMessage.value.publisherName || '系统消息',
currentMessage.value.publishTime || currentMessage.value.createTime
].filter(Boolean).join(' · ')
})
/**
* Purpose: columns supports SystemMessagesView.vue by holding or executing the columns page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const columns = [
{ title: '标题', dataIndex: 'title', key: 'title' },
{ title: '图片', key: 'image', width: 84 },
{ title: '范围', dataIndex: 'targetTypeName', key: 'targetTypeName', width: 140 },
{ title: '发布人', dataIndex: 'publisherName', key: 'publisherName', width: 140 },
{ title: '弹窗', key: 'popupEnabled', width: 90 },
{ title: '状态', key: 'status', width: 90 },
{ title: '发布时间', dataIndex: 'publishTime', key: 'publishTime', width: 180 },
{ title: '操作', key: 'action', width: 120 }
]
/**
* Purpose: syncDefaultTargetType supports SystemMessagesView.vue by holding or executing the sync default target type page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const syncDefaultTargetType = () => {
if (isPlatformAdmin.value && form.targetType === 'CURRENT_SHOP_ALL') {
form.targetType = 'PLATFORM_ALL'
}
if (!isPlatformAdmin.value && form.targetType === 'PLATFORM_ALL') {
form.targetType = 'CURRENT_SHOP_ALL'
}
}
/**
* Purpose: loadData supports SystemMessagesView.vue by holding or executing the load data page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const loadData = async () => {
loading.value = true
try {
const [messageList, options] = await Promise.all([
adminSystemMessageApi.listMessages(),
adminSystemMessageApi.getTargetOptions()
])
messages.value = messageList || []
targetOptions.value = options || { shops: [], users: [] }
syncDefaultTargetType()
} catch (error: any) {
message.error(error?.message || '消息数据加载失败')
} finally {
loading.value = false
}
}
/**
* Purpose: handleTargetTypeChange supports SystemMessagesView.vue by holding or executing the handle target type change page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleTargetTypeChange = () => {
form.shopIds = []
form.userIds = []
}
/**
* Purpose: removeImage supports SystemMessagesView.vue by holding or executing the remove image page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const removeImage = () => {
form.imageFileId = undefined
imagePreviewUrl.value = ''
}
/**
* Purpose: resetForm supports SystemMessagesView.vue by holding or executing the reset form page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const resetForm = () => {
form.title = ''
form.content = ''
form.imageFileId = undefined
form.targetType = isPlatformAdmin.value ? 'PLATFORM_ALL' : 'CURRENT_SHOP_ALL'
form.shopIds = []
form.userIds = []
popupEnabled.value = true
imagePreviewUrl.value = ''
}
/**
* Purpose: handleImageUpload supports SystemMessagesView.vue by holding or executing the handle image upload page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleImageUpload = async (options: any) => {
const file = options.file as File
if (!file?.type?.startsWith('image/')) {
message.warning('请上传图片文件')
options.onError?.(new Error('invalid image'))
return
}
if (file.size > 5 * 1024 * 1024) {
message.warning('图片不能超过 5MB')
options.onError?.(new Error('image too large'))
return
}
imageUploading.value = true
try {
const uploaded = await adminFileApi.uploadFile(file)
form.imageFileId = uploaded.id
imagePreviewUrl.value = await adminFileApi.getSignedUrl(uploaded.id)
options.onSuccess?.(uploaded)
} catch (error: any) {
message.error(error?.message || '图片上传失败')
options.onError?.(error)
} finally {
imageUploading.value = false
}
}
/**
* Purpose: handlePublish supports SystemMessagesView.vue by holding or executing the handle publish page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handlePublish = async () => {
if (!form.title.trim()) return message.warning('请填写消息标题')
if (!form.content.trim() && !form.imageFileId) return message.warning('请填写消息内容或上传消息图片')
if (imageUploading.value) return message.warning('图片还在上传中,请稍后发布')
if (needsShopSelection.value && !form.shopIds?.length) return message.warning('请选择接收店铺')
if (form.targetType === 'SELECTED_USERS' && !form.userIds?.length) return message.warning('请选择接收用户')
saving.value = true
try {
await adminSystemMessageApi.createMessage({ ...form, popupEnabled: popupEnabled.value ? 1 : 0 })
message.success('消息已发布')
resetForm()
await loadData()
} catch (error: any) {
message.error(error?.message || '消息发布失败')
} finally {
saving.value = false
}
}
/**
* Purpose: handleRevoke supports SystemMessagesView.vue by holding or executing the handle revoke page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const handleRevoke = async (id: IdType) => {
await adminSystemMessageApi.revokeMessage(id)
message.success('消息已撤回')
await loadData()
}
/**
* Purpose: previewMessage supports SystemMessagesView.vue by holding or executing the preview message page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const previewMessage = (record: SystemMessageVO) => {
currentMessage.value = record
previewVisible.value = true
}
onMounted(loadData)
</script>
<style scoped>
.system-messages {
padding: 18px;
max-width: 1180px;
margin: 0 auto;
}
.message-page-head {
max-width: 1120px;
margin: 0 auto 12px;
}
.message-page-head :deep(.ant-page-header) {
padding: 0 0 12px;
}
.message-page-head :deep(.ant-page-header-heading-title) {
color: var(--text-primary);
font-weight: 700;
}
.message-composer-shell {
max-width: 1120px;
margin: 0 auto 24px;
}
.message-composer-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
gap: 22px;
align-items: stretch;
}
.message-editor-panel,
.message-preview-panel {
min-width: 0;
}
.message-editor-panel {
padding: 24px;
border: 1px solid var(--theme-border);
border-radius: 22px;
background: var(--theme-card-bg);
box-shadow: 0 18px 48px color-mix(in srgb, var(--theme-primary) 12%, transparent);
}
.panel-heading {
display: flex;
gap: 14px;
align-items: center;
margin-bottom: 22px;
}
.panel-heading__icon {
display: grid;
width: 46px;
height: 46px;
flex: 0 0 auto;
place-items: center;
border-radius: 14px;
color: #ffffff;
font-size: 20px;
background: var(--theme-gradient);
box-shadow: var(--theme-button-shadow);
}
.panel-eyebrow {
margin: 0 0 4px;
color: var(--theme-primary);
font-size: 13px;
font-weight: 600;
}
.panel-heading h2 {
margin: 0;
color: var(--text-primary);
font-size: 22px;
font-weight: 750;
}
.message-form :deep(.ant-form-item-label > label) {
color: var(--text-primary);
font-weight: 600;
}
.message-form :deep(.ant-input),
.message-form :deep(.ant-input-number),
.message-form :deep(.ant-select-selector),
.message-form :deep(.ant-input-affix-wrapper) {
border-color: var(--theme-border);
border-radius: 10px;
}
.message-form :deep(.ant-input:focus),
.message-form :deep(.ant-input-focused),
.message-form :deep(.ant-select-focused .ant-select-selector),
.message-form :deep(.ant-input-affix-wrapper-focused) {
border-color: var(--theme-primary);
box-shadow: var(--theme-focus-shadow);
}
.scope-panel {
padding: 16px 16px 0;
margin-bottom: 18px;
border: 1px solid var(--theme-border);
border-radius: 16px;
background: var(--theme-gradient-soft);
}
.publish-footer {
display: flex;
gap: 16px;
align-items: center;
justify-content: space-between;
padding-top: 18px;
border-top: 1px solid var(--theme-border);
}
.popup-checkbox {
color: var(--text-secondary);
}
.message-preview-panel {
display: flex;
align-items: center;
justify-content: center;
}
.message-preview-panel :deep(.system-message-card) {
max-width: 420px;
}
.preview-read-button {
display: inline-flex;
min-height: 40px;
align-items: center;
justify-content: center;
gap: 8px;
padding: 0 18px;
border: 0;
border-radius: 12px;
color: #ffffff;
font-weight: 700;
background: var(--theme-gradient);
box-shadow: var(--theme-button-shadow);
cursor: default;
}
.admin-section-card {
max-width: 1120px;
margin-bottom: 16px;
margin-left: auto;
margin-right: auto;
border: 1px solid var(--theme-border);
border-radius: 18px;
box-shadow: 0 18px 42px color-mix(in srgb, var(--theme-primary) 10%, transparent);
overflow: hidden;
}
.admin-section-card :deep(.ant-card-head) {
color: var(--theme-primary);
background: var(--theme-gradient-soft);
}
.image-upload-row {
display: flex;
gap: 16px;
align-items: center;
}
.upload-placeholder {
display: grid;
gap: 4px;
place-items: center;
color: var(--text-secondary);
text-align: center;
}
.message-image-preview {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 6px;
}
.image-upload-copy {
color: var(--text-secondary);
line-height: 1.7;
}
.image-upload-copy small,
.muted {
color: var(--text-secondary);
font-size: 13px;
}
.table-image {
object-fit: cover;
border-radius: 6px;
}
:global(.message-detail-modal-wrap .ant-modal-content) {
padding: 0;
overflow: hidden;
border-radius: 8px;
background: transparent;
}
:global(.message-detail-modal-wrap .ant-modal-body) {
padding: 0;
}
:global(.message-detail-modal-wrap .ant-modal-close) {
color: var(--text-secondary);
}
:global(.message-detail-modal-wrap .message-detail-close-button) {
border: 0;
border-radius: 12px;
color: #ffffff;
font-weight: 700;
background: var(--theme-gradient);
box-shadow: var(--theme-button-shadow);
}
:global(.message-detail-modal-wrap .message-detail-close-button:hover),
:global(.message-detail-modal-wrap .message-detail-close-button:focus) {
color: #ffffff;
background: var(--theme-gradient);
filter: brightness(0.98);
}
@media (max-width: 960px) {
.message-composer-grid {
grid-template-columns: 1fr;
}
.message-preview-panel :deep(.system-message-card) {
max-width: 640px;
}
}
@media (max-width: 640px) {
.system-messages {
padding: 12px;
}
.message-editor-panel {
border-radius: 18px;
}
.image-upload-row,
.publish-footer {
align-items: stretch;
flex-direction: column;
}
.publish-footer :deep(.ant-space) {
justify-content: flex-end;
}
.preview-read-button {
width: 100%;
}
}
</style>