上传
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Pinia 状态管理入口 - 支持持久化存储
|
||||
*/
|
||||
import {
|
||||
createPinia
|
||||
} from 'pinia'
|
||||
|
||||
const pinia = createPinia()
|
||||
|
||||
export function setupStore(app) {
|
||||
app.use(pinia)
|
||||
}
|
||||
|
||||
export {
|
||||
pinia
|
||||
}
|
||||
|
||||
// 统一导出所有 store 模块
|
||||
export {
|
||||
useUserStore
|
||||
}
|
||||
from './modules/user'
|
||||
@@ -0,0 +1,31 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref, computed } from 'vue';
|
||||
import { setToken, removeToken, getToken, toast, setUserInfo, getUserInfo, router } from '@/utils';
|
||||
import { getLogin } from '@/api/moduleApi/user.js';
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const token = ref(getToken() || '');
|
||||
const userInfo = ref(getUserInfo() || {});
|
||||
|
||||
// 账号密码登录
|
||||
const login = async (params) => {
|
||||
const res = await getLogin(params);
|
||||
toast.success('登录成功');
|
||||
token.value = res.UserId;
|
||||
userInfo.value = res;
|
||||
setTimeout(() => {
|
||||
router.reLaunch('/pages/index/index');
|
||||
}, 2500);
|
||||
getLocalStorage(res.UserId, res);
|
||||
console.log('-----------', res);
|
||||
};
|
||||
// 本地存储
|
||||
const getLocalStorage = (tokenV, userInfoV) => {
|
||||
setToken(tokenV);
|
||||
setUserInfo(userInfoV);
|
||||
};
|
||||
|
||||
return {
|
||||
login,
|
||||
userInfo
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user