feat: 完善仪表盘公告区块内容

This commit is contained in:
Charles7c 2023-08-23 00:12:35 +08:00
parent 46e125d8c9
commit 315c059713
8 changed files with 301 additions and 33 deletions

View File

@ -16,8 +16,11 @@
package top.charles7c.cnadmin.system.mapper;
import java.util.List;
import top.charles7c.cnadmin.common.base.BaseMapper;
import top.charles7c.cnadmin.system.model.entity.AnnouncementDO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO;
/**
* 公告 Mapper
@ -25,4 +28,12 @@ import top.charles7c.cnadmin.system.model.entity.AnnouncementDO;
* @author Charles7c
* @since 2023/8/20 10:55
*/
public interface AnnouncementMapper extends BaseMapper<AnnouncementDO> {}
public interface AnnouncementMapper extends BaseMapper<AnnouncementDO> {
/**
* 查询仪表盘公告列表
*
* @return 公告列表
*/
List<AnnouncementDashboardVO> selectDashboardList();
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.cnadmin.system.model.vo;
import java.io.Serializable;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import top.charles7c.cnadmin.system.enums.AnnouncementTypeEnum;
/**
* 仪表盘公告信息
*
* @author Charles7c
* @since 2023/8/20 10:55
*/
@Data
@Schema(description = "仪表盘公告信息")
public class AnnouncementDashboardVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@Schema(description = "ID", example = "1")
private Long id;
/**
* 标题
*/
@Schema(description = "标题", example = "这是标题")
private String title;
/**
* 类型
*/
@Schema(description = "类型")
private AnnouncementTypeEnum type;
}

View File

@ -16,9 +16,12 @@
package top.charles7c.cnadmin.system.service;
import java.util.List;
import top.charles7c.cnadmin.common.base.BaseService;
import top.charles7c.cnadmin.system.model.query.AnnouncementQuery;
import top.charles7c.cnadmin.system.model.request.AnnouncementRequest;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDetailVO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementVO;
@ -29,4 +32,12 @@ import top.charles7c.cnadmin.system.model.vo.AnnouncementVO;
* @since 2023/8/20 10:55
*/
public interface AnnouncementService
extends BaseService<AnnouncementVO, AnnouncementDetailVO, AnnouncementQuery, AnnouncementRequest> {}
extends BaseService<AnnouncementVO, AnnouncementDetailVO, AnnouncementQuery, AnnouncementRequest> {
/**
* 查询仪表盘公告列表
*
* @return 公告列表
*/
List<AnnouncementDashboardVO> listDashboard();
}

View File

@ -16,6 +16,8 @@
package top.charles7c.cnadmin.system.service.impl;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@ -25,6 +27,7 @@ import top.charles7c.cnadmin.system.mapper.AnnouncementMapper;
import top.charles7c.cnadmin.system.model.entity.AnnouncementDO;
import top.charles7c.cnadmin.system.model.query.AnnouncementQuery;
import top.charles7c.cnadmin.system.model.request.AnnouncementRequest;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDetailVO;
import top.charles7c.cnadmin.system.model.vo.AnnouncementVO;
import top.charles7c.cnadmin.system.service.AnnouncementService;
@ -38,4 +41,10 @@ import top.charles7c.cnadmin.system.service.AnnouncementService;
@Service
@RequiredArgsConstructor
public class AnnouncementServiceImpl extends BaseServiceImpl<AnnouncementMapper, AnnouncementDO, AnnouncementVO,
AnnouncementDetailVO, AnnouncementQuery, AnnouncementRequest> implements AnnouncementService {}
AnnouncementDetailVO, AnnouncementQuery, AnnouncementRequest> implements AnnouncementService {
@Override
public List<AnnouncementDashboardVO> listDashboard() {
return baseMapper.selectDashboardList();
}
}

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="top.charles7c.cnadmin.system.mapper.AnnouncementMapper">
<select id="selectDashboardList"
resultType="top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO">
SELECT
`id`, `title`, `type`
FROM `sys_announcement`
WHERE (`effective_time` IS NULL OR NOW() > `effective_time`)
AND (`terminate_time` IS NULL OR `terminate_time` > NOW())
ORDER BY `sort` ASC, `effective_time` DESC
LIMIT 5
</select>
</mapper>

View File

