refactor: Separate store

This commit is contained in:
vben
2024-07-30 21:10:28 +08:00
parent cf0ec053e4
commit 89dcf522f5
40 changed files with 338 additions and 345 deletions

View File

@@ -1,18 +1,18 @@
<script lang="ts" setup>
import { AuthenticationLogin } from '@vben/common-ui';
import { useAccessStore } from '#/store';
import { useAuthStore } from '#/store';
defineOptions({ name: 'Login' });
const accessStore = useAccessStore();
const authStore = useAuthStore();
</script>
<template>
<AuthenticationLogin
:loading="accessStore.loading"
:loading="authStore.loginLoading"
password-placeholder="123456"
username-placeholder="vben"
@submit="accessStore.authLogin"
@submit="authStore.authLogin"
/>
</template>

View File

@@ -17,12 +17,11 @@ import {
WorkbenchTrends,
} from '@vben/common-ui';
import { preferences } from '@vben/preferences';
import { useAccessStore } from '#/store';
import { useUserStore } from '@vben/stores';
import AnalyticsVisitsSource from '../analytics/analytics-visits-source.vue';
const accessStore = useAccessStore();
const userStore = useUserStore();
const projectItems: WorkbenchProjectItem[] = [
{
@@ -201,10 +200,10 @@ const trendItems: WorkbenchTrendItem[] = [
<template>
<div class="p-5">
<WorkbenchHeader
:avatar="accessStore.userInfo?.avatar || preferences.app.defaultAvatar"
:avatar="userStore.userInfo?.avatar || preferences.app.defaultAvatar"
>
<template #title>
早安, {{ accessStore.userInfo?.realName }}, 开始您一天的工作吧
早安, {{ userStore.userInfo?.realName }}, 开始您一天的工作吧
</template>
<template #description> 今日晴20 - 32 </template>
</WorkbenchHeader>

View File

@@ -4,10 +4,11 @@ import type { LoginAndRegisterParams } from '@vben/common-ui';
import { useRouter } from 'vue-router';
import { AccessControl, useAccess } from '@vben/access';
import { resetAllStores, useUserStore } from '@vben/stores';
import { Button } from 'ant-design-vue';
import { resetAllStores, useAccessStore } from '#/store';
import { useAuthStore } from '#/store';
const accounts: Record<string, LoginAndRegisterParams> = {
admin: {
@@ -25,21 +26,22 @@ const accounts: Record<string, LoginAndRegisterParams> = {
};
const { accessMode, hasAccessByCodes } = useAccess();
const accessStore = useAccessStore();
const authStore = useAuthStore();
const userStore = useUserStore();
const router = useRouter();
function roleButtonType(role: string) {
return accessStore.userRoles.includes(role) ? 'primary' : 'default';
return userStore.userRoles.includes(role) ? 'primary' : 'default';
}
async function changeAccount(role: string) {
if (accessStore.userRoles.includes(role)) {
if (userStore.userRoles.includes(role)) {
return;
}
const account = accounts[role];
resetAllStores();
await accessStore.authLogin(account, async () => {
await authStore.authLogin(account, async () => {
router.go(0);
});
}
@@ -58,7 +60,7 @@ async function changeAccount(role: string) {
<div class="mb-3">
<span class="text-lg font-semibold">当前角色:</span>
<span class="text-primary mx-4 text-lg">
{{ accessStore.userRoles?.[0] }}
{{ userStore.userRoles?.[0] }}
</span>
</div>

View File

@@ -4,10 +4,11 @@ import type { LoginAndRegisterParams } from '@vben/common-ui';
import { useRouter } from 'vue-router';
import { useAccess } from '@vben/access';
import { resetAllStores, useUserStore } from '@vben/stores';
import { Button } from 'ant-design-vue';
import { resetAllStores, useAccessStore } from '#/store';
import { useAuthStore } from '#/store';
const accounts: Record<string, LoginAndRegisterParams> = {
admin: {
@@ -25,15 +26,16 @@ const accounts: Record<string, LoginAndRegisterParams> = {
};
const { accessMode, toggleAccessMode } = useAccess();
const accessStore = useAccessStore();
const userStore = useUserStore();
const accessStore = useAuthStore();
const router = useRouter();
function roleButtonType(role: string) {
return accessStore.userRoles.includes(role) ? 'primary' : 'default';
return userStore.userRoles.includes(role) ? 'primary' : 'default';
}
async function changeAccount(role: string) {
if (accessStore.userRoles.includes(role)) {
if (userStore.userRoles.includes(role)) {
return;
}
@@ -80,7 +82,7 @@ async function handleToggleAccessMode() {
<div class="mb-3">
<span class="text-lg font-semibold">当前账号:</span>
<span class="text-primary mx-4 text-lg">
{{ accessStore.userRoles?.[0] }}
{{ userStore.userRoles?.[0] }}
</span>
</div>