功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
@@ -0,0 +1,350 @@
<template>
<div class="system-messages admin-page">
<a-page-header title="消息发布" sub-title="发布站内消息,支持文本和单张图片" />
<a-card :bordered="false" class="admin-section-card">
<template #title>发布消息</template>
<a-form layout="vertical" :model="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="5" :maxlength="2000" placeholder="请输入消息内容,可配合图片展示" />
</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">
<span class="upload-plus">+</span>
<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>
<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>
<a-form-item>
<a-checkbox v-model:checked="popupEnabled">弹窗显示一次</a-checkbox>
</a-form-item>
<a-space>
<a-button type="primary" :loading="saving" @click="handlePublish">发布</a-button>
<a-button @click="resetForm">清空</a-button>
</a-space>
</a-form>
</a-card>
<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 }">
<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" title="消息详情" :footer="null" width="620px">
<h3>{{ currentMessage?.title }}</h3>
<p class="message-meta">{{ currentMessage?.publisherName }} · {{ currentMessage?.targetTypeName }} · {{ currentMessage?.publishTime }}</p>
<div v-if="currentMessage?.content" class="message-content">{{ currentMessage?.content }}</div>
<img v-if="currentMessage?.imageUrl" class="detail-image" :src="currentMessage.imageUrl" alt="消息图片" />
</a-modal>
</div>
</template>
<script setup lang="ts">
/**
* SystemMessagesView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import { adminFileApi, adminSystemMessageApi, type SystemMessageVO, type SystemMessageCreateRequest } from '@/api/admin'
import type { IdType } from '@/utils/id'
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/** saving is a reactive state variable used by the template and event handlers. */
const saving = ref(false)
/** imageUploading is a reactive state variable used by the template and event handlers. */
const imageUploading = ref(false)
const messages = ref<SystemMessageVO[]>([])
/** targetOptions is a reactive state variable used by the template and event handlers. */
const targetOptions = ref({ shops: [] as any[], users: [] as any[] })
/** popupEnabled is a reactive state variable used by the template and event handlers. */
const popupEnabled = ref(true)
/** previewVisible is a reactive state variable used by the template and event handlers. */
const previewVisible = ref(false)
const currentMessage = ref<SystemMessageVO | null>(null)
/** imagePreviewUrl is a reactive state variable used by the template and event handlers. */
const imagePreviewUrl = ref('')
const form = reactive<SystemMessageCreateRequest>({
title: '',
content: '',
imageFileId: undefined,
targetType: 'CURRENT_SHOP_ALL',
shopIds: [],
userIds: [],
popupEnabled: 1
})
/** targetTypes is a reactive state variable used by the template and event handlers. */
const targetTypes = computed(() => {
const shopCount = targetOptions.value.shops.length
const hasPlatformScope = shopCount > 1
return [
...(hasPlatformScope ? [{ label: '全平台', value: 'PLATFORM_ALL' }] : []),
{ label: hasPlatformScope ? '指定店铺全员' : '本店全员', value: hasPlatformScope ? 'SELECTED_SHOPS' : 'CURRENT_SHOP_ALL' },
{ label: '指定用户', value: 'SELECTED_USERS' }
]
})
/** needsShopSelection is a reactive state variable used by the template and event handlers. */
const needsShopSelection = computed(() => form.targetType === 'SELECTED_SHOPS' || form.targetType === 'SHOP_ALL')
/** shopOptions is a reactive state variable used by the template and event handlers. */
const shopOptions = computed(() => targetOptions.value.shops.map(shop => ({ label: shop.shopName, value: shop.id })))
/** userOptions is a reactive state variable used by the template and event handlers. */
const userOptions = computed(() => targetOptions.value.users.map(user => ({
label: `${user.nickname || user.account} ${user.shopName ? `(${user.shopName})` : ''}`,
value: user.id
})))
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 }
]
/** loadData is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
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: [] }
if (targetOptions.value.shops.length > 1 && form.targetType === 'CURRENT_SHOP_ALL') {
form.targetType = 'PLATFORM_ALL'
}
} catch (error: any) {
message.error(error?.message || '消息数据加载失败')
} finally {
loading.value = false
}
}
/** handleTargetTypeChange is a local helper used by this page script. */
const handleTargetTypeChange = () => {
form.shopIds = []
form.userIds = []
}
/** removeImage is a local helper used by this page script. */
const removeImage = () => {
form.imageFileId = undefined
imagePreviewUrl.value = ''
}
/** resetForm is a local helper used by this page script. */
const resetForm = () => {
form.title = ''
form.content = ''
form.imageFileId = undefined
form.targetType = targetOptions.value.shops.length > 1 ? 'PLATFORM_ALL' : 'CURRENT_SHOP_ALL'
form.shopIds = []
form.userIds = []
popupEnabled.value = true
imagePreviewUrl.value = ''
}
/** handleImageUpload is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
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
}
}
/** handlePublish is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
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
}
}
/** handleRevoke is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleRevoke = async (id: IdType) => {
await adminSystemMessageApi.revokeMessage(id)
message.success('消息已撤回')
await loadData()
}
/** previewMessage is a local helper used by this page script. */
const previewMessage = (record: SystemMessageVO) => {
currentMessage.value = record
previewVisible.value = true
}
onMounted(loadData)
</script>
<style scoped>
.system-messages {
padding: 16px;
}
.admin-section-card {
margin-bottom: 16px;
}
.image-upload-row {
display: flex;
gap: 16px;
align-items: center;
}
.upload-placeholder {
display: grid;
gap: 4px;
color: #8a7b83;
text-align: center;
}
.upload-plus {
font-size: 24px;
line-height: 1;
}
.message-image-preview {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 6px;
}
.image-upload-copy {
color: #5f5660;
line-height: 1.7;
}
.image-upload-copy small,
.message-meta,
.muted {
color: #7f7781;
font-size: 13px;
}
.message-content {
white-space: pre-wrap;
line-height: 1.8;
}
.detail-image {
display: block;
width: 100%;
max-height: 420px;
margin-top: 14px;
object-fit: contain;
border-radius: 8px;
background: #f7f2f4;
}
.table-image {
overflow: hidden;
border-radius: 6px;
object-fit: cover;
}
</style>