@ -1,6 +1,18 @@
import axios from 'axios';
import type { TableData } from '@arco-design/web-vue/es/table/interface';
const BASE_URL = '/dashboard';
export interface AnnouncementDashboardRecord {
id: string;
title: string;
type: number;
}
export function listAnnouncement() {
return axios.get<AnnouncementDashboardRecord[]>(`${BASE_URL}/announcement`);
}
export interface ContentDataRecord {
x: string;
y: number;

View File

@ -6,47 +6,128 @@
:body-style="{ padding: '15px 20px 13px 20px' }"
>
<template #extra>
<a-link>{{ $t('workplace.viewMore') }}</a-link>
<a-link href="/system/announcement">{{
$t('workplace.viewMore')
}}</a-link>
</template>
<div>
<div v-for="(item, idx) in list" :key="idx" class="item">
<a-tag :color="item.type" size="small">{{ item.label }}</a-tag>
<a-tag v-if="item.type === 1" color="orangered">活动</a-tag>
<a-tag v-else-if="item.type === 2" color="cyan">消息</a-tag>
<a-tag v-else color="blue">通知</a-tag>
<span class="item-content">
{{ item.content }}
<a-link @click="toDetail(item.id)">{{ item.title }}</a-link>
</span>
</div>
</div>
<!-- 详情区域 -->
<a-modal
:visible="detailVisible"
modal-class="detail"
width="70%"
:footer="false"
unmount-on-close
render-to-body
@cancel="handleDetailCancel"
>
<a-spin
:loading="detailLoading"
tip="公告正在赶来..."
style="width: 100%"
>
<template #icon>
<icon-sync />
</template>
<a-typography :style="{ marginTop: '-40px', textAlign: 'center' }">
<a-typography-title>
{{ detail.title }}
</a-typography-title>
<a-typography-paragraph>
<div class="meta-data">
<a-space>
<span>
<icon-user class="icon" />
<span class="label">发布人</span>
<span>{{ detail.createUserString }}</span>
</span>
<a-divider direction="vertical" />
<span>
<svg-icon icon-class="clock-circle" class="icon" />
<span class="label">发布时间</span>
<span>{{
detail.effectiveTime
? detail.effectiveTime
: detail.createTime
}}</span>
</span>
</a-space>
</div>
</a-typography-paragraph>
</a-typography>
<a-divider />
<v-md-preview :text="detail.content"></v-md-preview>
<a-divider />
<div v-if="detail.updateTime" class="update-time-row">
<span>
<icon-schedule class="icon" />
<span>最后更新于</span>
<span>{{ detail.updateTime }}</span>
</span>
</div>
</a-spin>
</a-modal>
</a-card>
</template>
<script lang="ts" setup>
const list = [
{
type: 'orangered',
label: '活动',
content: '内容最新优惠活动',
},
{
type: 'cyan',
label: '消息',
content: '新增内容尚未通过审核,详情请点击查看。',
},
{
type: 'blue',
label: '通知',
content: '当前产品试用期即将结束,如需续费请点击查看。',
},
{
type: 'blue',
label: '通知',
content: '1月新系统升级计划通知',
},
{
type: 'cyan',
label: '消息',
content: '新增内容已经通过审核,详情请点击查看。',
},
];
import { ref } from 'vue';
import {
AnnouncementDashboardRecord,
listAnnouncement,
} from '@/api/dashboard';
import { DataRecord, get } from '@/api/system/announcement';
const list = ref<AnnouncementDashboardRecord[]>([]);
const detail = ref<DataRecord>({});
const detailLoading = ref(false);
const detailVisible = ref(false);
/**
* 查询公告列表
*/
const getList = () => {
listAnnouncement().then((res) => {
list.value = res.data;
});
};
getList();
/**
* 查看详情
*
* @param id ID
*/
const toDetail = async (id: string) => {
if (detailLoading.value) return;
detailLoading.value = true;
detailVisible.value = true;
get(id)
.then((res) => {
detail.value = res.data;
})
.finally(() => {
detailLoading.value = false;
});
};
/**
* 关闭详情
*/
const handleDetailCancel = () => {
detailVisible.value = false;
detail.value = {};
};
</script>
<style scoped lang="less">
@ -56,6 +137,9 @@
width: 100%;
height: 24px;
margin-bottom: 4px;
.arco-link {
color: rgb(var(--gray-8));
}
.item-content {
flex: 1;
overflow: hidden;
@ -68,4 +152,17 @@
cursor: pointer;
}
}
.meta-data {
font-size: 15px;
text-align: center;
}
.icon {
margin-right: 3px;
}
.update-time-row {
text-align: right;
}
</style>

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.cnadmin.webapi.controller.common;
import java.util.List;
import lombok.RequiredArgsConstructor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.charles7c.cnadmin.common.model.vo.R;
import top.charles7c.cnadmin.monitor.annotation.Log;
import top.charles7c.cnadmin.system.model.vo.AnnouncementDashboardVO;
import top.charles7c.cnadmin.system.service.AnnouncementService;
/**
* 仪表盘 API
*
* @author Charles7c
* @since 2023/1/22 21:48
*/
@Tag(name = "仪表盘 API")
@Log(ignore = true)
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/dashboard")
public class DashboardController {
private final AnnouncementService announcementService;
@Operation(summary = "查询公告列表", description = "查询公告列表")
@GetMapping("/announcement")
public R<List<AnnouncementDashboardVO>> listAnnouncement() {
return R.ok(announcementService.listDashboard());
}
}