feat: add content management feature for superadmin

- Implemented API endpoint for fetching content list with filtering, sorting, and pagination.
- Added DTOs for content items and tenant information.
- Created frontend components for content management, including search and data table functionalities.
- Updated routing to include content management page.
- Enhanced the superadmin menu to navigate to the new content management section.
- Included necessary styles and scripts for the new content management interface.
This commit is contained in:
2025-12-24 16:24:50 +08:00
parent 568f5cda43
commit d60c1e9312
14 changed files with 1373 additions and 8 deletions

View File

@@ -0,0 +1,33 @@
package super
import (
"quyun/v2/app/http/super/dto"
"quyun/v2/app/requests"
"quyun/v2/app/services"
"github.com/gofiber/fiber/v3"
)
// content provides superadmin content endpoints.
//
// @provider
type content struct{}
// list
//
// @Summary 内容列表(平台侧汇总)
// @Tags Super
// @Accept json
// @Produce json
// @Param filter query dto.SuperContentPageFilter true "Filter"
// @Success 200 {object} requests.Pager{items=dto.SuperContentItem}
//
// @Router /super/v1/contents [get]
// @Bind filter query
func (*content) list(ctx fiber.Ctx, filter *dto.SuperContentPageFilter) (*requests.Pager, error) {
if filter == nil {
filter = &dto.SuperContentPageFilter{}
}
filter.Pagination.Format()
return services.Content.SuperContentPage(ctx, filter)
}

View File

@@ -0,0 +1,81 @@
package dto
import (
"strings"
"time"
"quyun/v2/app/requests"
"quyun/v2/database/models"
"quyun/v2/pkg/consts"
)
type SuperContentPageFilter struct {
requests.Pagination `json:",inline" query:",inline"`
requests.SortQueryFilter `json:",inline" query:",inline"`
ID *int64 `json:"id,omitempty" query:"id"`
TenantID *int64 `json:"tenant_id,omitempty" query:"tenant_id"`
TenantCode *string `json:"tenant_code,omitempty" query:"tenant_code"`
TenantName *string `json:"tenant_name,omitempty" query:"tenant_name"`
UserID *int64 `json:"user_id,omitempty" query:"user_id"`
Username *string `json:"username,omitempty" query:"username"`
Keyword *string `json:"keyword,omitempty" query:"keyword"`
Status *consts.ContentStatus `json:"status,omitempty" query:"status"`
Visibility *consts.ContentVisibility `json:"visibility,omitempty" query:"visibility"`
PublishedAtFrom *time.Time `json:"published_at_from,omitempty" query:"published_at_from"`
PublishedAtTo *time.Time `json:"published_at_to,omitempty" query:"published_at_to"`
CreatedAtFrom *time.Time `json:"created_at_from,omitempty" query:"created_at_from"`
CreatedAtTo *time.Time `json:"created_at_to,omitempty" query:"created_at_to"`
PriceAmountMin *int64 `json:"price_amount_min,omitempty" query:"price_amount_min"`
PriceAmountMax *int64 `json:"price_amount_max,omitempty" query:"price_amount_max"`
}
func (f *SuperContentPageFilter) KeywordTrimmed() string {
if f == nil || f.Keyword == nil {
return ""
}
return strings.TrimSpace(*f.Keyword)
}
func (f *SuperContentPageFilter) TenantCodeTrimmed() string {
if f == nil || f.TenantCode == nil {
return ""
}
return strings.ToLower(strings.TrimSpace(*f.TenantCode))
}
func (f *SuperContentPageFilter) TenantNameTrimmed() string {
if f == nil || f.TenantName == nil {
return ""
}
return strings.TrimSpace(*f.TenantName)
}
func (f *SuperContentPageFilter) UsernameTrimmed() string {
if f == nil || f.Username == nil {
return ""
}
return strings.TrimSpace(*f.Username)
}
type SuperContentTenantLite struct {
ID int64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
}
type SuperContentItem struct {
Content *models.Content `json:"content,omitempty"`
Price *models.ContentPrice `json:"price,omitempty"`
Tenant *SuperContentTenantLite `json:"tenant,omitempty"`
Owner *SuperUserLite `json:"owner,omitempty"`
StatusDescription string `json:"status_description,omitempty"`
VisibilityDescription string `json:"visibility_description,omitempty"`
}

View File

