瀏覽代碼

新增app通知功能

wyn 4 月之前
父節點
當前提交
433e7deae3
共有 3 個文件被更改,包括 255 次插入0 次删除
  1. 28 0
      src/api/system/appnotice/index.ts
  2. 52 0
      src/views/system/appnotice/AppNoticeDetail.vue
  3. 175 0
      src/views/system/appnotice/index.vue

+ 28 - 0
src/api/system/appnotice/index.ts

@@ -0,0 +1,28 @@
+import request from '@/config/axios'
+
+export interface NoticeVO {
+  id: number;
+  userId: number;
+  userType: number;
+  templateId?: number;
+  templateCode?: string;
+  templateNickname?: string;
+  templateContent?: string;
+  templateParams?: any;
+  templateType?: number;
+  title: string;
+  createTime?: number | string; // 创建时间(时间戳或字符串)
+  readStatus?: boolean; // 是否已读
+  readTime?: number | string; // 阅读时间(时间戳或字符串)
+}
+
+export interface AppNoticePageParam extends PageParam {
+  title?: string; // 消息标题
+  readStatus?: boolean; // 消息状态
+  createTime?: string[] | null; // 时间范围 [开始时间, 结束时间]
+}
+
+// 查询公告列表
+export const getAppNoticePage = (params: AppNoticePageParam) => {
+  return request.get({ url: '/system/app-notify-message/my-page', params })
+}

+ 52 - 0
src/views/system/appnotice/AppNoticeDetail.vue

@@ -0,0 +1,52 @@
+<template>
+  <Dialog v-model="dialogVisible" :max-height="350" :scroll="true" title="消息详情">
+    <el-descriptions :column="1" border>
+      <el-descriptions-item label="消息标题">
+        {{ detailData.title }}
+      </el-descriptions-item>
+      <el-descriptions-item label="发送人">
+        {{ detailData.templateNickname || 'admin' }}
+      </el-descriptions-item>
+      <el-descriptions-item label="创建时间">
+        {{ formatDate(detailData.createTime) }}
+      </el-descriptions-item>
+      <el-descriptions-item label="消息类型">
+        <dict-tag :type="DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE" :value="detailData.templateType" />
+      </el-descriptions-item>
+      <el-descriptions-item label="消息状态">
+        <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="detailData.readStatus" />
+      </el-descriptions-item>
+      <el-descriptions-item v-if="detailData.readStatus" label="阅读时间">
+        {{ formatDate(detailData.readTime) }}
+      </el-descriptions-item>
+      <el-descriptions-item label="消息内容">
+        {{ detailData.templateContent }}
+      </el-descriptions-item>
+    </el-descriptions>
+  </Dialog>
+</template>
+<script lang="ts" setup>
+import { DICT_TYPE } from '@/utils/dict'
+import { formatDate } from '@/utils/formatTime'
+import * as AppNoticeApi from '@/api/system/appnotice'
+
+defineOptions({ name: 'AppNoticeDetail' })
+
+const dialogVisible = ref(false) // 弹窗的是否展示
+const detailLoading = ref(false) // 表单的加载中
+const detailData = ref({} as AppNoticeApi.NoticeVO) // 详情数据
+
+/** 打开弹窗 */
+const open = async (data: AppNoticeApi.NoticeVO) => {
+  dialogVisible.value = true
+  // 设置数据
+  detailLoading.value = true
+  try {
+    detailData.value = data
+  } finally {
+    detailLoading.value = false
+  }
+}
+defineExpose({ open }) // 提供 open 方法,用于打开弹窗
+</script>
+

+ 175 - 0
src/views/system/appnotice/index.vue

@@ -0,0 +1,175 @@
+<template>
+  <ContentWrap>
+    <!-- 搜索工作栏 -->
+    <el-form
+      class="-mb-15px"
+      :model="queryParams"
+      ref="queryFormRef"
+      :inline="true"
+      label-width="68px"
+    >
+      <el-form-item label="消息标题" prop="title">
+        <el-input
+          v-model="queryParams.title"
+          placeholder="请输入消息标题"
+          clearable
+          @keyup.enter="handleQuery"
+          class="!w-240px"
+        />
+      </el-form-item>
+      <el-form-item label="消息状态" prop="readStatus">
+        <el-select
+          v-model="queryParams.readStatus"
+          placeholder="请选择"
+          clearable
+          class="!w-240px"
+        >
+          <el-option
+            v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
+            :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 v-loading="loading" :data="list">
+      <el-table-column
+        label="消息标题"
+        align="center"
+        prop="title"
+        min-width="260"
+        show-overflow-tooltip
+      />
+      <el-table-column label="发送人" align="center" prop="templateNickname" width="120">
+        <template #default="scope">
+          {{ scope.row.templateNickname || 'admin' }}
+        </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="templateContent"
+        show-overflow-tooltip
+        min-width="200"
+      />
+      <el-table-column label="消息状态" align="center" prop="readStatus" width="120">
+        <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="createTime"
+        width="180"
+        :formatter="dateFormatter"
+      />
+      <el-table-column
+        label="阅读时间"
+        align="center"
+        prop="readTime"
+        width="180"
+        :formatter="dateFormatter"
+      />
+      <el-table-column label="操作" align="center" width="100" fixed="right">
+        <template #default="scope">
+          <el-button link type="primary" @click="openDetail(scope.row)"> 详情 </el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+    <!-- 分页 -->
+    <Pagination
+      :total="total"
+      v-model:page="queryParams.pageNo"
+      v-model:limit="queryParams.pageSize"
+      @pagination="getList"
+    />
+  </ContentWrap>
+
+  <!-- 表单弹窗:详情 -->
+  <AppNoticeDetail ref="detailRef" />
+</template>
+<script lang="ts" setup>
+import { DICT_TYPE, getBoolDictOptions } from '@/utils/dict'
+import { dateFormatter } from '@/utils/formatTime'
+import * as AppNoticeApi from '@/api/system/appnotice'
+import AppNoticeDetail from './AppNoticeDetail.vue'
+
+defineOptions({ name: 'SystemAppNotice' })
+
+const message = useMessage() // 消息弹窗
+const { t } = useI18n() // 国际化
+
+const loading = ref(true) // 列表的加载中
+const total = ref(0) // 列表的总页数
+const list = ref<AppNoticeApi.NoticeVO[]>([]) // 列表的数据
+const queryParams = reactive<AppNoticeApi.AppNoticePageParam>({
+  pageNo: 1,
+  pageSize: 10,
+  title: undefined,
+  readStatus: undefined,
+  createTime: []
+})
+const queryFormRef = ref() // 搜索的表单
+
+/** 查询公告列表 */
+const getList = async () => {
+  loading.value = true
+  try {
+    const data = await AppNoticeApi.getAppNoticePage(queryParams)
+    list.value = data.list
+    total.value = data.total
+  } finally {
+    loading.value = false
+  }
+}
+
+/** 搜索按钮操作 */
+const handleQuery = () => {
+  queryParams.pageNo = 1
+  getList()
+}
+
+/** 重置按钮操作 */
+const resetQuery = () => {
+  queryFormRef.value.resetFields()
+  queryParams.createTime = []
+  handleQuery()
+}
+
+/** 打开详情弹窗 */
+const detailRef = ref()
+const openDetail = (row: AppNoticeApi.NoticeVO) => {
+  detailRef.value.open(row)
+}
+
+/** 初始化 **/
+onMounted(() => {
+  getList()
+})
+</script>