添加登录功能

This commit is contained in:
2025-02-28 16:20:58 +08:00
parent 81706fc48d
commit 28abe1b429
13 changed files with 181 additions and 14 deletions

View File

@@ -1,6 +1,10 @@
<script setup lang="ts">
import { dateZhCN, zhCN } from "naive-ui"
import { useMagicKeys, whenever } from "@vueuse/core"
import Login from "./components/Login.vue"
import { onMounted, watch } from "vue"
import { getMyProfile } from "./api"
import { authed, username } from "./store/user"
const { ctrl_s } = useMagicKeys({
passive: false,
@@ -17,15 +21,27 @@ const { ctrl_r } = useMagicKeys({
})
whenever(ctrl_s, () => {})
whenever(ctrl_r, () => {})
onMounted(async () => {
const data = await getMyProfile()
username.value = data
})
watch(authed, (v) => {
if (v) {
localStorage.setItem("web-isloggedin", "true")
} else {
localStorage.removeItem("web-isloggedin")
}
})
</script>
<template>
<n-config-provider
class="myContainer"
:locale="zhCN"
:date-locale="dateZhCN"
>
<router-view></router-view>
<n-config-provider class="myContainer" :locale="zhCN" :date-locale="dateZhCN">
<n-modal-provider>
<router-view></router-view>
<Login />
</n-modal-provider>
</n-config-provider>
</template>
<style scoped>