From a06c8c00b305b5446a565982ae6cf760122e3842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= <454313500@qq.com> Date: Mon, 15 Jan 2024 15:28:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Integral/SignInDto.cs | 31 ++++++++++ .../Services/Integral/IntegralService.cs | 40 +++++++++++++ .../Managers/IntegralManager.cs | 4 +- Yi.Bbs.Vue3/src/apis/integralApi.js | 7 +++ Yi.Bbs.Vue3/src/hooks/useAuths.js | 14 ++++- Yi.Bbs.Vue3/src/layout/AppHeader.vue | 4 +- Yi.Bbs.Vue3/src/views/signIn/index.vue | 59 +++++++++++++++---- 7 files changed, 142 insertions(+), 17 deletions(-) create mode 100644 Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Integral/SignInDto.cs diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Integral/SignInDto.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Integral/SignInDto.cs new file mode 100644 index 00000000..6923cf99 --- /dev/null +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application.Contracts/Dtos/Integral/SignInDto.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; + +namespace Yi.Framework.Bbs.Application.Contracts.Dtos.Integral +{ + public class SignInDto + { + /// + /// 签到数据 + /// + public List SignInItem { get; set; }=new List(); + + /// + /// 当前连续签到次数 + /// + public int CurrentContinuousNumber { get; set; } + } + + + public class SignInItemDto : EntityDto + { + /// + /// 签到时间 + /// + public DateTime CreationTime { get; set; } + } +} diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Integral/IntegralService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Integral/IntegralService.cs index b8c23ed2..a2172768 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Integral/IntegralService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Integral/IntegralService.cs @@ -4,8 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Volo.Abp.Application.Services; using Volo.Abp.Users; +using Yi.Framework.Bbs.Application.Contracts.Dtos.Integral; using Yi.Framework.Bbs.Domain.Managers; namespace Yi.Framework.Bbs.Application.Services.Integral @@ -31,5 +33,43 @@ namespace Yi.Framework.Bbs.Application.Services.Integral var value = await _integralManager.SignInAsync(_currentUser.Id ?? Guid.Empty); return new { value }; } + + /// + /// 获取本月签到记录 + /// + /// + [Authorize] + [HttpGet("integral/sign-in/record")] + public async Task GetSignInRecordAsync() + { + var output = new SignInDto(); + DateTime lastMonth = DateTime.Now.AddMonths(-1); + DateTime lastDayOfMonth = new DateTime(lastMonth.Year, lastMonth.Month, 1).AddMonths(1).AddDays(-1); + DateTime startOfLastDay = new DateTime(lastDayOfMonth.Year, lastDayOfMonth.Month, lastDayOfMonth.Day, 0, 0, 0); + + //获取当前用户本月的数据+上个月最后一天的数据 + var entities = await _integralManager._signInRepository.GetListAsync(x => x.CreatorId == CurrentUser.Id + && x.CreationTime >= startOfLastDay); + + if (entities is null) + { + //返回默认值 + return output; + } + //拿到最末尾的数据 + var lastEntity = entities.OrderBy(x => x.CreationTime).LastOrDefault(); + + //判断当前时间和最后时间是否为连续的 + if (lastEntity.CreationTime.Day >= DateTime.Now.AddDays(-1).Day) + { + + output.CurrentContinuousNumber = lastEntity.ContinuousNumber; + } + + //去除上个月查询的数据 + output.SignInItem = entities.Where(x=>x.CreationTime.Month==DateTime.Now.Month) .Select(x => new SignInItemDto { Id = x.Id, CreationTime = x.CreationTime }).OrderBy(x=>x.CreationTime).ToList(); + return output; + + } } } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/IntegralManager.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/IntegralManager.cs index 3cee684b..2d9ebb8d 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/IntegralManager.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Managers/IntegralManager.cs @@ -10,8 +10,8 @@ namespace Yi.Framework.Bbs.Domain.Managers { public class IntegralManager : DomainService { - private ISqlSugarRepository _levelRepository; - private ISqlSugarRepository _signInRepository; + public ISqlSugarRepository _levelRepository; + public ISqlSugarRepository _signInRepository; private readonly ILocalEventBus _localEventBus; public IntegralManager(ISqlSugarRepository levelRepository, ISqlSugarRepository signInRepository, ILocalEventBus localEventBus) { diff --git a/Yi.Bbs.Vue3/src/apis/integralApi.js b/Yi.Bbs.Vue3/src/apis/integralApi.js index 0f211e68..f1441a99 100644 --- a/Yi.Bbs.Vue3/src/apis/integralApi.js +++ b/Yi.Bbs.Vue3/src/apis/integralApi.js @@ -6,3 +6,10 @@ export function signIn() { method: "post" }); } + +export function signInRecord() { + return request({ + url: "/integral/sign-in/record", + method: "get" + }); +} diff --git a/Yi.Bbs.Vue3/src/hooks/useAuths.js b/Yi.Bbs.Vue3/src/hooks/useAuths.js index ddb5b926..20f301c4 100644 --- a/Yi.Bbs.Vue3/src/hooks/useAuths.js +++ b/Yi.Bbs.Vue3/src/hooks/useAuths.js @@ -2,6 +2,7 @@ import { ElMessage, ElMessageBox } from "element-plus"; import useUserStore from "@/stores/user"; import router from "@/router"; import { Session, Local } from "@/utils/storage"; +import{computed} from 'vue' import { userLogin, getUserDetailInfo, @@ -15,6 +16,8 @@ export const AUTH_USER = "AUTH_USER"; export default function useAuths(opt) { + + const defaultOpt = { loginUrl: "/login", // 登录页跳转url 默认: /login loginReUrl: "", // 登录页登陆成功后带重定向redirect=的跳转url 默认为空 @@ -33,6 +36,14 @@ export default function useAuths(opt) { return token; }; + +const isLogin=computed(()=>{ + + var token= Local.get(TokenKey); + return token? true : false; + +}) + // 存储token到cookies const setToken = (token) => { if (token == null) { @@ -179,6 +190,7 @@ export default function useAuths(opt) { logoutFun, clearStorage, registerFun, - loginSuccess + loginSuccess, + isLogin }; } diff --git a/Yi.Bbs.Vue3/src/layout/AppHeader.vue b/Yi.Bbs.Vue3/src/layout/AppHeader.vue index 59fa9665..f69fc29b 100644 --- a/Yi.Bbs.Vue3/src/layout/AppHeader.vue +++ b/Yi.Bbs.Vue3/src/layout/AppHeader.vue @@ -86,7 +86,7 @@ import useAuths from "@/hooks/useAuths"; import { Session } from "@/utils/storage"; import signalR from "@/utils/signalR"; -const { getToken, clearStorage } = useAuths(); +const { isLogin, clearStorage } = useAuths(); const configStore = useConfigStore(); const router = useRouter(); const route = useRoute(); @@ -130,8 +130,6 @@ const search = () => { router.push(routerPer); }; -const isLogin = getToken("AccessToken") ? true : false; - const handleGitClick = () => { window.open("https://gitee.com/ccnetcore/Yi"); }; diff --git a/Yi.Bbs.Vue3/src/views/signIn/index.vue b/Yi.Bbs.Vue3/src/views/signIn/index.vue index 7efc8d03..835be56d 100644 --- a/Yi.Bbs.Vue3/src/views/signIn/index.vue +++ b/Yi.Bbs.Vue3/src/views/signIn/index.vue @@ -1,26 +1,60 @@ 每日签到页持续coding中~~~ - - + 当前已连续签到{{number}}天 点击完成签到 - + + + + {{ data.day.split("-").slice(1).join("月") + "日" }} + + {{containSameDay(data.date)? "已签到✔️" : "" }} + + + @@ -30,4 +64,7 @@ const signInOnclic= async()=>{ width: 100%; height: 100%; } +.is-selected { + color: #1989fa; +}
+ {{ data.day.split("-").slice(1).join("月") + "日" }} + + {{containSameDay(data.date)? "已签到✔️" : "" }} +