qsh 3 months ago
parent 7665389a8d
commit 0555c0e42e
  1. 25
      src/api/system/notify/message/index.ts
  2. 28
      src/layout/components/Message/src/Message.vue
  3. 7
      src/store/modules/user.ts
  4. 306
      src/views/Profile/NotifyMessage.vue

@ -1,5 +1,4 @@
import request from '@/config/axios'
import qs from 'qs'
export interface NotifyMessageVO {
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({
url:
'/admin-api/system/notify-message/update-read?' +
qs.stringify({ ids: ids }, { indices: false })
url: '/admin-api/system/notify-message/update-read?',
data
})
}
// 标记所有站内信为已读
export const updateAllNotifyMessageRead = async () => {
return await request.put({ url: '/admin-api/system/notify-message/update-all-read' })
export const updateAllNotifyMessageRead = async (data: any) => {
return await request.put({ url: '/admin-api/system/notify-message/update-all-read', data })
}
// 获取当前用户的最新站内信列表
export const getUnreadNotifyMessageList = async () => {
return await request.get({ url: '/admin-api/system/notify-message/get-unread-list' })
export const getUnreadNotifyMessageList = async (params: any) => {
return await request.get({ url: '/admin-api/system/notify-message/get-unread-list', params })
}
// 获得当前用户的未读站内信数量
export const getUnreadNotifyMessageCount = async () => {
return await request.get({ url: '/admin-api/system/notify-message/get-unread-count' })
export const getUnreadNotifyMessageCount = async (params: any) => {
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>
import { formatDate } from '@/utils/formatTime'
import * as NotifyMessageApi from '@/api/system/notify/message'
import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()
const { push } = useRouter()
const activeName = ref('notice')
@ -9,16 +12,21 @@ const list = ref<any[]>([]) // 消息列表
//
const getList = async () => {
list.value = await NotifyMessageApi.getUnreadNotifyMessageList()
const data = await NotifyMessageApi.getUnreadNotifyMessageList({
roleId: userStore.getUser?.currentRole
})
list.value = data.list
// unreadCount 0
unreadCount.value = 0
}
//
const getUnreadCount = async () => {
NotifyMessageApi.getUnreadNotifyMessageCount().then((data) => {
unreadCount.value = data
})
NotifyMessageApi.getUnreadNotifyMessageCount({ roleId: userStore.getUser?.currentRole }).then(
(data) => {
unreadCount.value = data
}
)
}
//
@ -34,9 +42,9 @@ onMounted(() => {
//
getUnreadCount()
//
// msgInterval.value = setInterval(() => {
// getUnreadCount()
// }, 1000 * 60 * 2)
msgInterval.value = setInterval(() => {
getUnreadCount()
}, 1000 * 60 * 2)
})
onUnmounted(() => {
@ -56,10 +64,9 @@ onUnmounted(() => {
<div class="message-list">
<template v-for="item in list" :key="item.id">
<div class="message-item">
<img alt="" class="message-icon" src="@/assets/imgs/avatar.gif" />
<div class="message-content">
<span class="message-title">
{{ item.templateNickname }}{{ item.templateContent }}
{{ item.title }}
</span>
<span class="message-date">
{{ formatDate(item.createTime) }}
@ -94,7 +101,7 @@ onUnmounted(() => {
.message-item {
display: flex;
align-items: center;
padding: 20px 0;
padding: 0;
border-bottom: 1px solid var(--el-border-color-light);
&:last-child {
@ -113,6 +120,7 @@ onUnmounted(() => {
.message-title {
margin-bottom: 5px;
font-weight: bold;
}
.message-date {

@ -9,6 +9,7 @@ interface UserVO {
id: number
avatar: string
nickname: string
currentRole: number
}
interface UserInfoVO {
permissions: string[]
@ -25,7 +26,8 @@ export const useUserStore = defineStore('admin-user', {
user: {
id: 0,
avatar: '',
nickname: ''
nickname: '',
currentRole: 0
}
}),
getters: {
@ -72,7 +74,8 @@ export const useUserStore = defineStore('admin-user', {
this.user = {
id: 0,
avatar: '',
nickname: ''
nickname: '',
currentRole: 0
}
},
refresh() {

@ -1,177 +1,96 @@
<template>
<doc-alert title="站内信配置" url="https://doc.iocoder.cn/notify/" />
<ContentWrap>
<!-- 搜索工作栏 -->
<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 :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-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>
</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>
<el-text class="mb-10px" type="danger">tips: 双击展示消息详情</el-text>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list">
<el-table-column label="编号" align="center" prop="id" />
<el-table-column label="用户类型" align="center" prop="userType">
<template #default="scope">
<dict-tag :type="DICT_TYPE.USER_TYPE" :value="scope.row.userType" />
</template>
</el-table-column>
<el-table-column label="用户编号" align="center" prop="userId" width="80" />
<el-table-column label="模板编码" align="center" prop="templateCode" width="80" />
<el-table-column label="发送人名称" align="center" prop="templateNickname" width="180" />
<el-table-column
label="模版内容"
align="center"
prop="templateContent"
width="200"
show-overflow-tooltip
/>
<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"
<el-table
ref="tableRef"
v-loading="loading"
:data="list"
row-key="id"
@selection-change="handleSelectionChange"
@row-dblclick="handleDetail"
>
<el-table-column type="selection" :selectable="selectable" reserve-selection width="60px" />
<el-table-column label="类型" align="left" prop="messageType" width="200px" />
<el-table-column label="标题" align="left" prop="title" />
<el-table-column
label="时间"
align="left"
prop="createTime"
width="180"
:formatter="dateFormatter"
/>
</ContentWrap>
<!-- 表单弹窗详情 -->
<!-- <NotifyMessageDetail ref="detailRef" /> -->
<el-table-column label="状态" align="left" width="100px">
<template #default="{ row }">
<el-tag :type="row.readStatus ? 'success' : 'info'">
{{ 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>
<script lang="ts" setup name="NotifyMessage">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
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 total = ref(0) //
const list = ref([]) //
const list = ref<any[]>([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
userType: undefined,
userId: undefined,
templateCode: undefined,
templateType: undefined,
createTime: []
pageSize: 20,
messageType: undefined,
readStatus: undefined
})
const queryFormRef = ref() //
@ -187,26 +106,79 @@ const getList = async () => {
}
}
/** 某一行,是否允许选中 */
const selectable = (row: any) => {
return !row.readStatus
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
function handleDetail(row: any) {
if (!row.readStatus) {
handleReadOne(row.id)
}
}
const tableRef = ref() // Ref
const selectedIds = ref<number[]>([]) // ID
/** 标记全部站内信已读 **/
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 detailRef = ref()
const openDetail = (data: NotifyMessageApi.NotifyMessageVO) => {
detailRef.value.open(data)
/** 标记一条站内信已读 */
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(() => {
getOptions()
getList()
})
</script>

Loading…
Cancel
Save