Skip to content

Commit

Permalink
Merge pull request #1 from Hanmo123/main
Browse files Browse the repository at this point in the history
提交遗漏更改
  • Loading branch information
Hanmo123 authored Feb 11, 2023
2 parents c4edb47 + 70005b5 commit 5151d11
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
5 changes: 5 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ declare module '@vue/runtime-core' {
AllowSubmit: typeof import('./src/components/AllowSubmit.vue')['default']
GlobalMessage: typeof import('./src/components/GlobalMessage.vue')['default']
LoadingBar: typeof import('./src/components/LoadingBar.vue')['default']
NA: typeof import('naive-ui')['NA']
NBreadcrumb: typeof import('naive-ui')['NBreadcrumb']
NBreadcrumbItem: typeof import('naive-ui')['NBreadcrumbItem']
NButton: typeof import('naive-ui')['NButton']
NCheckbox: typeof import('naive-ui')['NCheckbox']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDataTable: typeof import('naive-ui')['NDataTable']
NDrawer: typeof import('naive-ui')['NDrawer']
NDrawerContent: typeof import('naive-ui')['NDrawerContent']
NDropdown: typeof import('naive-ui')['NDropdown']
NForm: typeof import('naive-ui')['NForm']
NFormItem: typeof import('naive-ui')['NFormItem']
NIcon: typeof import('naive-ui')['NIcon']
NInput: typeof import('naive-ui')['NInput']
NInputGroup: typeof import('naive-ui')['NInputGroup']
NInputNumber: typeof import('naive-ui')['NInputNumber']
NLoadingBarProvider: typeof import('naive-ui')['NLoadingBarProvider']
NMenu: typeof import('naive-ui')['NMenu']
NMessageProvider: typeof import('naive-ui')['NMessageProvider']
Expand All @@ -33,6 +37,7 @@ declare module '@vue/runtime-core' {
NTable: typeof import('naive-ui')['NTable']
NTabs: typeof import('naive-ui')['NTabs']
NTag: typeof import('naive-ui')['NTag']
NTime: typeof import('naive-ui')['NTime']
NUpload: typeof import('naive-ui')['NUpload']
NUploadDragger: typeof import('naive-ui')['NUploadDragger']
PAddress: typeof import('./src/components/Instance/Console/PAddress.vue')['default']
Expand Down
6 changes: 2 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts" setup>
import {onMounted} from 'vue';
import {useAuthData} from './stores/AuthStore';
import {auth} from './class/Client';
import {useRouter} from 'vue-router';
import colors from 'tailwindcss/colors';
import type {GlobalThemeOverrides} from "naive-ui";
Expand All @@ -11,11 +10,10 @@ const AuthData = useAuthData();
const router = useRouter();
onMounted(() => {
auth.fetch((res) => {
AuthData.$patch({loaded: true, status: res.data.status, ...res.data.attributes});
AuthData.load(() => {
if (!AuthData.status) {
router.isReady().then(() => router.push('/auth'));
console.log('未登录 转跳');
(window as any).message.warning('身份信息已过期,请重新登录');
}
});
});
Expand Down
3 changes: 3 additions & 0 deletions src/class/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ function Delete(url: string, params: {}, onSuccess: (res: any) => void) {
const auth = {
fetch(onSuccess: (res: any) => void) {
Get('/api/public/auth', {}, onSuccess);
},
login(name: string, password: string, onSuccess: (res: any) => void) {
Post('/api/public/auth/login', {name, password}, onSuccess);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/stores/AuthStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {defineStore} from 'pinia'
import {auth} from "@/class/Client";

export const useAuthData = defineStore('AuthStore', {
state: () => ({
Expand All @@ -16,5 +17,11 @@ export const useAuthData = defineStore('AuthStore', {
cancel();
});
},
load(callback: () => void) {
auth.fetch((res) => {
this.$patch({loaded: true, status: res.data.status, ...res.data.attributes});
callback();
});
}
}
})
27 changes: 24 additions & 3 deletions src/views/AuthView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@
import {ArrowForwardOutlined} from "@vicons/material";
import {ref} from "vue";
import AllowSubmit from "@/components/AllowSubmit.vue";
import {useAuthData} from "@/stores/AuthStore";
import {auth} from "@/class/Client";
import {useRouter} from "vue-router";
import {useMessage} from "naive-ui";
const AuthData = useAuthData();
const router = useRouter();
const message = useMessage();
const input = ref({
name: '',
pass: ''
});
const actions = {
login() {
auth.login(input.value.name, input.value.pass, () => {
AuthData.load(() => {
if (AuthData.status) {
router.isReady().then(() => router.push({name: 'instance'}));
message.success('登录成功,欢迎回来');
}
});
});
}
};
</script>

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

<n-button block type="primary" class="button" size="large">
<n-button block type="primary" class="button" size="large" @click="actions.login()">
登录
<n-icon class="ml-0.5" :size="16">
<ArrowForwardOutlined/>
Expand Down

0 comments on commit 5151d11

Please sign in to comment.