This commit is contained in:
2026-08-17 11:01:21 +08:00
parent 6e07cab51f
commit 255573ed06
705 changed files with 8762 additions and 36677 deletions
+22
View File
@@ -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'
+31
View File
@@ -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
};
});