🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements
Backend
• Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps
• Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go`
• Auto-migrate new tables in DB startup logic
Frontend
• Build complete “Model Management” module under `/console/models`
- New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs
- Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile`
• Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature
• Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes
Table UX improvements
• Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style)
• Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags
• Color all tags deterministically using `stringToColor` for consistent theming
• Change vendor column tag color to white for better contrast
Misc
• Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up
These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
"one-api/common"
|
|
|
|
|
"one-api/model"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// GetAllVendors 获取供应商列表(分页)
|
|
|
|
|
func GetAllVendors(c *gin.Context) {
|
|
|
|
|
pageInfo := common.GetPageQuery(c)
|
|
|
|
|
vendors, err := model.GetAllVendors(pageInfo.GetStartIdx(), pageInfo.GetPageSize())
|
|
|
|
|
if err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var total int64
|
|
|
|
|
model.DB.Model(&model.Vendor{}).Count(&total)
|
|
|
|
|
pageInfo.SetTotal(int(total))
|
|
|
|
|
pageInfo.SetItems(vendors)
|
|
|
|
|
common.ApiSuccess(c, pageInfo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SearchVendors 搜索供应商
|
|
|
|
|
func SearchVendors(c *gin.Context) {
|
|
|
|
|
keyword := c.Query("keyword")
|
|
|
|
|
pageInfo := common.GetPageQuery(c)
|
|
|
|
|
vendors, total, err := model.SearchVendors(keyword, pageInfo.GetStartIdx(), pageInfo.GetPageSize())
|
|
|
|
|
if err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
pageInfo.SetTotal(int(total))
|
|
|
|
|
pageInfo.SetItems(vendors)
|
|
|
|
|
common.ApiSuccess(c, pageInfo)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetVendorMeta 根据 ID 获取供应商
|
|
|
|
|
func GetVendorMeta(c *gin.Context) {
|
|
|
|
|
idStr := c.Param("id")
|
|
|
|
|
id, err := strconv.Atoi(idStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
v, err := model.GetVendorByID(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
common.ApiSuccess(c, v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateVendorMeta 新建供应商
|
|
|
|
|
func CreateVendorMeta(c *gin.Context) {
|
|
|
|
|
var v model.Vendor
|
|
|
|
|
if err := c.ShouldBindJSON(&v); err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if v.Name == "" {
|
|
|
|
|
common.ApiErrorMsg(c, "供应商名称不能为空")
|
|
|
|
|
return
|
|
|
|
|
}
|
🚀 refactor: migrate vendor-count aggregation to model layer & align frontend logic
Summary
• Backend
– Moved duplicate-name validation and total vendor-count aggregation from controllers (`controller/model_meta.go`, `controller/vendor_meta.go`, `controller/prefill_group.go`) to model layer (`model/model_meta.go`, `model/vendor_meta.go`, `model/prefill_group.go`).
– Added `GetVendorModelCounts()` and `Is*NameDuplicated()` helpers; controllers now call these instead of duplicating queries.
– API response for `/api/models` now returns `vendor_counts` with per-vendor totals across all pages, plus `all` summary.
– Removed redundant checks and unused imports, eliminating `go vet` warnings.
• Frontend
– `useModelsData.js` updated to consume backend-supplied `vendor_counts`, calculate the `all` total once, and drop legacy client-side counting logic.
– Simplified initial data flow: first render now triggers only one models request.
– Deleted obsolete `updateVendorCounts` helper and related comments.
– Ensured search flow also sets `vendorCounts`, keeping tab badges accurate.
Why
This refactor enforces single-responsibility (aggregation in model layer), delivers consistent totals irrespective of pagination, and removes redundant client queries, leading to cleaner code and better performance.
2025-08-06 01:40:08 +08:00
|
|
|
// 创建前先检查名称
|
|
|
|
|
if dup, err := model.IsVendorNameDuplicated(0, v.Name); err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
} else if dup {
|
|
|
|
|
common.ApiErrorMsg(c, "供应商名称已存在")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements
Backend
• Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps
• Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go`
• Auto-migrate new tables in DB startup logic
Frontend
• Build complete “Model Management” module under `/console/models`
- New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs
- Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile`
• Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature
• Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes
Table UX improvements
• Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style)
• Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags
• Color all tags deterministically using `stringToColor` for consistent theming
• Change vendor column tag color to white for better contrast
Misc
• Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up
These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
|
|
|
if err := v.Insert(); err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
common.ApiSuccess(c, &v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateVendorMeta 更新供应商
|
|
|
|
|
func UpdateVendorMeta(c *gin.Context) {
|
|
|
|
|
var v model.Vendor
|
|
|
|
|
if err := c.ShouldBindJSON(&v); err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if v.Id == 0 {
|
|
|
|
|
common.ApiErrorMsg(c, "缺少供应商 ID")
|
|
|
|
|
return
|
|
|
|
|
}
|
🚀 refactor: migrate vendor-count aggregation to model layer & align frontend logic
Summary
• Backend
– Moved duplicate-name validation and total vendor-count aggregation from controllers (`controller/model_meta.go`, `controller/vendor_meta.go`, `controller/prefill_group.go`) to model layer (`model/model_meta.go`, `model/vendor_meta.go`, `model/prefill_group.go`).
– Added `GetVendorModelCounts()` and `Is*NameDuplicated()` helpers; controllers now call these instead of duplicating queries.
– API response for `/api/models` now returns `vendor_counts` with per-vendor totals across all pages, plus `all` summary.
– Removed redundant checks and unused imports, eliminating `go vet` warnings.
• Frontend
– `useModelsData.js` updated to consume backend-supplied `vendor_counts`, calculate the `all` total once, and drop legacy client-side counting logic.
– Simplified initial data flow: first render now triggers only one models request.
– Deleted obsolete `updateVendorCounts` helper and related comments.
– Ensured search flow also sets `vendorCounts`, keeping tab badges accurate.
Why
This refactor enforces single-responsibility (aggregation in model layer), delivers consistent totals irrespective of pagination, and removes redundant client queries, leading to cleaner code and better performance.
2025-08-06 01:40:08 +08:00
|
|
|
// 名称冲突检查
|
|
|
|
|
if dup, err := model.IsVendorNameDuplicated(v.Id, v.Name); err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
} else if dup {
|
🚀 feat: Introduce full Model & Vendor Management suite (backend + frontend) and UI refinements
Backend
• Add `model/model_meta.go` and `model/vendor_meta.go` defining Model & Vendor entities with CRUD helpers, soft-delete and time stamps
• Create corresponding controllers `controller/model_meta.go`, `controller/vendor_meta.go` and register routes in `router/api-router.go`
• Auto-migrate new tables in DB startup logic
Frontend
• Build complete “Model Management” module under `/console/models`
- New pages, tables, filters, actions, hooks (`useModelsData`) and dynamic vendor tabs
- Modals `EditModelModal.jsx` & unified `EditVendorModal.jsx`; latter now uses default confirm/cancel footer and mobile-friendly modal sizing (`full-width` / `small`) via `useIsMobile`
• Update sidebar (`SiderBar.js`) and routing (`App.js`) to surface the feature
• Add helper updates (`render.js`) incl. `stringToColor`, dynamic LobeHub icon retrieval, and tag color palettes
Table UX improvements
• Replace separate status column with inline Enable / Disable buttons in operation column (matching channel table style)
• Limit visible tags to max 3; overflow represented as “+x” tag with padded `Popover` showing remaining tags
• Color all tags deterministically using `stringToColor` for consistent theming
• Change vendor column tag color to white for better contrast
Misc
• Minor layout tweaks, compact-mode toggle relocation, lint fixes and TypeScript/ESLint clean-up
These changes collectively deliver end-to-end model & vendor administration while unifying visual language across management tables.
2025-07-31 22:28:09 +08:00
|
|
|
common.ApiErrorMsg(c, "供应商名称已存在")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := v.Update(); err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
common.ApiSuccess(c, &v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteVendorMeta 删除供应商
|
|
|
|
|
func DeleteVendorMeta(c *gin.Context) {
|
|
|
|
|
idStr := c.Param("id")
|
|
|
|
|
id, err := strconv.Atoi(idStr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err := model.DB.Delete(&model.Vendor{}, id).Error; err != nil {
|
|
|
|
|
common.ApiError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
common.ApiSuccess(c, nil)
|
|
|
|
|
}
|