Skip to content

Commit

Permalink
refactor: 还原 loginStore 命名,重命名为 userStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Oct 15, 2023
1 parent e88c9a6 commit 8d39493
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 84 deletions.
2 changes: 1 addition & 1 deletion continew-admin-ui/src/api/auth/login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/login/types';
import { UserState } from '@/store/modules/user/types';

const BASE_URL = '/auth';

Expand Down
6 changes: 3 additions & 3 deletions continew-admin-ui/src/components/navbar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
>
<img
alt="avatar"
:src="getAvatar(loginStore.avatar, loginStore.gender)"
:src="getAvatar(userStore.avatar, userStore.gender)"
/>
</a-avatar>
<template #content>
Expand Down Expand Up @@ -192,7 +192,7 @@
<script lang="ts" setup>
import { computed, ref, inject } from 'vue';
import { useDark, useToggle, useFullscreen } from '@vueuse/core';
import { useAppStore, useLoginStore } from '@/store';
import { useAppStore, useUserStore } from '@/store';
import { LOCALE_OPTIONS } from '@/locale';
import useLocale from '@/hooks/locale';
import useUser from '@/hooks/user';
Expand All @@ -202,7 +202,7 @@
import MessageBox from '../message-box/index.vue';
const appStore = useAppStore();
const loginStore = useLoginStore();
const userStore = useUserStore();
const { logout } = useUser();
const { changeLocale, currentLocale } = useLocale();
const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();
Expand Down
6 changes: 3 additions & 3 deletions continew-admin-ui/src/directive/permission/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DirectiveBinding } from 'vue';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';

