|
|
@@ -1,15 +1,41 @@
|
|
|
import { defineStore } from 'pinia'
|
|
|
-import type { AgentState } from './helper'
|
|
|
-import { getLocalSetting } from './helper'
|
|
|
-import { store } from '@/store/helper'
|
|
|
+import { defaultState, getLocalState, setLocalState } from './helper'
|
|
|
+import { router } from '@/router'
|
|
|
+import { t } from '@/locales'
|
|
|
|
|
|
export const useAgentStore = defineStore('agent-store', {
|
|
|
- state: (): AgentState => getLocalSetting(),
|
|
|
- actions: {
|
|
|
+ state: (): Agent.AgentState => getLocalState(),
|
|
|
+ getters: {
|
|
|
+ getAgentHistoryByCurrentActive(state: Agent.AgentState) {
|
|
|
+ const index = state.history.findIndex(item => item.uuid === state.active)
|
|
|
+ if (index !== -1)
|
|
|
+ return state.history[index]
|
|
|
+ return null
|
|
|
+ },
|
|
|
|
|
|
+ getAgentByUuid(state: Agent.AgentState) {
|
|
|
+ return (uuid?: number) => {
|
|
|
+ if (uuid)
|
|
|
+ return state.agent.find(item => item.uuid === uuid)?.data ?? []
|
|
|
+ return state.agent.find(item => item.uuid === state.active)?.data ?? []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ actions: {
|
|
|
+ clearHistory() {
|
|
|
+ this.$state = { ...defaultState() }
|
|
|
+ this.recordState()
|
|
|
+ },
|
|
|
+ async reloadRoute(uuid?: number) {
|
|
|
+ this.recordState()
|
|
|
+ await router.push({ name: 'Agent', params: { uuid } })
|
|
|
+ },
|
|
|
+ recordState() {
|
|
|
+ setLocalState(this.$state)
|
|
|
+ },
|
|
|
},
|
|
|
})
|
|
|
|
|
|
export function useAgentStoreWithOut() {
|
|
|
- return useAgentStore(store)
|
|
|
+
|
|
|
}
|