mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 10:03:54 +08:00
update:调整文件夹
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import type { PublicConfig } from '@/api/auth'
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { getPublicConfig } from '@/api/auth'
|
||||
|
||||
// 初始化状态
|
||||
const initialConfigState: PublicConfig = {
|
||||
enableMobileRegister: false,
|
||||
version: '',
|
||||
year: '',
|
||||
allowUserRegister: false,
|
||||
mobileAreaList: [],
|
||||
beianIcpNum: '',
|
||||
beianGaNum: '',
|
||||
name: import.meta.env.VITE_APP_TITLE,
|
||||
}
|
||||
|
||||
export const useConfigStore = defineStore(
|
||||
'config',
|
||||
() => {
|
||||
// 定义全局配置
|
||||
const config = ref<PublicConfig>({ ...initialConfigState })
|
||||
|
||||
// 设置配置信息
|
||||
const setConfig = (val: PublicConfig) => {
|
||||
config.value = val
|
||||
}
|
||||
|
||||
// 获取公共配置
|
||||
const fetchPublicConfig = async () => {
|
||||
try {
|
||||
const configData = await getPublicConfig()
|
||||
console.log(configData)
|
||||
|
||||
setConfig(configData)
|
||||
return configData
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取公共配置失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 重置配置
|
||||
const resetConfig = () => {
|
||||
config.value = { ...initialConfigState }
|
||||
}
|
||||
|
||||
return {
|
||||
config,
|
||||
setConfig,
|
||||
fetchPublicConfig,
|
||||
resetConfig,
|
||||
}
|
||||
},
|
||||
{
|
||||
persist: {
|
||||
key: 'config',
|
||||
serializer: {
|
||||
serialize: state => JSON.stringify(state.config),
|
||||
deserialize: value => ({ config: JSON.parse(value) }),
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,19 @@
|
||||
import { createPinia } from 'pinia'
|
||||
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
|
||||
|
||||
const store = createPinia()
|
||||
store.use(
|
||||
createPersistedState({
|
||||
storage: {
|
||||
getItem: uni.getStorageSync,
|
||||
setItem: uni.setStorageSync,
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
export default store
|
||||
|
||||
export * from './config'
|
||||
export * from './plugin'
|
||||
// 模块统一导出
|
||||
export * from './user'
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { AgentFunction, PluginDefinition } from '@/api/agent/types'
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const usePluginStore = defineStore(
|
||||
'plugin',
|
||||
() => {
|
||||
// 所有可用插件
|
||||
const allFunctions = ref<PluginDefinition[]>([])
|
||||
|
||||
// 当前智能体的插件配置
|
||||
const currentFunctions = ref<AgentFunction[]>([])
|
||||
|
||||
// 当前编辑的智能体ID
|
||||
const currentAgentId = ref('')
|
||||
|
||||
// 设置所有可用插件
|
||||
const setAllFunctions = (functions: PluginDefinition[]) => {
|
||||
allFunctions.value = functions
|
||||
}
|
||||
|
||||
// 设置当前智能体的插件配置
|
||||
const setCurrentFunctions = (functions: AgentFunction[]) => {
|
||||
currentFunctions.value = functions
|
||||
}
|
||||
|
||||
// 设置当前智能体ID
|
||||
const setCurrentAgentId = (agentId: string) => {
|
||||
currentAgentId.value = agentId
|
||||
}
|
||||
|
||||
// 更新插件配置(用于保存时调用)
|
||||
const updateFunctions = (functions: AgentFunction[]) => {
|
||||
currentFunctions.value = functions
|
||||
}
|
||||
|
||||
// 清空数据
|
||||
const clear = () => {
|
||||
allFunctions.value = []
|
||||
currentFunctions.value = []
|
||||
currentAgentId.value = ''
|
||||
}
|
||||
|
||||
return {
|
||||
allFunctions,
|
||||
currentFunctions,
|
||||
currentAgentId,
|
||||
setAllFunctions,
|
||||
setCurrentFunctions,
|
||||
setCurrentAgentId,
|
||||
updateFunctions,
|
||||
clear,
|
||||
}
|
||||
},
|
||||
{
|
||||
persist: false, // 不持久化,每次进入页面重新加载
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,83 @@
|
||||
import type { UserInfo } from '@/api/auth'
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import {
|
||||
getUserInfo as _getUserInfo,
|
||||
} from '@/api/auth'
|
||||
|
||||
// 初始化状态
|
||||
const userInfoState: UserInfo & { avatar?: string, token?: string } = {
|
||||
id: 0,
|
||||
username: '',
|
||||
realName: '',
|
||||
email: '',
|
||||
mobile: '',
|
||||
status: 0,
|
||||
superAdmin: 0,
|
||||
avatar: '/static/images/default-avatar.png',
|
||||
token: '',
|
||||
}
|
||||
|
||||
export const useUserStore = defineStore(
|
||||
'user',
|
||||
() => {
|
||||
// 定义用户信息
|
||||
const userInfo = ref<UserInfo & { avatar?: string, token?: string }>({ ...userInfoState })
|
||||
// 设置用户信息
|
||||
const setUserInfo = (val: UserInfo & { avatar?: string, token?: string }) => {
|
||||
console.log('设置用户信息', val)
|
||||
// 若头像为空 则使用默认头像
|
||||
if (!val.avatar) {
|
||||
val.avatar = userInfoState.avatar
|
||||
}
|
||||
else {
|
||||
val.avatar = 'https://oss.laf.run/ukw0y1-site/avatar.jpg?feige'
|
||||
}
|
||||
userInfo.value = val
|
||||
}
|
||||
const setUserAvatar = (avatar: string) => {
|
||||
userInfo.value.avatar = avatar
|
||||
console.log('设置用户头像', avatar)
|
||||
console.log('userInfo', userInfo.value)
|
||||
}
|
||||
// 删除用户信息
|
||||
const removeUserInfo = () => {
|
||||
userInfo.value = { ...userInfoState }
|
||||
uni.removeStorageSync('userInfo')
|
||||
uni.removeStorageSync('token')
|
||||
}
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
const getUserInfo = async () => {
|
||||
const userData = await _getUserInfo()
|
||||
const userInfoWithExtras = {
|
||||
...userData,
|
||||
avatar: userInfoState.avatar,
|
||||
token: uni.getStorageSync('token') || '',
|
||||
}
|
||||
setUserInfo(userInfoWithExtras)
|
||||
uni.setStorageSync('userInfo', userInfoWithExtras)
|
||||
// TODO 这里可以增加获取用户路由的方法 根据用户的角色动态生成路由
|
||||
return userInfoWithExtras
|
||||
}
|
||||
/**
|
||||
* 退出登录 并 删除用户信息
|
||||
*/
|
||||
const logout = async () => {
|
||||
removeUserInfo()
|
||||
}
|
||||
|
||||
return {
|
||||
userInfo,
|
||||
getUserInfo,
|
||||
setUserInfo,
|
||||
setUserAvatar,
|
||||
logout,
|
||||
removeUserInfo,
|
||||
}
|
||||
},
|
||||
{
|
||||
persist: true,
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user