feat: 实现基础设施层

axios 请求封装及七个业务模块 API,Pinia 状态管理(auth/system/models/tools),Mock 适配器与数据,以及流式对话、轮询、倒计时组合式函数。
This commit is contained in:
caoxiaozhu
2026-07-10 16:45:06 +08:00
parent 8aa67003c8
commit ca9e05aa91
17 changed files with 1197 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import { defineStore } from 'pinia'
import { ref, watch } from 'vue'
import type { CustomTool } from '@/types'
/**
* 自定义工具 storelocalStorage 持久化)
* 原 web 项目 customTools 仅存本地,无后端
*/
export const useToolsStore = defineStore('tools', () => {
const STORAGE_KEY = 'customTools'
const tools = ref<CustomTool[]>(loadFromStorage())
function loadFromStorage(): CustomTool[] {
try {
return JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]')
} catch {
return []
}
}
// 持久化
watch(
tools,
(val) => {
localStorage.setItem(STORAGE_KEY, JSON.stringify(val))
},
{ deep: true },
)
function addTool(tool: CustomTool) {
tools.value.push(tool)
}
function updateTool(id: string, data: Partial<CustomTool>) {
const idx = tools.value.findIndex((t) => t.id === id)
if (idx !== -1) tools.value[idx] = { ...tools.value[idx], ...data }
}
function removeTool(id: string) {
tools.value = tools.value.filter((t) => t.id !== id)
}
function getTool(id: string): CustomTool | undefined {
return tools.value.find((t) => t.id === id)
}
return { tools, addTool, updateTool, removeTool, getTool }
})