添加登录功能
This commit is contained in:
28
src/App.vue
28
src/App.vue
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user