@@ -25,6 +25,13 @@ func Provide(opts ...opt.Option) error {
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*content, error) {
obj := &content{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*order, error) {
obj := &order{}
@@ -34,6 +41,7 @@ func Provide(opts ...opt.Option) error {
}
if err := container.Container.Provide(func(
auth *auth,
content *content,
middlewares *middlewares.Middlewares,
order *order,
tenant *tenant,
@@ -41,6 +49,7 @@ func Provide(opts ...opt.Option) error {
) (contracts.HttpRoute, error) {
obj := &Routes{
auth: auth,
content: content,
middlewares: middlewares,
order: order,
tenant: tenant,

View File

@@ -24,10 +24,11 @@ type Routes struct {
log *log.Entry `inject:"false"`
middlewares *middlewares.Middlewares
// Controller instances
auth *auth
order *order
tenant *tenant
user *user
auth *auth
content *content
order *order
tenant *tenant
user *user
}
// Prepare initializes the routes provider with logging configuration.
@@ -55,6 +56,12 @@ func (r *Routes) Register(router fiber.Router) {
r.auth.login,
Body[dto.LoginForm]("form"),
))
// Register routes for controller: content
r.log.Debugf("Registering route: Get /super/v1/contents -> content.list")
router.Get("/super/v1/contents"[len(r.Path()):], DataFunc1(
r.content.list,
Query[dto.SuperContentPageFilter]("filter"),
))
// Register routes for controller: order
r.log.Debugf("Registering route: Get /super/v1/orders -> order.list")
router.Get("/super/v1/orders"[len(r.Path()):], DataFunc1(

View File

@@ -181,6 +181,262 @@ func (s *content) SuperTenantContentsPage(ctx context.Context, tenantID int64, f
}, nil
}
func (s *content) SuperContentPage(ctx context.Context, filter *superdto.SuperContentPageFilter) (*requests.Pager, error) {
if filter == nil {
filter = &superdto.SuperContentPageFilter{}
}
log.WithFields(log.Fields{
"tenant_id": lo.FromPtr(filter.TenantID),
"tenant_code": filter.TenantCodeTrimmed(),
"tenant_name": filter.TenantNameTrimmed(),
"user_id": lo.FromPtr(filter.UserID),
"username": filter.UsernameTrimmed(),
"keyword": filter.KeywordTrimmed(),
"status": lo.FromPtr(filter.Status),
"visibility": lo.FromPtr(filter.Visibility),
"page": filter.Page,
"limit": filter.Limit,
}).Info("services.content.super_page")
filter.Pagination.Format()
cTbl, query := models.ContentQuery.QueryContext(ctx)
// 注意:该查询会按需 join users/tenants/content_prices必须显式 select contents.*
// 否则重复列名id/created_at/updated_at 等)会被扫描到 Content 模型上导致字段错乱。
query = query.Select(cTbl.ALL)
conds := []gen.Condition{
cTbl.DeletedAt.IsNull(),
}
if filter.ID != nil && *filter.ID > 0 {
conds = append(conds, cTbl.ID.Eq(*filter.ID))
}
if filter.TenantID != nil && *filter.TenantID > 0 {
conds = append(conds, cTbl.TenantID.Eq(*filter.TenantID))
}
if filter.UserID != nil && *filter.UserID > 0 {
conds = append(conds, cTbl.UserID.Eq(*filter.UserID))
}
if kw := strings.TrimSpace(filter.KeywordTrimmed()); kw != "" {
conds = append(conds, cTbl.Title.Like(database.WrapLike(kw)))
}
if filter.Status != nil {
conds = append(conds, cTbl.Status.Eq(*filter.Status))
}
if filter.Visibility != nil {
conds = append(conds, cTbl.Visibility.Eq(*filter.Visibility))
}
if filter.PublishedAtFrom != nil {
conds = append(conds, cTbl.PublishedAt.Gte(*filter.PublishedAtFrom))
}
if filter.PublishedAtTo != nil {
conds = append(conds, cTbl.PublishedAt.Lte(*filter.PublishedAtTo))
}
if filter.CreatedAtFrom != nil {
conds = append(conds, cTbl.CreatedAt.Gte(*filter.CreatedAtFrom))
}
if filter.CreatedAtTo != nil {
conds = append(conds, cTbl.CreatedAt.Lte(*filter.CreatedAtTo))
}
// Owner username keyword.
if username := filter.UsernameTrimmed(); username != "" {
uTbl, _ := models.UserQuery.QueryContext(ctx)
query = query.LeftJoin(uTbl, uTbl.ID.EqCol(cTbl.UserID))
conds = append(conds, uTbl.Username.Like(database.WrapLike(username)))
}
// Tenant code/name keyword.
tenantCode := filter.TenantCodeTrimmed()
tenantName := filter.TenantNameTrimmed()
if tenantCode != "" || tenantName != "" {
tTbl, _ := models.TenantQuery.QueryContext(ctx)
query = query.LeftJoin(tTbl, tTbl.ID.EqCol(cTbl.TenantID))
if tenantCode != "" {
conds = append(conds, tTbl.Code.Like(database.WrapLike(tenantCode)))
}
if tenantName != "" {
conds = append(conds, tTbl.Name.Like(database.WrapLike(tenantName)))
}
}
// Price amount range filter (content_prices is 1:1 by content_id within tenant).
needPriceJoin := (filter.PriceAmountMin != nil && *filter.PriceAmountMin >= 0) || (filter.PriceAmountMax != nil && *filter.PriceAmountMax >= 0)
if needPriceJoin {
cpTbl, _ := models.ContentPriceQuery.QueryContext(ctx)
query = query.LeftJoin(cpTbl, cpTbl.ContentID.EqCol(cTbl.ID))
if filter.PriceAmountMin != nil && *filter.PriceAmountMin >= 0 {
conds = append(conds, cpTbl.PriceAmount.Gte(*filter.PriceAmountMin))
}
if filter.PriceAmountMax != nil && *filter.PriceAmountMax >= 0 {
conds = append(conds, cpTbl.PriceAmount.Lte(*filter.PriceAmountMax))
}
}
// Sort whitelist.
orderBys := make([]field.Expr, 0, 8)
allowedAsc := map[string]field.Expr{
"id": cTbl.ID.Asc(),
"tenant_id": cTbl.TenantID.Asc(),
"user_id": cTbl.UserID.Asc(),
"title": cTbl.Title.Asc(),
"status": cTbl.Status.Asc(),
"visibility": cTbl.Visibility.Asc(),
"published_at": cTbl.PublishedAt.Asc(),
"created_at": cTbl.CreatedAt.Asc(),
"updated_at": cTbl.UpdatedAt.Asc(),
}
allowedDesc := map[string]field.Expr{
"id": cTbl.ID.Desc(),
"tenant_id": cTbl.TenantID.Desc(),
"user_id": cTbl.UserID.Desc(),
"title": cTbl.Title.Desc(),
"status": cTbl.Status.Desc(),
"visibility": cTbl.Visibility.Desc(),
"published_at": cTbl.PublishedAt.Desc(),
"created_at": cTbl.CreatedAt.Desc(),
"updated_at": cTbl.UpdatedAt.Desc(),
}
for _, f := range filter.AscFields() {
f = strings.TrimSpace(f)
if f == "" {
continue
}
if ob, ok := allowedAsc[f]; ok {
orderBys = append(orderBys, ob)
}
}
for _, f := range filter.DescFields() {
f = strings.TrimSpace(f)
if f == "" {
continue
}
if ob, ok := allowedDesc[f]; ok {
orderBys = append(orderBys, ob)
}
}
if len(orderBys) == 0 {
orderBys = append(orderBys, cTbl.ID.Desc())
} else {
orderBys = append(orderBys, cTbl.ID.Desc())
}
items, total, err := query.Where(conds...).Order(orderBys...).FindByPage(int(filter.Offset()), int(filter.Limit))
if err != nil {
return nil, err
}
tenantIDs := lo.Uniq(lo.FilterMap(items, func(item *models.Content, _ int) (int64, bool) {
if item == nil || item.TenantID <= 0 {
return 0, false
}
return item.TenantID, true
}))
ownerIDs := lo.Uniq(lo.FilterMap(items, func(item *models.Content, _ int) (int64, bool) {
if item == nil || item.UserID <= 0 {
return 0, false
}
return item.UserID, true
}))
contentIDs := lo.Uniq(lo.FilterMap(items, func(item *models.Content, _ int) (int64, bool) {
if item == nil || item.ID <= 0 {
return 0, false
}
return item.ID, true
}))
tenantMap := map[int64]*models.Tenant{}
if len(tenantIDs) > 0 {
tTbl, tQuery := models.TenantQuery.QueryContext(ctx)
tenants, err := tQuery.Where(tTbl.ID.In(tenantIDs...)).Find()
if err != nil {
return nil, err
}
for _, te := range tenants {
if te == nil {
continue
}
tenantMap[te.ID] = te
}
}
ownerMap := map[int64]*superdto.SuperUserLite{}
if len(ownerIDs) > 0 {
uTbl, uQuery := models.UserQuery.QueryContext(ctx)
users, err := uQuery.Where(uTbl.ID.In(ownerIDs...)).Find()
if err != nil {
return nil, err
}
for _, u := range users {
if u == nil {
continue
}
ownerMap[u.ID] = &superdto.SuperUserLite{
ID: u.ID,
Username: u.Username,
Status: u.Status,
Roles: u.Roles,
VerifiedAt: u.VerifiedAt,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
StatusDescription: u.Status.Description(),
}
}
}
priceByContent := map[int64]*models.ContentPrice{}
if len(contentIDs) > 0 {
cpTbl, cpQuery := models.ContentPriceQuery.QueryContext(ctx)
conds := []gen.Condition{
cpTbl.ContentID.In(contentIDs...),
}
if len(tenantIDs) > 0 {
conds = append(conds, cpTbl.TenantID.In(tenantIDs...))
}
prices, err := cpQuery.Where(conds...).Find()
if err != nil {
return nil, err
}
for _, p := range prices {
if p == nil {
continue
}
priceByContent[p.ContentID] = p
}
}
respItems := lo.Map(items, func(model *models.Content, _ int) *superdto.SuperContentItem {
if model == nil {
return nil
}
te := tenantMap[model.TenantID]
var lite *superdto.SuperContentTenantLite
if te != nil {
lite = &superdto.SuperContentTenantLite{
ID: te.ID,
Code: te.Code,
Name: te.Name,
}
}
return &superdto.SuperContentItem{
Content: model,
Price: priceByContent[model.ID],
Tenant: lite,
Owner: ownerMap[model.UserID],
StatusDescription: model.Status.Description(),
VisibilityDescription: model.Visibility.Description(),
}
})
return &requests.Pager{
Pagination: filter.Pagination,
Total: total,
Items: respItems,
}, nil
}
func (s *content) SuperUpdateTenantContentStatus(
ctx context.Context,
operatorUserID, tenantID, contentID int64,

View File

@@ -77,6 +77,165 @@ const docTemplate = `{
}
}
},
"/super/v1/contents": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Super"
],
"summary": "内容列表(平台侧汇总)",
"parameters": [
{
"type": "string",
"description": "Asc specifies comma-separated field names to sort ascending by.",
"name": "asc",
"in": "query"
},
{
"type": "string",
"name": "created_at_from",
"in": "query"
},
{
"type": "string",
"name": "created_at_to",
"in": "query"
},
{
"type": "string",
"description": "Desc specifies comma-separated field names to sort descending by.",
"name": "desc",
"in": "query"
},
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "keyword",
"in": "query"
},
{
"type": "integer",
"description": "Limit is page size; only values in {10,20,50,100} are accepted (otherwise defaults to 10).",
"name": "limit",
"in": "query"
},
{
"type": "integer",
"description": "Page is 1-based page index; values \u003c= 0 are normalized to 1.",
"name": "page",
"in": "query"
},
{
"type": "integer",
"name": "price_amount_max",
"in": "query"
},
{
"type": "integer",
"name": "price_amount_min",
"in": "query"
},
{
"type": "string",
"name": "published_at_from",
"in": "query"
},
{
"type": "string",
"name": "published_at_to",
"in": "query"
},
{
"enum": [
"draft",
"reviewing",
"published",
"unpublished",
"blocked"
],
"type": "string",
"x-enum-varnames": [
"ContentStatusDraft",
"ContentStatusReviewing",
"ContentStatusPublished",
"ContentStatusUnpublished",
"ContentStatusBlocked"
],
"name": "status",
"in": "query"
},
{
"type": "string",
"name": "tenant_code",
"in": "query"
},
{
"type": "integer",
"name": "tenant_id",
"in": "query"
},
{
"type": "string",
"name": "tenant_name",
"in": "query"
},
{
"type": "integer",
"name": "user_id",
"in": "query"
},
{
"type": "string",
"name": "username",
"in": "query"
},
{
"enum": [
"public",
"tenant_only",
"private"
],
"type": "string",
"x-enum-varnames": [
"ContentVisibilityPublic",
"ContentVisibilityTenantOnly",
"ContentVisibilityPrivate"
],
"name": "visibility",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/requests.Pager"
},
{
"type": "object",
"properties": {
"items": {
"$ref": "#/definitions/dto.SuperContentItem"
}
}
}
]
}
}
}
}
},
"/super/v1/orders": {
"get": {
"consumes": [
@@ -4467,6 +4626,43 @@ const docTemplate = `{
}
}
},
"dto.SuperContentItem": {
"type": "object",
"properties": {
"content": {
"$ref": "#/definitions/models.Content"
},
"owner": {
"$ref": "#/definitions/dto.SuperUserLite"
},
"price": {
"$ref": "#/definitions/models.ContentPrice"
},
"status_description": {
"type": "string"
},
"tenant": {
"$ref": "#/definitions/dto.SuperContentTenantLite"
},
"visibility_description": {
"type": "string"
}
}
},
"dto.SuperContentTenantLite": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"dto.SuperOrderDetail": {
"type": "object",
"properties": {

View File

@@ -71,6 +71,165 @@
}
}
},
"/super/v1/contents": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Super"
],
"summary": "内容列表(平台侧汇总)",
"parameters": [
{
"type": "string",
"description": "Asc specifies comma-separated field names to sort ascending by.",
"name": "asc",
"in": "query"
},
{
"type": "string",
"name": "created_at_from",
"in": "query"
},
{
"type": "string",
"name": "created_at_to",
"in": "query"
},
{
"type": "string",
"description": "Desc specifies comma-separated field names to sort descending by.",
"name": "desc",
"in": "query"
},
{
"type": "integer",
"name": "id",
"in": "query"
},
{
"type": "string",
"name": "keyword",
"in": "query"
},
{
"type": "integer",
"description": "Limit is page size; only values in {10,20,50,100} are accepted (otherwise defaults to 10).",
"name": "limit",
"in": "query"
},
{
"type": "integer",
"description": "Page is 1-based page index; values \u003c= 0 are normalized to 1.",
"name": "page",
"in": "query"
},
{
"type": "integer",
"name": "price_amount_max",
"in": "query"
},
{
"type": "integer",
"name": "price_amount_min",
"in": "query"
},
{
"type": "string",
"name": "published_at_from",
"in": "query"
},
{
"type": "string",
"name": "published_at_to",
"in": "query"
},
{
"enum": [
"draft",
"reviewing",
"published",
"unpublished",
"blocked"
],
"type": "string",
"x-enum-varnames": [
"ContentStatusDraft",
"ContentStatusReviewing",
"ContentStatusPublished",
"ContentStatusUnpublished",
"ContentStatusBlocked"
],
"name": "status",
"in": "query"
},
{
"type": "string",
"name": "tenant_code",
"in": "query"
},
{
"type": "integer",
"name": "tenant_id",
"in": "query"
},
{
"type": "string",
"name": "tenant_name",
"in": "query"
},
{
"type": "integer",
"name": "user_id",
"in": "query"
},
{
"type": "string",
"name": "username",
"in": "query"
},
{
"enum": [
"public",
"tenant_only",
"private"
],
"type": "string",
"x-enum-varnames": [
"ContentVisibilityPublic",
"ContentVisibilityTenantOnly",
"ContentVisibilityPrivate"
],
"name": "visibility",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/requests.Pager"
},
{
"type": "object",
"properties": {
"items": {
"$ref": "#/definitions/dto.SuperContentItem"
}
}
}
]
}
}
}
}
},
"/super/v1/orders": {
"get": {
"consumes": [
@@ -4461,6 +4620,43 @@
}
}
},
"dto.SuperContentItem": {
"type": "object",
"properties": {
"content": {
"$ref": "#/definitions/models.Content"
},
"owner": {
"$ref": "#/definitions/dto.SuperUserLite"
},
"price": {
"$ref": "#/definitions/models.ContentPrice"
},
"status_description": {
"type": "string"
},
"tenant": {
"$ref": "#/definitions/dto.SuperContentTenantLite"
},
"visibility_description": {
"type": "string"
}
}
},
"dto.SuperContentTenantLite": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
}
}
},
"dto.SuperOrderDetail": {
"type": "object",
"properties": {

View File

@@ -651,6 +651,30 @@ definitions:
description: Order is the created or existing order record (may be nil for
owner/free-path without order).
type: object
dto.SuperContentItem:
properties:
content:
$ref: '#/definitions/models.Content'
owner:
$ref: '#/definitions/dto.SuperUserLite'
price:
$ref: '#/definitions/models.ContentPrice'
status_description:
type: string
tenant:
$ref: '#/definitions/dto.SuperContentTenantLite'
visibility_description:
type: string
type: object
dto.SuperContentTenantLite:
properties:
code:
type: string
id:
type: integer
name:
type: string
type: object
dto.SuperOrderDetail:
properties:
buyer:
@@ -1557,6 +1581,109 @@ paths:
$ref: '#/definitions/dto.LoginResponse'
tags:
- Super
/super/v1/contents:
get:
consumes:
- application/json
parameters:
- description: Asc specifies comma-separated field names to sort ascending by.
in: query
name: asc
type: string
- in: query
name: created_at_from
type: string
- in: query
name: created_at_to
type: string
- description: Desc specifies comma-separated field names to sort descending
by.
in: query
name: desc
type: string
- in: query
name: id
type: integer
- in: query
name: keyword
type: string
- description: Limit is page size; only values in {10,20,50,100} are accepted
(otherwise defaults to 10).
in: query
name: limit
type: integer
- description: Page is 1-based page index; values <= 0 are normalized to 1.
in: query
name: page
type: integer
- in: query
name: price_amount_max
type: integer
- in: query
name: price_amount_min
type: integer
- in: query
name: published_at_from
type: string
- in: query
name: published_at_to
type: string
- enum:
- draft
- reviewing
- published
- unpublished
- blocked
in: query
name: status
type: string
x-enum-varnames:
- ContentStatusDraft
- ContentStatusReviewing
- ContentStatusPublished
- ContentStatusUnpublished
- ContentStatusBlocked
- in: query
name: tenant_code
type: string
- in: query
name: tenant_id
type: integer
- in: query
name: tenant_name
type: string
- in: query
name: user_id
type: integer
- in: query
name: username
type: string
- enum:
- public
- tenant_only
- private
in: query
name: visibility
type: string
x-enum-varnames:
- ContentVisibilityPublic
- ContentVisibilityTenantOnly
- ContentVisibilityPrivate
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/requests.Pager'
- properties:
items:
$ref: '#/definitions/dto.SuperContentItem'
type: object
summary: 内容列表(平台侧汇总)
tags:
- Super
/super/v1/orders:
get:
consumes:

View File

@@ -22,6 +22,7 @@
- `/superadmin/tenants`:租户管理
- `/superadmin/users`:用户管理
- `/superadmin/orders`:订单管理
- `/superadmin/contents`:内容管理(跨租户汇总)
## 1.1 迭代路线(按优先级依次实现)
@@ -34,7 +35,10 @@
- 平台侧退款(支持强制退款,记录操作人)
3) **租户管理增强**
- 租户详情页(基本信息、过期续期、状态变更、管理员/成员/内容管理)
4) **用户管理增强**
4) **内容管理**
- 内容列表(跨租户查询/筛选/分页/排序、下架/封禁)
- 可选:内容详情页(资源/定价/审计)
5) **用户管理增强**
- 用户详情页(角色、状态、余额/冻结、加入/拥有的租户、操作记录)
- 角色授予/回收(`super_admin`
5) **审计与运维**

