feat: 新增显示签到记录

This commit is contained in:
陈淳
2024-01-15 15:28:32 +08:00
parent 40195ea993
commit a06c8c00b3
7 changed files with 142 additions and 17 deletions

View File

@@ -6,3 +6,10 @@ export function signIn() {
method: "post"
});
}
export function signInRecord() {
return request({
url: "/integral/sign-in/record",
method: "get"
});
}

View File

@@ -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
};
}

View File

@@ -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");
};

View File

@@ -1,26 +1,60 @@
<template>
<div class="everyday-box">
<h4>每日签到页持续coding中~~~</h4>
<h5>当前已连续签到{{number}}</h5>
<el-button type="primary" @click="signInOnclic">点击完成签到</el-button>
<el-calendar v-model="signInRecordData">
<template #date-cell="{ data }">
<p :class="containSameDay(data.date) ? 'is-selected' : ''">
{{ data.day.split("-").slice(1).join("月") + "日" }}
<br/>
{{containSameDay(data.date)? "已签到✔️" : "" }}
</p>
</template>
</el-calendar>
</div>
</template>
<script setup>
import { onMounted, ref, reactive, computed, nextTick, watch } from "vue";
import { signIn } from "@/apis/integralApi.js";
import { signIn, signInRecord } from "@/apis/integralApi.js";
import useAuths from "@/hooks/useAuths";
const { isLogin } = useAuths();
const number=ref(0);
const signInData=ref([]);
const signInRecordData = ref(new Date());
const signInOnclic = async () => {
const { data: data } = await signIn();
const signInOnclic= async()=>{
const { data: data}= await signIn();
ElMessage({
message: `恭喜!运气爆棚,今日获得:${data.value} 钱钱`,
type: "success",
});
ElMessage({
message: `恭喜!运气爆棚,今日获得:${data.value} 钱钱`,
type: "success",
});
};
onMounted(async () => {
//登录后才去查询签到记录
if (isLogin) {
const { data:{signInItem,currentContinuousNumber} } = await signInRecord();
number.value=currentContinuousNumber;
signInData.value=signInItem;
}
});
const containSameDay=(time)=>{
return signInData.value.filter(x=>isSameDay(x.creationTime,time)).length==0?false:true;
}
//判断两个时间是否为同一天
const isSameDay=(time1, time2)=> {
const date1 = new Date(time1);
const date2 = new Date(time2);
return (
date1.getFullYear() === date2.getFullYear() &&
date1.getMonth() === date2.getMonth() &&
date1.getDate() === date2.getDate()
);
}
</script>
@@ -30,4 +64,7 @@ const signInOnclic= async()=>{
width: 100%;
height: 100%;
}
.is-selected {
color: #1989fa;
}
</style>