feat:【system】通知公告 100%

This commit is contained in:
YunaiV
2025-12-17 09:06:24 +08:00
parent aafd7da31f
commit 3c5b99c88b
5 changed files with 582 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
<template>
<!-- 搜索框入口 -->
<wd-search
:placeholder="searchPlaceholder"
:hide-cancel="true"
disabled
@click="visible = true"
/>
<!-- 搜索弹窗 -->
<wd-popup
v-model="visible"
position="top"
custom-style="border-radius: 0 0 24rpx 24rpx;"
safe-area-inset-top
@close="visible = false"
>
<view class="p-32rpx">
<view class="mb-24rpx text-32rpx text-[#333] font-semibold">
搜索通知公告
</view>
<view class="mb-24rpx">
<view class="mb-12rpx text-28rpx text-[#666]">
公告标题
</view>
<wd-input
v-model="formData.title"
placeholder="请输入公告标题"
clearable
/>
</view>
<view class="mb-32rpx">
<view class="mb-12rpx text-28rpx text-[#666]">
公告状态
</view>
<wd-radio-group v-model="formData.status" shape="button">
<wd-radio :value="-1">
全部
</wd-radio>
<wd-radio
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:value="dict.value"
>
{{ dict.label }}
</wd-radio>
</wd-radio-group>
</view>
<view class="w-full flex justify-center gap-24rpx">
<wd-button class="flex-1" plain @click="handleReset">
重置
</wd-button>
<wd-button class="flex-1" type="primary" @click="handleSearch">
搜索
</wd-button>
</view>
</view>
</wd-popup>
</template>
<script lang="ts" setup>
import { computed, reactive, ref, watch } from 'vue'
import { getDictLabel, getIntDictOptions } from '@/hooks/useDict'
import { DICT_TYPE } from '@/utils/constants'
/** 搜索表单数据 */
export interface SearchFormData {
title?: string
status?: number
}
const props = defineProps<{
searchParams?: Partial<SearchFormData>
}>()
const emit = defineEmits<{
search: [data: SearchFormData]
reset: []
}>()
const visible = ref(false)
const formData = reactive<SearchFormData>({
title: undefined,
status: -1 as number,
})
/** 搜索条件 placeholder 拼接 */
const searchPlaceholder = computed(() => {
const conditions: string[] = []
if (props.searchParams?.title) {
conditions.push(`公告标题:${props.searchParams.title}`)
}
if (props.searchParams?.status !== undefined && props.searchParams.status !== -1) {
conditions.push(`公告状态0正常 1关闭:${getDictLabel(DICT_TYPE.COMMON_STATUS, props.searchParams.status)}`)
}
return conditions.length > 0 ? conditions.join(' | ') : '搜索通知公告'
})
/** 监听弹窗打开,同步外部参数 */
watch(visible, (val) => {
if (val && props.searchParams) {
formData.title = props.searchParams.title
formData.status = props.searchParams.status ?? -1
}
})
/** 搜索 */
function handleSearch() {
visible.value = false
emit('search', { ...formData } as SearchFormData)
}
/** 重置 */
function handleReset() {
formData.title = undefined
formData.status = -1
visible.value = false
emit('reset')
}
</script>

View File

