v1.0.0
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
import type { App } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
export const store = createPinia()
|
||||
|
||||
export function setupStore(app: App) {
|
||||
app.use(store)
|
||||
}
|
||||
|
||||
export * from './modules'
|
||||
@@ -0,0 +1,26 @@
|
||||
// import { ss } from '@/utils/storage'
|
||||
|
||||
// const LOCAL_NAME = 'appSetting'
|
||||
|
||||
export type Theme = 'light' | 'dark' | 'auto'
|
||||
|
||||
export type Language = 'zh-CN' | 'zh-TW' | 'en-US' | 'ko-KR'
|
||||
|
||||
export interface AdminState {
|
||||
siderCollapsed: boolean
|
||||
theme: Theme
|
||||
language: Language
|
||||
}
|
||||
|
||||
export function defaultSetting(): AdminState {
|
||||
return { siderCollapsed: false, theme: 'light', language: 'zh-CN' }
|
||||
}
|
||||
|
||||
// export function getLocalSetting(): AdminState {
|
||||
// const localSetting: AdminState | undefined = ss.get(LOCAL_NAME)
|
||||
// return { ...defaultSetting(), ...localSetting }
|
||||
// }
|
||||
|
||||
// export function setLocalSetting(setting: AdminState): void {
|
||||
// ss.set(LOCAL_NAME, setting)
|
||||
// }
|
||||
@@ -0,0 +1,34 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { AdminState, Language, Theme } from './helper'
|
||||
import { defaultSetting } from './helper'
|
||||
import { store } from '@/store'
|
||||
|
||||
export const useAdminStore = defineStore('admin-store', {
|
||||
// state: (): AdminState => getLocalSetting(),
|
||||
state: (): AdminState => defaultSetting(),
|
||||
actions: {
|
||||
setSiderCollapsed(collapsed: boolean) {
|
||||
this.siderCollapsed = collapsed
|
||||
// this.recordState()
|
||||
},
|
||||
|
||||
setTheme(theme: Theme) {
|
||||
this.theme = theme
|
||||
// this.recordState()
|
||||
},
|
||||
|
||||
setLanguage(language: Language) {
|
||||
if (this.language !== language)
|
||||
this.language = language
|
||||
// this.recordState()
|
||||
},
|
||||
|
||||
// recordState() {
|
||||
// setLocalSetting(this.$state)
|
||||
// },
|
||||
},
|
||||
})
|
||||
|
||||
export function useAdminStoreWithOut() {
|
||||
return useAdminStore(store)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'appSetting'
|
||||
|
||||
export type Theme = 'light' | 'dark' | 'auto'
|
||||
|
||||
export type Language = 'zh-CN' | 'zh-TW' | 'en-US' | 'ko-KR'
|
||||
|
||||
export interface AppState {
|
||||
siderCollapsed: boolean
|
||||
theme: Theme
|
||||
language: Language
|
||||
}
|
||||
|
||||
export function defaultSetting(): AppState {
|
||||
return { siderCollapsed: false, theme: 'light', language: 'zh-CN' }
|
||||
}
|
||||
|
||||
export function getLocalSetting(): AppState {
|
||||
const localSetting: AppState | undefined = ss.get(LOCAL_NAME)
|
||||
return { ...defaultSetting(), ...localSetting }
|
||||
}
|
||||
|
||||
export function setLocalSetting(setting: AppState): void {
|
||||
ss.set(LOCAL_NAME, setting)
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { AppState, Language, Theme } from './helper'
|
||||
import { getLocalSetting, setLocalSetting } from './helper'
|
||||
import { store } from '@/store'
|
||||
|
||||
export const useAppStore = defineStore('app-store', {
|
||||
state: (): AppState => getLocalSetting(),
|
||||
actions: {
|
||||
setSiderCollapsed(collapsed: boolean) {
|
||||
this.siderCollapsed = collapsed
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
setTheme(theme: Theme) {
|
||||
this.theme = theme
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
setLanguage(language: Language) {
|
||||
if (this.language !== language) {
|
||||
this.language = language
|
||||
this.recordState()
|
||||
}
|
||||
},
|
||||
|
||||
recordState() {
|
||||
setLocalSetting(this.$state)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export function useAppStoreWithOut() {
|
||||
return useAppStore(store)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'SECRET_TOKEN'
|
||||
|
||||
export function getToken() {
|
||||
return ss.get(LOCAL_NAME)
|
||||
}
|
||||
|
||||
export function setToken(token: string) {
|
||||
return ss.set(LOCAL_NAME, token)
|
||||
}
|
||||
|
||||
export function setUserInfo(userInfo: User.Info) {
|
||||
return ss.set(LOCAL_NAME, userInfo)
|
||||
}
|
||||
|
||||
export function getUserInfo() {
|
||||
return ss.get(LOCAL_NAME)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
// ss.clear()
|
||||
return ss.remove(LOCAL_NAME)
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { getToken, getUserInfo, removeToken, setToken } from './helper'
|
||||
import { store } from '@/store'
|
||||
import { fetchSession } from '@/api'
|
||||
|
||||
interface SessionResponse {
|
||||
auth: boolean
|
||||
model: 'ChatGPTAPI' | 'ChatGPTUnofficialProxyAPI'
|
||||
}
|
||||
|
||||
export interface AuthState {
|
||||
token: string | undefined
|
||||
userInfo: User.Info | undefined
|
||||
session: SessionResponse | null
|
||||
|
||||
}
|
||||
|
||||
export const useAuthStore = defineStore('auth-store', {
|
||||
state: (): AuthState => ({
|
||||
userInfo: getUserInfo(),
|
||||
token: getToken(),
|
||||
session: null,
|
||||
}),
|
||||
|
||||
getters: {
|
||||
isChatGPTAPI(state): boolean {
|
||||
return state.session?.model === 'ChatGPTAPI'
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
async getSession() {
|
||||
try {
|
||||
const { data } = await fetchSession<SessionResponse>()
|
||||
this.session = { ...data }
|
||||
return Promise.resolve(data)
|
||||
}
|
||||
catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
},
|
||||
|
||||
setToken(token: string) {
|
||||
this.token = token
|
||||
setToken(token)
|
||||
},
|
||||
|
||||
setUserInfo(userInfo: User.Info) {
|
||||
this.userInfo = userInfo
|
||||
this.setUserInfo(userInfo)
|
||||
},
|
||||
|
||||
// 清除所有的本地储存
|
||||
removeToken() {
|
||||
this.token = undefined
|
||||
removeToken()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export function useAuthStoreWithout() {
|
||||
return useAuthStore(store)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from './app'
|
||||
export * from './user'
|
||||
export * from './settings'
|
||||
export * from './auth'
|
||||
export * from './admin'
|
||||
export * from './notice'
|
||||
export * from './panel'
|
||||
@@ -0,0 +1,21 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'noticeStore'
|
||||
|
||||
export interface NoticeStore {
|
||||
global: number[]
|
||||
username: { [key: string]: number[] }
|
||||
}
|
||||
|
||||
export function defaultSetting(): NoticeStore {
|
||||
return { global: [], username: {} }
|
||||
}
|
||||
|
||||
export function getLocalSetting(): NoticeStore {
|
||||
const localSetting: NoticeStore | undefined = ss.get(LOCAL_NAME)
|
||||
return { ...defaultSetting(), ...localSetting }
|
||||
}
|
||||
|
||||
export function setLocalSetting(setting: NoticeStore): void {
|
||||
ss.set(LOCAL_NAME, setting)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { NoticeStore } from './helper'
|
||||
import { getLocalSetting, setLocalSetting } from './helper'
|
||||
import { store } from '@/store'
|
||||
|
||||
export const useNoticeStore = defineStore('notice-store', {
|
||||
state: (): NoticeStore => getLocalSetting(),
|
||||
actions: {
|
||||
|
||||
// 设置已读
|
||||
setReadByGlobal(noticeId: number) {
|
||||
console.log('设置全局已读', noticeId)
|
||||
this.global.push(noticeId)
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
// 设置用户已读
|
||||
setReadByUsername(username: string, noticeId: number) {
|
||||
if (!this.username[username])
|
||||
this.username[username] = []
|
||||
this.username[username].push(noticeId)
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
// 判断是否为已读通知
|
||||
getReadByNoticeId(noticeId: number, username?: string): boolean {
|
||||
if (!this.global.includes(noticeId) && (!username || (!this.username[username] || !this.username[username].includes(noticeId))))
|
||||
return false
|
||||
return true
|
||||
},
|
||||
|
||||
recordState() {
|
||||
setLocalSetting(this.$state)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export function useNoticeStoreWithOut() {
|
||||
return useNoticeStore(store)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
import { PanelPanelConfigStyleEnum, PanelStateNetworkModeEnum } from '@/enum'
|
||||
import defaultBackground from '@/assets/defaultBackground.webp'
|
||||
const LOCAL_NAME = 'panelStorage'
|
||||
|
||||
export function defaultStatePanelConfig(): Panel.panelConfig {
|
||||
return {
|
||||
backgroundImageSrc: defaultBackground,
|
||||
backgroundBlur: 0,
|
||||
iconStyle: PanelPanelConfigStyleEnum.icon,
|
||||
iconTextColor: '#ffffff',
|
||||
logoText: 'Sun-Panel',
|
||||
logoImageSrc: '',
|
||||
clockShowSecond: false,
|
||||
}
|
||||
}
|
||||
|
||||
export function defaultState(): Panel.State {
|
||||
return {
|
||||
rightSiderCollapsed: false,
|
||||
leftSiderCollapsed: false,
|
||||
networkMode: PanelStateNetworkModeEnum.wan,
|
||||
panelConfig: { ...defaultStatePanelConfig() },
|
||||
}
|
||||
}
|
||||
|
||||
export function getLocalState(): Panel.State {
|
||||
const localState = ss.get(LOCAL_NAME)
|
||||
return { ...defaultState(), ...localState }
|
||||
}
|
||||
|
||||
export function setLocalState(state: Panel.State) {
|
||||
ss.set(LOCAL_NAME, state)
|
||||
}
|
||||
|
||||
export function removeLocalState() {
|
||||
ss.remove(LOCAL_NAME)
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { defaultState, defaultStatePanelConfig, getLocalState, removeLocalState, setLocalState } from './helper'
|
||||
import { router } from '@/router'
|
||||
import type { PanelStateNetworkModeEnum } from '@/enum'
|
||||
import { get as getUserConfig } from '@/api/panel/userConfig'
|
||||
export const usePanelState = defineStore('panel', {
|
||||
state: (): Panel.State => getLocalState() || defaultState(),
|
||||
|
||||
getters: {
|
||||
// getChatHistoryByCurrentActive(state: AiApplet.State) {
|
||||
// const index = state.history.findIndex(item => item.id === state.active)
|
||||
// if (index !== -1)
|
||||
// return state.history[index]
|
||||
// return null
|
||||
// },
|
||||
|
||||
},
|
||||
|
||||
actions: {
|
||||
setLeftSiderCollapsed(Collapsed: boolean) {
|
||||
this.leftSiderCollapsed = Collapsed
|
||||
// this.recordState()
|
||||
},
|
||||
|
||||
setRightSiderCollapsed(Collapsed: boolean) {
|
||||
this.rightSiderCollapsed = Collapsed
|
||||
// this.recordState()
|
||||
},
|
||||
|
||||
setNetworkMode(mode: PanelStateNetworkModeEnum) {
|
||||
this.networkMode = mode
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
// 获取云端的面板配置
|
||||
updatePanelConfigByCloud() {
|
||||
getUserConfig<Panel.userConfig>().then((res) => {
|
||||
if (res.code === 0)
|
||||
this.panelConfig = res.data.panel
|
||||
this.recordState()
|
||||
})
|
||||
},
|
||||
|
||||
resetPanelConfig() {
|
||||
this.panelConfig = defaultStatePanelConfig()
|
||||
},
|
||||
|
||||
// async refreshSpaceNoteList(spaceId: string) {
|
||||
// await getListBySpaceNoteId<Common.ListResponse<SNote.InfoTree[]>>(spaceId).then((res) => {
|
||||
// this.notesList = res.data.list
|
||||
// })
|
||||
// },
|
||||
|
||||
async reloadRoute(id?: number) {
|
||||
// this.recordState()
|
||||
await router.push({ name: 'AppletDialog', params: { aiAppletId: id } })
|
||||
},
|
||||
|
||||
recordState() {
|
||||
setLocalState(this.$state)
|
||||
},
|
||||
|
||||
removeState() {
|
||||
removeLocalState()
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'settingsStorage'
|
||||
|
||||
export interface SettingsState {
|
||||
systemMessage: string
|
||||
temperature: number
|
||||
top_p: number
|
||||
}
|
||||
|
||||
export function defaultSetting(): SettingsState {
|
||||
return {
|
||||
systemMessage: 'You are ChatGPT, a large language model trained by OpenAI. Follow the user\'s instructions carefully. Respond using markdown.',
|
||||
temperature: 0.8,
|
||||
top_p: 1,
|
||||
}
|
||||
}
|
||||
|
||||
export function getLocalState(): SettingsState {
|
||||
const localSetting: SettingsState | undefined = ss.get(LOCAL_NAME)
|
||||
return { ...defaultSetting(), ...localSetting }
|
||||
}
|
||||
|
||||
export function setLocalState(setting: SettingsState): void {
|
||||
ss.set(LOCAL_NAME, setting)
|
||||
}
|
||||
|
||||
export function removeLocalState() {
|
||||
ss.remove(LOCAL_NAME)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { SettingsState } from './helper'
|
||||
import { defaultSetting, getLocalState, removeLocalState, setLocalState } from './helper'
|
||||
|
||||
export const useSettingStore = defineStore('setting-store', {
|
||||
state: (): SettingsState => getLocalState(),
|
||||
actions: {
|
||||
updateSetting(settings: Partial<SettingsState>) {
|
||||
this.$state = { ...this.$state, ...settings }
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
resetSetting() {
|
||||
this.$state = defaultSetting()
|
||||
removeLocalState()
|
||||
},
|
||||
|
||||
recordState() {
|
||||
setLocalState(this.$state)
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
// import userDefaultAvatar from '@/assets/userDefaultAvatar.png'
|
||||
|
||||
const LOCAL_NAME = 'userStorage'
|
||||
|
||||
export interface UserInfo extends User.Info {
|
||||
// name: string
|
||||
// description: string
|
||||
}
|
||||
|
||||
export interface UserState {
|
||||
userInfo: UserInfo
|
||||
}
|
||||
|
||||
export function defaultSetting(): UserState {
|
||||
return {
|
||||
userInfo: {
|
||||
// headImage: userDefaultAvatar,
|
||||
name: '-- --',
|
||||
// description: 'Star on <a href="https://github.com/Chanzhaoyu/chatgpt-bot" class="text-blue-500" target="_blank" >GitHub</a>',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function getLocalState(): UserState {
|
||||
const localSetting: UserState | undefined = ss.get(LOCAL_NAME)
|
||||
return { ...defaultSetting(), ...localSetting }
|
||||
}
|
||||
|
||||
export function setLocalState(setting: UserState): void {
|
||||
ss.set(LOCAL_NAME, setting)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { UserState } from './helper'
|
||||
import { defaultSetting, getLocalState, setLocalState } from './helper'
|
||||
|
||||
export const useUserStore = defineStore('user-store', {
|
||||
state: (): UserState => getLocalState(),
|
||||
actions: {
|
||||
updateUserInfo(userInfo: User.Info) {
|
||||
this.userInfo = { ...this.userInfo, ...userInfo }
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
// updateUserHeadImage(userInfo: User.Info) {
|
||||
// this.userInfo = { ...this.userInfo, ...userInfo }
|
||||
// this.recordState()
|
||||
// },
|
||||
|
||||
resetUserInfo() {
|
||||
this.userInfo = { ...defaultSetting().userInfo }
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
recordState() {
|
||||
setLocalState(this.$state)
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user