feat: 增加登录管理系统
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
IBillRecord,
|
IBillRecord,
|
||||||
IBillSummaryStats
|
IBillSummaryStats
|
||||||
} from '@/types/bill'
|
} from '@/types/bill'
|
||||||
|
import { IStatsChart } from 'vue3-common/dist/types'
|
||||||
|
|
||||||
export const addBillRecordApi = (billRecord: IBillRecord): Promise<boolean> =>
|
export const addBillRecordApi = (billRecord: IBillRecord): Promise<boolean> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
@@ -41,7 +42,7 @@ export const queryBillSummaryApi = (query: IBillQuery): Promise<IBillRecord[]> =
|
|||||||
params: query
|
params: query
|
||||||
})
|
})
|
||||||
|
|
||||||
export const queryBillStatsApi = (type: string, query: IBillQuery): Promise<any> =>
|
export const queryBillStatsApi = (type: string, query: IBillQuery): Promise<IStatsChart[]> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: `/home-service/bill/stats/${type}`,
|
url: `/home-service/bill/stats/${type}`,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
@@ -73,35 +74,35 @@ export const addBillPayApi = (billPay: IBillPay): Promise<boolean> =>
|
|||||||
data: billPay
|
data: billPay
|
||||||
})
|
})
|
||||||
|
|
||||||
export const updateBillPayApi = (id: number, billPay: IBillPay): Promise<any> =>
|
export const updateBillPayApi = (id: number, billPay: IBillPay): Promise<boolean> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: `/admin-service/bill-manage/pay/${id}`,
|
url: `/admin-service/bill-manage/pay/${id}`,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: billPay
|
data: billPay
|
||||||
})
|
})
|
||||||
|
|
||||||
export const addBillBookApi = (billBook: IBillBook): Promise<any> =>
|
export const addBillBookApi = (billBook: IBillBook): Promise<boolean> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: '/admin-service/bill-manage/book',
|
url: '/admin-service/bill-manage/book',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: billBook
|
data: billBook
|
||||||
})
|
})
|
||||||
|
|
||||||
export const updateBillBookApi = (id: number, billBook: IBillBook): Promise<any> =>
|
export const updateBillBookApi = (id: number, billBook: IBillBook): Promise<boolean> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: `/admin-service/bill-manage/book/${id}`,
|
url: `/admin-service/bill-manage/book/${id}`,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: billBook
|
data: billBook
|
||||||
})
|
})
|
||||||
|
|
||||||
export const addBillCategoryApi = (billCategory: IBillCategory): Promise<any> =>
|
export const addBillCategoryApi = (billCategory: IBillCategory): Promise<boolean> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: '/admin-service/bill-manage/category',
|
url: '/admin-service/bill-manage/category',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: billCategory
|
data: billCategory
|
||||||
})
|
})
|
||||||
|
|
||||||
export const updateBillCategoryApi = (id: number, billCategory: IBillCategory): Promise<any> =>
|
export const updateBillCategoryApi = (id: number, billCategory: IBillCategory): Promise<boolean> =>
|
||||||
cloudService({
|
cloudService({
|
||||||
url: `/admin-service/bill-manage/category/${id}`,
|
url: `/admin-service/bill-manage/category/${id}`,
|
||||||
method: 'put',
|
method: 'put',
|
||||||
|
|||||||
@@ -8,3 +8,9 @@ export const loginHomeApi = (name: string, password: string): Promise<ISession>
|
|||||||
params: { name, password }
|
params: { name, password }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const loginAdminApi = (name: string, password: string): Promise<ISession> =>
|
||||||
|
cloudService({
|
||||||
|
url: '/admin-service/session',
|
||||||
|
method: 'post',
|
||||||
|
params: { name, password }
|
||||||
|
})
|
||||||
|
|||||||
@@ -43,7 +43,13 @@
|
|||||||
<el-button type="primary" style="width: 100%;"
|
<el-button type="primary" style="width: 100%;"
|
||||||
:disabled="!authStore.isVerified"
|
:disabled="!authStore.isVerified"
|
||||||
:loading="authStore.loginLoading"
|
:loading="authStore.loginLoading"
|
||||||
@click.prevent="handleLogin()">登录
|
@click.prevent="handleLogin('common')">登录
|
||||||
|
</el-button>
|
||||||
|
<div />
|
||||||
|
<el-button type="primary" style="width: 100%;"
|
||||||
|
:disabled="!authStore.isVerified"
|
||||||
|
:loading="authStore.loginLoading"
|
||||||
|
@click.prevent="handleLogin('admin')">登录管理系统
|
||||||
</el-button>
|
</el-button>
|
||||||
|
|
||||||
<div class="login-type">
|
<div class="login-type">
|
||||||
@@ -79,6 +85,7 @@ import { onMounted, reactive, ref } from 'vue'
|
|||||||
import { loginRules } from '@/utils/element/elRules'
|
import { loginRules } from '@/utils/element/elRules'
|
||||||
import { isMobile } from 'vue3-common/utils/layoutUtil'
|
import { isMobile } from 'vue3-common/utils/layoutUtil'
|
||||||
import { getLocalStorage, setLocalStorage } from 'vue3-common/utils/storageUtil'
|
import { getLocalStorage, setLocalStorage } from 'vue3-common/utils/storageUtil'
|
||||||
|
import { ILoginType } from '@/types/auth'
|
||||||
|
|
||||||
const rules = reactive<FormRules>(loginRules)
|
const rules = reactive<FormRules>(loginRules)
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
@@ -94,13 +101,13 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleLogin = async () => {
|
const handleLogin = async (type: ILoginType) => {
|
||||||
loginFormRef.value.validate(async (valid: any) => {
|
loginFormRef.value.validate(async (valid: any) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
authStore.loginLoading = true
|
authStore.loginLoading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await authStore.handleLogin('common')
|
await authStore.handleLogin(type)
|
||||||
userStore.handleSession(authStore.homeSession)
|
userStore.handleSession(authStore.homeSession)
|
||||||
|
|
||||||
// 2. 存储账户密码到localStorage中
|
// 2. 存储账户密码到localStorage中
|
||||||
@@ -110,8 +117,10 @@ const handleLogin = async () => {
|
|||||||
|
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
await router.push('/mobile-home')
|
await router.push('/mobile-home')
|
||||||
} else {
|
} else if (type === 'common') {
|
||||||
await router.push('/home')
|
await router.push('/home')
|
||||||
|
} else {
|
||||||
|
await router.push('/admin')
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
authStore.loginLoading = false
|
authStore.loginLoading = false
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<!-- <img :src="logoInfo.logo" alt="logo">-->
|
<!-- <img :src="logoInfo.logo" alt="logo">-->
|
||||||
</router-link>
|
</router-link>
|
||||||
<router-link v-else key="expand" class="logo" to="/admin/dashboard">
|
<router-link v-else key="expand" class="logo" to="/admin/dashboard">
|
||||||
<img :src="getAssetsImageFile('logo/vue.png')"
|
<img :src="getAssetsImageFile('logo/logo.png')"
|
||||||
alt="logo">
|
alt="logo">
|
||||||
</router-link>
|
</router-link>
|
||||||
</transition>
|
</transition>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const profileClick = () => {
|
|||||||
|
|
||||||
const logoutClick = () => {
|
const logoutClick = () => {
|
||||||
commonElMessageBox('请确认是否退出登录?').then(() => {
|
commonElMessageBox('请确认是否退出登录?').then(() => {
|
||||||
router.push('/login')
|
router.push('/')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ILoginType, ISession } from '@/types/auth'
|
import { ILoginType, ISession } from '@/types/auth'
|
||||||
import { loginHomeApi } from '@/apis/session'
|
import { loginAdminApi, loginHomeApi } from '@/apis/session'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { emailPattern, phonePattern } from '@/utils/element/elRules'
|
import { emailPattern, phonePattern } from '@/utils/element/elRules'
|
||||||
|
|
||||||
@@ -90,6 +90,9 @@ export const useAuthStore = defineStore('auth', {
|
|||||||
case 'email':
|
case 'email':
|
||||||
this.homeSession = await loginHomeApi(email, emailCode)
|
this.homeSession = await loginHomeApi(email, emailCode)
|
||||||
break
|
break
|
||||||
|
case 'admin':
|
||||||
|
this.homeSession = await loginAdminApi(username, password)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export type ILoginType = 'common' | 'phone' | 'email'
|
export type ILoginType = 'common' | 'phone' | 'email' | 'admin'
|
||||||
|
|
||||||
export type IAccountType = 'QQ' | 'WeChat' | 'Phone' | 'EMail'
|
export type IAccountType = 'QQ' | 'WeChat' | 'Phone' | 'EMail'
|
||||||
|
|
||||||
|
|||||||
@@ -55,11 +55,6 @@ export const homeMeta: IRouteMetaConfig = {
|
|||||||
order: 4,
|
order: 4,
|
||||||
redirect: '/home/others/admin'
|
redirect: '/home/others/admin'
|
||||||
},
|
},
|
||||||
'/home/others/admin': {
|
|
||||||
title: '管理系统',
|
|
||||||
icon: '',
|
|
||||||
redirect: '/admin'
|
|
||||||
},
|
|
||||||
'/home/others/blog': {
|
'/home/others/blog': {
|
||||||
title: '个人博客',
|
title: '个人博客',
|
||||||
icon: '',
|
icon: '',
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
</script>
|
|
||||||
@@ -31,6 +31,7 @@ const loginInfo = reactive({
|
|||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
authStore.isVerified = false
|
||||||
// authStore.resetLoginForm()
|
// authStore.resetLoginForm()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user