xiaozhi-esp32-server/main/manager-mobile/src/store/config.ts
lapy 2be70e8e6c feat(manager-mobile): westernize H5 app, copy, and shared crypto
- English locale defaults; remove duplicate zh-only locale files

- SM2 utility sharing with the web client where applicable
2026-04-25 17:05:15 +01:00

65 lines
1.4 KiB
TypeScript

import type { PublicConfig } from '@/api/auth'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getPublicConfig } from '@/api/auth'
// Initialize state
const initialConfigState: PublicConfig = {
enableMobileRegister: false,
version: '',
year: '',
allowUserRegister: false,
mobileAreaList: [],
beianIcpNum: '',
beianGaNum: '',
name: import.meta.env.VITE_APP_TITLE,
}
export const useConfigStore = defineStore(
'config',
() => {
// Define global configuration
const config = ref<PublicConfig>({ ...initialConfigState })
// Set configuration info
const setConfig = (val: PublicConfig) => {
config.value = val
}
// Get public configuration
const fetchPublicConfig = async () => {
try {
const configData = await getPublicConfig()
console.log(configData)
setConfig(configData)
return configData
}
catch (error) {
console.error('Failed to get public configuration:', error)
throw error
}
}
// Reset configuration
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) }),
},
},
},
)