dev-cjl #3
@@ -1,5 +1,4 @@
|
|||||||
import request from '@/config/axios'
|
import request from '@/config/axios'
|
||||||
import qs from 'qs'
|
|
||||||
|
|
||||||
export interface NotifyMessageVO {
|
export interface NotifyMessageVO {
|
||||||
id: number
|
id: number
|
||||||
@@ -26,25 +25,29 @@ export const getMyNotifyMessagePage = async (params: PageParam) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 批量标记已读
|
// 批量标记已读
|
||||||
export const updateNotifyMessageRead = async (ids) => {
|
export const updateNotifyMessageRead = async (data: any) => {
|
||||||
return await request.put({
|
return await request.put({
|
||||||
url:
|
url: '/admin-api/system/notify-message/update-read?',
|
||||||
'/admin-api/system/notify-message/update-read?' +
|
data
|
||||||
qs.stringify({ ids: ids }, { indices: false })
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 标记所有站内信为已读
|
// 标记所有站内信为已读
|
||||||
export const updateAllNotifyMessageRead = async () => {
|
export const updateAllNotifyMessageRead = async (data: any) => {
|
||||||
return await request.put({ url: '/admin-api/system/notify-message/update-all-read' })
|
return await request.put({ url: '/admin-api/system/notify-message/update-all-read', data })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前用户的最新站内信列表
|
// 获取当前用户的最新站内信列表
|
||||||
export const getUnreadNotifyMessageList = async () => {
|
export const getUnreadNotifyMessageList = async (params: any) => {
|
||||||
return await request.get({ url: '/admin-api/system/notify-message/get-unread-list' })
|
return await request.get({ url: '/admin-api/system/notify-message/get-unread-list', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获得当前用户的未读站内信数量
|
// 获得当前用户的未读站内信数量
|
||||||
export const getUnreadNotifyMessageCount = async () => {
|
export const getUnreadNotifyMessageCount = async (params: any) => {
|
||||||
return await request.get({ url: '/admin-api/system/notify-message/get-unread-count' })
|
return await request.get({ url: '/admin-api/system/notify-message/get-unread-count', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取详情
|
||||||
|
export const getNotifyMessageDetail = async (id: number) => {
|
||||||
|
return await request.get({ url: '/admin-api/system/notify-message/get', params: { id } })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<script lang="ts" name="Message" setup>
|
<script lang="ts" name="Message" setup>
|
||||||
import { formatDate } from '@/utils/formatTime'
|
import { formatDate } from '@/utils/formatTime'
|
||||||
import * as NotifyMessageApi from '@/api/system/notify/message'
|
import * as NotifyMessageApi from '@/api/system/notify/message'
|
||||||
|
import { useUserStore } from '@/store/modules/user'
|
||||||
|
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
const { push } = useRouter()
|
const { push } = useRouter()
|
||||||
const activeName = ref('notice')
|
const activeName = ref('notice')
|
||||||
@@ -9,16 +12,21 @@ const list = ref<any[]>([]) // 消息列表
|
|||||||
|
|
||||||
// 获得消息列表
|
// 获得消息列表
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
list.value = await NotifyMessageApi.getUnreadNotifyMessageList()
|
const data = await NotifyMessageApi.getUnreadNotifyMessageList({
|
||||||
|
roleId: userStore.getUser?.currentRole
|
||||||
|
})
|
||||||
|
list.value = data.list
|
||||||
// 强制设置 unreadCount 为 0,避免小红点因为轮询太慢,不消除
|
// 强制设置 unreadCount 为 0,避免小红点因为轮询太慢,不消除
|
||||||
unreadCount.value = 0
|
unreadCount.value = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获得未读消息数
|
// 获得未读消息数
|
||||||
const getUnreadCount = async () => {
|
const getUnreadCount = async () => {
|
||||||
NotifyMessageApi.getUnreadNotifyMessageCount().then((data) => {
|
NotifyMessageApi.getUnreadNotifyMessageCount({ roleId: userStore.getUser?.currentRole }).then(
|
||||||
unreadCount.value = data
|
(data) => {
|
||||||
})
|
unreadCount.value = data
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 跳转我的站内信
|
// 跳转我的站内信
|
||||||
@@ -34,9 +42,9 @@ onMounted(() => {
|
|||||||
// 首次加载小红点
|
// 首次加载小红点
|
||||||
getUnreadCount()
|
getUnreadCount()
|
||||||
// 轮询刷新小红点
|
// 轮询刷新小红点
|
||||||
// msgInterval.value = setInterval(() => {
|
msgInterval.value = setInterval(() => {
|
||||||
// getUnreadCount()
|
getUnreadCount()
|
||||||
// }, 1000 * 60 * 2)
|
}, 1000 * 60 * 2)
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
@@ -56,10 +64,9 @@ onUnmounted(() => {
|
|||||||
<div class="message-list">
|
<div class="message-list">
|
||||||
<template v-for="item in list" :key="item.id">
|
<template v-for="item in list" :key="item.id">
|
||||||
<div class="message-item">
|
<div class="message-item">
|
||||||
<img alt="" class="message-icon" src="@/assets/imgs/avatar.gif" />
|
|
||||||
<div class="message-content">
|
<div class="message-content">
|
||||||
<span class="message-title">
|
<span class="message-title">
|
||||||
{{ item.templateNickname }}:{{ item.templateContent }}
|
{{ item.title }}
|
||||||
</span>
|
</span>
|
||||||
<span class="message-date">
|
<span class="message-date">
|
||||||
{{ formatDate(item.createTime) }}
|
{{ formatDate(item.createTime) }}
|
||||||
@@ -94,7 +101,7 @@ onUnmounted(() => {
|
|||||||
.message-item {
|
.message-item {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 20px 0;
|
padding: 0;
|
||||||
border-bottom: 1px solid var(--el-border-color-light);
|
border-bottom: 1px solid var(--el-border-color-light);
|
||||||
|
|
||||||
&:last-child {
|
&:last-child {
|
||||||
@@ -113,6 +120,7 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
.message-title {
|
.message-title {
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-date {
|
.message-date {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ interface UserVO {
|
|||||||
id: number
|
id: number
|
||||||
avatar: string
|
avatar: string
|
||||||
nickname: string
|
nickname: string
|
||||||
|
currentRole: number
|
||||||
}
|
}
|
||||||
interface UserInfoVO {
|
interface UserInfoVO {
|
||||||
permissions: string[]
|
permissions: string[]
|
||||||
@@ -25,7 +26,8 @@ export const useUserStore = defineStore('admin-user', {
|
|||||||
user: {
|
user: {
|
||||||
id: 0,
|
id: 0,
|
||||||
avatar: '',
|
avatar: '',
|
||||||
nickname: ''
|
nickname: '',
|
||||||
|
currentRole: 0
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
@@ -72,7 +74,8 @@ export const useUserStore = defineStore('admin-user', {
|
|||||||
this.user = {
|
this.user = {
|
||||||
id: 0,
|
id: 0,
|
||||||
avatar: '',
|
avatar: '',
|
||||||
nickname: ''
|
nickname: '',
|
||||||
|
currentRole: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
refresh() {
|
refresh() {
|
||||||
|
|||||||
@@ -1,177 +1,96 @@
|
|||||||
<template>
|
<template>
|
||||||
<doc-alert title="站内信配置" url="https://doc.iocoder.cn/notify/" />
|
<!-- 搜索工作栏 -->
|
||||||
|
<el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="0">
|
||||||
|
<el-form-item>
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.messageType"
|
||||||
|
placeholder="消息类型"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
@change="handleQuery"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in typeOptions"
|
||||||
|
:key="item.value"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.readStatus"
|
||||||
|
placeholder="状态"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
@change="handleQuery"
|
||||||
|
>
|
||||||
|
<el-option label="已读" :value="true" />
|
||||||
|
<el-option label="未读" :value="false" />
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button :disabled="selectedIds.length == 0" @click="handleUpdateList">
|
||||||
|
标记已读
|
||||||
|
</el-button>
|
||||||
|
<el-button @click="handleUpdateAll"> 全部已读 </el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
<ContentWrap>
|
<el-text class="mb-10px" type="danger">tips: 双击展示消息详情</el-text>
|
||||||
<!-- 搜索工作栏 -->
|
|
||||||
<el-form
|
|
||||||
class="-mb-15px"
|
|
||||||
:model="queryParams"
|
|
||||||
ref="queryFormRef"
|
|
||||||
:inline="true"
|
|
||||||
label-width="68px"
|
|
||||||
>
|
|
||||||
<el-form-item label="用户编号" prop="userId">
|
|
||||||
<el-input
|
|
||||||
v-model="queryParams.userId"
|
|
||||||
placeholder="请输入用户编号"
|
|
||||||
clearable
|
|
||||||
@keyup.enter="handleQuery"
|
|
||||||
class="!w-240px"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="用户类型" prop="userType">
|
|
||||||
<el-select
|
|
||||||
v-model="queryParams.userType"
|
|
||||||
placeholder="请选择用户类型"
|
|
||||||
clearable
|
|
||||||
class="!w-240px"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="dict in getIntDictOptions(DICT_TYPE.USER_TYPE)"
|
|
||||||
:key="dict.value"
|
|
||||||
:label="dict.label"
|
|
||||||
:value="dict.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="模板编码" prop="templateCode">
|
|
||||||
<el-input
|
|
||||||
v-model="queryParams.templateCode"
|
|
||||||
placeholder="请输入模板编码"
|
|
||||||
clearable
|
|
||||||
@keyup.enter="handleQuery"
|
|
||||||
class="!w-240px"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="模版类型" prop="templateType">
|
|
||||||
<el-select
|
|
||||||
v-model="queryParams.templateType"
|
|
||||||
placeholder="请选择模版类型"
|
|
||||||
clearable
|
|
||||||
class="!w-240px"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE)"
|
|
||||||
:key="dict.value"
|
|
||||||
:label="dict.label"
|
|
||||||
:value="dict.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="创建时间" prop="createTime">
|
|
||||||
<el-date-picker
|
|
||||||
v-model="queryParams.createTime"
|
|
||||||
value-format="YYYY-MM-DD HH:mm:ss"
|
|
||||||
type="daterange"
|
|
||||||
start-placeholder="开始日期"
|
|
||||||
end-placeholder="结束日期"
|
|
||||||
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
|
|
||||||
class="!w-240px"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item>
|
|
||||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
|
||||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
</ContentWrap>
|
|
||||||
|
|
||||||
<!-- 列表 -->
|
<!-- 列表 -->
|
||||||
<ContentWrap>
|
<el-table
|
||||||
<el-table v-loading="loading" :data="list">
|
ref="tableRef"
|
||||||
<el-table-column label="编号" align="center" prop="id" />
|
v-loading="loading"
|
||||||
<el-table-column label="用户类型" align="center" prop="userType">
|
:data="list"
|
||||||
<template #default="scope">
|
row-key="id"
|
||||||
<dict-tag :type="DICT_TYPE.USER_TYPE" :value="scope.row.userType" />
|
@selection-change="handleSelectionChange"
|
||||||
</template>
|
@row-dblclick="handleDetail"
|
||||||
</el-table-column>
|
>
|
||||||
<el-table-column label="用户编号" align="center" prop="userId" width="80" />
|
<el-table-column type="selection" :selectable="selectable" reserve-selection width="60px" />
|
||||||
<el-table-column label="模板编码" align="center" prop="templateCode" width="80" />
|
<el-table-column label="类型" align="left" prop="messageType" width="200px" />
|
||||||
<el-table-column label="发送人名称" align="center" prop="templateNickname" width="180" />
|
<el-table-column label="标题" align="left" prop="title" />
|
||||||
<el-table-column
|
<el-table-column
|
||||||
label="模版内容"
|
label="时间"
|
||||||
align="center"
|
align="left"
|
||||||
prop="templateContent"
|
prop="createTime"
|
||||||
width="200"
|
width="180"
|
||||||
show-overflow-tooltip
|
:formatter="dateFormatter"
|
||||||
/>
|
|
||||||
<el-table-column
|
|
||||||
label="模版参数"
|
|
||||||
align="center"
|
|
||||||
prop="templateParams"
|
|
||||||
width="180"
|
|
||||||
show-overflow-tooltip
|
|
||||||
>
|
|
||||||
<template #default="scope"> {{ scope.row.templateParams }}</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="模版类型" align="center" prop="templateType" width="120">
|
|
||||||
<template #default="scope">
|
|
||||||
<dict-tag :type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE" :value="scope.row.templateType" />
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="是否已读" align="center" prop="readStatus" width="100">
|
|
||||||
<template #default="scope">
|
|
||||||
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.readStatus" />
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
label="阅读时间"
|
|
||||||
align="center"
|
|
||||||
prop="readTime"
|
|
||||||
width="180"
|
|
||||||
:formatter="dateFormatter"
|
|
||||||
/>
|
|
||||||
<el-table-column
|
|
||||||
label="创建时间"
|
|
||||||
align="center"
|
|
||||||
prop="createTime"
|
|
||||||
width="180"
|
|
||||||
:formatter="dateFormatter"
|
|
||||||
/>
|
|
||||||
<el-table-column label="操作" align="center" fixed="right">
|
|
||||||
<template #default="scope">
|
|
||||||
<el-button
|
|
||||||
link
|
|
||||||
type="primary"
|
|
||||||
@click="openDetail(scope.row)"
|
|
||||||
v-hasPermi="['system:notify-message:query']"
|
|
||||||
>
|
|
||||||
详情
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
<!-- 分页 -->
|
|
||||||
<Pagination
|
|
||||||
:total="total"
|
|
||||||
v-model:page="queryParams.pageNo"
|
|
||||||
v-model:limit="queryParams.pageSize"
|
|
||||||
@pagination="getList"
|
|
||||||
/>
|
/>
|
||||||
</ContentWrap>
|
<el-table-column label="状态" align="left" width="100px">
|
||||||
|
<template #default="{ row }">
|
||||||
<!-- 表单弹窗:详情 -->
|
<el-tag :type="row.readStatus ? 'success' : 'info'">
|
||||||
<!-- <NotifyMessageDetail ref="detailRef" /> -->
|
{{ row.readStatus ? '已读' : '未读' }}
|
||||||
|
</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<!-- 分页 -->
|
||||||
|
<Pagination
|
||||||
|
:total="total"
|
||||||
|
v-model:page="queryParams.pageNo"
|
||||||
|
v-model:limit="queryParams.pageSize"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup name="NotifyMessage">
|
<script lang="ts" setup name="NotifyMessage">
|
||||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
|
||||||
import { dateFormatter } from '@/utils/formatTime'
|
import { dateFormatter } from '@/utils/formatTime'
|
||||||
import * as NotifyMessageApi from '@/api/system/notify/message'
|
import * as NotifyMessageApi from '@/api/system/notify/message'
|
||||||
// import NotifyMessageDetail from './NotifyMessageDetail.vue'
|
import { useUserStore } from '@/store/modules/user'
|
||||||
|
import { getGeneralSysDictData } from '@/api/system/dict/dict.data'
|
||||||
|
|
||||||
defineOptions({ name: 'SystemNotifyMessage' })
|
const userStore = useUserStore()
|
||||||
|
const message = useMessage() // 消息
|
||||||
|
|
||||||
const loading = ref(true) // 列表的加载中
|
const loading = ref(true) // 列表的加载中
|
||||||
const total = ref(0) // 列表的总页数
|
const total = ref(0) // 列表的总页数
|
||||||
const list = ref([]) // 列表的数据
|
const list = ref<any[]>([]) // 列表的数据
|
||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
pageNo: 1,
|
pageNo: 1,
|
||||||
pageSize: 10,
|
pageSize: 20,
|
||||||
userType: undefined,
|
messageType: undefined,
|
||||||
userId: undefined,
|
readStatus: undefined
|
||||||
templateCode: undefined,
|
|
||||||
templateType: undefined,
|
|
||||||
createTime: []
|
|
||||||
})
|
})
|
||||||
const queryFormRef = ref() // 搜索的表单
|
const queryFormRef = ref() // 搜索的表单
|
||||||
|
|
||||||
@@ -187,26 +106,79 @@ const getList = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 某一行,是否允许选中 */
|
||||||
|
const selectable = (row: any) => {
|
||||||
|
return !row.readStatus
|
||||||
|
}
|
||||||
|
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
const handleQuery = () => {
|
const handleQuery = () => {
|
||||||
queryParams.pageNo = 1
|
queryParams.pageNo = 1
|
||||||
getList()
|
getList()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 重置按钮操作 */
|
function handleDetail(row: any) {
|
||||||
const resetQuery = () => {
|
if (!row.readStatus) {
|
||||||
queryFormRef.value.resetFields()
|
handleReadOne(row.id)
|
||||||
handleQuery()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 详情操作 */
|
const tableRef = ref() // 表格的 Ref
|
||||||
const detailRef = ref()
|
const selectedIds = ref<number[]>([]) // 表格的选中 ID 数组
|
||||||
const openDetail = (data: NotifyMessageApi.NotifyMessageVO) => {
|
|
||||||
detailRef.value.open(data)
|
/** 标记全部站内信已读 **/
|
||||||
|
const handleUpdateAll = async () => {
|
||||||
|
await NotifyMessageApi.updateAllNotifyMessageRead({
|
||||||
|
roleId: userStore.getUser?.currentRole
|
||||||
|
})
|
||||||
|
message.success('全部已读成功!')
|
||||||
|
tableRef.value.clearSelection()
|
||||||
|
await getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 标记一些站内信已读 **/
|
||||||
|
const handleUpdateList = async () => {
|
||||||
|
if (selectedIds.value.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await NotifyMessageApi.updateNotifyMessageRead({
|
||||||
|
ids: selectedIds.value,
|
||||||
|
roleId: userStore.getUser?.currentRole
|
||||||
|
})
|
||||||
|
message.success('批量已读成功!')
|
||||||
|
tableRef.value.clearSelection()
|
||||||
|
await getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 标记一条站内信已读 */
|
||||||
|
const handleReadOne = async (id: number) => {
|
||||||
|
await NotifyMessageApi.updateNotifyMessageRead({
|
||||||
|
ids: [id],
|
||||||
|
roleId: userStore.getUser?.currentRole
|
||||||
|
})
|
||||||
|
await getList()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 当表格选择项发生变化时会触发该事件 */
|
||||||
|
const handleSelectionChange = (array: NotifyMessageApi.NotifyMessageVO[]) => {
|
||||||
|
selectedIds.value = []
|
||||||
|
if (!array) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
array.forEach((row) => selectedIds.value.push(row.id))
|
||||||
|
}
|
||||||
|
|
||||||
|
const typeOptions = ref<any[]>([])
|
||||||
|
|
||||||
|
function getOptions() {
|
||||||
|
getGeneralSysDictData('message_type').then((data) => {
|
||||||
|
typeOptions.value = data
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 初始化 **/
|
/** 初始化 **/
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
getOptions()
|
||||||
getList()
|
getList()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user