refactor: 还原 loginStore 命名,重命名为 userStore

This commit is contained in:
Charles7c 2023-10-15 21:19:12 +08:00
parent e88c9a6553
commit 8d394937cf
25 changed files with 84 additions and 84 deletions

View File

@ -1,6 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router'; import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/login/types'; import { UserState } from '@/store/modules/user/types';
const BASE_URL = '/auth'; const BASE_URL = '/auth';

View File

@ -162,7 +162,7 @@
> >
<img <img
alt="avatar" alt="avatar"
:src="getAvatar(loginStore.avatar, loginStore.gender)" :src="getAvatar(userStore.avatar, userStore.gender)"
/> />
</a-avatar> </a-avatar>
<template #content> <template #content>
@ -192,7 +192,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref, inject } from 'vue'; import { computed, ref, inject } from 'vue';
import { useDark, useToggle, useFullscreen } from '@vueuse/core'; import { useDark, useToggle, useFullscreen } from '@vueuse/core';
import { useAppStore, useLoginStore } from '@/store'; import { useAppStore, useUserStore } from '@/store';
import { LOCALE_OPTIONS } from '@/locale'; import { LOCALE_OPTIONS } from '@/locale';
import useLocale from '@/hooks/locale'; import useLocale from '@/hooks/locale';
import useUser from '@/hooks/user'; import useUser from '@/hooks/user';
@ -202,7 +202,7 @@
import MessageBox from '../message-box/index.vue'; import MessageBox from '../message-box/index.vue';
const appStore = useAppStore(); const appStore = useAppStore();
const loginStore = useLoginStore(); const userStore = useUserStore();
const { logout } = useUser(); const { logout } = useUser();
const { changeLocale, currentLocale } = useLocale(); const { changeLocale, currentLocale } = useLocale();
const { isFullscreen, toggle: toggleFullScreen } = useFullscreen(); const { isFullscreen, toggle: toggleFullScreen } = useFullscreen();

View File

