Skip to content

Commit 5151d11

Browse files
authored
Merge pull request #1 from Hanmo123/main
提交遗漏更改
2 parents c4edb47 + 70005b5 commit 5151d11

5 files changed

Lines changed: 41 additions & 7 deletions

File tree

components.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ declare module '@vue/runtime-core' {
1010
AllowSubmit: typeof import('./src/components/AllowSubmit.vue')['default']
1111
GlobalMessage: typeof import('./src/components/GlobalMessage.vue')['default']
1212
LoadingBar: typeof import('./src/components/LoadingBar.vue')['default']
13+
NA: typeof import('naive-ui')['NA']
1314
NBreadcrumb: typeof import('naive-ui')['NBreadcrumb']
1415
NBreadcrumbItem: typeof import('naive-ui')['NBreadcrumbItem']
1516
NButton: typeof import('naive-ui')['NButton']
17+
NCheckbox: typeof import('naive-ui')['NCheckbox']
1618
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
1719
NDataTable: typeof import('naive-ui')['NDataTable']
1820
NDrawer: typeof import('naive-ui')['NDrawer']
1921
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
2022
NDropdown: typeof import('naive-ui')['NDropdown']
2123
NForm: typeof import('naive-ui')['NForm']
24+
NFormItem: typeof import('naive-ui')['NFormItem']
2225
NIcon: typeof import('naive-ui')['NIcon']
2326
NInput: typeof import('naive-ui')['NInput']
2427
NInputGroup: typeof import('naive-ui')['NInputGroup']
28+
NInputNumber: typeof import('naive-ui')['NInputNumber']
2529
NLoadingBarProvider: typeof import('naive-ui')['NLoadingBarProvider']
2630
NMenu: typeof import('naive-ui')['NMenu']
2731
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
@@ -33,6 +37,7 @@ declare module '@vue/runtime-core' {
3337
NTable: typeof import('naive-ui')['NTable']
3438
NTabs: typeof import('naive-ui')['NTabs']
3539
NTag: typeof import('naive-ui')['NTag']
40+
NTime: typeof import('naive-ui')['NTime']
3641
NUpload: typeof import('naive-ui')['NUpload']
3742
NUploadDragger: typeof import('naive-ui')['NUploadDragger']
3843
PAddress: typeof import('./src/components/Instance/Console/PAddress.vue')['default']

src/App.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script lang="ts" setup>
22
import {onMounted} from 'vue';
33
import {useAuthData} from './stores/AuthStore';
4-
import {auth} from './class/Client';
54
import {useRouter} from 'vue-router';
65
import colors from 'tailwindcss/colors';
76
import type {GlobalThemeOverrides} from "naive-ui";
@@ -11,11 +10,10 @@ const AuthData = useAuthData();
1110
const router = useRouter();
1211
1312
onMounted(() => {
14-
auth.fetch((res) => {
15-
AuthData.$patch({loaded: true, status: res.data.status, ...res.data.attributes});
13+
AuthData.load(() => {
1614
if (!AuthData.status) {
1715
router.isReady().then(() => router.push('/auth'));
18-
console.log('未登录 转跳');
16+
(window as any).message.warning('身份信息已过期,请重新登录');
1917
}
2018
});
2119
});

src/class/Client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ function Delete(url: string, params: {}, onSuccess: (res: any) => void) {
3737
const auth = {
3838
fetch(onSuccess: (res: any) => void) {
3939
Get('/api/public/auth', {}, onSuccess);
40+
},
41+
login(name: string, password: string, onSuccess: (res: any) => void) {
42+
Post('/api/public/auth/login', {name, password}, onSuccess);
4043
}
4144
}
4245

src/stores/AuthStore.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {defineStore} from 'pinia'
2+
import {auth} from "@/class/Client";
23

34
export const useAuthData = defineStore('AuthStore', {
45
state: () => ({
@@ -16,5 +17,11 @@ export const useAuthData = defineStore('AuthStore', {
1617
cancel();
1718
});
1819
},
20+
load(callback: () => void) {
21+
auth.fetch((res) => {
22+
this.$patch({loaded: true, status: res.data.status, ...res.data.attributes});
23+
callback();
24+
});
25+
}
1926
}
2027
})

src/views/AuthView.vue

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,31 @@
22
import {ArrowForwardOutlined} from "@vicons/material";
33
import {ref} from "vue";
44
import AllowSubmit from "@/components/AllowSubmit.vue";
5+
import {useAuthData} from "@/stores/AuthStore";
6+
import {auth} from "@/class/Client";
7+
import {useRouter} from "vue-router";
8+
import {useMessage} from "naive-ui";
59
10+
const AuthData = useAuthData();
11+
const router = useRouter();
12+
const message = useMessage();
613
const input = ref({
714
name: '',
815
pass: ''
916
});
17+
18+
const actions = {
19+
login() {
20+
auth.login(input.value.name, input.value.pass, () => {
21+
AuthData.load(() => {
22+
if (AuthData.status) {
23+
router.isReady().then(() => router.push({name: 'instance'}));
24+
message.success('登录成功,欢迎回来');
25+
}
26+
});
27+
});
28+
}
29+
};
1030
</script>
1131

1232
<template>
@@ -23,11 +43,12 @@ const input = ref({
2343
<div class="font-bold text-3xl text-gray-700 mt-1">PowerPanel</div>
2444
</div>
2545
<div class="login-form">
26-
<n-form @submit.prevent>
46+
<n-form @submit.prevent="actions.login()">
2747
<n-input v-model:value="input.name" placeholder="输入用户名" class="mt-10" size="large"/>
28-
<n-input v-model:value="input.name" placeholder="输入密码" class="mt-4" size="large"/>
48+
<n-input v-model:value="input.pass" type="password" placeholder="输入密码" class="mt-4"
49+
size="large"/>
2950

30-
<n-button block type="primary" class="button" size="large">
51+
<n-button block type="primary" class="button" size="large" @click="actions.login()">
3152
登录
3253
<n-icon class="ml-0.5" :size="16">
3354
<ArrowForwardOutlined/>

0 commit comments

Comments
 (0)