feat: 添加内容置顶功能,更新相关数据模型和前端视图
This commit is contained in:
@@ -41,6 +41,7 @@ type ContentUpdateForm struct {
|
|||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Price *float64 `json:"price"`
|
Price *float64 `json:"price"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
IsPinned *bool `json:"is_pinned"`
|
||||||
CoverIDs []string `json:"cover_ids"`
|
CoverIDs []string `json:"cover_ids"`
|
||||||
MediaIDs []string `json:"media_ids"`
|
MediaIDs []string `json:"media_ids"`
|
||||||
}
|
}
|
||||||
@@ -71,6 +72,7 @@ type CreatorContentItem struct {
|
|||||||
VideoCount int `json:"video_count"`
|
VideoCount int `json:"video_count"`
|
||||||
AudioCount int `json:"audio_count"`
|
AudioCount int `json:"audio_count"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
|
IsPinned bool `json:"is_pinned"`
|
||||||
IsPurchased bool `json:"is_purchased"`
|
IsPurchased bool `json:"is_purchased"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ type UploadInitForm struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UploadInitResponse struct {
|
type UploadInitResponse struct {
|
||||||
UploadID string `json:"upload_id"`
|
UploadID string `json:"upload_id"`
|
||||||
Key string `json:"key"` // For S3 direct
|
Key string `json:"key"` // For S3 direct
|
||||||
ChunkSize int64 `json:"chunk_size"`
|
ChunkSize int64 `json:"chunk_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UploadPartForm struct {
|
type UploadPartForm struct {
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func (s *common) InitUpload(ctx context.Context, userID int64, form *common_dto.
|
|||||||
localPath = "./storage"
|
localPath = "./storage"
|
||||||
}
|
}
|
||||||
tempDir := filepath.Join(localPath, "temp", uploadID)
|
tempDir := filepath.Join(localPath, "temp", uploadID)
|
||||||
if err := os.MkdirAll(tempDir, 0755); err != nil {
|
if err := os.MkdirAll(tempDir, 0o755); err != nil {
|
||||||
return nil, errorx.ErrInternalError.WithCause(err)
|
return nil, errorx.ErrInternalError.WithCause(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ func (s *common) CompleteUpload(ctx context.Context, userID int64, form *common_
|
|||||||
}
|
}
|
||||||
|
|
||||||
hash := hex.EncodeToString(hasher.Sum(nil))
|
hash := hex.EncodeToString(hasher.Sum(nil))
|
||||||
dst.Close(); // Ensure flush before potential removal
|
dst.Close() // Ensure flush before potential removal
|
||||||
os.RemoveAll(tempDir)
|
os.RemoveAll(tempDir)
|
||||||
|
|
||||||
// Deduplication Logic (Similar to Upload)
|
// Deduplication Logic (Similar to Upload)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"quyun/v2/app/errorx"
|
"quyun/v2/app/errorx"
|
||||||
@@ -129,6 +130,7 @@ func (s *creator) ListContents(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if filter.Key != nil && *filter.Key != "" {
|
if filter.Key != nil && *filter.Key != "" {
|
||||||
|
fmt.Printf("DEBUG: Filter Key: '%s'\n", *filter.Key)
|
||||||
q = q.Where(tbl.Key.Eq(*filter.Key))
|
q = q.Where(tbl.Key.Eq(*filter.Key))
|
||||||
}
|
}
|
||||||
if filter.Keyword != nil && *filter.Keyword != "" {
|
if filter.Keyword != nil && *filter.Keyword != "" {
|
||||||
@@ -205,6 +207,7 @@ func (s *creator) ListContents(
|
|||||||
VideoCount: videoCount,
|
VideoCount: videoCount,
|
||||||
AudioCount: audioCount,
|
AudioCount: audioCount,
|
||||||
Status: string(item.Status),
|
Status: string(item.Status),
|
||||||
|
IsPinned: item.IsPinned,
|
||||||
IsPurchased: false,
|
IsPurchased: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -311,11 +314,48 @@ func (s *creator) UpdateContent(
|
|||||||
if form.Status != "" {
|
if form.Status != "" {
|
||||||
contentUpdates.Status = consts.ContentStatus(form.Status)
|
contentUpdates.Status = consts.ContentStatus(form.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine final status
|
||||||
|
finalStatus := c.Status
|
||||||
|
if form.Status != "" {
|
||||||
|
finalStatus = consts.ContentStatus(form.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validation: Only published content can be pinned
|
||||||
|
if form.IsPinned != nil && *form.IsPinned && finalStatus != consts.ContentStatusPublished {
|
||||||
|
return errorx.ErrBadRequest.WithMsg("只有已发布的内容支持置顶")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform standard updates
|
||||||
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(contentUpdates)
|
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(contentUpdates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle IsPinned Logic
|
||||||
|
if finalStatus != consts.ContentStatusPublished {
|
||||||
|
// Force Unpin if not published
|
||||||
|
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.IsPinned.Value(false))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if form.IsPinned != nil {
|
||||||
|
// Explicit Pin Update requested
|
||||||
|
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.IsPinned.Value(*form.IsPinned))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If setting to true, unpin others
|
||||||
|
if *form.IsPinned {
|
||||||
|
if _, err := tx.Content.WithContext(ctx).
|
||||||
|
Where(tx.Content.TenantID.Eq(tid), tx.Content.ID.Neq(cid)).
|
||||||
|
UpdateSimple(tx.Content.IsPinned.Value(false)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Update Price
|
// 3. Update Price
|
||||||
// Check if price exists
|
// Check if price exists
|
||||||
if form.Price != nil {
|
if form.Price != nil {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- +goose Up
|
||||||
|
ALTER TABLE contents ADD COLUMN is_pinned BOOLEAN DEFAULT FALSE;
|
||||||
|
COMMENT ON COLUMN contents.is_pinned IS 'Whether content is pinned/featured';
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE contents DROP COLUMN is_pinned;
|
||||||
@@ -38,10 +38,11 @@ type Content struct {
|
|||||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
|
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
|
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
|
||||||
Key string `gorm:"column:key;type:character varying(32);comment:Musical key/tone" json:"key"` // Musical key/tone
|
Key string `gorm:"column:key;type:character varying(32);comment:Musical key/tone" json:"key"` // Musical key/tone
|
||||||
ContentAssets []*ContentAsset `gorm:"foreignKey:ContentID;references:ID" json:"content_assets,omitempty"`
|
IsPinned bool `gorm:"column:is_pinned;type:boolean;comment:Whether content is pinned/featured" json:"is_pinned"` // Whether content is pinned/featured
|
||||||
Comments []*Comment `gorm:"foreignKey:ContentID;references:ID" json:"comments,omitempty"`
|
Comments []*Comment `gorm:"foreignKey:ContentID;references:ID" json:"comments,omitempty"`
|
||||||
Author *User `gorm:"foreignKey:UserID;references:ID" json:"author,omitempty"`
|
Author *User `gorm:"foreignKey:UserID;references:ID" json:"author,omitempty"`
|
||||||
|
ContentAssets []*ContentAsset `gorm:"foreignKey:ContentID;references:ID" json:"content_assets,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quick operations without importing query package
|
// Quick operations without importing query package
|
||||||
|
|||||||
@@ -45,12 +45,7 @@ func newContent(db *gorm.DB, opts ...gen.DOOption) contentQuery {
|
|||||||
_contentQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
_contentQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||||
_contentQuery.DeletedAt = field.NewField(tableName, "deleted_at")
|
_contentQuery.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||||
_contentQuery.Key = field.NewString(tableName, "key")
|
_contentQuery.Key = field.NewString(tableName, "key")
|
||||||
_contentQuery.ContentAssets = contentQueryHasManyContentAssets{
|
_contentQuery.IsPinned = field.NewBool(tableName, "is_pinned")
|
||||||
db: db.Session(&gorm.Session{}),
|
|
||||||
|
|
||||||
RelationField: field.NewRelation("ContentAssets", "ContentAsset"),
|
|
||||||
}
|
|
||||||
|
|
||||||
_contentQuery.Comments = contentQueryHasManyComments{
|
_contentQuery.Comments = contentQueryHasManyComments{
|
||||||
db: db.Session(&gorm.Session{}),
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
@@ -63,6 +58,12 @@ func newContent(db *gorm.DB, opts ...gen.DOOption) contentQuery {
|
|||||||
RelationField: field.NewRelation("Author", "User"),
|
RelationField: field.NewRelation("Author", "User"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_contentQuery.ContentAssets = contentQueryHasManyContentAssets{
|
||||||
|
db: db.Session(&gorm.Session{}),
|
||||||
|
|
||||||
|
RelationField: field.NewRelation("ContentAssets", "ContentAsset"),
|
||||||
|
}
|
||||||
|
|
||||||
_contentQuery.fillFieldMap()
|
_contentQuery.fillFieldMap()
|
||||||
|
|
||||||
return _contentQuery
|
return _contentQuery
|
||||||
@@ -92,12 +93,13 @@ type contentQuery struct {
|
|||||||
UpdatedAt field.Time
|
UpdatedAt field.Time
|
||||||
DeletedAt field.Field
|
DeletedAt field.Field
|
||||||
Key field.String // Musical key/tone
|
Key field.String // Musical key/tone
|
||||||
ContentAssets contentQueryHasManyContentAssets
|
IsPinned field.Bool // Whether content is pinned/featured
|
||||||
|
Comments contentQueryHasManyComments
|
||||||
Comments contentQueryHasManyComments
|
|
||||||
|
|
||||||
Author contentQueryBelongsToAuthor
|
Author contentQueryBelongsToAuthor
|
||||||
|
|
||||||
|
ContentAssets contentQueryHasManyContentAssets
|
||||||
|
|
||||||
fieldMap map[string]field.Expr
|
fieldMap map[string]field.Expr
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +135,7 @@ func (c *contentQuery) updateTableName(table string) *contentQuery {
|
|||||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||||
c.Key = field.NewString(table, "key")
|
c.Key = field.NewString(table, "key")
|
||||||
|
c.IsPinned = field.NewBool(table, "is_pinned")
|
||||||
|
|
||||||
c.fillFieldMap()
|
c.fillFieldMap()
|
||||||
|
|
||||||
@@ -165,7 +168,7 @@ func (c *contentQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *contentQuery) fillFieldMap() {
|
func (c *contentQuery) fillFieldMap() {
|
||||||
c.fieldMap = make(map[string]field.Expr, 23)
|
c.fieldMap = make(map[string]field.Expr, 24)
|
||||||
c.fieldMap["id"] = c.ID
|
c.fieldMap["id"] = c.ID
|
||||||
c.fieldMap["tenant_id"] = c.TenantID
|
c.fieldMap["tenant_id"] = c.TenantID
|
||||||
c.fieldMap["user_id"] = c.UserID
|
c.fieldMap["user_id"] = c.UserID
|
||||||
@@ -186,109 +189,29 @@ func (c *contentQuery) fillFieldMap() {
|
|||||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
c.fieldMap["deleted_at"] = c.DeletedAt
|
||||||
c.fieldMap["key"] = c.Key
|
c.fieldMap["key"] = c.Key
|
||||||
|
c.fieldMap["is_pinned"] = c.IsPinned
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c contentQuery) clone(db *gorm.DB) contentQuery {
|
func (c contentQuery) clone(db *gorm.DB) contentQuery {
|
||||||
c.contentQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
c.contentQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||||
c.ContentAssets.db = db.Session(&gorm.Session{Initialized: true})
|
|
||||||
c.ContentAssets.db.Statement.ConnPool = db.Statement.ConnPool
|
|
||||||
c.Comments.db = db.Session(&gorm.Session{Initialized: true})
|
c.Comments.db = db.Session(&gorm.Session{Initialized: true})
|
||||||
c.Comments.db.Statement.ConnPool = db.Statement.ConnPool
|
c.Comments.db.Statement.ConnPool = db.Statement.ConnPool
|
||||||
c.Author.db = db.Session(&gorm.Session{Initialized: true})
|
c.Author.db = db.Session(&gorm.Session{Initialized: true})
|
||||||
c.Author.db.Statement.ConnPool = db.Statement.ConnPool
|
c.Author.db.Statement.ConnPool = db.Statement.ConnPool
|
||||||
|
c.ContentAssets.db = db.Session(&gorm.Session{Initialized: true})
|
||||||
|
c.ContentAssets.db.Statement.ConnPool = db.Statement.ConnPool
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c contentQuery) replaceDB(db *gorm.DB) contentQuery {
|
func (c contentQuery) replaceDB(db *gorm.DB) contentQuery {
|
||||||
c.contentQueryDo.ReplaceDB(db)
|
c.contentQueryDo.ReplaceDB(db)
|
||||||
c.ContentAssets.db = db.Session(&gorm.Session{})
|
|
||||||
c.Comments.db = db.Session(&gorm.Session{})
|
c.Comments.db = db.Session(&gorm.Session{})
|
||||||
c.Author.db = db.Session(&gorm.Session{})
|
c.Author.db = db.Session(&gorm.Session{})
|
||||||
|
c.ContentAssets.db = db.Session(&gorm.Session{})
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
type contentQueryHasManyContentAssets struct {
|
|
||||||
db *gorm.DB
|
|
||||||
|
|
||||||
field.RelationField
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssets) Where(conds ...field.Expr) *contentQueryHasManyContentAssets {
|
|
||||||
if len(conds) == 0 {
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
exprs := make([]clause.Expression, 0, len(conds))
|
|
||||||
for _, cond := range conds {
|
|
||||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
||||||
}
|
|
||||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssets) WithContext(ctx context.Context) *contentQueryHasManyContentAssets {
|
|
||||||
a.db = a.db.WithContext(ctx)
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssets) Session(session *gorm.Session) *contentQueryHasManyContentAssets {
|
|
||||||
a.db = a.db.Session(session)
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssets) Model(m *Content) *contentQueryHasManyContentAssetsTx {
|
|
||||||
return &contentQueryHasManyContentAssetsTx{a.db.Model(m).Association(a.Name())}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssets) Unscoped() *contentQueryHasManyContentAssets {
|
|
||||||
a.db = a.db.Unscoped()
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
type contentQueryHasManyContentAssetsTx struct{ tx *gorm.Association }
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssetsTx) Find() (result []*ContentAsset, err error) {
|
|
||||||
return result, a.tx.Find(&result)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssetsTx) Append(values ...*ContentAsset) (err error) {
|
|
||||||
targetValues := make([]interface{}, len(values))
|
|
||||||
for i, v := range values {
|
|
||||||
targetValues[i] = v
|
|
||||||
}
|
|
||||||
return a.tx.Append(targetValues...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssetsTx) Replace(values ...*ContentAsset) (err error) {
|
|
||||||
targetValues := make([]interface{}, len(values))
|
|
||||||
for i, v := range values {
|
|
||||||
targetValues[i] = v
|
|
||||||
}
|
|
||||||
return a.tx.Replace(targetValues...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssetsTx) Delete(values ...*ContentAsset) (err error) {
|
|
||||||
targetValues := make([]interface{}, len(values))
|
|
||||||
for i, v := range values {
|
|
||||||
targetValues[i] = v
|
|
||||||
}
|
|
||||||
return a.tx.Delete(targetValues...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssetsTx) Clear() error {
|
|
||||||
return a.tx.Clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssetsTx) Count() int64 {
|
|
||||||
return a.tx.Count()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a contentQueryHasManyContentAssetsTx) Unscoped() *contentQueryHasManyContentAssetsTx {
|
|
||||||
a.tx = a.tx.Unscoped()
|
|
||||||
return &a
|
|
||||||
}
|
|
||||||
|
|
||||||
type contentQueryHasManyComments struct {
|
type contentQueryHasManyComments struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
|
||||||
@@ -451,6 +374,87 @@ func (a contentQueryBelongsToAuthorTx) Unscoped() *contentQueryBelongsToAuthorTx
|
|||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type contentQueryHasManyContentAssets struct {
|
||||||
|
db *gorm.DB
|
||||||
|
|
||||||
|
field.RelationField
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssets) Where(conds ...field.Expr) *contentQueryHasManyContentAssets {
|
||||||
|
if len(conds) == 0 {
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
exprs := make([]clause.Expression, 0, len(conds))
|
||||||
|
for _, cond := range conds {
|
||||||
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||||
|
}
|
||||||
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssets) WithContext(ctx context.Context) *contentQueryHasManyContentAssets {
|
||||||
|
a.db = a.db.WithContext(ctx)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssets) Session(session *gorm.Session) *contentQueryHasManyContentAssets {
|
||||||
|
a.db = a.db.Session(session)
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssets) Model(m *Content) *contentQueryHasManyContentAssetsTx {
|
||||||
|
return &contentQueryHasManyContentAssetsTx{a.db.Model(m).Association(a.Name())}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssets) Unscoped() *contentQueryHasManyContentAssets {
|
||||||
|
a.db = a.db.Unscoped()
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
|
type contentQueryHasManyContentAssetsTx struct{ tx *gorm.Association }
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssetsTx) Find() (result []*ContentAsset, err error) {
|
||||||
|
return result, a.tx.Find(&result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssetsTx) Append(values ...*ContentAsset) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Append(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssetsTx) Replace(values ...*ContentAsset) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Replace(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssetsTx) Delete(values ...*ContentAsset) (err error) {
|
||||||
|
targetValues := make([]interface{}, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
targetValues[i] = v
|
||||||
|
}
|
||||||
|
return a.tx.Delete(targetValues...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssetsTx) Clear() error {
|
||||||
|
return a.tx.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssetsTx) Count() int64 {
|
||||||
|
return a.tx.Count()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a contentQueryHasManyContentAssetsTx) Unscoped() *contentQueryHasManyContentAssetsTx {
|
||||||
|
a.tx = a.tx.Unscoped()
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
type contentQueryDo struct{ gen.DO }
|
type contentQueryDo struct{ gen.DO }
|
||||||
|
|
||||||
func (c contentQueryDo) Debug() *contentQueryDo {
|
func (c contentQueryDo) Debug() *contentQueryDo {
|
||||||
|
|||||||
@@ -61,64 +61,73 @@
|
|||||||
<!-- Info -->
|
<!-- Info -->
|
||||||
<div class="flex-1 min-w-0 flex flex-col justify-between">
|
<div class="flex-1 min-w-0 flex flex-col justify-between">
|
||||||
<div>
|
<div>
|
||||||
<div class="flex items-center justify-between mb-2">
|
<div class="flex items-center justify-between mb-2">
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<span class="text-xs px-1.5 py-0.5 border rounded text-slate-500" v-if="item.genre">[{{ getGenreLabel(item.genre) }}]</span>
|
<span v-if="item.is_pinned" class="bg-red-600 text-white text-xs px-1.5 py-0.5 rounded font-bold">置顶</span>
|
||||||
<span class="text-xs px-1.5 py-0.5 border rounded text-slate-500" v-if="item.key">[{{ item.key }}]</span>
|
<span class="text-xs px-1.5 py-0.5 border rounded text-slate-500" v-if="item.genre">[{{ getGenreLabel(item.genre) }}]</span>
|
||||||
<h3
|
<span class="text-xs px-1.5 py-0.5 border rounded text-slate-500" v-if="item.key">[{{ item.key }}]</span>
|
||||||
class="font-bold text-slate-900 text-lg truncate hover:text-primary-600 cursor-pointer transition-colors"
|
<h3
|
||||||
@click="$router.push(`/creator/contents/${item.id}`)">
|
class="font-bold text-slate-900 text-lg truncate hover:text-primary-600 cursor-pointer transition-colors"
|
||||||
{{ item.title }}</h3>
|
@click="$router.push(`/creator/contents/${item.id}`)">
|
||||||
</div>
|
{{ item.title }}</h3>
|
||||||
<!-- Status Badge -->
|
</div>
|
||||||
<div class="flex items-center gap-2">
|
<!-- Status Badge -->
|
||||||
<span v-if="item.status === 'blocked'"
|
<div class="flex items-center gap-2">
|
||||||
class="text-red-500 text-xs flex items-center gap-1 cursor-help" title="已被封禁">
|
<span v-if="item.status === 'blocked'"
|
||||||
<i class="pi pi-info-circle"></i> 封禁
|
class="text-red-500 text-xs flex items-center gap-1 cursor-help" title="已被封禁">
|
||||||
</span>
|
<i class="pi pi-info-circle"></i> 封禁
|
||||||
<span class="px-2.5 py-1 rounded text-xs font-bold"
|
</span>
|
||||||
:class="statusStyle(item.status).bg + ' ' + statusStyle(item.status).text">
|
<span class="px-2.5 py-1 rounded text-xs font-bold"
|
||||||
{{ statusStyle(item.status).label }}
|
:class="statusStyle(item.status).bg + ' ' + statusStyle(item.status).text">
|
||||||
</span>
|
{{ statusStyle(item.status).label }}
|
||||||
</div>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="flex items-center gap-6 text-sm text-slate-500">
|
|
||||||
<span v-if="item.price > 0" class="text-red-600 font-bold">¥ {{ item.price.toFixed(2) }}</span>
|
<div class="flex items-center gap-6 text-sm text-slate-500">
|
||||||
<span v-else class="text-green-600 font-bold">免费</span>
|
<span v-if="item.price > 0" class="text-red-600 font-bold">¥ {{ item.price.toFixed(2) }}</span>
|
||||||
|
<span v-else class="text-green-600 font-bold">免费</span>
|
||||||
<span class="flex items-center gap-1" title="图片" v-if="item.image_count > 0">
|
|
||||||
<i class="pi pi-image"></i> {{ item.image_count }}
|
<span class="flex items-center gap-1" title="图片" v-if="item.image_count > 0">
|
||||||
</span>
|
<i class="pi pi-image"></i> {{ item.image_count }}
|
||||||
<span class="flex items-center gap-1" title="视频" v-if="item.video_count > 0">
|
</span>
|
||||||
<i class="pi pi-video"></i> {{ item.video_count }}
|
<span class="flex items-center gap-1" title="视频" v-if="item.video_count > 0">
|
||||||
</span>
|
<i class="pi pi-video"></i> {{ item.video_count }}
|
||||||
<span class="flex items-center gap-1" title="音频" v-if="item.audio_count > 0">
|
</span>
|
||||||
<i class="pi pi-microphone"></i> {{ item.audio_count }}
|
<span class="flex items-center gap-1" title="音频" v-if="item.audio_count > 0">
|
||||||
</span>
|
<i class="pi pi-microphone"></i> {{ item.audio_count }}
|
||||||
|
</span>
|
||||||
<span title="浏览量"><i class="pi pi-eye mr-1"></i> {{ item.views }}</span>
|
|
||||||
<span title="点赞数"><i class="pi pi-thumbs-up mr-1"></i> {{ item.likes }}</span>
|
<span title="浏览量"><i class="pi pi-eye mr-1"></i> {{ item.views }}</span>
|
||||||
<!-- Date field missing in DTO, using hardcoded or omitting -->
|
<span title="点赞数"><i class="pi pi-thumbs-up mr-1"></i> {{ item.likes }}</span>
|
||||||
</div>
|
<!-- Date field missing in DTO, using hardcoded or omitting -->
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<!-- Actions -->
|
|
||||||
<div class="flex items-center gap-4 pt-3 border-t border-slate-50 mt-2">
|
<!-- Actions -->
|
||||||
<button class="text-sm text-slate-500 hover:text-primary-600 font-medium cursor-pointer"
|
<div class="flex items-center gap-4 pt-3 border-t border-slate-50 mt-2">
|
||||||
@click="$router.push(`/creator/contents/${item.id}`)"><i class="pi pi-file-edit mr-1"></i>
|
<button class="text-sm text-slate-500 hover:text-primary-600 font-medium cursor-pointer" @click="$router.push(`/creator/contents/${item.id}`)"><i
|
||||||
编辑</button>
|
class="pi pi-file-edit mr-1"></i> 编辑</button>
|
||||||
<button v-if="item.status === 'published'"
|
<button v-if="item.status === 'published'"
|
||||||
class="text-sm text-slate-500 hover:text-orange-600 font-medium cursor-pointer"
|
class="text-sm text-slate-500 hover:text-orange-600 font-medium cursor-pointer"
|
||||||
@click="handleStatusChange(item.id, 'unpublished')"><i
|
@click="handleStatusChange(item.id, 'unpublished')"><i
|
||||||
class="pi pi-arrow-down mr-1"></i> 下架</button>
|
class="pi pi-arrow-down mr-1"></i> 下架</button>
|
||||||
<button v-if="item.status === 'unpublished'"
|
<button v-if="item.status === 'unpublished'"
|
||||||
class="text-sm text-slate-500 hover:text-green-600 font-medium cursor-pointer"
|
class="text-sm text-slate-500 hover:text-green-600 font-medium cursor-pointer"
|
||||||
@click="handleStatusChange(item.id, 'published')"><i
|
@click="handleStatusChange(item.id, 'published')"><i
|
||||||
class="pi pi-arrow-up mr-1"></i> 上架</button>
|
class="pi pi-arrow-up mr-1"></i> 上架</button>
|
||||||
<button class="text-sm text-slate-500 hover:text-red-600 font-medium ml-auto cursor-pointer"
|
<template v-if="item.status === 'published'">
|
||||||
@click="handleDelete(item.id)"><i class="pi pi-trash mr-1"></i> 删除</button>
|
<button v-if="!item.is_pinned"
|
||||||
</div>
|
class="text-sm text-slate-500 hover:text-blue-600 font-medium cursor-pointer"
|
||||||
|
@click="handlePin(item.id, true)"><i
|
||||||
|
class="pi pi-bookmark mr-1"></i> 置顶</button>
|
||||||
|
<button v-else
|
||||||
|
class="text-sm text-blue-600 font-medium cursor-pointer"
|
||||||
|
@click="handlePin(item.id, false)"><i
|
||||||
|
class="pi pi-bookmark-fill mr-1"></i> 取消置顶</button>
|
||||||
|
</template> <button class="text-sm text-slate-500 hover:text-red-600 font-medium ml-auto cursor-pointer" @click="handleDelete(item.id)"><i
|
||||||
|
class="pi pi-trash mr-1"></i> 删除</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -129,11 +138,14 @@
|
|||||||
import { onMounted, ref, watch } from 'vue';
|
import { onMounted, ref, watch } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useToast } from 'primevue/usetoast';
|
import { useToast } from 'primevue/usetoast';
|
||||||
|
import { useConfirm } from 'primevue/useconfirm';
|
||||||
|
import ConfirmDialog from 'primevue/confirmdialog';
|
||||||
import { commonApi } from '../../api/common';
|
import { commonApi } from '../../api/common';
|
||||||
import { creatorApi } from '../../api/creator';
|
import { creatorApi } from '../../api/creator';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
const confirm = useConfirm();
|
||||||
const contents = ref([]);
|
const contents = ref([]);
|
||||||
const filterStatus = ref('all');
|
const filterStatus = ref('all');
|
||||||
const filterGenre = ref('all');
|
const filterGenre = ref('all');
|
||||||
@@ -206,24 +218,61 @@ const statusStyle = (status) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleStatusChange = async (id, status) => {
|
const handleStatusChange = (id, status) => {
|
||||||
try {
|
const action = status === 'published' ? '上架' : '下架';
|
||||||
await creatorApi.updateContent(id, { status });
|
confirm.require({
|
||||||
toast.add({ severity: 'success', summary: '更新成功', life: 2000 });
|
message: `确定要${action}该内容吗?`,
|
||||||
fetchContents();
|
header: '操作确认',
|
||||||
} catch (e) {
|
icon: 'pi pi-exclamation-triangle',
|
||||||
console.error(e);
|
acceptClass: status === 'unpublished' ? 'p-button-danger' : '',
|
||||||
toast.add({ severity: 'error', summary: '更新失败', detail: e.message, life: 3000 });
|
accept: async () => {
|
||||||
}
|
try {
|
||||||
|
await creatorApi.updateContent(id, { status });
|
||||||
|
toast.add({ severity: 'success', summary: '更新成功', life: 2000 });
|
||||||
|
fetchContents();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
toast.add({ severity: 'error', summary: '更新失败', detail: e.message, life: 3000 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = async (id) => {
|
const handlePin = (id, isPinned) => {
|
||||||
if (!confirm('确定要删除吗?')) return;
|
const action = isPinned ? '置顶' : '取消置顶';
|
||||||
try {
|
confirm.require({
|
||||||
await creatorApi.deleteContent(id);
|
message: `确定要${action}该内容吗?`,
|
||||||
fetchContents();
|
header: '操作确认',
|
||||||
} catch (e) {
|
icon: 'pi pi-info-circle',
|
||||||
console.error(e);
|
accept: async () => {
|
||||||
}
|
try {
|
||||||
|
await creatorApi.updateContent(id, { is_pinned: isPinned });
|
||||||
|
toast.add({ severity: 'success', summary: isPinned ? '已置顶' : '已取消置顶', life: 2000 });
|
||||||
|
fetchContents();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
toast.add({ severity: 'error', summary: '操作失败', detail: e.message, life: 3000 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = (id) => {
|
||||||
|
confirm.require({
|
||||||
|
message: '确定要删除该内容吗?此操作不可恢复。',
|
||||||
|
header: '删除确认',
|
||||||
|
icon: 'pi pi-exclamation-triangle',
|
||||||
|
acceptClass: 'p-button-danger',
|
||||||
|
accept: async () => {
|
||||||
|
try {
|
||||||
|
await creatorApi.deleteContent(id);
|
||||||
|
fetchContents();
|
||||||
|
toast.add({ severity: 'success', summary: '删除成功', life: 2000 });
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
toast.add({ severity: 'error', summary: '删除失败', detail: e.message, life: 3000 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user