[go: nahoru, domu]

Skip to content

Commit

Permalink
✨ feat: 支持自动签到
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Dec 19, 2023
1 parent a45940b commit e802a2f
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 79 deletions.
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ declare module 'vue' {
NPagination: typeof import('naive-ui')['NPagination']
NPopover: typeof import('naive-ui')['NPopover']
NProgress: typeof import('naive-ui')['NProgress']
NQrCode: typeof import('naive-ui')['NQrCode']
NRadio: typeof import('naive-ui')['NRadio']
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
NResult: typeof import('naive-ui')['NResult']
Expand Down
1 change: 1 addition & 0 deletions electron/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class MainProcess {
sandbox: false,
webSecurity: false,
hardwareAcceleration: true,
nodeIntegration: true,
},
});

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"pinia": "^2.1.6",
"pinia-plugin-persistedstate": "^3.2.0",
"plyr": "^3.7.8",
"qrcode.vue": "^3.4.1",
"screenfull": "^6.0.2",
"vue-router": "^4.2.4",
"vue-slider-component": "4.1.0-beta.7"
Expand All @@ -59,7 +58,7 @@
"electron-vite": "^1.0.29",
"eslint": "^8.47.0",
"eslint-plugin-vue": "^9.17.0",
"naive-ui": "^2.35.0",
"naive-ui": "^2.36.0",
"prettier": "^3.0.2",
"sass": "^1.66.1",
"terser": "^5.19.2",
Expand Down
33 changes: 11 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@
<script setup>
import { storeToRefs } from "pinia";
import { darkTheme, NButton } from "naive-ui";
import { useRouter } from "vue-router";
import { darkTheme, NButton } from "naive-ui";
import { musicData, siteStatus, siteSettings } from "@/stores";
import { initPlayer } from "@/utils/Player";
import { checkPlatform } from "@/utils/helper";
import { initPlayer } from "@/utils/Player";
import userSignIn from "@/utils/userSignIn";
import globalShortcut from "@/utils/globalShortcut";
import globalEvents from "@/utils/globalEvents";
import packageJson from "@/../package.json";
Expand All @@ -92,7 +93,7 @@ const router = useRouter();
const music = musicData();
const status = siteStatus();
const settings = siteSettings();
const { autoPlay, showSider } = storeToRefs(settings);
const { autoPlay, showSider, autoSignIn } = storeToRefs(settings);
const { showPlayBar, asideMenuCollapsed, showFullPlayer } = storeToRefs(status);
// 公告数据
Expand All @@ -113,7 +114,7 @@ if ("serviceWorker" in navigator) {
$notification.create({
title: "🎉 有更新啦",
content: "检测到软件内资源有更新,是否重新启动软件以应用更新?",
meta: "v " + (packageJson.version || "1.0.0"),
meta: "当前版本 v " + (packageJson.version || "1.0.0"),
action: () =>
h(
NButton,
Expand Down Expand Up @@ -178,17 +179,19 @@ const handleKeyUp = (event) => {
globalShortcut(event, router);
};
onMounted(() => {
onMounted(async () => {
// 挂载方法
window.$canNotConnect = canNotConnect;
// 主播放器
initPlayer(autoPlay.value);
await initPlayer(autoPlay.value);
// 全局事件
globalEvents(router);
// 键盘监听
if (!checkPlatform.electron()) {
window.addEventListener("keyup", handleKeyUp);
}
// 自动签到
if (autoSignIn.value) await userSignIn(settings);
// 显示公告
showAnnouncements();
});
Expand Down
8 changes: 7 additions & 1 deletion src/components/Modal/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@

<script setup>
import { storeToRefs } from "pinia";
import { siteData } from "@/stores";
import { siteData, siteSettings } from "@/stores";
import { getLoginState, refreshLogin } from "@/api/login";
import { setCookies, toLogout, isLogin } from "@/utils/auth";
import userSignIn from "@/utils/userSignIn";
const data = siteData();
const settings = siteSettings();
const { userData } = storeToRefs(data);
const { autoSignIn } = storeToRefs(settings);
// 登录数据
const loginModalShow = ref(false);
Expand Down Expand Up @@ -83,6 +86,9 @@ const setLoginData = async (loginData) => {
setCookies(loginData.cookie);
// 获取用户信息
await data.setUserProfile();
await data.setDailySongsData();
// 签到
if (autoSignIn.value) await userSignIn();
// 更改状态
data.userLoginStatus = true;
$message.success("登录成功");
Expand Down
25 changes: 13 additions & 12 deletions src/components/Modal/LoginQRCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
<template>
<div class="login-qr">
<div class="qr-img">
<n-skeleton v-if="!qrImg" class="qr" />
<QrcodeVue
v-else
:class="['qr', qrStatusCode === 802 ? 'hidden' : null]"
:value="qrImg"
:size="180"
:margin="4"
level="L"
foreground="#000"
background="#fff"
/>
<Transition name="fade" mode="out-in">
<n-qr-code
v-if="qrImg"
:value="qrImg"
:class="['qr', qrStatusCode === 802 ? 'hidden' : null]"
:size="156"
:icon-size="30"
icon-src="/images/icons/favicon.png?asset"
error-correction-level="H"
/>
<n-skeleton v-else class="qr" />
</Transition>
<Transition name="fade" mode="out-in">
<div v-if="qrStatusCode === 802" class="refresh" @click="getQrData">
<n-icon size="22">
Expand All @@ -28,7 +29,6 @@

<script setup>
import { getQrKey, checkQr } from "@/api/login";
import QrcodeVue from "qrcode.vue";
const emit = defineEmits(["setLoginData"]);
Expand Down Expand Up @@ -133,6 +133,7 @@ onBeforeUnmount(() => {
min-width: 180px;
height: 180px;
width: 180px;
box-sizing: border-box;
transition: opacity 0.3s;
&.hidden {
opacity: 0.2;
Expand Down
16 changes: 9 additions & 7 deletions src/components/Nav/UserData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { useRouter } from "vue-router";
import { NIcon, NText, NNumberAnimation, NButton } from "naive-ui";
import { siteData, siteSettings } from "@/stores";
import SvgIcon from "@/components/Global/SvgIcon";
import userSignIn from "@/utils/userSignIn";
const data = siteData();
const router = useRouter();
Expand All @@ -61,9 +62,6 @@ const userMenuShow = ref(false);
// 登录弹窗
const loginRef = ref(null);
// 是否签到
const signInStatus = ref(false);
// 图标渲染
const renderIcon = (icon) => {
return () => h(NIcon, null, () => h(SvgIcon, { icon }));
Expand Down Expand Up @@ -91,6 +89,8 @@ const createUserNumber = (num, text, duration = 1000) => {
// 生成导航栏用户信息
const createUserData = () => {
// 是否签到
const signInStatus = sessionStorage.getItem("lastSignInDate") ? true : false;
return h(
"div",
{ className: "nav-user-data" },
Expand All @@ -108,12 +108,14 @@ const createUserData = () => {
NButton,
{
round: true,
renderIcon: renderIcon(signInStatus.value ? "calendar-check" : "calendar-badge"),
onclick: () => {
$message.warning("施工中( 新建文件夹 )");
renderIcon: renderIcon(signInStatus ? "calendar-check" : "calendar-badge"),
disabled: signInStatus,
onclick: async () => {
userMenuShow.value = false;
await userSignIn();
},
},
() => [signInStatus.value ? "Lv." + userData.value.detail?.level || 1 : "立即签到"],
() => [signInStatus ? "今日已签到" : "立即签到"],
),
]),
]
Expand Down
Loading

0 comments on commit e802a2f

Please sign in to comment.