@@ -0,0 +1,130 @@
<template>
<view class="page-container">
<!-- 顶部导航栏 -->
<wd-navbar
title="通知公告详情"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 详情内容 -->
<view>
<wd-cell-group border>
<wd-cell title="公告编号" :value="String(formData?.id ?? '-')" />
<wd-cell title="公告标题" :value="String(formData?.title ?? '-')" />
<wd-cell title="公告内容" :value="String(formData?.content ?? '-')" />
<wd-cell title="公告类型">
<dict-tag :type="DICT_TYPE.SYSTEM_NOTICE_TYPE" :value="formData?.type" />
</wd-cell>
<wd-cell title="公告状态">
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="formData?.status" />
</wd-cell>
<wd-cell title="创建时间" :value="formatDateTime(formData?.createTime) || '-'" />
</wd-cell-group>
</view>
<!-- 底部操作按钮 -->
<view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx">
<view class="w-full flex gap-24rpx">
<wd-button
v-if="hasAccessByCodes(['system:notice:update'])"
class="flex-1" type="warning" @click="handleEdit"
>
编辑
</wd-button>
<wd-button
v-if="hasAccessByCodes(['system:notice:delete'])"
class="flex-1" type="error" :loading="deleting" @click="handleDelete"
>
删除
</wd-button>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import type { Notice } from '@/api/system/notice'
import { onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { deleteNotice, getNotice } from '@/api/system/notice'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
import { DICT_TYPE } from '@/utils/constants'
import { formatDateTime } from '@/utils/date'
const props = defineProps<{
id?: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const toast = useToast()
const formData = ref<Notice>()
const deleting = ref(false)
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-system/notice/index')
}
/** 加载通知公告详情 */
async function getDetail() {
if (!props.id) {
return
}
try {
toast.loading('加载中...')
formData.value = await getNotice(props.id)
} finally {
toast.close()
}
}
/** 编辑通知公告 */
function handleEdit() {
uni.navigateTo({
url: `/pages-system/notice/form/index?id=${props.id}`,
})
}
/** 删除通知公告 */
function handleDelete() {
if (!props.id) {
return
}
uni.showModal({
title: '提示',
content: '确定要删除该通知公告吗?',
success: async (res) => {
if (!res.confirm) {
return
}
deleting.value = true
try {
await deleteNotice(props.id)
toast.success('删除成功')
setTimeout(() => {
handleBack()
}, 500)
} finally {
deleting.value = false
}
},
})
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,152 @@
<template>
<view class="page-container">
<!-- 顶部导航栏 -->
<wd-navbar
:title="getTitle"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 表单区域 -->
<view>
<wd-form ref="formRef" :model="formData" :rules="formRules">
<wd-cell-group border>
<wd-input
v-model="formData.title"
label="公告标题"
label-width="180rpx"
prop="title"
clearable
placeholder="请输入公告标题"
/>
<wd-input
v-model="formData.content"
label="公告内容"
label-width="180rpx"
prop="content"
clearable
placeholder="请输入公告内容"
/>
<wd-cell title="公告类型" title-width="180rpx" prop="type" center>
<wd-radio-group v-model="formData.type" shape="button">
<wd-radio
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_NOTICE_TYPE)"
:key="dict.value"
:value="dict.value"
>
{{ dict.label }}
</wd-radio>
</wd-radio-group>
</wd-cell>
<wd-cell title="公告状态" title-width="180rpx" prop="status" center>
<wd-radio-group v-model="formData.status" shape="button">
<wd-radio
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
:key="dict.value"
:value="dict.value"
>
{{ dict.label }}
</wd-radio>
</wd-radio-group>
</wd-cell>
</wd-cell-group>
</wd-form>
</view>
<!-- 底部保存按钮 -->
<view class="fixed bottom-0 left-0 right-0 bg-white p-24rpx">
<wd-button
type="primary"
block
:loading="formLoading"
@click="handleSubmit"
>
保存
</wd-button>
</view>
</view>
</template>
<script lang="ts" setup>
import type { Notice } from '@/api/system/notice'
import { computed, onMounted, ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { createNotice, getNotice, updateNotice } from '@/api/system/notice'
import { getIntDictOptions } from '@/hooks/useDict'
import { navigateBackPlus } from '@/utils'
import { DICT_TYPE } from '@/utils/constants'
const props = defineProps<{
id?: number | any
}>()
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const toast = useToast()
const getTitle = computed(() => props.id ? '编辑通知公告' : '新增通知公告')
const formLoading = ref(false)
const formData = ref<Notice>({
id: undefined,
title: '',
content: '',
type: 0,
status: 0,
})
const formRules = {
title: [{ required: true, message: '公告标题不能为空' }],
content: [{ required: true, message: '公告内容不能为空' }],
type: [{ required: true, message: '公告类型不能为空' }],
status: [{ required: true, message: '公告状态不能为空' }],
}
const formRef = ref()
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-system/notice/index')
}
/** 加载通知公告详情 */
async function getDetail() {
if (!props.id) {
return
}
formData.value = await getNotice(props.id)
}
/** 提交表单 */
async function handleSubmit() {
const { valid } = await formRef.value.validate()
if (!valid) {
return
}
formLoading.value = true
try {
if (props.id) {
await updateNotice(formData.value)
toast.success('修改成功')
} else {
await createNotice(formData.value)
toast.success('新增成功')
}
setTimeout(() => {
handleBack()
}, 500)
} finally {
formLoading.value = false
}
}
/** 初始化 */
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -0,0 +1,172 @@
<template>
<view class="page-container">
<!-- 顶部导航栏 -->
<wd-navbar
title="通知公告管理"
left-arrow placeholder safe-area-inset-top fixed
@click-left="handleBack"
/>
<!-- 搜索组件 -->
<SearchForm
:search-params="queryParams"
@search="handleQuery"
@reset="handleReset"
/>
<!-- 通知公告列表 -->
<view class="p-24rpx">
<view
v-for="item in list"
:key="item.id"
class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
@click="handleDetail(item)"
>
<view class="p-24rpx">
<view class="mb-16rpx flex items-center justify-between">
<view class="text-32rpx text-[#333] font-semibold">
{{ item.title }}
</view>
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="item.status" />
</view>
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
<text class="mr-8rpx shrink-0 text-[#999]">公告内容</text>
<text class="min-w-0 flex-1 truncate">{{ item.content }}</text>
</view>
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
<text class="mr-8rpx text-[#999]">公告类型</text>
<dict-tag :type="DICT_TYPE.SYSTEM_NOTICE_TYPE" :value="item.type" />
</view>
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
<text class="mr-8rpx text-[#999]">创建时间</text>
<text class="line-clamp-1">{{ formatDateTime(item.createTime) || '-' }}</text>
</view>
</view>
</view>
<!-- 加载更多 -->
<view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
<wd-status-tip image="content" tip="暂无通知公告数据" />
</view>
<wd-loadmore
v-if="list.length > 0"
:state="loadMoreState"
@reload="loadMore"
/>
</view>
<!-- 新增按钮 -->
<wd-fab
v-if="hasAccessByCodes(['system:notice:create'])"
position="right-bottom"
type="primary"
:expandable="false"
@click="handleAdd"
/>
</view>
</template>
<script lang="ts" setup>
import type { SearchFormData } from './components/search-form.vue'
import type { Notice } from '@/api/system/notice'
import type { LoadMoreState } from '@/http/types'
import { onReachBottom } from '@dcloudio/uni-app'
import { onMounted, reactive, ref } from 'vue'
import { getNoticePage } from '@/api/system/notice'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
import { DICT_TYPE } from '@/utils/constants'
import { formatDateTime } from '@/utils/date'
import SearchForm from './components/search-form.vue'
definePage({
style: {
navigationBarTitleText: '',
navigationStyle: 'custom',
},
})
const { hasAccessByCodes } = useAccess()
const total = ref(0)
const list = ref<Notice[]>([])
const loadMoreState = ref<LoadMoreState>('loading') // 加载更多状态
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
title: undefined as string | undefined,
status: -1 as number, // -1 表示全部
})
/** 返回上一页 */
function handleBack() {
navigateBackPlus()
}
/** 查询通知公告列表 */
async function getList() {
loadMoreState.value = 'loading'
try {
const data = await getNoticePage({
...queryParams,
status: queryParams.status === -1 ? undefined : queryParams.status,
})
list.value = [...list.value, ...data.list]
total.value = data.total
loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
} catch {
queryParams.pageNo = queryParams.pageNo > 1 ? queryParams.pageNo - 1 : 1
loadMoreState.value = 'error'
}
}
/** 搜索按钮操作 */
function handleQuery(data?: SearchFormData) {
queryParams.title = data?.title
queryParams.status = data?.status ?? -1
queryParams.pageNo = 1
list.value = []
getList()
}
/** 重置按钮操作 */
function handleReset() {
handleQuery()
}
/** 加载更多 */
function loadMore() {
if (loadMoreState.value === 'finished') {
return
}
queryParams.pageNo++
getList()
}
/** 新增通知公告 */
function handleAdd() {
uni.navigateTo({
url: '/pages-system/notice/form/index',
})
}
/** 查看详情 */
function handleDetail(item: Notice) {
uni.navigateTo({
url: `/pages-system/notice/detail/index?id=${item.id}`,
})
}
/** 触底加载更多 */
onReachBottom(() => {
loadMore()
})
/** 初始化 */
onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped>
</style>

View File

@@ -69,6 +69,14 @@ const menuGroupsData: MenuGroup[] = [
iconColor: '#eb2f96',
permission: 'system:post:query',
},
{
key: 'notice',
name: '通知公告',
icon: 'spool',
url: '/pages-system/notice/index',
iconColor: '#faad14',
permission: 'system:notice:query',
},
],
},
{