@ -1,10 +1,10 @@
import { DirectiveBinding } from 'vue'; import { DirectiveBinding } from 'vue';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
function checkPermission(el: HTMLElement, binding: DirectiveBinding) { function checkPermission(el: HTMLElement, binding: DirectiveBinding) {
const { value } = binding; const { value } = binding;
const loginStore = useLoginStore(); const userStore = useUserStore();
const { permissions, roles } = loginStore; const { permissions, roles } = userStore;
const superAdmin = 'admin'; const superAdmin = 'admin';
const allPermission = '*'; const allPermission = '*';

View File

@ -1,15 +1,15 @@
import { RouteLocationNormalized, RouteRecordRaw } from 'vue-router'; import { RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
export default function usePermission() { export default function usePermission() {
const loginStore = useLoginStore(); const userStore = useUserStore();
return { return {
accessRouter(route: RouteLocationNormalized | RouteRecordRaw) { accessRouter(route: RouteLocationNormalized | RouteRecordRaw) {
return ( return (
!route.meta?.requiresAuth || !route.meta?.requiresAuth ||
!route.meta?.roles || !route.meta?.roles ||
route.meta?.roles?.includes('*') || 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>) { includeRole(arr1: Array<string>, arr2: Array<string>) {

View File

@ -2,14 +2,14 @@ import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { Notification } from '@arco-design/web-vue'; import { Notification } from '@arco-design/web-vue';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
export default function useUser() { export default function useUser() {
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter(); const router = useRouter();
const loginStore = useLoginStore(); const userStore = useUserStore();
const logout = async (logoutTo?: string) => { const logout = async (logoutTo?: string) => {
await loginStore.logout(); await userStore.logout();
const currentRoute = router.currentRoute.value; const currentRoute = router.currentRoute.value;
Notification.success(t('login.logout.success')); Notification.success(t('login.logout.success'));
router.push({ router.push({

View File

@ -47,7 +47,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ref, computed, watch, provide, onMounted } from 'vue'; import { ref, computed, watch, provide, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router'; import { useRouter, useRoute } from 'vue-router';
import { useAppStore, useLoginStore } from '@/store'; import { useAppStore, useUserStore } from '@/store';
import NavBar from '@/components/navbar/index.vue'; import NavBar from '@/components/navbar/index.vue';
import Menu from '@/components/menu/index.vue'; import Menu from '@/components/menu/index.vue';
import Footer from '@/components/footer/index.vue'; import Footer from '@/components/footer/index.vue';
@ -58,7 +58,7 @@
const isInit = ref(false); const isInit = ref(false);
const appStore = useAppStore(); const appStore = useAppStore();
const loginStore = useLoginStore(); const userStore = useUserStore();
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
const permission = usePermission(); const permission = usePermission();
@ -88,7 +88,7 @@
appStore.updateSettings({ menuCollapse: val }); appStore.updateSettings({ menuCollapse: val });
}; };
watch( watch(
() => loginStore.roles, () => userStore.roles,
(roleValue) => { (roleValue) => {
if (roleValue && !permission.accessRouter(route)) if (roleValue && !permission.accessRouter(route))
router.push({ name: 'notFound' }); router.push({ name: 'notFound' });

View File

@ -2,14 +2,14 @@ import type { Router, RouteRecordNormalized } from 'vue-router';
import NProgress from 'nprogress'; // progress bar import NProgress from 'nprogress'; // progress bar
import usePermission from '@/hooks/permission'; import usePermission from '@/hooks/permission';
import { useLoginStore, useAppStore } from '@/store'; import { useUserStore, useAppStore } from '@/store';
import { fixedRoutes, demoRoutes } from '../routes'; import { fixedRoutes, demoRoutes } from '../routes';
import { WHITE_LIST, NOT_FOUND } from '../constants'; import { WHITE_LIST, NOT_FOUND } from '../constants';
export default function setupPermissionGuard(router: Router) { export default function setupPermissionGuard(router: Router) {
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
const appStore = useAppStore(); const appStore = useAppStore();
const loginStore = useLoginStore(); const userStore = useUserStore();
const Permission = usePermission(); const Permission = usePermission();
const permissionsAllow = Permission.accessRouter(to); const permissionsAllow = Permission.accessRouter(to);
if (appStore.menuFromServer) { if (appStore.menuFromServer) {
@ -52,7 +52,7 @@ export default function setupPermissionGuard(router: Router) {
const destination = const destination =
Permission.findFirstPermissionRoute( Permission.findFirstPermissionRoute(
[...fixedRoutes, ...demoRoutes], [...fixedRoutes, ...demoRoutes],
loginStore.roles[0] userStore.roles[0]
) || NOT_FOUND; ) || NOT_FOUND;
next(destination); next(destination);
} }

View File

@ -1,13 +1,13 @@
import type { Router, LocationQueryRaw } from 'vue-router'; import type { Router, LocationQueryRaw } from 'vue-router';
import NProgress from 'nprogress'; // progress bar import NProgress from 'nprogress'; // progress bar
import { useLoginStore, useAppStore } from '@/store'; import { useUserStore, useAppStore } from '@/store';
import { isLogin } from '@/utils/auth'; import { isLogin } from '@/utils/auth';
export default function setupUserLoginInfoGuard(router: Router) { export default function setupUserLoginInfoGuard(router: Router) {
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
NProgress.start(); NProgress.start();
const loginStore = useLoginStore(); const userStore = useUserStore();
const appStore = useAppStore(); const appStore = useAppStore();
appStore.init(); appStore.init();
if (isLogin()) { if (isLogin()) {
@ -16,14 +16,14 @@ export default function setupUserLoginInfoGuard(router: Router) {
NProgress.done(); NProgress.done();
return; return;
} }
if (loginStore.roles[0]) { if (userStore.roles[0]) {
next(); next();
} else { } else {
try { try {
await loginStore.getInfo(); await userStore.getInfo();
next(); next();
} catch (error) { } catch (error) {
await loginStore.logout(); await userStore.logout();
next({ next({
name: 'login', name: 'login',
query: { query: {

View File

@ -1,10 +1,10 @@
import { createPinia } from 'pinia'; import { createPinia } from 'pinia';
import useAppStore from './modules/app'; import useAppStore from './modules/app';
import useLoginStore from './modules/login'; import useUserStore from './modules/user';
import useDictStore from './modules/dict'; import useDictStore from './modules/dict';
import useTabBarStore from './modules/tab-bar'; import useTabBarStore from './modules/tab-bar';
const pinia = createPinia(); const pinia = createPinia();
export { useAppStore, useLoginStore, useDictStore, useTabBarStore }; export { useAppStore, useUserStore, useDictStore, useTabBarStore };
export default pinia; export default pinia;

View File

@ -12,7 +12,7 @@ import { removeRouteListener } from '@/utils/route-listener';
import { UserState } from './types'; import { UserState } from './types';
import useAppStore from '../app'; import useAppStore from '../app';
const useLoginStore = defineStore('user', { const useUserStore = defineStore('user', {
state: (): UserState => ({ state: (): UserState => ({
id: '', id: '',
username: '', username: '',
@ -96,4 +96,4 @@ const useLoginStore = defineStore('user', {
}, },
}); });
export default useLoginStore; export default useUserStore;

View File

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

View File

@ -1,6 +1,6 @@
import axios from 'axios'; import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios'; import type { AxiosRequestConfig, AxiosResponse } from 'axios';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import { getToken } from '@/utils/auth'; import { getToken } from '@/utils/auth';
import modalErrorWrapper from '@/utils/modal-error-wrapper'; import modalErrorWrapper from '@/utils/modal-error-wrapper';
import messageErrorWrapper from '@/utils/message-error-wrapper'; import messageErrorWrapper from '@/utils/message-error-wrapper';
@ -58,8 +58,8 @@ axios.interceptors.response.use(
escToClose: false, escToClose: false,
okText: '重新登录', okText: '重新登录',
async onOk() { async onOk() {
const loginStore = useLoginStore(); const userStore = useUserStore();
await loginStore.logout(); await userStore.logout();
window.location.reload(); window.location.reload();
}, },
}); });

View File

@ -11,12 +11,12 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed } from 'vue'; import { computed } from 'vue';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
const loginStore = useLoginStore(); const userStore = useUserStore();
const userInfo = computed(() => { const userInfo = computed(() => {
return { return {
nickname: loginStore.nickname, nickname: userStore.nickname,
}; };
}); });
</script> </script>

View File

@ -36,10 +36,10 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import getAvatar from '@/utils/avatar'; import getAvatar from '@/utils/avatar';
const userInfo = useLoginStore(); const userInfo = useUserStore();
</script> </script>
<style scoped lang="less"> <style scoped lang="less">

View File

@ -56,7 +56,7 @@
import { getCurrentInstance, ref, toRefs, reactive } from 'vue'; import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useStorage } from '@vueuse/core'; import { useStorage } from '@vueuse/core';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import { LoginReq } from '@/api/auth/login'; import { LoginReq } from '@/api/auth/login';
import { ValidatedError } from '@arco-design/web-vue'; import { ValidatedError } from '@arco-design/web-vue';
import { encryptByRsa } from '@/utils/encrypt'; import { encryptByRsa } from '@/utils/encrypt';
@ -65,7 +65,7 @@
const { proxy } = getCurrentInstance() as any; const { proxy } = getCurrentInstance() as any;
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter(); const router = useRouter();
const loginStore = useLoginStore(); const userStore = useUserStore();
const loading = ref(false); const loading = ref(false);
const captchaImgBase64 = ref(); const captchaImgBase64 = ref();
const loginConfig = useStorage('login-config', { const loginConfig = useStorage('login-config', {
@ -100,7 +100,7 @@
* 获取验证码 * 获取验证码
*/ */
const getCaptcha = () => { const getCaptcha = () => {
loginStore.getImgCaptcha().then((res) => { userStore.getImgCaptcha().then((res) => {
form.value.uuid = res.data.uuid; form.value.uuid = res.data.uuid;
captchaImgBase64.value = res.data.img; captchaImgBase64.value = res.data.img;
}); });
@ -123,7 +123,7 @@
if (loading.value) return; if (loading.value) return;
if (!errors) { if (!errors) {
loading.value = true; loading.value = true;
loginStore userStore
.login({ .login({
username: values.username, username: values.username,
password: encryptByRsa(values.password) || '', password: encryptByRsa(values.password) || '',

View File

@ -40,12 +40,12 @@
<script lang="ts" setup> <script lang="ts" setup>
import { getCurrentInstance, ref, toRefs, reactive, computed } from 'vue'; import { getCurrentInstance, ref, toRefs, reactive, computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import { LoginReq } from '@/api/auth/login'; import { LoginReq } from '@/api/auth/login';
const { proxy } = getCurrentInstance() as any; const { proxy } = getCurrentInstance() as any;
const { t } = useI18n(); const { t } = useI18n();
const loginStore = useLoginStore(); const userStore = useUserStore();
const loading = ref(false); const loading = ref(false);
const captchaLoading = ref(false); const captchaLoading = ref(false);
const captchaDisable = ref(false); const captchaDisable = ref(false);

View File

@ -42,12 +42,12 @@
<script lang="ts" setup> <script lang="ts" setup>
import { getCurrentInstance, ref, toRefs, reactive, computed } from 'vue'; import { getCurrentInstance, ref, toRefs, reactive, computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import { LoginReq } from '@/api/auth/login'; import { LoginReq } from '@/api/auth/login';
const { proxy } = getCurrentInstance() as any; const { proxy } = getCurrentInstance() as any;
const { t } = useI18n(); const { t } = useI18n();
const loginStore = useLoginStore(); const userStore = useUserStore();
const loading = ref(false); const loading = ref(false);
const captchaLoading = ref(false); const captchaLoading = ref(false);
const captchaDisable = ref(false); const captchaDisable = ref(false);

View File

@ -7,14 +7,14 @@
<script setup lang="ts"> <script setup lang="ts">
import { getCurrentInstance, ref } from 'vue'; import { getCurrentInstance, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
const { proxy } = getCurrentInstance() as any; const { proxy } = getCurrentInstance() as any;
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const loginStore = useLoginStore(); const userStore = useUserStore();
const loading = ref(false); const loading = ref(false);
const source = route.query.source as string; const source = route.query.source as string;
@ -25,7 +25,7 @@
if (loading.value) return; if (loading.value) return;
loading.value = true; loading.value = true;
const { redirect, ...othersQuery } = router.currentRoute.value.query; const { redirect, ...othersQuery } = router.currentRoute.value.query;
loginStore userStore
.socialLogin(source, othersQuery) .socialLogin(source, othersQuery)
.then(() => { .then(() => {
router.push({ router.push({

View File

@ -56,20 +56,20 @@
import { FieldRule } from '@arco-design/web-vue'; import { FieldRule } from '@arco-design/web-vue';
import { BasicInfoModel, updateBasicInfo } from '@/api/system/user-center'; import { BasicInfoModel, updateBasicInfo } from '@/api/system/user-center';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
const { proxy } = getCurrentInstance() as any; const { proxy } = getCurrentInstance() as any;
const { t } = useI18n(); const { t } = useI18n();
const loginStore = useLoginStore(); const userStore = useUserStore();
const loading = ref(false); const loading = ref(false);
const data = reactive({ const data = reactive({
// //
form: { form: {
username: loginStore.username, username: userStore.username,
nickname: loginStore.nickname, nickname: userStore.nickname,
gender: loginStore.gender, gender: userStore.gender,
} as BasicInfoModel, } as BasicInfoModel,
// //
rules: computed((): Record<string, FieldRule[]> => { rules: computed((): Record<string, FieldRule[]> => {
@ -107,8 +107,8 @@
nickname: form.value.nickname, nickname: form.value.nickname,
gender: form.value.gender, gender: form.value.gender,
}) })
.then((res) => { .then(() => {
loginStore.getInfo(); userStore.getInfo();
proxy.$message.success(t('userCenter.basicInfo.form.save.success')); proxy.$message.success(t('userCenter.basicInfo.form.save.success'));
}) })
.finally(() => { .finally(() => {

View File

@ -62,9 +62,9 @@
OperationLogRecord, OperationLogRecord,
listOperationLog, listOperationLog,
} from '@/api/monitor/log'; } from '@/api/monitor/log';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
const loginStore = useLoginStore(); const userStore = useUserStore();
const dataList = ref<OperationLogRecord[]>([]); const dataList = ref<OperationLogRecord[]>([]);
const total = ref(0); const total = ref(0);
@ -73,7 +73,7 @@
const data = reactive({ const data = reactive({
// //
queryParams: { queryParams: {
uid: loginStore.id, uid: userStore.id,
page: 1, page: 1,
size: 10, size: 10,
sort: ['createTime,desc'], sort: ['createTime,desc'],

View File

@ -7,12 +7,12 @@
</template> </template>
<template #description> <template #description>
<div class="content"> <div class="content">
<a-typography-paragraph v-if="loginStore.email"> <a-typography-paragraph v-if="userStore.email">
{{ {{
$t( $t(
'userCenter.securitySettings.updateEmail.placeholder.success.email' 'userCenter.securitySettings.updateEmail.placeholder.success.email'
) )
}}{{ loginStore.email }} }}{{ userStore.email }}
</a-typography-paragraph> </a-typography-paragraph>
<a-typography-paragraph v-else class="tip"> <a-typography-paragraph v-else class="tip">
{{ {{
@ -114,13 +114,13 @@
import { getMailCaptcha } from '@/api/common/captcha'; import { getMailCaptcha } from '@/api/common/captcha';
import { updateEmail } from '@/api/system/user-center'; import { updateEmail } from '@/api/system/user-center';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import { encryptByRsa } from '@/utils/encrypt'; import { encryptByRsa } from '@/utils/encrypt';
const { proxy } = getCurrentInstance() as any; const { proxy } = getCurrentInstance() as any;
const { t } = useI18n(); const { t } = useI18n();
const loginStore = useLoginStore(); const userStore = useUserStore();
const captchaTime = ref(60); const captchaTime = ref(60);
const captchaTimer = ref(); const captchaTimer = ref();
const captchaLoading = ref(false); const captchaLoading = ref(false);
@ -155,7 +155,7 @@
}, },
{ {
validator: (value, callback) => { validator: (value, callback) => {
if (value === loginStore.email) { if (value === userStore.email) {
callback( callback(
t( t(
'userCenter.securitySettings.updateEmail.form.error.validator.newEmail' 'userCenter.securitySettings.updateEmail.form.error.validator.newEmail'
@ -261,7 +261,7 @@
currentPassword: encryptByRsa(form.currentPassword) || '', currentPassword: encryptByRsa(form.currentPassword) || '',
}).then((res) => { }).then((res) => {
handleCancel(); handleCancel();
loginStore.getInfo(); userStore.getInfo();
proxy.$message.success(res.msg); proxy.$message.success(res.msg);
}); });
} }

View File

@ -7,12 +7,12 @@
</template> </template>
<template #description> <template #description>
<div class="content"> <div class="content">
<a-typography-paragraph v-if="loginStore.phone"> <a-typography-paragraph v-if="userStore.phone">
{{ {{
$t( $t(
'userCenter.securitySettings.updatePhone.placeholder.success.phone' 'userCenter.securitySettings.updatePhone.placeholder.success.phone'
) )
}}{{ loginStore.phone }} }}{{ userStore.phone }}
</a-typography-paragraph> </a-typography-paragraph>
<a-typography-paragraph v-else class="tip"> <a-typography-paragraph v-else class="tip">
{{ {{
@ -32,9 +32,9 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
const loginStore = useLoginStore(); const userStore = useUserStore();
</script> </script>
<style scoped lang="less"></style> <style scoped lang="less"></style>

View File

@ -7,7 +7,7 @@
</template> </template>
<template #description> <template #description>
<div class="content"> <div class="content">
<a-typography-paragraph v-if="loginStore.pwdResetTime"> <a-typography-paragraph v-if="userStore.pwdResetTime">
{{ {{
$t( $t(
'userCenter.securitySettings.updatePwd.placeholder.success.password' 'userCenter.securitySettings.updatePwd.placeholder.success.password'
@ -102,13 +102,13 @@
import { FieldRule } from '@arco-design/web-vue'; import { FieldRule } from '@arco-design/web-vue';
import { updatePassword } from '@/api/system/user-center'; import { updatePassword } from '@/api/system/user-center';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import { encryptByRsa } from '@/utils/encrypt'; import { encryptByRsa } from '@/utils/encrypt';
const { proxy } = getCurrentInstance() as any; const { proxy } = getCurrentInstance() as any;
const { t } = useI18n(); const { t } = useI18n();
const loginStore = useLoginStore(); const userStore = useUserStore();
const visible = ref(false); const visible = ref(false);
// //

View File

@ -38,31 +38,31 @@
layout="inline-horizontal" layout="inline-horizontal"
> >
<a-descriptions-item :label="$t('userCenter.panel.label.nickname')">{{ <a-descriptions-item :label="$t('userCenter.panel.label.nickname')">{{
loginStore.nickname userStore.nickname
}}</a-descriptions-item> }}</a-descriptions-item>
<a-descriptions-item :label="$t('userCenter.panel.label.gender')"> <a-descriptions-item :label="$t('userCenter.panel.label.gender')">
<div v-if="loginStore.gender === 1"> <div v-if="userStore.gender === 1">
{{ $t('userCenter.panel.male') }} {{ $t('userCenter.panel.male') }}
<icon-man style="color: #19bbf1" /> <icon-man style="color: #19bbf1" />
</div> </div>
<div v-else-if="loginStore.gender === 2"> <div v-else-if="userStore.gender === 2">
{{ $t('userCenter.panel.female') }} {{ $t('userCenter.panel.female') }}
<icon-woman style="color: #fa7fa9" /> <icon-woman style="color: #fa7fa9" />
</div> </div>
<div v-else>{{ $t('userCenter.panel.unknown') }}</div> <div v-else>{{ $t('userCenter.panel.unknown') }}</div>
</a-descriptions-item> </a-descriptions-item>
<a-descriptions-item :label="$t('userCenter.panel.label.phone')">{{ <a-descriptions-item :label="$t('userCenter.panel.label.phone')">{{
loginStore.phone || '暂无' userStore.phone || '暂无'
}}</a-descriptions-item> }}</a-descriptions-item>
<a-descriptions-item :label="$t('userCenter.panel.label.email')">{{ <a-descriptions-item :label="$t('userCenter.panel.label.email')">{{
loginStore.email || '暂无' userStore.email || '暂无'
}}</a-descriptions-item> }}</a-descriptions-item>
<a-descriptions-item :label="$t('userCenter.panel.label.deptName')">{{ <a-descriptions-item :label="$t('userCenter.panel.label.deptName')">{{
loginStore.deptName userStore.deptName
}}</a-descriptions-item> }}</a-descriptions-item>
<a-descriptions-item <a-descriptions-item
:label="$t('userCenter.panel.label.registrationDate')" :label="$t('userCenter.panel.label.registrationDate')"
>{{ loginStore.registrationDate }}</a-descriptions-item >{{ userStore.registrationDate }}</a-descriptions-item
> >
</a-descriptions> </a-descriptions>
</a-space> </a-space>
@ -73,16 +73,16 @@
import { getCurrentInstance, ref } from 'vue'; import { getCurrentInstance, ref } from 'vue';
import { FileItem, RequestOption } from '@arco-design/web-vue'; import { FileItem, RequestOption } from '@arco-design/web-vue';
import { uploadAvatar } from '@/api/system/user-center'; import { uploadAvatar } from '@/api/system/user-center';
import { useLoginStore } from '@/store'; import { useUserStore } from '@/store';
import getAvatar from '@/utils/avatar'; import getAvatar from '@/utils/avatar';
const { proxy } = getCurrentInstance() as any; const { proxy } = getCurrentInstance() as any;
const loginStore = useLoginStore(); const userStore = useUserStore();
const avatar = { const avatar = {
uid: '-2', uid: '-2',
name: 'avatar.png', name: 'avatar.png',
url: getAvatar(loginStore.avatar, loginStore.gender), url: getAvatar(userStore.avatar, userStore.gender),
}; };
const avatarList = ref<FileItem[]>([avatar]); const avatarList = ref<FileItem[]>([avatar]);
@ -107,7 +107,7 @@
uploadAvatar(formData) uploadAvatar(formData)
.then((res) => { .then((res) => {
onSuccess(res); onSuccess(res);
loginStore.avatar = res.data.avatar; userStore.avatar = res.data.avatar;
proxy.$message.success(res.msg); proxy.$message.success(res.msg);
}) })
.catch((error) => { .catch((error) => {