@@ -16,7 +16,11 @@ | |||||
<!--语言选择--> | <!--语言选择--> | ||||
<lang-select class="navItem" style="color: #ffffff" /> | <lang-select class="navItem" style="color: #ffffff" /> | ||||
<div class="avatar" v-if="userInfoPinia.userInfo" @click="routerTo"> | |||||
<div | |||||
class="avatar" | |||||
v-if="userInfoPinia.userInfo.avatarUrl" | |||||
@click="routerTo" | |||||
> | |||||
<img | <img | ||||
:src=" | :src=" | ||||
userInfoPinia.userInfo.avatarUrl | userInfoPinia.userInfo.avatarUrl | ||||
@@ -5,10 +5,10 @@ import { | |||||
} from "../../apis/myAccount"; | } from "../../apis/myAccount"; | ||||
export const userInfoModules = defineStore("userInfo", () => { | export const userInfoModules = defineStore("userInfo", () => { | ||||
// state | // state | ||||
const userInfo = ref(null) | |||||
function setEmail(params) { | |||||
email.value = params | |||||
} | |||||
const userInfo = ref({ | |||||
avatarUrl: null | |||||
}) | |||||
// 登录获取用户信息 | // 登录获取用户信息 | ||||
async function getUserInfo() { | async function getUserInfo() { | ||||
const res = await getUserInfoApi() | const res = await getUserInfoApi() | ||||
@@ -16,9 +16,11 @@ export const userInfoModules = defineStore("userInfo", () => { | |||||
} | } | ||||
// 退出清除用户信息 | // 退出清除用户信息 | ||||
function loginOut(params) { | function loginOut(params) { | ||||
userInfo.value = null | |||||
userInfo.value = { | |||||
avatarUrl: null | |||||
} | |||||
} | } | ||||
return { userInfo, setEmail, getUserInfo, loginOut }; | |||||
return { userInfo, getUserInfo, loginOut }; | |||||
}, | }, | ||||
{ | { | ||||
persist: true, | persist: true, |
@@ -8,7 +8,6 @@ export {} | |||||
declare module '@vue/runtime-core' { | declare module '@vue/runtime-core' { | ||||
export interface GlobalComponents { | export interface GlobalComponents { | ||||
Breadcrumb: typeof import('./../components/Breadcrumb/index.vue')['default'] | Breadcrumb: typeof import('./../components/Breadcrumb/index.vue')['default'] | ||||
copy: typeof import('./../components/myLoading copy.vue')['default'] | |||||
ElAlert: typeof import('element-plus/es')['ElAlert'] | ElAlert: typeof import('element-plus/es')['ElAlert'] | ||||
ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb'] | ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb'] | ||||
ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem'] | ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem'] | ||||
@@ -1,12 +1,16 @@ | |||||
import axios from 'axios' | import axios from 'axios' | ||||
import router from '@/router/index' | import router from '@/router/index' | ||||
import { ElMessage } from 'element-plus' | import { ElMessage } from 'element-plus' | ||||
ElMessage | |||||
// ElMessage | |||||
import { userInfoModules } from "@/store/modules/userInfo"; | |||||
// import stores from '@/store/index' | |||||
import { store } from '@/store/index'; // 因为不是在setup环境而是js中,必须重新初始化加载store | |||||
const userInfoPinia = userInfoModules(store); //pinia | |||||
// 开发环境需以 "/api" 拼接,其他环境需以 "/C" 拼接 | // 开发环境需以 "/api" 拼接,其他环境需以 "/C" 拼接 | ||||
const env = process.env.NODE_ENV == 'development' ? "/api" : "/C" | const env = process.env.NODE_ENV == 'development' ? "/api" : "/C" | ||||
// console.log(process.env.NODE_ENV, 'env') | // console.log(process.env.NODE_ENV, 'env') | ||||
/** | /** | ||||
* @description:发送Axios请求 | * @description:发送Axios请求 | ||||
*/ | */ | ||||