feat(site-category): support for custom sorting #902

This commit is contained in:
Jacky 2025-03-15 10:55:01 +08:00
parent efc9b1c365
commit f3d4cdbeb4
No known key found for this signature in database
GPG key ID: 215C21B10DF38B4D
5 changed files with 12 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import (
"github.com/0xJacky/Nginx-UI/model" "github.com/0xJacky/Nginx-UI/model"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/uozi-tech/cosy" "github.com/uozi-tech/cosy"
"gorm.io/gorm"
) )
func GetCategory(c *gin.Context) { func GetCategory(c *gin.Context) {
@ -11,7 +12,9 @@ func GetCategory(c *gin.Context) {
} }
func GetCategoryList(c *gin.Context) { func GetCategoryList(c *gin.Context) {
cosy.Core[model.SiteCategory](c).PagingList() cosy.Core[model.SiteCategory](c).GormScope(func(tx *gorm.DB) *gorm.DB {
return tx.Order("order_id ASC")
}).PagingList()
} }
func AddCategory(c *gin.Context) { func AddCategory(c *gin.Context) {
@ -39,3 +42,7 @@ func DeleteCategory(c *gin.Context) {
func RecoverCategory(c *gin.Context) { func RecoverCategory(c *gin.Context) {
cosy.Core[model.SiteCategory](c).Recover() cosy.Core[model.SiteCategory](c).Recover()
} }
func UpdateCategoriesOrder(c *gin.Context) {
cosy.Core[model.SiteCategory](c).UpdateOrder()
}

View file

@ -31,4 +31,5 @@ func InitCategoryRouter(r *gin.RouterGroup) {
r.POST("site_categories/:id", ModifyCategory) r.POST("site_categories/:id", ModifyCategory)
r.DELETE("site_categories/:id", DeleteCategory) r.DELETE("site_categories/:id", DeleteCategory)
r.POST("site_categories/:id/recover", RecoverCategory) r.POST("site_categories/:id/recover", RecoverCategory)
r.POST("site_categories/order", UpdateCategoriesOrder)
} }

View file

@ -11,6 +11,7 @@ import columns from '@/views/site/site_category/columns'
:api="site_category" :api="site_category"
:columns="columns" :columns="columns"
:scroll-x="600" :scroll-x="600"
sortable
> >
<template #edit="{ data }"> <template #edit="{ data }">
<div class="mb-2"> <div class="mb-2">

View file

@ -9,20 +9,19 @@ const columns: Column[] = [{
edit: { edit: {
type: input, type: input,
}, },
handle: true,
pithy: true, pithy: true,
width: 120, width: 120,
}, { }, {
title: () => $gettext('Created at'), title: () => $gettext('Created at'),
dataIndex: 'created_at', dataIndex: 'created_at',
customRender: datetime, customRender: datetime,
sorter: true,
pithy: true, pithy: true,
width: 150, width: 150,
}, { }, {
title: () => $gettext('Updated at'), title: () => $gettext('Updated at'),
dataIndex: 'updated_at', dataIndex: 'updated_at',
customRender: datetime, customRender: datetime,
sorter: true,
pithy: true, pithy: true,
width: 150, width: 150,
}, { }, {

View file

@ -4,4 +4,5 @@ type SiteCategory struct {
Model Model
Name string `json:"name"` Name string `json:"name"`
SyncNodeIds []uint64 `json:"sync_node_ids" gorm:"serializer:json"` SyncNodeIds []uint64 `json:"sync_node_ids" gorm:"serializer:json"`
OrderID int `json:"-" gorm:"default:0"`
} }