🎨 重构用户端前端为vue开发,完善基础类和角色相关接口

This commit is contained in:
2026-02-10 21:55:45 +08:00
parent db934ebed7
commit 56e821b222
92 changed files with 18377 additions and 21 deletions

View File

@@ -41,8 +41,8 @@ func RegisterTables() {
return
}
// 初始化 PostgreSQL 扩展pgvector
InitPgSQLExtensions()
// 初始化 PostgreSQL 扩展(仅创建 pgvector 扩展
InitPgSQLExtension()
db := global.GVA_DB
err := db.AutoMigrate(
@@ -100,6 +100,9 @@ func RegisterTables() {
os.Exit(0)
}
// 创建向量索引(必须在 AutoMigrate 之后)
CreateVectorIndexes()
err = bizModel()
if err != nil {

View File

@@ -0,0 +1,48 @@
package initialize
import (
"git.echol.cn/loser/st/server/global"
"go.uber.org/zap"
)
// InitPgSQLExtension 初始化 PostgreSQL 扩展(仅创建 pgvector 扩展)
// 必须在 AutoMigrate 之前调用
func InitPgSQLExtension() {
if global.GVA_CONFIG.System.DbType != "pgsql" {
return
}
db := global.GVA_DB
// 安装 pgvector 扩展(用于向量存储)
if err := db.Exec("CREATE EXTENSION IF NOT EXISTS vector").Error; err != nil {
global.GVA_LOG.Error("failed to create pgvector extension", zap.Error(err))
global.GVA_LOG.Warn("请确保 PostgreSQL 已安装 pgvector 扩展")
} else {
global.GVA_LOG.Info("pgvector extension is ready")
}
}
// CreateVectorIndexes 创建向量索引
// 必须在 AutoMigrate 之后调用(确保表已存在)
func CreateVectorIndexes() {
if global.GVA_CONFIG.System.DbType != "pgsql" {
return
}
db := global.GVA_DB
// 为 ai_memory_vectors 表创建 HNSW 索引(余弦相似度)
sql := `
CREATE INDEX IF NOT EXISTS idx_memory_vectors_embedding
ON ai_memory_vectors
USING hnsw (embedding vector_cosine_ops)
`
if err := db.Exec(sql).Error; err != nil {
global.GVA_LOG.Error("failed to create vector indexes", zap.Error(err))
return
}
global.GVA_LOG.Info("vector indexes created successfully")
}

View File

@@ -35,6 +35,10 @@ func (fs justFilesFilesystem) Open(name string) (http.File, error) {
func Routers() *gin.Engine {
Router := gin.New()
// 设置文件上传大小限制10MB
Router.MaxMultipartMemory = 10 << 20 // 10 MB
// 使用自定义的 Recovery 中间件,记录 panic 并入库
Router.Use(middleware.GinRecovery(true))
if gin.Mode() == gin.DebugMode {
@@ -58,6 +62,24 @@ func Routers() *gin.Engine {
systemRouter := router.RouterGroupApp.System
exampleRouter := router.RouterGroupApp.Example
appRouter := router.RouterGroupApp.App // 前台应用路由
// 前台用户端静态文件服务web-app
// 开发环境:直接使用 web-app/public 目录
// 生产环境:使用打包后的 web-app/dist 目录
webAppPath := "../web-app/public"
if _, err := os.Stat(webAppPath); err == nil {
Router.Static("/css", webAppPath+"/css")
Router.Static("/scripts", webAppPath+"/scripts")
Router.Static("/img", webAppPath+"/img")
Router.Static("/fonts", webAppPath+"/fonts")
Router.Static("/webfonts", webAppPath+"/webfonts")
Router.StaticFile("/auth.html", webAppPath+"/auth.html")
Router.StaticFile("/dashboard-example.html", webAppPath+"/dashboard-example.html")
Router.StaticFile("/favicon.ico", webAppPath+"/favicon.ico")
global.GVA_LOG.Info("前台静态文件服务已启动: " + webAppPath)
}
// 管理后台前端静态文件web
// 如果想要不使用nginx代理前端网页可以修改 web/.env.production 下的
// VUE_APP_BASE_API = /
// VUE_APP_BASE_PATH = http://localhost
@@ -67,10 +89,10 @@ func Routers() *gin.Engine {
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
Router.StaticFS(global.GVA_CONFIG.Local.StorePath, justFilesFilesystem{http.Dir(global.GVA_CONFIG.Local.StorePath)}) // Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件")
// 跨域,如需跨域可以打开下面的注释
// Router.Use(middleware.Cors()) // 直接放行全部跨域请求
// Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
// global.GVA_LOG.Info("use middleware cors")
// 跨域配置(前台应用需要)
Router.Use(middleware.Cors()) // 直接放行全部跨域请求
global.GVA_LOG.Info("use middleware cors")
docs.SwaggerInfo.BasePath = global.GVA_CONFIG.System.RouterPrefix
Router.GET(global.GVA_CONFIG.System.RouterPrefix+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
global.GVA_LOG.Info("register swagger handler")
@@ -121,8 +143,9 @@ func Routers() *gin.Engine {
// 前台应用路由(新增)
{
appGroup := PublicGroup.Group("app") // 统一使用 /app 前缀
appRouter.InitAuthRouter(appGroup) // 认证路由:/app/auth/* 和 /app/user/*
appGroup := PublicGroup.Group("app") // 统一使用 /app 前缀
appRouter.InitAuthRouter(appGroup) // 认证路由:/app/auth/* 和 /app/user/*
appRouter.InitCharacterRouter(appGroup) // 角色卡路由:/app/character/*
}
//插件路由安装