feat: add user_list
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
)
|
||||
|
||||
type TenantFilter struct {
|
||||
@@ -35,3 +36,7 @@ func (form *TenantExpireUpdateForm) ParseDuration() (time.Duration, error) {
|
||||
}
|
||||
return duration, nil
|
||||
}
|
||||
|
||||
type TenantStatusUpdateForm struct {
|
||||
Status consts.TenantStatus `json:"status" validate:"required,oneof=normal disabled"`
|
||||
}
|
||||
|
||||
20
backend/app/http/super/dto/user.go
Normal file
20
backend/app/http/super/dto/user.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
)
|
||||
|
||||
type UserPageFilter struct {
|
||||
requests.Pagination
|
||||
requests.SortQueryFilter
|
||||
|
||||
Username *string `query:"username"`
|
||||
TenantID *int64 `query:"tenant_id"`
|
||||
}
|
||||
|
||||
type UserItem struct {
|
||||
*models.User
|
||||
|
||||
StatusDescription string `json:"status_description,omitempty"`
|
||||
}
|
||||
@@ -26,13 +26,13 @@ func Provide(opts ...opt.Option) error {
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
authController *authController,
|
||||
staticController *staticController,
|
||||
tenant *tenant,
|
||||
user *user,
|
||||
) (contracts.HttpRoute, error) {
|
||||
obj := &Routes{
|
||||
authController: authController,
|
||||
staticController: staticController,
|
||||
tenant: tenant,
|
||||
authController: authController,
|
||||
tenant: tenant,
|
||||
user: user,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
@@ -56,5 +56,12 @@ func Provide(opts ...opt.Option) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func() (*user, error) {
|
||||
obj := &user{}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/super/dto"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.ipao.vip/atom"
|
||||
_ "go.ipao.vip/atom/contracts"
|
||||
. "go.ipao.vip/atom/fen"
|
||||
"quyun/v2/app/http/super/dto"
|
||||
)
|
||||
|
||||
// Routes implements the HttpRoute contract and provides route registration
|
||||
@@ -21,9 +20,9 @@ import (
|
||||
type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
// Controller instances
|
||||
authController *authController
|
||||
staticController *staticController
|
||||
tenant *tenant
|
||||
authController *authController
|
||||
tenant *tenant
|
||||
user *user
|
||||
}
|
||||
|
||||
// Prepare initializes the routes provider with logging configuration.
|
||||
@@ -59,8 +58,18 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
PathParam[int64]("tenantID"),
|
||||
Body[dto.TenantExpireUpdateForm]("form"),
|
||||
))
|
||||
|
||||
router.Get("/super/*", Func(r.staticController.static))
|
||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID/status -> tenant.updateStatus")
|
||||
router.Patch("/super/v1/tenants/:tenantID/status", Func2(
|
||||
r.tenant.updateStatus,
|
||||
PathParam[int64]("tenantID"),
|
||||
Body[dto.TenantStatusUpdateForm]("form"),
|
||||
))
|
||||
// Register routes for controller: user
|
||||
r.log.Debugf("Registering route: Get /super/v1/users -> user.list")
|
||||
router.Get("/super/v1/users", DataFunc1(
|
||||
r.user.list,
|
||||
Query[dto.UserPageFilter]("filter"),
|
||||
))
|
||||
|
||||
r.log.Info("Successfully registered all routes")
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type staticController struct{}
|
||||
|
||||
// Static
|
||||
//
|
||||
// @Tags Super
|
||||
// @Router /super/*
|
||||
func (ctl *staticController) static(ctx fiber.Ctx) error {
|
||||
root := "/home/rogee/Projects/quyun_v2/frontend/superadmin/dist/"
|
||||
param := ctx.Params("*")
|
||||
file := filepath.Join(root, param)
|
||||
// // Static
|
||||
// //
|
||||
// // @Tags Super
|
||||
// // @Router /super/*
|
||||
// func (ctl *staticController) static(ctx fiber.Ctx) error {
|
||||
// root := "/home/rogee/Projects/quyun_v2/frontend/superadmin/dist/"
|
||||
// param := ctx.Params("*")
|
||||
// file := filepath.Join(root, param)
|
||||
|
||||
// if file not exits use index.html
|
||||
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
file = filepath.Join(root, "index.html")
|
||||
}
|
||||
// // if file not exits use index.html
|
||||
// if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
// file = filepath.Join(root, "index.html")
|
||||
// }
|
||||
|
||||
return ctx.SendFile(file)
|
||||
}
|
||||
// return ctx.SendFile(file)
|
||||
// }
|
||||
|
||||
@@ -47,3 +47,19 @@ func (*tenant) updateExpire(ctx fiber.Ctx, tenantID int64, form *dto.TenantExpir
|
||||
|
||||
return services.Tenant.AddExpireDuration(ctx, tenantID, duration)
|
||||
}
|
||||
|
||||
// updateStatus
|
||||
//
|
||||
// @Summary 更新租户状态
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantID path int64 true "TenantID"
|
||||
// @Param form body dto.TenantStatusUpdateForm true "Form"
|
||||
//
|
||||
// @Router /super/v1/tenants/:tenantID/status [patch]
|
||||
// @Bind tenantID path
|
||||
// @Bind form body
|
||||
func (*tenant) updateStatus(ctx fiber.Ctx, tenantID int64, form *dto.TenantStatusUpdateForm) error {
|
||||
return services.Tenant.UpdateStatus(ctx, tenantID, form.Status)
|
||||
}
|
||||
|
||||
28
backend/app/http/super/user.go
Normal file
28
backend/app/http/super/user.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/super/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
_ "quyun/v2/database/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type user struct{}
|
||||
|
||||
// list
|
||||
//
|
||||
// @Summary 租户列表
|
||||
// @Tags Super
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param filter query dto.UserPageFilter true "Filter"
|
||||
// @Success 200 {object} requests.Pager{items=dto.UserItem}
|
||||
//
|
||||
// @Router /super/v1/users [get]
|
||||
// @Bind filter query
|
||||
func (*user) list(ctx fiber.Ctx, filter *dto.UserPageFilter) (*requests.Pager, error) {
|
||||
return services.User.Page(ctx, filter)
|
||||
}
|
||||
@@ -195,3 +195,21 @@ func (t *tenant) AddExpireDuration(ctx context.Context, tenantID int64, duration
|
||||
}
|
||||
return m.Save(ctx)
|
||||
}
|
||||
|
||||
// UpdateStatus
|
||||
func (t *tenant) UpdateStatus(ctx context.Context, tenantID int64, status consts.TenantStatus) error {
|
||||
logrus.WithField("tenant_id", tenantID).WithField("status", status).Info("update tenant status")
|
||||
|
||||
m, err := t.FindByID(ctx, tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.Status = status
|
||||
_, err = m.Update(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ package services
|
||||
import (
|
||||
"context"
|
||||
|
||||
"quyun/v2/app/http/super/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/samber/lo"
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
@@ -52,16 +54,8 @@ func (t *user) SetStatus(ctx context.Context, userID int64, status consts.UserSt
|
||||
return m.Save(ctx)
|
||||
}
|
||||
|
||||
type UserPageFilter struct {
|
||||
requests.Pagination
|
||||
requests.SortQueryFilter
|
||||
|
||||
Username *string `query:"username"`
|
||||
TenantID *int64 `query:"tenant_id"`
|
||||
}
|
||||
|
||||
// Page
|
||||
func (t *user) Page(ctx context.Context, filter *UserPageFilter) (*requests.Pager, error) {
|
||||
func (t *user) Page(ctx context.Context, filter *dto.UserPageFilter) (*requests.Pager, error) {
|
||||
tbl, query := models.UserQuery.QueryContext(ctx)
|
||||
|
||||
conds := []gen.Condition{}
|
||||
@@ -76,11 +70,18 @@ func (t *user) Page(ctx context.Context, filter *UserPageFilter) (*requests.Page
|
||||
}
|
||||
|
||||
filter.Pagination.Format()
|
||||
items, total, err := query.Where(conds...).Order(tbl.ID.Desc()).FindByPage(int(filter.Offset()), int(filter.Limit))
|
||||
users, total, err := query.Where(conds...).Order(tbl.ID.Desc()).FindByPage(int(filter.Offset()), int(filter.Limit))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := lo.Map(users, func(model *models.User, _ int) *dto.UserItem {
|
||||
return &dto.UserItem{
|
||||
User: model,
|
||||
StatusDescription: model.Status.Description(),
|
||||
}
|
||||
})
|
||||
|
||||
return &requests.Pager{
|
||||
Pagination: filter.Pagination,
|
||||
Total: total,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"quyun/v2/app/commands/testx"
|
||||
"quyun/v2/app/http/super/dto"
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
@@ -115,7 +116,7 @@ func (t *UserTestSuite) Test_Page() {
|
||||
err := m.Create(t.T().Context())
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
pager, err := User.Page(t.T().Context(), &UserPageFilter{
|
||||
pager, err := User.Page(t.T().Context(), &dto.UserPageFilter{
|
||||
Username: &username,
|
||||
})
|
||||
|
||||
@@ -192,7 +193,7 @@ func (t *UserTestSuite) Test_Page() {
|
||||
So(err, ShouldBeNil)
|
||||
}
|
||||
|
||||
pager, err := User.Page(t.T().Context(), &UserPageFilter{
|
||||
pager, err := User.Page(t.T().Context(), &dto.UserPageFilter{
|
||||
TenantID: lo.ToPtr(int64(1)),
|
||||
})
|
||||
|
||||
|
||||
@@ -151,9 +151,8 @@ const docTemplate = `{
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/v1/medias/{id}": {
|
||||
"post": {
|
||||
"description": "Test",
|
||||
"/super/v1/tenants/{tenantID}/status": {
|
||||
"patch": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
@@ -161,27 +160,52 @@ const docTemplate = `{
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Test"
|
||||
"Super"
|
||||
],
|
||||
"summary": "Test",
|
||||
"summary": "更新租户状态",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ID",
|
||||
"name": "id",
|
||||
"format": "int64",
|
||||
"description": "TenantID",
|
||||
"name": "tenantID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "年龄",
|
||||
"name": "age",
|
||||
"description": "Form",
|
||||
"name": "form",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.TenantStatusUpdateForm"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/super/v1/users": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Super"
|
||||
],
|
||||
"summary": "租户列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "asc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "名称",
|
||||
"name": "name",
|
||||
"name": "desc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
@@ -193,11 +217,21 @@ const docTemplate = `{
|
||||
"type": "integer",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "tenantID",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "username",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "成功",
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
@@ -206,8 +240,8 @@ const docTemplate = `{
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"list": {
|
||||
"$ref": "#/definitions/v1.ResponseItem"
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.UserItem"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,16 +354,17 @@ const docTemplate = `{
|
||||
"status": {
|
||||
"$ref": "#/definitions/consts.TenantStatus"
|
||||
},
|
||||
"status_description": {
|
||||
"type": "string"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"userBalance": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
"user_balance": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userCount": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
"user_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"user_id": {
|
||||
"type": "integer"
|
||||
@@ -345,6 +380,78 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.TenantStatusUpdateForm": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"status"
|
||||
],
|
||||
"properties": {
|
||||
"status": {
|
||||
"enum": [
|
||||
"normal",
|
||||
"disabled"
|
||||
],
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/consts.TenantStatus"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.UserItem": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"deleted_at": {
|
||||
"$ref": "#/definitions/gorm.DeletedAt"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"metas": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"owned": {
|
||||
"$ref": "#/definitions/models.Tenant"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/consts.Role"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/definitions/consts.UserStatus"
|
||||
},
|
||||
"status_description": {
|
||||
"type": "string"
|
||||
},
|
||||
"tenants": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/models.Tenant"
|
||||
}
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"verified_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gorm.DeletedAt": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -465,9 +572,6 @@ const docTemplate = `{
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1.ResponseItem": {
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
|
||||
@@ -145,9 +145,8 @@
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/v1/medias/{id}": {
|
||||
"post": {
|
||||
"description": "Test",
|
||||
"/super/v1/tenants/{tenantID}/status": {
|
||||
"patch": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
@@ -155,27 +154,52 @@
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Test"
|
||||
"Super"
|
||||
],
|
||||
"summary": "Test",
|
||||
"summary": "更新租户状态",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ID",
|
||||
"name": "id",
|
||||
"format": "int64",
|
||||
"description": "TenantID",
|
||||
"name": "tenantID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "年龄",
|
||||
"name": "age",
|
||||
"description": "Form",
|
||||
"name": "form",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.TenantStatusUpdateForm"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/super/v1/users": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Super"
|
||||
],
|
||||
"summary": "租户列表",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"name": "asc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "名称",
|
||||
"name": "name",
|
||||
"name": "desc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
@@ -187,11 +211,21 @@
|
||||
"type": "integer",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"name": "tenantID",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"name": "username",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "成功",
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"allOf": [
|
||||
{
|
||||
@@ -200,8 +234,8 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"list": {
|
||||
"$ref": "#/definitions/v1.ResponseItem"
|
||||
"items": {
|
||||
"$ref": "#/definitions/dto.UserItem"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -314,16 +348,17 @@
|
||||
"status": {
|
||||
"$ref": "#/definitions/consts.TenantStatus"
|
||||
},
|
||||
"status_description": {
|
||||
"type": "string"
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"userBalance": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
"user_balance": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userCount": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
"user_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"user_id": {
|
||||
"type": "integer"
|
||||
@@ -339,6 +374,78 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.TenantStatusUpdateForm": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"status"
|
||||
],
|
||||
"properties": {
|
||||
"status": {
|
||||
"enum": [
|
||||
"normal",
|
||||
"disabled"
|
||||
],
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/consts.TenantStatus"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.UserItem": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"created_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"deleted_at": {
|
||||
"$ref": "#/definitions/gorm.DeletedAt"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"metas": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"owned": {
|
||||
"$ref": "#/definitions/models.Tenant"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/consts.Role"
|
||||
}
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/definitions/consts.UserStatus"
|
||||
},
|
||||
"status_description": {
|
||||
"type": "string"
|
||||
},
|
||||
"tenants": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/models.Tenant"
|
||||
}
|
||||
},
|
||||
"updated_at": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
},
|
||||
"verified_at": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gorm.DeletedAt": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -459,9 +566,6 @@
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1.ResponseItem": {
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"securityDefinitions": {
|
||||
|
||||
@@ -71,16 +71,16 @@ definitions:
|
||||
type: string
|
||||
status:
|
||||
$ref: '#/definitions/consts.TenantStatus'
|
||||
status_description:
|
||||
type: string
|
||||
updated_at:
|
||||
type: string
|
||||
user_balance:
|
||||
type: integer
|
||||
user_count:
|
||||
type: integer
|
||||
user_id:
|
||||
type: integer
|
||||
userBalance:
|
||||
format: int64
|
||||
type: integer
|
||||
userCount:
|
||||
format: int64
|
||||
type: integer
|
||||
users:
|
||||
items:
|
||||
$ref: '#/definitions/models.User'
|
||||
@@ -88,6 +88,52 @@ definitions:
|
||||
uuid:
|
||||
type: string
|
||||
type: object
|
||||
dto.TenantStatusUpdateForm:
|
||||
properties:
|
||||
status:
|
||||
allOf:
|
||||
- $ref: '#/definitions/consts.TenantStatus'
|
||||
enum:
|
||||
- normal
|
||||
- disabled
|
||||
required:
|
||||
- status
|
||||
type: object
|
||||
dto.UserItem:
|
||||
properties:
|
||||
created_at:
|
||||
type: string
|
||||
deleted_at:
|
||||
$ref: '#/definitions/gorm.DeletedAt'
|
||||
id:
|
||||
type: integer
|
||||
metas:
|
||||
items:
|
||||
type: integer
|
||||
type: array
|
||||
owned:
|
||||
$ref: '#/definitions/models.Tenant'
|
||||
password:
|
||||
type: string
|
||||
roles:
|
||||
items:
|
||||
$ref: '#/definitions/consts.Role'
|
||||
type: array
|
||||
status:
|
||||
$ref: '#/definitions/consts.UserStatus'
|
||||
status_description:
|
||||
type: string
|
||||
tenants:
|
||||
items:
|
||||
$ref: '#/definitions/models.Tenant'
|
||||
type: array
|
||||
updated_at:
|
||||
type: string
|
||||
username:
|
||||
type: string
|
||||
verified_at:
|
||||
type: string
|
||||
type: object
|
||||
gorm.DeletedAt:
|
||||
properties:
|
||||
time:
|
||||
@@ -168,8 +214,6 @@ definitions:
|
||||
total:
|
||||
type: integer
|
||||
type: object
|
||||
v1.ResponseItem:
|
||||
type: object
|
||||
externalDocs:
|
||||
description: OpenAPI
|
||||
url: https://swagger.io/resources/open-api/
|
||||
@@ -265,24 +309,39 @@ paths:
|
||||
summary: 更新过期时间
|
||||
tags:
|
||||
- Super
|
||||
/v1/medias/{id}:
|
||||
post:
|
||||
/super/v1/tenants/{tenantID}/status:
|
||||
patch:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Test
|
||||
parameters:
|
||||
- description: ID
|
||||
- description: TenantID
|
||||
format: int64
|
||||
in: path
|
||||
name: id
|
||||
name: tenantID
|
||||
required: true
|
||||
type: integer
|
||||
- description: 年龄
|
||||
in: query
|
||||
name: age
|
||||
type: integer
|
||||
- description: 名称
|
||||
in: query
|
||||
name: name
|
||||
- description: Form
|
||||
in: body
|
||||
name: form
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/dto.TenantStatusUpdateForm'
|
||||
produces:
|
||||
- application/json
|
||||
responses: {}
|
||||
summary: 更新租户状态
|
||||
tags:
|
||||
- Super
|
||||
/super/v1/users:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- in: query
|
||||
name: asc
|
||||
type: string
|
||||
- in: query
|
||||
name: desc
|
||||
type: string
|
||||
- in: query
|
||||
name: limit
|
||||
@@ -290,21 +349,27 @@ paths:
|
||||
- in: query
|
||||
name: page
|
||||
type: integer
|
||||
- in: query
|
||||
name: tenantID
|
||||
type: integer
|
||||
- in: query
|
||||
name: username
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: 成功
|
||||
description: OK
|
||||
schema:
|
||||
allOf:
|
||||
- $ref: '#/definitions/requests.Pager'
|
||||
- properties:
|
||||
list:
|
||||
$ref: '#/definitions/v1.ResponseItem'
|
||||
items:
|
||||
$ref: '#/definitions/dto.UserItem'
|
||||
type: object
|
||||
summary: Test
|
||||
summary: 租户列表
|
||||
tags:
|
||||
- Test
|
||||
- Super
|
||||
securityDefinitions:
|
||||
BasicAuth:
|
||||
type: basic
|
||||
|
||||
@@ -15,6 +15,20 @@ type Role string
|
||||
// ENUM(pending_verify, verified, banned, )
|
||||
type UserStatus string
|
||||
|
||||
// Description
|
||||
func (t UserStatus) Description() string {
|
||||
switch t {
|
||||
case UserStatusPendingVerify:
|
||||
return "待审核"
|
||||
case UserStatusVerified:
|
||||
return "已审核"
|
||||
case UserStatusBanned:
|
||||
return "已封禁"
|
||||
default:
|
||||
return "未知状态"
|
||||
}
|
||||
}
|
||||
|
||||
// tenants
|
||||
|
||||
// swagger:enum TenantStatus
|
||||
|
||||
4
frontend/superadmin/dist/index.html
vendored
4
frontend/superadmin/dist/index.html
vendored
@@ -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-5TB6SaKe.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="./assets/index-7wg5D3fl.css">
|
||||
<script type="module" crossorigin src="./assets/index-BRu67wro.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="./assets/index-BMyA_4RT.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -10,7 +10,10 @@ const model = ref([
|
||||
},
|
||||
{
|
||||
label: 'Super Admin',
|
||||
items: [{ label: 'Tenants', icon: 'pi pi-fw pi-building', to: '/superadmin/tenants' }]
|
||||
items: [
|
||||
{ label: 'Tenants', icon: 'pi pi-fw pi-building', to: '/superadmin/tenants' },
|
||||
{ label: 'Users', icon: 'pi pi-fw pi-users', to: '/superadmin/users' }
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'UI Components',
|
||||
|
||||
@@ -116,6 +116,11 @@ const router = createRouter({
|
||||
path: '/superadmin/tenants',
|
||||
name: 'superadmin-tenants',
|
||||
component: () => import('@/views/superadmin/Tenants.vue')
|
||||
},
|
||||
{
|
||||
path: '/superadmin/users',
|
||||
name: 'superadmin-users',
|
||||
component: () => import('@/views/superadmin/Users.vue')
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
25
frontend/superadmin/src/service/UserService.js
Normal file
25
frontend/superadmin/src/service/UserService.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { requestJson } from './apiClient';
|
||||
|
||||
function normalizeItems(items) {
|
||||
if (Array.isArray(items)) return items;
|
||||
if (items && typeof items === 'object') return [items];
|
||||
return [];
|
||||
}
|
||||
|
||||
export const UserService = {
|
||||
async listUsers({ page, limit, tenantID, username, sortField, sortOrder } = {}) {
|
||||
const query = { page, limit, tenantID, username };
|
||||
if (sortField && sortOrder) {
|
||||
if (sortOrder === 1) query.asc = sortField;
|
||||
if (sortOrder === -1) query.desc = sortField;
|
||||
}
|
||||
|
||||
const data = await requestJson('/super/v1/users', { query });
|
||||
return {
|
||||
page: data?.page ?? page ?? 1,
|
||||
limit: data?.limit ?? limit ?? 10,
|
||||
total: data?.total ?? 0,
|
||||
items: normalizeItems(data?.items)
|
||||
};
|
||||
}
|
||||
};
|
||||
@@ -166,12 +166,27 @@ onMounted(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DataTable :value="tenants" dataKey="id" :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"
|
||||
<DataTable
|
||||
:value="tenants"
|
||||
dataKey="id"
|
||||
: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="flex" responsiveLayout="scroll">
|
||||
scrollable
|
||||
scrollHeight="flex"
|
||||
responsiveLayout="scroll"
|
||||
>
|
||||
<Column field="id" header="ID" sortable style="min-width: 6rem" />
|
||||
<Column field="code" header="Code" style="min-width: 10rem" />
|
||||
<Column field="name" header="名称" sortable style="min-width: 14rem" />
|
||||
@@ -184,8 +199,7 @@ onMounted(() => {
|
||||
<Column field="user_balance" header="余额" sortable style="min-width: 8rem" />
|
||||
<Column field="expired_at" header="过期时间" sortable style="min-width: 14rem">
|
||||
<template #body="{ data }">
|
||||
<span v-if="data.expired_at" v-tooltip="getExpiryDaysInfo(data.expired_at).tooltipText"
|
||||
:class="getExpiryDaysInfo(data.expired_at).textClass">
|
||||
<span v-if="data.expired_at" v-tooltip="getExpiryDaysInfo(data.expired_at).tooltipText" :class="getExpiryDaysInfo(data.expired_at).textClass">
|
||||
{{ formatDate(data.expired_at) }}
|
||||
</span>
|
||||
<span v-else>-</span>
|
||||
@@ -203,8 +217,7 @@ onMounted(() => {
|
||||
</Column>
|
||||
<Column header="操作" :exportable="false" style="min-width: 10rem">
|
||||
<template #body="{ data }">
|
||||
<Button label="续期" icon="pi pi-refresh" size="small" severity="secondary"
|
||||
@click="openRenewDialog(data)" />
|
||||
<Button label="续期" icon="pi pi-refresh" size="small" severity="secondary" @click="openRenewDialog(data)" />
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
@@ -219,8 +232,7 @@ onMounted(() => {
|
||||
<div class="flex flex-col gap-4">
|
||||
<div>
|
||||
<label class="block font-medium mb-2">续期时长</label>
|
||||
<Select v-model="renewDuration" :options="durationOptions" optionLabel="label" optionValue="value"
|
||||
placeholder="选择续期时长" fluid />
|
||||
<Select v-model="renewDuration" :options="durationOptions" optionLabel="label" optionValue="value" placeholder="选择续期时长" fluid />
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
|
||||
176
frontend/superadmin/src/views/superadmin/Users.vue
Normal file
176
frontend/superadmin/src/views/superadmin/Users.vue
Normal file
@@ -0,0 +1,176 @@
|
||||
<script setup>
|
||||
import { UserService } from '@/service/UserService';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
const users = ref([]);
|
||||
const loading = ref(false);
|
||||
|
||||
const totalRecords = ref(0);
|
||||
const page = ref(1);
|
||||
const rows = ref(10);
|
||||
|
||||
const tenantID = ref(null);
|
||||
const username = ref('');
|
||||
const sortField = ref('id');
|
||||
const sortOrder = ref(-1);
|
||||
|
||||
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 getStatusSeverity(status) {
|
||||
switch (status) {
|
||||
case 'active':
|
||||
case 'verified':
|
||||
return 'success';
|
||||
case 'pending_verify':
|
||||
case 'pending':
|
||||
return 'warn';
|
||||
case 'banned':
|
||||
case 'disabled':
|
||||
return 'danger';
|
||||
default:
|
||||
return 'secondary';
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const result = await UserService.listUsers({
|
||||
page: page.value,
|
||||
limit: rows.value,
|
||||
tenantID: tenantID.value ?? undefined,
|
||||
username: username.value,
|
||||
sortField: sortField.value,
|
||||
sortOrder: sortOrder.value
|
||||
});
|
||||
users.value = result.items;
|
||||
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;
|
||||
loadUsers();
|
||||
}
|
||||
|
||||
function onReset() {
|
||||
tenantID.value = null;
|
||||
username.value = '';
|
||||
sortField.value = 'id';
|
||||
sortOrder.value = -1;
|
||||
page.value = 1;
|
||||
rows.value = 10;
|
||||
loadUsers();
|
||||
}
|
||||
|
||||
function onPage(event) {
|
||||
page.value = (event.page ?? 0) + 1;
|
||||
rows.value = event.rows ?? rows.value;
|
||||
loadUsers();
|
||||
}
|
||||
|
||||
function onSort(event) {
|
||||
sortField.value = event.sortField ?? sortField.value;
|
||||
sortOrder.value = event.sortOrder ?? sortOrder.value;
|
||||
loadUsers();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadUsers();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="card">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 mb-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<h4 class="m-0">用户列表</h4>
|
||||
<Tag :value="`总数:${totalRecords}`" severity="secondary" />
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<InputNumber v-model="tenantID" placeholder="TenantID" :useGrouping="false" class="w-40" />
|
||||
<IconField>
|
||||
<InputIcon>
|
||||
<i class="pi pi-search" />
|
||||
</InputIcon>
|
||||
<InputText v-model="username" placeholder="用户名" @keyup.enter="onSearch" />
|
||||
</IconField>
|
||||
<Button label="查询" icon="pi pi-search" severity="secondary" @click="onSearch" />
|
||||
<Button label="重置" icon="pi pi-refresh" severity="secondary" @click="onReset" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DataTable
|
||||
:value="users"
|
||||
dataKey="id"
|
||||
: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="flex"
|
||||
responsiveLayout="scroll"
|
||||
>
|
||||
<Column field="id" header="ID" sortable style="min-width: 6rem" />
|
||||
<Column field="username" header="用户名" sortable style="min-width: 14rem" />
|
||||
<Column field="status" header="状态" sortable style="min-width: 10rem">
|
||||
<template #body="{ data }">
|
||||
<Tag :value="data.status_description || '-'" :severity="getStatusSeverity(data.status)" />
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="roles" header="角色" style="min-width: 16rem">
|
||||
<template #body="{ data }">
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<Tag v-for="role in data.roles || []" :key="role" :value="role" severity="secondary" />
|
||||
<span v-if="!data.roles || data.roles.length === 0" class="text-muted-color">-</span>
|
||||
</div>
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="verified_at" header="认证时间" sortable style="min-width: 14rem">
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data.verified_at) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="created_at" header="创建时间" sortable style="min-width: 14rem">
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data.created_at) }}
|
||||
</template>
|
||||
</Column>
|
||||
<Column field="updated_at" header="更新时间" sortable style="min-width: 14rem">
|
||||
<template #body="{ data }">
|
||||
{{ formatDate(data.updated_at) }}
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user