function checkPermission(el: HTMLElement, binding: DirectiveBinding) {
const { value } = binding;
const loginStore = useLoginStore();
const { permissions, roles } = loginStore;
const userStore = useUserStore();
const { permissions, roles } = userStore;
const superAdmin = 'admin';
const allPermission = '*';

Expand Down
6 changes: 3 additions & 3 deletions continew-admin-ui/src/hooks/permission.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';

export default function usePermission() {
const loginStore = useLoginStore();
const userStore = useUserStore();
return {
accessRouter(route: RouteLocationNormalized | RouteRecordRaw) {
return (
!route.meta?.requiresAuth ||
!route.meta?.roles ||
route.meta?.roles?.includes('*') ||
this.includeRole(route.meta?.roles, loginStore.roles)
this.includeRole(route.meta?.roles, userStore.roles)
);
},
includeRole(arr1: Array<string>, arr2: Array<string>) {
Expand Down
6 changes: 3 additions & 3 deletions continew-admin-ui/src/hooks/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Notification } from '@arco-design/web-vue';

import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';

export default function useUser() {
const { t } = useI18n();
const router = useRouter();
const loginStore = useLoginStore();
const userStore = useUserStore();
const logout = async (logoutTo?: string) => {
await loginStore.logout();
await userStore.logout();
const currentRoute = router.currentRoute.value;
Notification.success(t('login.logout.success'));
router.push({
Expand Down
6 changes: 3 additions & 3 deletions continew-admin-ui/src/layout/default-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<script lang="ts" setup>
import { ref, computed, watch, provide, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import { useAppStore, useLoginStore } from '@/store';
import { useAppStore, useUserStore } from '@/store';
import NavBar from '@/components/navbar/index.vue';
import Menu from '@/components/menu/index.vue';
import Footer from '@/components/footer/index.vue';
Expand All @@ -58,7 +58,7 @@
const isInit = ref(false);
const appStore = useAppStore();
const loginStore = useLoginStore();
const userStore = useUserStore();
const router = useRouter();
const route = useRoute();
const permission = usePermission();
Expand Down Expand Up @@ -88,7 +88,7 @@
appStore.updateSettings({ menuCollapse: val });
};
watch(
() => loginStore.roles,
() => userStore.roles,
(roleValue) => {
if (roleValue && !permission.accessRouter(route))
router.push({ name: 'notFound' });
Expand Down
6 changes: 3 additions & 3 deletions continew-admin-ui/src/router/guard/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { Router, RouteRecordNormalized } from 'vue-router';
import NProgress from 'nprogress'; // progress bar

import usePermission from '@/hooks/permission';
import { useLoginStore, useAppStore } from '@/store';
import { useUserStore, useAppStore } from '@/store';
import { fixedRoutes, demoRoutes } from '../routes';
import { WHITE_LIST, NOT_FOUND } from '../constants';

export default function setupPermissionGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
const appStore = useAppStore();
const loginStore = useLoginStore();
const userStore = useUserStore();
const Permission = usePermission();
const permissionsAllow = Permission.accessRouter(to);
if (appStore.menuFromServer) {
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function setupPermissionGuard(router: Router) {
const destination =
Permission.findFirstPermissionRoute(
[...fixedRoutes, ...demoRoutes],
loginStore.roles[0]
userStore.roles[0]
) || NOT_FOUND;
next(destination);
}
Expand Down
10 changes: 5 additions & 5 deletions continew-admin-ui/src/router/guard/userLoginInfo.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Router, LocationQueryRaw } from 'vue-router';
import NProgress from 'nprogress'; // progress bar

import { useLoginStore, useAppStore } from '@/store';
import { useUserStore, useAppStore } from '@/store';
import { isLogin } from '@/utils/auth';

export default function setupUserLoginInfoGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
NProgress.start();
const loginStore = useLoginStore();
const userStore = useUserStore();
const appStore = useAppStore();
appStore.init();
if (isLogin()) {
Expand All @@ -16,14 +16,14 @@ export default function setupUserLoginInfoGuard(router: Router) {
NProgress.done();
return;
}
if (loginStore.roles[0]) {
if (userStore.roles[0]) {
next();
} else {
try {
await loginStore.getInfo();
await userStore.getInfo();
next();
} catch (error) {
await loginStore.logout();
await userStore.logout();
next({
name: 'login',
query: {
Expand Down
4 changes: 2 additions & 2 deletions continew-admin-ui/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createPinia } from 'pinia';
import useAppStore from './modules/app';
import useLoginStore from './modules/login';
import useUserStore from './modules/user';
import useDictStore from './modules/dict';
import useTabBarStore from './modules/tab-bar';

const pinia = createPinia();

export { useAppStore, useLoginStore, useDictStore, useTabBarStore };
export { useAppStore, useUserStore, useDictStore, useTabBarStore };
export default pinia;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { removeRouteListener } from '@/utils/route-listener';
import { UserState } from './types';
import useAppStore from '../app';

const useLoginStore = defineStore('user', {
const useUserStore = defineStore('user', {
state: (): UserState => ({
id: '',
username: '',
Expand Down Expand Up @@ -96,4 +96,4 @@ const useLoginStore = defineStore('user', {
},
});

export default useLoginStore;
export default useUserStore;
6 changes: 3 additions & 3 deletions continew-admin-ui/src/utils/permission.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';

/**
* 权限判断
Expand All @@ -7,8 +7,8 @@ import { useLoginStore } from '@/store';
* @return true 有权限,false 没有权限
*/
export default function checkPermission(value: Array<string>) {
const loginStore = useLoginStore();
const { permissions, roles } = loginStore;
const userStore = useUserStore();
const { permissions, roles } = userStore;
const superAdmin = 'admin';
const allPermission = '*';

Expand Down
6 changes: 3 additions & 3 deletions continew-admin-ui/src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';
import { getToken } from '@/utils/auth';
import modalErrorWrapper from '@/utils/modal-error-wrapper';
import messageErrorWrapper from '@/utils/message-error-wrapper';
Expand Down Expand Up @@ -58,8 +58,8 @@ axios.interceptors.response.use(
escToClose: false,
okText: '重新登录',
async onOk() {
const loginStore = useLoginStore();
await loginStore.logout();
const userStore = useUserStore();
await userStore.logout();
window.location.reload();
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

<script lang="ts" setup>
import { computed } from 'vue';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';
const loginStore = useLoginStore();
const userStore = useUserStore();
const userInfo = computed(() => {
return {
nickname: loginStore.nickname,
nickname: userStore.nickname,
};
});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
</template>

<script lang="ts" setup>
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';
import getAvatar from '@/utils/avatar';
const userInfo = useLoginStore();
const userInfo = useUserStore();
</script>

<style scoped lang="less">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
import { useI18n } from 'vue-i18n';
import { useStorage } from '@vueuse/core';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';
import { LoginReq } from '@/api/auth/login';
import { ValidatedError } from '@arco-design/web-vue';
import { encryptByRsa } from '@/utils/encrypt';
Expand All @@ -65,7 +65,7 @@
const { proxy } = getCurrentInstance() as any;
const { t } = useI18n();
const router = useRouter();
const loginStore = useLoginStore();
const userStore = useUserStore();
const loading = ref(false);
const captchaImgBase64 = ref();
const loginConfig = useStorage('login-config', {
Expand Down Expand Up @@ -100,7 +100,7 @@
* 获取验证码
*/
const getCaptcha = () => {
loginStore.getImgCaptcha().then((res) => {
userStore.getImgCaptcha().then((res) => {
form.value.uuid = res.data.uuid;
captchaImgBase64.value = res.data.img;
});
Expand All @@ -123,7 +123,7 @@
if (loading.value) return;
if (!errors) {
loading.value = true;
loginStore
userStore
.login({
username: values.username,
password: encryptByRsa(values.password) || '',
Expand Down
4 changes: 2 additions & 2 deletions continew-admin-ui/src/views/login/components/email-login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
<script lang="ts" setup>
import { getCurrentInstance, ref, toRefs, reactive, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';
import { LoginReq } from '@/api/auth/login';
const { proxy } = getCurrentInstance() as any;
const { t } = useI18n();
const loginStore = useLoginStore();
const userStore = useUserStore();
const loading = ref(false);
const captchaLoading = ref(false);
const captchaDisable = ref(false);
Expand Down
4 changes: 2 additions & 2 deletions continew-admin-ui/src/views/login/components/phone-login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
<script lang="ts" setup>
import { getCurrentInstance, ref, toRefs, reactive, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';
import { LoginReq } from '@/api/auth/login';
const { proxy } = getCurrentInstance() as any;
const { t } = useI18n();
const loginStore = useLoginStore();
const userStore = useUserStore();
const loading = ref(false);
const captchaLoading = ref(false);
const captchaDisable = ref(false);
Expand Down
6 changes: 3 additions & 3 deletions continew-admin-ui/src/views/login/social/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<script setup lang="ts">
import { getCurrentInstance, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';
import { useI18n } from 'vue-i18n';
const { proxy } = getCurrentInstance() as any;
const { t } = useI18n();
const route = useRoute();
const router = useRouter();
const loginStore = useLoginStore();
const userStore = useUserStore();
const loading = ref(false);
const source = route.query.source as string;
Expand All @@ -25,7 +25,7 @@
if (loading.value) return;
loading.value = true;
const { redirect, ...othersQuery } = router.currentRoute.value.query;
loginStore
userStore
.socialLogin(source, othersQuery)
.then(() => {
router.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@
import { FieldRule } from '@arco-design/web-vue';
import { BasicInfoModel, updateBasicInfo } from '@/api/system/user-center';
import { useI18n } from 'vue-i18n';
import { useLoginStore } from '@/store';
import { useUserStore } from '@/store';
const { proxy } = getCurrentInstance() as any;
const { t } = useI18n();
const loginStore = useLoginStore();
const userStore = useUserStore();
const loading = ref(false);
const data = reactive({
// 表单数据
form: {
username: loginStore.username,
nickname: loginStore.nickname,
gender: loginStore.gender,
username: userStore.username,
nickname: userStore.nickname,
gender: userStore.gender,
} as BasicInfoModel,
// 表单验证规则
rules: computed((): Record<string, FieldRule[]> => {
Expand Down Expand Up @@ -107,8 +107,8 @@
nickname: form.value.nickname,
gender: form.value.gender,
})
.then((res) => {
loginStore.getInfo();
.then(() => {
userStore.getInfo();
proxy.$message.success(t('userCenter.basicInfo.form.save.success'));
})
.finally(() => {
Expand Down
Loading

0 comments on commit 8d39493

Please sign in to comment.