|
|
@@ -6,7 +6,7 @@ import { t } from '@/locales'
|
|
|
export const useAgentStore = defineStore('agent-store', {
|
|
|
state: (): Agent.AgentState => getLocalState(),
|
|
|
getters: {
|
|
|
- getAgentHistoryByCurrentActive(state: Agent.AgentState) {
|
|
|
+ getAgentAgentHistoryByCurrentActive(state: Agent.AgentState) {
|
|
|
const index = state.history.findIndex(item => item.uuid === state.active)
|
|
|
if (index !== -1)
|
|
|
return state.history[index]
|
|
|
@@ -22,7 +22,165 @@ export const useAgentStore = defineStore('agent-store', {
|
|
|
},
|
|
|
},
|
|
|
actions: {
|
|
|
- clearHistory() {
|
|
|
+ setUsingContext(context: boolean) {
|
|
|
+ this.usingContext = context
|
|
|
+ this.recordState()
|
|
|
+ },
|
|
|
+
|
|
|
+ addAgentHistory(history: Agent.AgentHistory, agentData: Agent.Agent[] = []) {
|
|
|
+ this.history.unshift(history)
|
|
|
+ this.agent.unshift({ uuid: history.uuid, data: agentData })
|
|
|
+ this.active = history.uuid
|
|
|
+ this.reloadRoute(history.uuid)
|
|
|
+ },
|
|
|
+
|
|
|
+ updateAgentHistory(uuid: number, edit: Partial<Agent.AgentHistory>) {
|
|
|
+ const index = this.history.findIndex(item => item.uuid === uuid)
|
|
|
+ if (index !== -1) {
|
|
|
+ this.history[index] = { ...this.history[index], ...edit }
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ async deleteAgentHistory(index: number) {
|
|
|
+ this.history.splice(index, 1)
|
|
|
+ this.agent.splice(index, 1)
|
|
|
+
|
|
|
+ if (this.history.length === 0) {
|
|
|
+ this.active = null
|
|
|
+ this.reloadRoute()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (index > 0 && index <= this.history.length) {
|
|
|
+ const uuid = this.history[index - 1].uuid
|
|
|
+ this.active = uuid
|
|
|
+ this.reloadRoute(uuid)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (index === 0) {
|
|
|
+ if (this.history.length > 0) {
|
|
|
+ const uuid = this.history[0].uuid
|
|
|
+ this.active = uuid
|
|
|
+ this.reloadRoute(uuid)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (index > this.history.length) {
|
|
|
+ const uuid = this.history[this.history.length - 1].uuid
|
|
|
+ this.active = uuid
|
|
|
+ this.reloadRoute(uuid)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ async setActive(uuid: number) {
|
|
|
+ this.active = uuid
|
|
|
+ return await this.reloadRoute(uuid)
|
|
|
+ },
|
|
|
+
|
|
|
+ getAgentByUuidAndIndex(uuid: number, index: number) {
|
|
|
+ if (!uuid || uuid === 0) {
|
|
|
+ if (this.agent.length)
|
|
|
+ return this.agent[0].data[index]
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ const agentIndex = this.agent.findIndex(item => item.uuid === uuid)
|
|
|
+ if (agentIndex !== -1)
|
|
|
+ return this.agent[agentIndex].data[index]
|
|
|
+ return null
|
|
|
+ },
|
|
|
+
|
|
|
+ addAgentByUuid(uuid: number, agent: Agent.Agent) {
|
|
|
+ if (!uuid || uuid === 0) {
|
|
|
+ if (this.history.length === 0) {
|
|
|
+ const uuid = Date.now()
|
|
|
+ this.history.push({ uuid, title: agent.text, isEdit: false })
|
|
|
+ this.agent.push({ uuid, data: [agent] })
|
|
|
+ this.active = uuid
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.agent[0].data.push(agent)
|
|
|
+ if (this.history[0].title === t('agent.newAgentTitle'))
|
|
|
+ this.history[0].title = agent.text
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ const index = this.agent.findIndex(item => item.uuid === uuid)
|
|
|
+ if (index !== -1) {
|
|
|
+ this.agent[index].data.push(agent)
|
|
|
+ if (this.history[index].title === t('agent.newAgentTitle'))
|
|
|
+ this.history[index].title = agent.text
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateAgentByUuid(uuid: number, index: number, agent: Agent.Agent) {
|
|
|
+ if (!uuid || uuid === 0) {
|
|
|
+ if (this.agent.length) {
|
|
|
+ this.agent[0].data[index] = agent
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const agentIndex = this.agent.findIndex(item => item.uuid === uuid)
|
|
|
+ if (agentIndex !== -1) {
|
|
|
+ this.agent[agentIndex].data[index] = agent
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateAgentSomeByUuid(uuid: number, index: number, agent: Partial<Agent.Agent>) {
|
|
|
+ if (!uuid || uuid === 0) {
|
|
|
+ if (this.agent.length) {
|
|
|
+ this.agent[0].data[index] = { ...this.agent[0].data[index], ...agent }
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const agentIndex = this.agent.findIndex(item => item.uuid === uuid)
|
|
|
+ if (agentIndex !== -1) {
|
|
|
+ this.agent[agentIndex].data[index] = { ...this.agent[agentIndex].data[index], ...agent }
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ deleteAgentByUuid(uuid: number, index: number) {
|
|
|
+ if (!uuid || uuid === 0) {
|
|
|
+ if (this.agent.length) {
|
|
|
+ this.agent[0].data.splice(index, 1)
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const agentIndex = this.agent.findIndex(item => item.uuid === uuid)
|
|
|
+ if (agentIndex !== -1) {
|
|
|
+ this.agent[agentIndex].data.splice(index, 1)
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ clearAgentByUuid(uuid: number) {
|
|
|
+ if (!uuid || uuid === 0) {
|
|
|
+ if (this.agent.length) {
|
|
|
+ this.agent[0].data = []
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const index = this.agent.findIndex(item => item.uuid === uuid)
|
|
|
+ if (index !== -1) {
|
|
|
+ this.agent[index].data = []
|
|
|
+ this.recordState()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ clearAgentHistory() {
|
|
|
this.$state = { ...defaultState() }
|
|
|
this.recordState()
|
|
|
},
|