🔄 fix: improve vendor-tab filtering & counts, resolve SQL ambiguity, and reload data correctly
Backend • model/model_meta.go – Import strconv – SearchModels: support numeric vendor ID filter vs. fuzzy name search – Explicitly order by `models.id` to avoid “ambiguous column name: id” error Frontend • hooks/useModelsData.js – Change vendor-filter API to pass vendor ID – Automatically reload models when `activeVendorKey` changes – Update vendor counts only when viewing “All” to preserve other tab totals • Add missing effect in EditModelModal to refresh vendor list only when modal visible • Other minor updates to keep lints clean Result Tabs now: 1. Trigger API requests on click 2. Show accurate per-vendor totals 3. Filter models without resetting other counts Backend search handles both vendor IDs and names without SQL errors.
This commit is contained in:
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"one-api/common"
|
||||
"strconv"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -96,13 +97,18 @@ func SearchModels(keyword string, vendor string, offset int, limit int) ([]*Mode
|
||||
db = db.Where("model_name LIKE ? OR description LIKE ? OR tags LIKE ?", like, like, like)
|
||||
}
|
||||
if vendor != "" {
|
||||
db = db.Joins("JOIN vendors ON vendors.id = models.vendor_id").Where("vendors.name LIKE ?", "%"+vendor+"%")
|
||||
// 如果是数字,按供应商 ID 精确匹配;否则按名称模糊匹配
|
||||
if vid, err := strconv.Atoi(vendor); err == nil {
|
||||
db = db.Where("models.vendor_id = ?", vid)
|
||||
} else {
|
||||
db = db.Joins("JOIN vendors ON vendors.id = models.vendor_id").Where("vendors.name LIKE ?", "%"+vendor+"%")
|
||||
}
|
||||
}
|
||||
var total int64
|
||||
err := db.Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
err = db.Offset(offset).Limit(limit).Order("id DESC").Find(&models).Error
|
||||
err = db.Offset(offset).Limit(limit).Order("models.id DESC").Find(&models).Error
|
||||
return models, total, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user