View File

@@ -7,8 +7,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sakai Vue</title>
<link href="https://fonts.cdnfonts.com/css/lato" rel="stylesheet">
<script type="module" crossorigin src="./assets/index-PWlTeOhw.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-B8J4fGz4.css">
<script type="module" crossorigin src="./assets/index-DZI8LZQ2.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-Vam7Oj9y.css">
</head>
<body>

View File

@@ -13,7 +13,8 @@ const model = ref([
items: [
{ label: 'Tenants', icon: 'pi pi-fw pi-building', to: '/superadmin/tenants' },
{ label: 'Users', icon: 'pi pi-fw pi-users', to: '/superadmin/users' },
{ label: 'Orders', icon: 'pi pi-fw pi-shopping-cart', to: '/superadmin/orders' }
{ label: 'Orders', icon: 'pi pi-fw pi-shopping-cart', to: '/superadmin/orders' },
{ label: 'Contents', icon: 'pi pi-fw pi-file', to: '/superadmin/contents' }
]
}
]);

View File

@@ -139,6 +139,11 @@ const router = createRouter({
name: 'superadmin-orders',
component: () => import('@/views/superadmin/Orders.vue')
},
{
path: '/superadmin/contents',
name: 'superadmin-contents',
component: () => import('@/views/superadmin/Contents.vue')
},
{
path: '/superadmin/orders/:orderID',
name: 'superadmin-order-detail',

View File

@@ -7,6 +7,66 @@ function normalizeItems(items) {
}
export const ContentService = {
async listContents({
page,
limit,
id,
tenant_id,
tenant_code,
tenant_name,
user_id,
username,
keyword,
status,
visibility,
published_at_from,
published_at_to,
created_at_from,
created_at_to,
price_amount_min,
price_amount_max,
sortField,
sortOrder
} = {}) {
const iso = (d) => {
if (!d) return undefined;
const date = d instanceof Date ? d : new Date(d);
if (Number.isNaN(date.getTime())) return undefined;
return date.toISOString();
};
const query = {
page,
limit,
id,
tenant_id,
tenant_code,
tenant_name,
user_id,
username,
keyword,
status,
visibility,
published_at_from: iso(published_at_from),
published_at_to: iso(published_at_to),
created_at_from: iso(created_at_from),
created_at_to: iso(created_at_to),
price_amount_min,
price_amount_max
};
if (sortField && sortOrder) {
if (sortOrder === 1) query.asc = sortField;
if (sortOrder === -1) query.desc = sortField;
}
const data = await requestJson('/super/v1/contents', { query });
return {
page: data?.page ?? page ?? 1,
limit: data?.limit ?? limit ?? 10,
total: data?.total ?? 0,
items: normalizeItems(data?.items)
};
},
async listTenantContents(
tenantID,
{

View File

@@ -0,0 +1,390 @@
<script setup>
import SearchField from '@/components/SearchField.vue';
import SearchPanel from '@/components/SearchPanel.vue';
import { ContentService } from '@/service/ContentService';
import { useToast } from 'primevue/usetoast';
import { computed, onMounted, ref } from 'vue';
const toast = useToast();
const loading = ref(false);
const contents = ref([]);
const totalRecords = ref(0);
const page = ref(1);
const rows = ref(10);
const contentID = ref(null);
const tenantID = ref(null);
const tenantCode = ref('');
const tenantName = ref('');
const ownerUserID = ref(null);
const ownerUsername = ref('');
const keyword = ref('');
const status = ref('');
const visibility = ref('');
const publishedAtFrom = ref(null);
const publishedAtTo = ref(null);
const createdAtFrom = ref(null);
const createdAtTo = ref(null);
const priceAmountMin = ref(null);
const priceAmountMax = ref(null);
const sortField = ref('id');
const sortOrder = ref(-1);
const statusOptions = [
{ label: '全部', value: '' },
{ label: 'draft', value: 'draft' },
{ label: 'reviewing', value: 'reviewing' },
{ label: 'published', value: 'published' },
{ label: 'unpublished', value: 'unpublished' },
{ label: 'blocked', value: 'blocked' }
];
const visibilityOptions = [
{ label: '全部', value: '' },
{ label: 'public', value: 'public' },
{ label: 'tenant_only', value: 'tenant_only' },
{ label: 'private', value: 'private' }
];
function formatDate(value) {
if (!value) return '-';
if (String(value).startsWith('0001-01-01')) return '-';
const date = new Date(value);
if (Number.isNaN(date.getTime())) return String(value);
return date.toLocaleString();
}
function formatCny(amountInCents) {
const amount = Number(amountInCents) / 100;
if (!Number.isFinite(amount)) return '-';
return new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY' }).format(amount);
}
function getContentStatusSeverity(value) {
switch (value) {
case 'published':
return 'success';
case 'reviewing':
return 'warn';
case 'blocked':
return 'danger';
case 'draft':
case 'unpublished':
default:
return 'secondary';
}
}
function getContentVisibilitySeverity(value) {
switch (value) {
case 'public':
return 'info';
case 'tenant_only':
return 'warn';
case 'private':
return 'secondary';
default:
return 'secondary';
}
}
async function loadContents() {
loading.value = true;
try {
const result = await ContentService.listContents({
page: page.value,
limit: rows.value,
id: contentID.value || undefined,
tenant_id: tenantID.value || undefined,
tenant_code: tenantCode.value,
tenant_name: tenantName.value,
user_id: ownerUserID.value || undefined,
username: ownerUsername.value,
keyword: keyword.value,
status: status.value || undefined,
visibility: visibility.value || undefined,
published_at_from: publishedAtFrom.value || undefined,
published_at_to: publishedAtTo.value || undefined,
created_at_from: createdAtFrom.value || undefined,
created_at_to: createdAtTo.value || undefined,
price_amount_min: priceAmountMin.value ?? undefined,
price_amount_max: priceAmountMax.value ?? undefined,
sortField: sortField.value,
sortOrder: sortOrder.value
});
contents.value = (result.items || []).map((item) => ({ ...item, __key: item?.content?.id ?? undefined }));
totalRecords.value = result.total;
} catch (error) {
toast.add({ severity: 'error', summary: '加载失败', detail: error?.message || '无法加载内容列表', life: 4000 });
} finally {
loading.value = false;
}
}
function onSearch() {
page.value = 1;
loadContents();
}
function onReset() {
contentID.value = null;
tenantID.value = null;
tenantCode.value = '';
tenantName.value = '';
ownerUserID.value = null;
ownerUsername.value = '';
keyword.value = '';
status.value = '';
visibility.value = '';
publishedAtFrom.value = null;
publishedAtTo.value = null;
createdAtFrom.value = null;
createdAtTo.value = null;
priceAmountMin.value = null;
priceAmountMax.value = null;
sortField.value = 'id';
sortOrder.value = -1;
page.value = 1;
rows.value = 10;
loadContents();
}
function onPage(event) {
page.value = (event.page ?? 0) + 1;
rows.value = event.rows ?? rows.value;
loadContents();
}
function onSort(event) {
sortField.value = event.sortField ?? sortField.value;
sortOrder.value = event.sortOrder ?? sortOrder.value;
loadContents();
}
const unpublishDialogVisible = ref(false);
const unpublishLoading = ref(false);
const unpublishItem = ref(null);
const unpublishTenantID = computed(() => Number(unpublishItem.value?.tenant?.id ?? 0));
const unpublishContentID = computed(() => Number(unpublishItem.value?.content?.id ?? 0));
function openUnpublishDialog(row) {
unpublishItem.value = row;
unpublishDialogVisible.value = true;
}
async function confirmUnpublish() {
const teID = unpublishTenantID.value;
const cID = unpublishContentID.value;
if (!teID || !cID) return;
unpublishLoading.value = true;
try {
await ContentService.updateTenantContentStatus(teID, cID, { status: 'unpublished' });
toast.add({ severity: 'success', summary: '下架成功', detail: `ContentID: ${cID}`, life: 3000 });
unpublishDialogVisible.value = false;
await loadContents();
} catch (error) {
toast.add({ severity: 'error', summary: '下架失败', detail: error?.message || '无法下架内容', life: 4000 });
} finally {
unpublishLoading.value = false;
}
}
onMounted(() => {
loadContents();
});
</script>
<template>
<div class="card">
<div class="flex items-center justify-between mb-4">
<div class="flex flex-col">
<h4 class="m-0">内容列表</h4>
<span class="text-muted-color">平台侧汇总跨租户</span>
</div>
<Button label="刷新" icon="pi pi-refresh" severity="secondary" @click="loadContents" :disabled="loading" />
</div>
<div class="flex flex-col gap-4">
<SearchPanel :loading="loading" @search="onSearch" @reset="onReset">
<SearchField label="ContentID">
<InputNumber v-model="contentID" :min="1" placeholder="精确匹配" class="w-full" />
</SearchField>
<SearchField label="TenantID">
<InputNumber v-model="tenantID" :min="1" placeholder="精确匹配" class="w-full" />
</SearchField>
<SearchField label="TenantCode">
<InputText v-model="tenantCode" placeholder="模糊匹配" class="w-full" @keyup.enter="onSearch" />
</SearchField>
<SearchField label="TenantName">
<InputText v-model="tenantName" placeholder="模糊匹配" class="w-full" @keyup.enter="onSearch" />
</SearchField>
<SearchField label="OwnerUserID">
<InputNumber v-model="ownerUserID" :min="1" placeholder="精确匹配" class="w-full" />
</SearchField>
<SearchField label="OwnerUsername">
<InputText v-model="ownerUsername" placeholder="模糊匹配" class="w-full" @keyup.enter="onSearch" />
</SearchField>
<SearchField label="Keyword">
<InputText v-model="keyword" placeholder="标题关键词" class="w-full" @keyup.enter="onSearch" />
</SearchField>
<SearchField label="状态">
<Select v-model="status" :options="statusOptions" optionLabel="label" optionValue="value" placeholder="请选择" class="w-full" />
</SearchField>
<SearchField label="可见性">
<Select v-model="visibility" :options="visibilityOptions" optionLabel="label" optionValue="value" placeholder="请选择" class="w-full" />
</SearchField>
<SearchField label="价格 From(分)">
<InputNumber v-model="priceAmountMin" :min="0" placeholder=">= 0" class="w-full" />
</SearchField>
<SearchField label="价格 To(分)">
<InputNumber v-model="priceAmountMax" :min="0" placeholder=">= 0" class="w-full" />
</SearchField>
<SearchField label="发布时间 From">
<DatePicker v-model="publishedAtFrom" showIcon showButtonBar placeholder="开始时间" class="w-full" />
</SearchField>
<SearchField label="发布时间 To">
<DatePicker v-model="publishedAtTo" showIcon showButtonBar placeholder="结束时间" class="w-full" />
</SearchField>
<SearchField label="创建时间 From">
<DatePicker v-model="createdAtFrom" showIcon showButtonBar placeholder="开始时间" class="w-full" />
</SearchField>
<SearchField label="创建时间 To">
<DatePicker v-model="createdAtTo" showIcon showButtonBar placeholder="结束时间" class="w-full" />
</SearchField>
</SearchPanel>
<DataTable
:value="contents"
dataKey="__key"
:loading="loading"
lazy
:paginator="true"
:rows="rows"
:totalRecords="totalRecords"
:first="(page - 1) * rows"
:rowsPerPageOptions="[10, 20, 50, 100]"
sortMode="single"
:sortField="sortField"
:sortOrder="sortOrder"
@page="onPage"
@sort="onSort"
currentPageReportTemplate="显示第 {first} - {last} 条,共 {totalRecords} 条"
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
scrollable
scrollHeight="640px"
responsiveLayout="scroll"
>
<Column header="ID" sortable sortField="id" style="min-width: 8rem">
<template #body="{ data }">
<span class="text-muted-color">{{ data?.content?.id ?? '-' }}</span>
</template>
</Column>
<Column header="标题" sortable sortField="title" style="min-width: 22rem">
<template #body="{ data }">
<div class="flex flex-col">
<span class="font-medium truncate max-w-[520px]">{{ data?.content?.title ?? '-' }}</span>
<span class="text-muted-color">TenantID: {{ data?.tenant?.id ?? data?.content?.tenant_id ?? '-' }}</span>
</div>
</template>
</Column>
<Column header="租户" sortable sortField="tenant_id" style="min-width: 18rem">
<template #body="{ data }">
<router-link
v-if="data?.tenant?.id"
class="inline-flex items-center gap-1 font-medium text-primary hover:underline"
:to="`/superadmin/tenants/${data.tenant.id}`"
>
<span class="truncate max-w-[220px]">{{ data?.tenant?.name ?? data?.tenant?.code ?? '-' }}</span>
<i class="pi pi-external-link text-xs" />
</router-link>
<span v-else class="font-medium text-muted-color">{{ data?.tenant?.name ?? data?.tenant?.code ?? '-' }}</span>
<div class="flex flex-col">
<span class="text-muted-color">ID: {{ data?.tenant?.id ?? data?.content?.tenant_id ?? '-' }}</span>
<span class="text-muted-color">Code: {{ data?.tenant?.code ?? '-' }}</span>
</div>
</template>
</Column>
<Column header="Owner" sortable sortField="user_id" style="min-width: 14rem">
<template #body="{ data }">
<router-link
v-if="(data?.owner?.id ?? data?.content?.user_id) > 0"
class="inline-flex items-center gap-1 font-medium text-primary hover:underline"
:to="`/superadmin/users/${data?.owner?.id ?? data?.content?.user_id}`"
>
<span class="truncate max-w-[200px]">{{ data?.owner?.username ?? `ID:${data?.content?.user_id ?? '-'}` }}</span>
<i class="pi pi-external-link text-xs" />
</router-link>
<span v-else class="font-medium text-muted-color">-</span>
<div class="flex flex-col">
<span class="text-muted-color">ID: {{ data?.content?.user_id ?? '-' }}</span>
</div>
</template>
</Column>
<Column header="状态" sortable sortField="status" style="min-width: 12rem">
<template #body="{ data }">
<Tag :value="data?.status_description || data?.content?.status || '-'" :severity="getContentStatusSeverity(data?.content?.status)" />
</template>
</Column>
<Column header="可见性" sortable sortField="visibility" style="min-width: 12rem">
<template #body="{ data }">
<Tag :value="data?.visibility_description || data?.content?.visibility || '-'" :severity="getContentVisibilitySeverity(data?.content?.visibility)" />
</template>
</Column>
<Column header="价格" style="min-width: 10rem">
<template #body="{ data }">
<span v-if="data?.price && (data.price.price_amount ?? null) !== null">
{{ Number(data.price.price_amount) === 0 ? '免费' : formatCny(data.price.price_amount) }}
</span>
<span v-else class="text-muted-color">-</span>
</template>
</Column>
<Column header="发布时间" sortable sortField="published_at" style="min-width: 14rem">
<template #body="{ data }">
{{ formatDate(data?.content?.published_at) }}
</template>
</Column>
<Column header="创建时间" sortable sortField="created_at" style="min-width: 14rem">
<template #body="{ data }">
{{ formatDate(data?.content?.created_at) }}
</template>
</Column>
<Column header="操作" style="min-width: 10rem">
<template #body="{ data }">
<Button
v-if="data?.content?.status === 'published'"
label="下架"
icon="pi pi-ban"
severity="danger"
text
size="small"
class="p-0"
@click="openUnpublishDialog(data)"
/>
<span v-else class="text-muted-color">-</span>
</template>
</Column>
</DataTable>
</div>
</div>
<Dialog v-model:visible="unpublishDialogVisible" :modal="true" :style="{ width: '460px' }">
<template #header>
<div class="flex items-center gap-2">
<span class="font-medium">下架内容</span>
<span class="text-muted-color truncate max-w-[280px]">{{ unpublishItem?.content?.title ?? '-' }}</span>
</div>
</template>
<div class="flex flex-col gap-2">
<div class="text-muted-color">确认将该内容下架下架后租户端将不可见/不可购买</div>
<div class="text-sm text-muted-color">ContentID: {{ unpublishItem?.content?.id ?? '-' }}</div>
<div class="text-sm text-muted-color">TenantID: {{ unpublishItem?.tenant?.id ?? unpublishItem?.content?.tenant_id ?? '-' }}</div>
</div>
<template #footer>
<Button label="取消" icon="pi pi-times" text @click="unpublishDialogVisible = false" :disabled="unpublishLoading" />
<Button label="确认下架" icon="pi pi-ban" severity="danger" @click="confirmUnpublish" :loading="unpublishLoading" />
</template>
</Dialog>
</template>