feat(用户): 实现用户信息获取及配置写入功能
添加获取用户信息的API接口和Pinia存储 在登录流程中增加用户信息获取和配置写入操作 新增opencode配置写入的IPC通信功能
This commit is contained in:
25
src/renderer/stores/user.js
Normal file
25
src/renderer/stores/user.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
const STORAGE_KEY = 'user_info';
|
||||
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const userInfo = ref(JSON.parse(localStorage.getItem(STORAGE_KEY) || 'null'));
|
||||
|
||||
const nickname = computed(() => userInfo.value?.nickname || '');
|
||||
const email = computed(() => userInfo.value?.email || '');
|
||||
const isLoggedIn = computed(() => !!userInfo.value);
|
||||
|
||||
function setUserInfo(info) {
|
||||
userInfo.value = info;
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(info));
|
||||
}
|
||||
|
||||
function clearUserInfo() {
|
||||
userInfo.value = null;
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
localStorage.removeItem('Authorization');
|
||||
}
|
||||
|
||||
return { userInfo, nickname, email, isLoggedIn, setUserInfo, clearUserInfo };
|
||||
});
|
||||
Reference in New Issue
Block a user