Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
88b32a50ad | ||
![]() |
909724321e | ||
![]() |
6da966fe0c | ||
![]() |
06b7842580 | ||
![]() |
c63133380f | ||
![]() |
e09410270f | ||
![]() |
fe46cc7499 | ||
![]() |
44112c2470 | ||
![]() |
2ecf594db6 | ||
![]() |
4bab884e99 | ||
![]() |
05bd8e6eff | ||
![]() |
fc7d1f2ee1 | ||
![]() |
0ba0bda7f8 | ||
![]() |
09c7f0f6a5 | ||
![]() |
c4f1b2818b | ||
![]() |
ee45ac1e90 | ||
![]() |
5438f75643 | ||
![]() |
89d762a8c5 |
12
Dockerfile
12
Dockerfile
@ -11,10 +11,10 @@ RUN npm install -g pnpm
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制后端
|
||||
COPY ./server ./server
|
||||
# 复制前端
|
||||
COPY ./web ./web
|
||||
# 复制后端
|
||||
COPY ./server ./server
|
||||
|
||||
# 构建前端项目
|
||||
WORKDIR /app/web
|
||||
@ -33,10 +33,12 @@ RUN cp -rf ../web/dist/* ./resource/public/admin/
|
||||
|
||||
# 编译hotgo服务端
|
||||
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
||||
RUN go mod download
|
||||
RUN go mod tidy
|
||||
|
||||
# 安装gf
|
||||
RUN wget -O gf "https://github.com/gogf/gf/releases/latest/download/gf_$(go env GOOS)_$(go env GOARCH)" && chmod +x gf && ./gf install -y && rm ./gf
|
||||
# 将deploy里的gf文件复制到当前目录
|
||||
COPY ./deploy/gf .
|
||||
RUN chmod +x gf && ./gf install -y && rm ./gf
|
||||
|
||||
RUN gf build
|
||||
|
||||
@ -44,7 +46,7 @@ RUN gf build
|
||||
FROM alpine:latest
|
||||
|
||||
# 安装 ca-certificates 用于 HTTPS 请求
|
||||
RUN apk --no-cache add ca-certificates tzdata
|
||||
RUN apk --no-cache add ca-certificates tzdata ffmpeg
|
||||
|
||||
# 设置时区
|
||||
ENV TZ=Asia/Shanghai
|
||||
|
@ -35,14 +35,14 @@ services:
|
||||
--character-set-server=utf8mb4
|
||||
--collation-server=utf8mb4_unicode_ci
|
||||
--tls_version="TLSv1.2,TLSv1.3"
|
||||
--init-file /data/application/init.sql
|
||||
--binlog_expire_logs_seconds=604800
|
||||
# --init-file /data/application/init.sql
|
||||
# --default-authentication-plugin=mysql_native_password
|
||||
ports:
|
||||
- 3306:3306
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
- ./deploy/init.sql:/data/application/init.sql
|
||||
# - ./deploy/init.sql:/data/application/init.sql
|
||||
networks:
|
||||
- gmanager
|
||||
healthcheck:
|
||||
|
67
server/api/admin/activity/activity.go
Normal file
67
server/api/admin/activity/activity.go
Normal file
@ -0,0 +1,67 @@
|
||||
// Package activity
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2025 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.17.8
|
||||
package activity
|
||||
|
||||
import (
|
||||
"hotgo/internal/model/input/form"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// ListReq 查询活动管理列表
|
||||
type ListReq struct {
|
||||
g.Meta `path:"/activity/list" method:"get" tags:"活动管理" summary:"获取活动管理列表"`
|
||||
sysin.ActivityListInp
|
||||
}
|
||||
|
||||
type ListRes struct {
|
||||
form.PageRes
|
||||
List []*sysin.ActivityListModel `json:"list" dc:"数据列表"`
|
||||
}
|
||||
|
||||
// ExportReq 导出活动管理列表
|
||||
type ExportReq struct {
|
||||
g.Meta `path:"/activity/export" method:"get" tags:"活动管理" summary:"导出活动管理列表"`
|
||||
sysin.ActivityListInp
|
||||
}
|
||||
|
||||
type ExportRes struct{}
|
||||
|
||||
// ViewReq 获取活动管理指定信息
|
||||
type ViewReq struct {
|
||||
g.Meta `path:"/activity/view" method:"get" tags:"活动管理" summary:"获取活动管理指定信息"`
|
||||
sysin.ActivityViewInp
|
||||
}
|
||||
|
||||
type ViewRes struct {
|
||||
*sysin.ActivityViewModel
|
||||
}
|
||||
|
||||
// EditReq 修改/新增活动管理
|
||||
type EditReq struct {
|
||||
g.Meta `path:"/activity/edit" method:"post" tags:"活动管理" summary:"修改/新增活动管理"`
|
||||
sysin.ActivityEditInp
|
||||
}
|
||||
|
||||
type EditRes struct{}
|
||||
|
||||
// DeleteReq 删除活动管理
|
||||
type DeleteReq struct {
|
||||
g.Meta `path:"/activity/delete" method:"post" tags:"活动管理" summary:"删除活动管理"`
|
||||
sysin.ActivityDeleteInp
|
||||
}
|
||||
|
||||
type DeleteRes struct{}
|
||||
|
||||
// StatusReq 更新活动管理状态
|
||||
type StatusReq struct {
|
||||
g.Meta `path:"/activity/status" method:"post" tags:"活动管理" summary:"更新活动管理状态"`
|
||||
sysin.ActivityStatusInp
|
||||
}
|
||||
|
||||
type StatusRes struct{}
|
@ -6,8 +6,9 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// UploadFileReq 上传文件
|
||||
@ -17,6 +18,14 @@ type UploadFileReq struct {
|
||||
|
||||
type UploadFileRes *sysin.AttachmentListModel
|
||||
|
||||
type UploadVideoReq struct {
|
||||
g.Meta `path:"/upload/video" tags:"附件" method:"post" summary:"上传视频"`
|
||||
}
|
||||
|
||||
type UploadVideoRes struct {
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
// CheckMultipartReq 检查文件分片
|
||||
type CheckMultipartReq struct {
|
||||
g.Meta `path:"/upload/checkMultipart" tags:"附件" method:"post" summary:"检查文件分片"`
|
||||
|
16
server/api/api/activity/activity.go
Normal file
16
server/api/api/activity/activity.go
Normal file
@ -0,0 +1,16 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package activity
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hotgo/api/api/activity/v1"
|
||||
)
|
||||
|
||||
type IActivityV1 interface {
|
||||
ActivityList(ctx context.Context, req *v1.ActivityListReq) (res *v1.ActivityListRes, err error)
|
||||
ActivityDetail(ctx context.Context, req *v1.ActivityDetailReq) (res *v1.ActivityDetailRes, err error)
|
||||
}
|
29
server/api/api/activity/v1/activity.go
Normal file
29
server/api/api/activity/v1/activity.go
Normal file
@ -0,0 +1,29 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"hotgo/internal/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// 获取活动列表请求
|
||||
type ActivityListReq struct {
|
||||
g.Meta `path:"/activity/list" method:"get" tags:"活动" summary:"获取活动列表"`
|
||||
}
|
||||
|
||||
// 获取活动列表响应
|
||||
type ActivityListRes struct {
|
||||
List []*entity.Activity `json:"list" dc:"活动列表"`
|
||||
Total int `json:"total" dc:"总数"`
|
||||
}
|
||||
|
||||
// 查看活动详情请求
|
||||
type ActivityDetailReq struct {
|
||||
g.Meta `path:"/activity/detail" method:"get" tags:"活动" summary:"查看活动详情"`
|
||||
Id int64 `json:"id" v:"required#活动ID必填" dc:"活动ID"`
|
||||
}
|
||||
|
||||
// 查看活动详情响应
|
||||
type ActivityDetailRes struct {
|
||||
*entity.Activity `dc:"活动"`
|
||||
}
|
@ -8,7 +8,10 @@ import (
|
||||
|
||||
// 获取课程列表请求
|
||||
type LessonListReq struct {
|
||||
g.Meta `path:"/lesson/list" method:"get" tags:"课程" summary:"获取课程列表"`
|
||||
g.Meta `path:"/lesson/list" method:"get" tags:"课程" summary:"获取课程列表"`
|
||||
CategoryId int64 `json:"categoryId" dc:"分类ID"`
|
||||
Difficuty int `json:"difficuty" dc:"难度"`
|
||||
Subject string `json:"subject" dc:"专题"`
|
||||
}
|
||||
|
||||
// 获取课程列表响应
|
||||
|
15
server/api/api/mycourse/mycourse.go
Normal file
15
server/api/api/mycourse/mycourse.go
Normal file
@ -0,0 +1,15 @@
|
||||
// =================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package mycourse
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hotgo/api/api/mycourse/v1"
|
||||
)
|
||||
|
||||
type IMycourseV1 interface {
|
||||
MyCourseList(ctx context.Context, req *v1.MyCourseListReq) (res *v1.MyCourseListRes, err error)
|
||||
}
|
36
server/api/api/mycourse/v1/mycourse.go
Normal file
36
server/api/api/mycourse/v1/mycourse.go
Normal file
@ -0,0 +1,36 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
// MyCourseListReq 获取我的课程列表请求
|
||||
type MyCourseListReq struct {
|
||||
g.Meta `path:"/mycourse/list" method:"get" tags:"我的课程" summary:"获取我的课程列表"`
|
||||
Status string `json:"status" dc:"学习状态筛选:learning-学习中,completed-已完成,空值-全部"`
|
||||
Page int `json:"page" d:"1" dc:"页码,从1开始"`
|
||||
PageSize int `json:"pageSize" d:"10" dc:"每页数量,默认10条"`
|
||||
}
|
||||
|
||||
// MyCourseListRes 获取我的课程列表响应
|
||||
type MyCourseListRes struct {
|
||||
List []*MyCourseItem `json:"list" dc:"课程列表"`
|
||||
Total int `json:"total" dc:"总记录数"`
|
||||
Page int `json:"page" dc:"当前页码"`
|
||||
PageSize int `json:"pageSize" dc:"每页数量"`
|
||||
}
|
||||
|
||||
// MyCourseItem 我的课程项目
|
||||
type MyCourseItem struct {
|
||||
Id int64 `json:"id" dc:"课程ID"`
|
||||
Title string `json:"title" dc:"课程标题"`
|
||||
Description string `json:"description" dc:"课程描述"`
|
||||
Cover string `json:"cover" dc:"课程封面图片URL"`
|
||||
Instructor string `json:"instructor" dc:"讲师姓名"`
|
||||
Duration int `json:"duration" dc:"课程时长(秒)"`
|
||||
Progress int `json:"progress" dc:"学习进度(0-100)"`
|
||||
Status string `json:"status" dc:"学习状态:learning-学习中,completed-已完成"`
|
||||
EnrollTime *gtime.Time `json:"enrollTime" dc:"报名时间"`
|
||||
LastStudyTime *gtime.Time `json:"lastStudyTime" dc:"最后学习时间"`
|
||||
}
|
@ -21,6 +21,7 @@ require (
|
||||
github.com/gogf/gf/v2 v2.9.1-0.20250624075347-5fa656d1cc92
|
||||
github.com/gogf/selfupdate v0.0.0-20231215043001-5c48c528462f
|
||||
github.com/golang-jwt/jwt/v5 v5.2.2
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/kayon/iploc v0.0.0-20200312105652-bda3e968a794
|
||||
github.com/minio/minio-go/v7 v7.0.94
|
||||
@ -86,7 +87,6 @@ require (
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/btree v1.1.3 // indirect
|
||||
github.com/google/go-querystring v1.0.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
|
||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
|
@ -7,12 +7,17 @@ package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"hotgo/api/admin/common"
|
||||
"hotgo/internal/library/storager"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/validate"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
var Upload = new(cUpload)
|
||||
@ -36,6 +41,73 @@ func (c *cUpload) UploadFile(ctx context.Context, _ *common.UploadFileReq) (res
|
||||
return service.CommonUpload().UploadFile(ctx, uploadType, file)
|
||||
}
|
||||
|
||||
// UploadVideo 上传视频
|
||||
func (c *cUpload) UploadVideo(ctx context.Context, _ *common.UploadVideoReq) (res common.UploadVideoRes, err error) {
|
||||
r := g.RequestFromCtx(ctx)
|
||||
uploadType := r.Header.Get("uploadType")
|
||||
if uploadType != "default" && !validate.InSlice(storager.KindSlice, uploadType) {
|
||||
err = gerror.New("上传类型是无效的")
|
||||
return
|
||||
}
|
||||
|
||||
file := r.GetUploadFile("file")
|
||||
if file == nil {
|
||||
err = gerror.New("没有找到上传的文件")
|
||||
return
|
||||
}
|
||||
|
||||
m3u8UUID := uuid.New().String()
|
||||
|
||||
// 1. 保存上传视频到本地临时目录
|
||||
tmpDir := "./tmp/video"
|
||||
_, _ = file.Save(tmpDir + "/" + m3u8UUID)
|
||||
tmpFile := tmpDir + "/" + m3u8UUID + "/" + file.Filename
|
||||
|
||||
// 2. 用ffmpeg切片为m3u8和ts文件
|
||||
|
||||
hlsDir := "./tmp/hls/" + m3u8UUID
|
||||
_ = os.MkdirAll(hlsDir, 0755)
|
||||
|
||||
defer func() {
|
||||
os.RemoveAll(hlsDir)
|
||||
os.RemoveAll(tmpDir + "/" + m3u8UUID)
|
||||
}()
|
||||
|
||||
m3u8File := m3u8UUID + ".m3u8"
|
||||
m3u8Path := hlsDir + "/" + m3u8File
|
||||
ffmpegCmd := exec.Command("ffmpeg", "-i", tmpFile, "-c:v", "libx264", "-hls_time", "10", "-hls_playlist_type", "vod", m3u8Path)
|
||||
err = ffmpegCmd.Run()
|
||||
if err != nil {
|
||||
err = gerror.Wrap(err, "ffmpeg切片失败")
|
||||
return
|
||||
}
|
||||
|
||||
// 3. 遍历切片目录,上传所有m3u8和ts文件到minio
|
||||
minioDrive := new(storager.MinioDrive)
|
||||
var m3u8MinioPath string
|
||||
files, _ := filepath.Glob(hlsDir + "/*")
|
||||
for _, f := range files {
|
||||
fileInfo, errStat := os.Stat(f)
|
||||
if errStat == nil && !fileInfo.IsDir() {
|
||||
minioPath, err2 := minioDrive.UploadFromPath(ctx, f, filepath.Base(f))
|
||||
if err2 != nil {
|
||||
err = err2
|
||||
return
|
||||
}
|
||||
if filepath.Ext(f) == ".m3u8" {
|
||||
m3u8MinioPath = minioPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m3u8MinioPath = storager.LastUrl(ctx, m3u8MinioPath, "minio")
|
||||
|
||||
// 4. 返回m3u8文件的minio路径
|
||||
return common.UploadVideoRes{
|
||||
Path: m3u8MinioPath,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CheckMultipart 检查文件分片
|
||||
func (c *cUpload) CheckMultipart(ctx context.Context, req *common.CheckMultipartReq) (res *common.CheckMultipartRes, err error) {
|
||||
data, err := service.CommonUpload().CheckMultipart(ctx, &req.CheckMultipartInp)
|
||||
|
73
server/internal/controller/admin/sys/activity.go
Normal file
73
server/internal/controller/admin/sys/activity.go
Normal file
@ -0,0 +1,73 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2025 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.17.8
|
||||
package sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hotgo/api/admin/activity"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
var (
|
||||
Activity = cActivity{}
|
||||
)
|
||||
|
||||
type cActivity struct{}
|
||||
|
||||
// List 查看活动管理列表
|
||||
func (c *cActivity) List(ctx context.Context, req *activity.ListReq) (res *activity.ListRes, err error) {
|
||||
list, totalCount, err := service.SysActivity().List(ctx, &req.ActivityListInp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if list == nil {
|
||||
list = []*sysin.ActivityListModel{}
|
||||
}
|
||||
|
||||
res = new(activity.ListRes)
|
||||
res.List = list
|
||||
res.PageRes.Pack(req, totalCount)
|
||||
return
|
||||
}
|
||||
|
||||
// Export 导出活动管理列表
|
||||
func (c *cActivity) Export(ctx context.Context, req *activity.ExportReq) (res *activity.ExportRes, err error) {
|
||||
err = service.SysActivity().Export(ctx, &req.ActivityListInp)
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 更新活动管理
|
||||
func (c *cActivity) Edit(ctx context.Context, req *activity.EditReq) (res *activity.EditRes, err error) {
|
||||
err = service.SysActivity().Edit(ctx, &req.ActivityEditInp)
|
||||
return
|
||||
}
|
||||
|
||||
// View 获取指定活动管理信息
|
||||
func (c *cActivity) View(ctx context.Context, req *activity.ViewReq) (res *activity.ViewRes, err error) {
|
||||
data, err := service.SysActivity().View(ctx, &req.ActivityViewInp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res = new(activity.ViewRes)
|
||||
res.ActivityViewModel = data
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除活动管理
|
||||
func (c *cActivity) Delete(ctx context.Context, req *activity.DeleteReq) (res *activity.DeleteRes, err error) {
|
||||
err = service.SysActivity().Delete(ctx, &req.ActivityDeleteInp)
|
||||
return
|
||||
}
|
||||
|
||||
// Status 更新活动管理状态
|
||||
func (c *cActivity) Status(ctx context.Context, req *activity.StatusReq) (res *activity.StatusRes, err error) {
|
||||
err = service.SysActivity().Status(ctx, &req.ActivityStatusInp)
|
||||
return
|
||||
}
|
5
server/internal/controller/api/activity/activity.go
Normal file
5
server/internal/controller/api/activity/activity.go
Normal file
@ -0,0 +1,5 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package activity
|
15
server/internal/controller/api/activity/activity_new.go
Normal file
15
server/internal/controller/api/activity/activity_new.go
Normal file
@ -0,0 +1,15 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package activity
|
||||
|
||||
import (
|
||||
"hotgo/api/api/activity"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() activity.IActivityV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package activity
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
v1 "hotgo/api/api/activity/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) ActivityDetail(ctx context.Context, req *v1.ActivityDetailReq) (res *v1.ActivityDetailRes, err error) {
|
||||
activity := new(entity.Activity)
|
||||
err = dao.Activity.Ctx(ctx).Where("id = ?", req.Id).Scan(activity)
|
||||
if err != nil {
|
||||
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
||||
}
|
||||
if activity.Id == 0 {
|
||||
return nil, gerror.NewCode(gcode.CodeNotFound, "活动不存在")
|
||||
}
|
||||
res = &v1.ActivityDetailRes{
|
||||
Activity: activity,
|
||||
}
|
||||
return
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package activity
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
|
||||
v1 "hotgo/api/api/activity/v1"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) ActivityList(ctx context.Context, req *v1.ActivityListReq) (res *v1.ActivityListRes, err error) {
|
||||
// 查询活动列表
|
||||
var list []*entity.Activity
|
||||
err = dao.Activity.Ctx(ctx).Scan(&list)
|
||||
if err != nil {
|
||||
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
||||
}
|
||||
|
||||
// 统计总数
|
||||
total, err := dao.Activity.Ctx(ctx).Count()
|
||||
if err != nil {
|
||||
return nil, gerror.NewCode(gcode.CodeDbOperationError, "统计总数失败")
|
||||
}
|
||||
|
||||
res = &v1.ActivityListRes{
|
||||
List: list,
|
||||
Total: total,
|
||||
}
|
||||
return
|
||||
}
|
@ -9,20 +9,42 @@ import (
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (c *ControllerV1) LessonList(ctx context.Context, req *v1.LessonListReq) (res *v1.LessonListRes, err error) {
|
||||
// 构建查询条件
|
||||
query := dao.Lesson.Ctx(ctx)
|
||||
|
||||
// 分类过滤
|
||||
if req.CategoryId != -1 && req.CategoryId > 0 {
|
||||
query = query.Where("category_id = ?", req.CategoryId)
|
||||
}
|
||||
|
||||
// 难度过滤
|
||||
if req.Difficuty != -1 {
|
||||
query = query.Where("difficulty = ?", req.Difficuty)
|
||||
}
|
||||
|
||||
// 专题过滤(subject为all时不过滤,否则用JSON_CONTAINS)
|
||||
if req.Subject != "" && req.Subject != "all" {
|
||||
query = query.WhereLike("subject", "%"+req.Subject+"%")
|
||||
}
|
||||
|
||||
// 查询课程列表
|
||||
var list []*entity.Lesson
|
||||
err = dao.Lesson.Ctx(ctx).Scan(&list)
|
||||
err = query.Scan(&list)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
return nil, gerror.NewCode(gcode.CodeDbOperationError, "数据库错误")
|
||||
}
|
||||
|
||||
// 统计总数
|
||||
total, err := dao.Lesson.Ctx(ctx).Count()
|
||||
total, err := query.Count()
|
||||
if err != nil {
|
||||
return nil, gerror.NewCode(gcode.CodeDbOperationError, "统计总数失败")
|
||||
}
|
||||
|
||||
res = &v1.LessonListRes{
|
||||
List: list,
|
||||
Total: total,
|
||||
|
15
server/internal/controller/api/mycourse/mycourse.go
Normal file
15
server/internal/controller/api/mycourse/mycourse.go
Normal file
@ -0,0 +1,15 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package mycourse
|
||||
|
||||
import (
|
||||
"hotgo/api/api/mycourse"
|
||||
)
|
||||
|
||||
type ControllerV1 struct{}
|
||||
|
||||
func NewV1() mycourse.IMycourseV1 {
|
||||
return &ControllerV1{}
|
||||
}
|
18
server/internal/controller/api/mycourse/mycourse_v1_list.go
Normal file
18
server/internal/controller/api/mycourse/mycourse_v1_list.go
Normal file
@ -0,0 +1,18 @@
|
||||
package mycourse
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "hotgo/api/api/mycourse/v1"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
// MyCourseList 获取我的课程列表
|
||||
func (c *ControllerV1) MyCourseList(ctx context.Context, req *v1.MyCourseListReq) (res *v1.MyCourseListRes, err error) {
|
||||
// 调用服务层处理业务逻辑
|
||||
data, err := service.MyCourse().GetList(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
@ -25,10 +25,14 @@ type ActivityColumns struct {
|
||||
Title string // 活动标题
|
||||
Introduction string // 活动介绍
|
||||
Cover string // 活动封面图
|
||||
Imgs string // 说明图片
|
||||
Banner string // 活动头图
|
||||
Video string // 活动视频
|
||||
StartTime string // 活动开始时间
|
||||
EndTime string // 活动结束时间
|
||||
CategoryId string // 分类id
|
||||
Extra string // 扩展字段
|
||||
Attachment string // 活动附件
|
||||
Status string // 活动状态
|
||||
Revision string // 乐观锁
|
||||
CreatedBy string // 创建人
|
||||
CreatedTime string // 创建时间
|
||||
@ -42,10 +46,14 @@ var activityColumns = ActivityColumns{
|
||||
Title: "title",
|
||||
Introduction: "introduction",
|
||||
Cover: "cover",
|
||||
Imgs: "imgs",
|
||||
Banner: "banner",
|
||||
Video: "video",
|
||||
StartTime: "start_time",
|
||||
EndTime: "end_time",
|
||||
CategoryId: "category_id",
|
||||
Extra: "extra",
|
||||
Attachment: "attachment",
|
||||
Status: "status",
|
||||
Revision: "revision",
|
||||
CreatedBy: "created_by",
|
||||
CreatedTime: "created_time",
|
||||
|
@ -41,6 +41,8 @@ type LessonColumns struct {
|
||||
CreatedTime string // 创建时间
|
||||
UpdatedBy string // 更新人
|
||||
UpdatedTime string // 更新时间
|
||||
Difficulty string // 课程难度
|
||||
Subject string // 所属专题
|
||||
}
|
||||
|
||||
// lessonColumns holds the columns for the table hg_lesson.
|
||||
@ -65,6 +67,8 @@ var lessonColumns = LessonColumns{
|
||||
CreatedTime: "created_time",
|
||||
UpdatedBy: "updated_by",
|
||||
UpdatedTime: "updated_time",
|
||||
Difficulty: "difficulty",
|
||||
Subject: "subject",
|
||||
}
|
||||
|
||||
// NewLessonDao creates and returns a new DAO object for table data access.
|
||||
|
@ -27,7 +27,7 @@ type LessonSectionColumns struct {
|
||||
Name string // 章节名
|
||||
SortOrder string // 排序号
|
||||
ParentId string // 父章节id
|
||||
Level string // 章节层级;1=章,2=节
|
||||
Level string // 章节层级
|
||||
Revision string // 乐观锁
|
||||
CreatedBy string // 创建人
|
||||
CreatedTime string // 创建时间
|
||||
|
@ -7,14 +7,18 @@ package storager
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mime"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/os/gfile"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// MinioDrive minio对象存储驱动
|
||||
@ -63,6 +67,59 @@ func (d *MinioDrive) Upload(ctx context.Context, file *ghttp.UploadFile) (fullPa
|
||||
return
|
||||
}
|
||||
|
||||
// UploadFromPath 从本地文件上传
|
||||
func (d *MinioDrive) UploadFromPath(ctx context.Context, path string, filename string) (fullPath string, err error) {
|
||||
if config.MinioPath == "" {
|
||||
err = gerror.New("minio存储驱动必须配置存储路径!")
|
||||
return
|
||||
}
|
||||
|
||||
client, err := minio.New(config.MinioEndpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(config.MinioAccessKey, config.MinioSecretKey, ""),
|
||||
Secure: config.MinioUseSSL == 1,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err = s3utils.CheckValidBucketName(config.MinioBucket); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fullPath = config.MinioPath + gtime.Date() + "/" + filename
|
||||
if err = s3utils.CheckValidObjectName(fullPath); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if fileInfo.IsDir() {
|
||||
return "", fmt.Errorf("上传路径是目录: %s", path)
|
||||
}
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
stat, err := file.Stat()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
opts := minio.PutObjectOptions{
|
||||
ContentType: mime.TypeByExtension(filepath.Ext(path)),
|
||||
}
|
||||
if opts.ContentType == "" {
|
||||
opts.ContentType = "application/octet-stream"
|
||||
}
|
||||
|
||||
_, err = client.PutObject(ctx, config.MinioBucket, fullPath, file, stat.Size(), opts)
|
||||
return
|
||||
}
|
||||
|
||||
// CreateMultipart 创建分片事件
|
||||
func (d *MinioDrive) CreateMultipart(ctx context.Context, in *CheckMultipartParams) (res *MultipartProgress, err error) {
|
||||
err = gerror.New("当前驱动暂不支持分片上传!")
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
_ "hotgo/internal/logic/common"
|
||||
_ "hotgo/internal/logic/hook"
|
||||
_ "hotgo/internal/logic/middleware"
|
||||
_ "hotgo/internal/logic/mycourse"
|
||||
_ "hotgo/internal/logic/pay"
|
||||
_ "hotgo/internal/logic/sys"
|
||||
_ "hotgo/internal/logic/tcpclient"
|
||||
|
@ -6,12 +6,13 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/library/response"
|
||||
"hotgo/utility/simple"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gcode"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/gogf/gf/v2/text/gstr"
|
||||
)
|
||||
|
||||
// ApiAuth API鉴权中间件
|
||||
|
129
server/internal/logic/mycourse/mycourse.go
Normal file
129
server/internal/logic/mycourse/mycourse.go
Normal file
@ -0,0 +1,129 @@
|
||||
package mycourse
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "hotgo/api/api/mycourse/v1"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/service"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
type sMyCourse struct{}
|
||||
|
||||
func init() {
|
||||
service.RegisterMyCourse(New())
|
||||
}
|
||||
|
||||
func New() *sMyCourse {
|
||||
return &sMyCourse{}
|
||||
}
|
||||
|
||||
// GetList 获取我的课程列表
|
||||
func (s *sMyCourse) GetList(ctx context.Context, req *v1.MyCourseListReq) (res *v1.MyCourseListRes, err error) {
|
||||
// 获取用户ID(测试环境下使用默认用户ID)
|
||||
userId := contexts.GetUserId(ctx)
|
||||
if userId <= 0 {
|
||||
// 测试环境下使用默认用户ID
|
||||
userId = 1
|
||||
}
|
||||
|
||||
// 模拟数据 - 实际项目中应该从数据库查询
|
||||
// TODO: 后续可以替换为真实的数据库查询
|
||||
mockData := []*v1.MyCourseItem{
|
||||
{
|
||||
Id: 1,
|
||||
Title: "Go语言基础教程",
|
||||
Description: "从零开始学习Go语言,掌握基础语法和核心概念",
|
||||
Cover: "https://example.com/covers/go-basic.jpg",
|
||||
Instructor: "张老师",
|
||||
Duration: 7200, // 2小时
|
||||
Progress: 75,
|
||||
Status: "learning",
|
||||
EnrollTime: gtime.New("2024-01-15 10:30:00"),
|
||||
LastStudyTime: gtime.New("2024-01-20 14:20:00"),
|
||||
},
|
||||
{
|
||||
Id: 2,
|
||||
Title: "Vue.js实战开发",
|
||||
Description: "深入学习Vue.js框架,构建现代化前端应用",
|
||||
Cover: "https://example.com/covers/vue-practice.jpg",
|
||||
Instructor: "李老师",
|
||||
Duration: 10800, // 3小时
|
||||
Progress: 100,
|
||||
Status: "completed",
|
||||
EnrollTime: gtime.New("2024-01-10 09:15:00"),
|
||||
LastStudyTime: gtime.New("2024-01-18 16:45:00"),
|
||||
},
|
||||
{
|
||||
Id: 3,
|
||||
Title: "MySQL数据库优化",
|
||||
Description: "学习MySQL性能优化技巧和最佳实践",
|
||||
Cover: "https://example.com/covers/mysql-optimization.jpg",
|
||||
Instructor: "王老师",
|
||||
Duration: 5400, // 1.5小时
|
||||
Progress: 45,
|
||||
Status: "learning",
|
||||
EnrollTime: gtime.New("2024-01-20 14:00:00"),
|
||||
LastStudyTime: gtime.New("2024-01-22 10:30:00"),
|
||||
},
|
||||
{
|
||||
Id: 4,
|
||||
Title: "Python数据分析",
|
||||
Description: "使用Python进行数据分析和可视化",
|
||||
Cover: "https://example.com/covers/python-analysis.jpg",
|
||||
Instructor: "赵老师",
|
||||
Duration: 9000, // 2.5小时
|
||||
Progress: 100,
|
||||
Status: "completed",
|
||||
EnrollTime: gtime.New("2024-01-05 11:00:00"),
|
||||
LastStudyTime: gtime.New("2024-01-12 15:30:00"),
|
||||
},
|
||||
}
|
||||
|
||||
// 根据状态筛选
|
||||
var filteredData []*v1.MyCourseItem
|
||||
if req.Status != "" {
|
||||
for _, item := range mockData {
|
||||
if item.Status == req.Status {
|
||||
filteredData = append(filteredData, item)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filteredData = mockData
|
||||
}
|
||||
|
||||
totalCount := len(filteredData)
|
||||
|
||||
// 分页处理
|
||||
pageNum := req.Page
|
||||
pageSize := req.PageSize
|
||||
if pageNum <= 0 {
|
||||
pageNum = 1
|
||||
}
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
|
||||
start := (pageNum - 1) * pageSize
|
||||
end := start + pageSize
|
||||
|
||||
var list []*v1.MyCourseItem
|
||||
if start >= totalCount {
|
||||
list = []*v1.MyCourseItem{}
|
||||
} else {
|
||||
if end > totalCount {
|
||||
end = totalCount
|
||||
}
|
||||
list = filteredData[start:end]
|
||||
}
|
||||
|
||||
res = &v1.MyCourseListRes{
|
||||
List: list,
|
||||
Total: totalCount,
|
||||
Page: pageNum,
|
||||
PageSize: pageSize,
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
156
server/internal/logic/sys/activity.go
Normal file
156
server/internal/logic/sys/activity.go
Normal file
@ -0,0 +1,156 @@
|
||||
// Package sys
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2025 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.17.8
|
||||
package sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"hotgo/internal/dao"
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/hgorm/handler"
|
||||
"hotgo/internal/model/input/form"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
"hotgo/utility/convert"
|
||||
"hotgo/utility/excel"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type sSysActivity struct{}
|
||||
|
||||
func NewSysActivity() *sSysActivity {
|
||||
return &sSysActivity{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
service.RegisterSysActivity(NewSysActivity())
|
||||
}
|
||||
|
||||
// Model 活动管理ORM模型
|
||||
func (s *sSysActivity) Model(ctx context.Context, option ...*handler.Option) *gdb.Model {
|
||||
return handler.Model(dao.Activity.Ctx(ctx), option...)
|
||||
}
|
||||
|
||||
// List 获取活动管理列表
|
||||
func (s *sSysActivity) List(ctx context.Context, in *sysin.ActivityListInp) (list []*sysin.ActivityListModel, totalCount int, err error) {
|
||||
mod := s.Model(ctx)
|
||||
|
||||
// 字段过滤
|
||||
mod = mod.Fields(sysin.ActivityListModel{})
|
||||
|
||||
// 查询id
|
||||
if in.Id > 0 {
|
||||
mod = mod.Where(dao.Activity.Columns().Id, in.Id)
|
||||
}
|
||||
|
||||
// 查询活动状态
|
||||
if in.Status > 0 {
|
||||
mod = mod.Where(dao.Activity.Columns().Status, in.Status)
|
||||
}
|
||||
|
||||
// 分页
|
||||
mod = mod.Page(in.Page, in.PerPage)
|
||||
|
||||
// 排序
|
||||
mod = mod.OrderDesc(dao.Activity.Columns().Id)
|
||||
|
||||
// 查询数据
|
||||
if err = mod.ScanAndCount(&list, &totalCount, false); err != nil {
|
||||
err = gerror.Wrap(err, "获取活动管理列表失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Export 导出活动管理
|
||||
func (s *sSysActivity) Export(ctx context.Context, in *sysin.ActivityListInp) (err error) {
|
||||
list, totalCount, err := s.List(ctx, in)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 字段的排序是依据tags的字段顺序,如果你不想使用默认的排序方式,可以直接定义 tags = []string{"字段名称", "字段名称2", ...}
|
||||
tags, err := convert.GetEntityDescTags(sysin.ActivityExportModel{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
fileName = "导出活动管理-" + gctx.CtxId(ctx)
|
||||
sheetName = fmt.Sprintf("索引条件共%v行,共%v页,当前导出是第%v页,本页共%v行", totalCount, form.CalPageCount(totalCount, in.PerPage), in.Page, len(list))
|
||||
exports []sysin.ActivityExportModel
|
||||
)
|
||||
|
||||
if err = gconv.Scan(list, &exports); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = excel.ExportByStructs(ctx, tags, exports, fileName, sheetName)
|
||||
return
|
||||
}
|
||||
|
||||
// Edit 修改/新增活动管理
|
||||
func (s *sSysActivity) Edit(ctx context.Context, in *sysin.ActivityEditInp) (err error) {
|
||||
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
|
||||
|
||||
// 修改
|
||||
if in.Id > 0 {
|
||||
in.UpdatedBy = contexts.GetUserId(ctx)
|
||||
if _, err = s.Model(ctx).
|
||||
Fields(sysin.ActivityUpdateFields{}).
|
||||
WherePri(in.Id).Data(in).Update(); err != nil {
|
||||
err = gerror.Wrap(err, "修改活动管理失败,请稍后重试!")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 新增
|
||||
in.CreatedBy = contexts.GetUserId(ctx)
|
||||
if _, err = s.Model(ctx, &handler.Option{FilterAuth: false}).
|
||||
Fields(sysin.ActivityInsertFields{}).
|
||||
Data(in).OmitEmptyData().Insert(); err != nil {
|
||||
err = gerror.Wrap(err, "新增活动管理失败,请稍后重试!")
|
||||
}
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
// Delete 删除活动管理
|
||||
func (s *sSysActivity) Delete(ctx context.Context, in *sysin.ActivityDeleteInp) (err error) {
|
||||
|
||||
if _, err = s.Model(ctx).WherePri(in.Id).Unscoped().Delete(); err != nil {
|
||||
err = gerror.Wrap(err, "删除活动管理失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// View 获取活动管理指定信息
|
||||
func (s *sSysActivity) View(ctx context.Context, in *sysin.ActivityViewInp) (res *sysin.ActivityViewModel, err error) {
|
||||
if err = s.Model(ctx).WherePri(in.Id).Scan(&res); err != nil {
|
||||
err = gerror.Wrap(err, "获取活动管理信息,请稍后重试!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Status 更新活动管理状态
|
||||
func (s *sSysActivity) Status(ctx context.Context, in *sysin.ActivityStatusInp) (err error) {
|
||||
if _, err = s.Model(ctx).WherePri(in.Id).Data(g.Map{
|
||||
dao.Activity.Columns().Status: in.Status,
|
||||
dao.Activity.Columns().UpdatedBy: contexts.GetUserId(ctx),
|
||||
}).Update(); err != nil {
|
||||
err = gerror.Wrap(err, "更新活动管理状态失败,请稍后重试!")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
@ -52,6 +52,11 @@ func (s *sSysLesson) List(ctx context.Context, in *sysin.LessonListInp) (list []
|
||||
// 字段过滤
|
||||
mod = mod.Fields(sysin.LessonListModel{})
|
||||
|
||||
// 查询id
|
||||
if in.Id > 0 {
|
||||
mod = mod.Where(dao.Lesson.Columns().Id, in.Id)
|
||||
}
|
||||
|
||||
// 查询课程名
|
||||
if in.Name != "" {
|
||||
mod = mod.WhereLike(dao.Lesson.Columns().Name, in.Name)
|
||||
|
@ -16,10 +16,14 @@ type Activity struct {
|
||||
Title interface{} // 活动标题
|
||||
Introduction interface{} // 活动介绍
|
||||
Cover interface{} // 活动封面图
|
||||
Imgs interface{} // 说明图片
|
||||
Banner interface{} // 活动头图
|
||||
Video interface{} // 活动视频
|
||||
StartTime interface{} // 活动开始时间
|
||||
EndTime interface{} // 活动结束时间
|
||||
CategoryId interface{} // 分类id
|
||||
StartTime *gtime.Time // 活动开始时间
|
||||
EndTime *gtime.Time // 活动结束时间
|
||||
Extra interface{} // 扩展字段
|
||||
Attachment interface{} // 活动附件
|
||||
Status interface{} // 活动状态
|
||||
Revision interface{} // 乐观锁
|
||||
CreatedBy interface{} // 创建人
|
||||
CreatedTime *gtime.Time // 创建时间
|
||||
|
@ -32,4 +32,6 @@ type Lesson struct {
|
||||
CreatedTime *gtime.Time // 创建时间
|
||||
UpdatedBy interface{} // 更新人
|
||||
UpdatedTime *gtime.Time // 更新时间
|
||||
Difficulty interface{} // 课程难度
|
||||
Subject interface{} // 所属专题
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ type LessonSection struct {
|
||||
Name interface{} // 章节名
|
||||
SortOrder interface{} // 排序号
|
||||
ParentId interface{} // 父章节id
|
||||
Level interface{} // 章节层级;1=章,2=节
|
||||
Level interface{} // 章节层级
|
||||
Revision interface{} // 乐观锁
|
||||
CreatedBy interface{} // 创建人
|
||||
CreatedTime *gtime.Time // 创建时间
|
||||
|
@ -10,17 +10,21 @@ import (
|
||||
|
||||
// Activity is the golang structure for table activity.
|
||||
type Activity struct {
|
||||
Id int `json:"id" orm:"id" description:"id"`
|
||||
Id int64 `json:"id" orm:"id" description:"id"`
|
||||
Title string `json:"title" orm:"title" description:"活动标题"`
|
||||
Introduction string `json:"introduction" orm:"introduction" description:"活动介绍"`
|
||||
Cover string `json:"cover" orm:"cover" description:"活动封面图"`
|
||||
Imgs string `json:"imgs" orm:"imgs" description:"说明图片"`
|
||||
Banner string `json:"banner" orm:"banner" description:"活动头图"`
|
||||
Video string `json:"video" orm:"video" description:"活动视频"`
|
||||
StartTime string `json:"startTime" orm:"start_time" description:"活动开始时间"`
|
||||
EndTime string `json:"endTime" orm:"end_time" description:"活动结束时间"`
|
||||
CategoryId int `json:"categoryId" orm:"category_id" description:"分类id"`
|
||||
StartTime *gtime.Time `json:"startTime" orm:"start_time" description:"活动开始时间"`
|
||||
EndTime *gtime.Time `json:"endTime" orm:"end_time" description:"活动结束时间"`
|
||||
Extra string `json:"extra" orm:"extra" description:"扩展字段"`
|
||||
Attachment string `json:"attachment" orm:"attachment" description:"活动附件"`
|
||||
Status int `json:"status" orm:"status" description:"活动状态"`
|
||||
Revision int `json:"revision" orm:"revision" description:"乐观锁"`
|
||||
CreatedBy int `json:"createdBy" orm:"created_by" description:"创建人"`
|
||||
CreatedBy int64 `json:"createdBy" orm:"created_by" description:"创建人"`
|
||||
CreatedTime *gtime.Time `json:"createdTime" orm:"created_time" description:"创建时间"`
|
||||
UpdatedBy int `json:"updatedBy" orm:"updated_by" description:"更新人"`
|
||||
UpdatedBy int64 `json:"updatedBy" orm:"updated_by" description:"更新人"`
|
||||
UpdatedTime *gtime.Time `json:"updatedTime" orm:"updated_time" description:"更新时间"`
|
||||
}
|
||||
|
@ -30,4 +30,6 @@ type Lesson struct {
|
||||
CreatedTime *gtime.Time `json:"createdTime" orm:"created_time" description:"创建时间"`
|
||||
UpdatedBy int64 `json:"updatedBy" orm:"updated_by" description:"更新人"`
|
||||
UpdatedTime *gtime.Time `json:"updatedTime" orm:"updated_time" description:"更新时间"`
|
||||
Difficulty int `json:"difficulty" orm:"difficulty" description:"课程难度"`
|
||||
Subject string `json:"subject" orm:"subject" description:"所属专题"`
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ type LessonSection struct {
|
||||
Name string `json:"name" orm:"name" description:"章节名"`
|
||||
SortOrder int `json:"sortOrder" orm:"sort_order" description:"排序号"`
|
||||
ParentId int `json:"parentId" orm:"parent_id" description:"父章节id"`
|
||||
Level int `json:"level" orm:"level" description:"章节层级;1=章,2=节"`
|
||||
Level int `json:"level" orm:"level" description:"章节层级"`
|
||||
Revision int `json:"revision" orm:"revision" description:"乐观锁"`
|
||||
CreatedBy int64 `json:"createdBy" orm:"created_by" description:"创建人"`
|
||||
CreatedTime *gtime.Time `json:"createdTime" orm:"created_time" description:"创建时间"`
|
||||
|
143
server/internal/model/input/sysin/activity.go
Normal file
143
server/internal/model/input/sysin/activity.go
Normal file
@ -0,0 +1,143 @@
|
||||
// Package sysin
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2025 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.17.8
|
||||
package sysin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/form"
|
||||
"hotgo/utility/validate"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
// ActivityUpdateFields 修改活动管理字段过滤
|
||||
type ActivityUpdateFields struct {
|
||||
Title string `json:"title" dc:"活动标题"`
|
||||
Introduction string `json:"introduction" dc:"活动介绍"`
|
||||
Cover string `json:"cover" dc:"活动封面图"`
|
||||
Imgs string `json:"imgs" dc:"说明图片"`
|
||||
Banner string `json:"banner" dc:"活动头图"`
|
||||
Video string `json:"video" dc:"活动视频"`
|
||||
StartTime *gtime.Time `json:"startTime" dc:"活动开始时间"`
|
||||
EndTime *gtime.Time `json:"endTime" dc:"活动结束时间"`
|
||||
Attachment string `json:"attachment" dc:"活动附件"`
|
||||
Status int `json:"status" dc:"活动状态"`
|
||||
UpdatedBy int64 `json:"updatedBy" dc:"更新人"`
|
||||
}
|
||||
|
||||
// ActivityInsertFields 新增活动管理字段过滤
|
||||
type ActivityInsertFields struct {
|
||||
Title string `json:"title" dc:"活动标题"`
|
||||
Introduction string `json:"introduction" dc:"活动介绍"`
|
||||
Cover string `json:"cover" dc:"活动封面图"`
|
||||
Imgs string `json:"imgs" dc:"说明图片"`
|
||||
Banner string `json:"banner" dc:"活动头图"`
|
||||
Video string `json:"video" dc:"活动视频"`
|
||||
StartTime *gtime.Time `json:"startTime" dc:"活动开始时间"`
|
||||
EndTime *gtime.Time `json:"endTime" dc:"活动结束时间"`
|
||||
Attachment string `json:"attachment" dc:"活动附件"`
|
||||
Status int `json:"status" dc:"活动状态"`
|
||||
CreatedBy int64 `json:"createdBy" dc:"创建人"`
|
||||
}
|
||||
|
||||
// ActivityEditInp 修改/新增活动管理
|
||||
type ActivityEditInp struct {
|
||||
entity.Activity
|
||||
}
|
||||
|
||||
func (in *ActivityEditInp) Filter(ctx context.Context) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type ActivityEditModel struct{}
|
||||
|
||||
// ActivityDeleteInp 删除活动管理
|
||||
type ActivityDeleteInp struct {
|
||||
Id interface{} `json:"id" v:"required#id不能为空" dc:"id"`
|
||||
}
|
||||
|
||||
func (in *ActivityDeleteInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type ActivityDeleteModel struct{}
|
||||
|
||||
// ActivityViewInp 获取指定活动管理信息
|
||||
type ActivityViewInp struct {
|
||||
Id int `json:"id" v:"required#id不能为空" dc:"id"`
|
||||
}
|
||||
|
||||
func (in *ActivityViewInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type ActivityViewModel struct {
|
||||
entity.Activity
|
||||
}
|
||||
|
||||
// ActivityListInp 获取活动管理列表
|
||||
type ActivityListInp struct {
|
||||
form.PageReq
|
||||
Id int `json:"id" dc:"id"`
|
||||
Status int `json:"status" dc:"活动状态"`
|
||||
}
|
||||
|
||||
func (in *ActivityListInp) Filter(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type ActivityListModel struct {
|
||||
Id int `json:"id" dc:"id"`
|
||||
Title string `json:"title" dc:"活动标题"`
|
||||
Cover string `json:"cover" dc:"活动封面图"`
|
||||
Banner string `json:"banner" dc:"活动头图"`
|
||||
StartTime *gtime.Time `json:"startTime" dc:"活动开始时间"`
|
||||
EndTime *gtime.Time `json:"endTime" dc:"活动结束时间"`
|
||||
Status int `json:"status" dc:"活动状态"`
|
||||
}
|
||||
|
||||
// ActivityExportModel 导出活动管理
|
||||
type ActivityExportModel struct {
|
||||
Id int `json:"id" dc:"id"`
|
||||
Title string `json:"title" dc:"活动标题"`
|
||||
Cover string `json:"cover" dc:"活动封面图"`
|
||||
Banner string `json:"banner" dc:"活动头图"`
|
||||
Video string `json:"video" dc:"活动视频"`
|
||||
StartTime *gtime.Time `json:"startTime" dc:"活动开始时间"`
|
||||
EndTime *gtime.Time `json:"endTime" dc:"活动结束时间"`
|
||||
Status int `json:"status" dc:"活动状态"`
|
||||
}
|
||||
|
||||
// ActivityStatusInp 更新活动管理状态
|
||||
type ActivityStatusInp struct {
|
||||
Id int `json:"id" v:"required#id不能为空" dc:"id"`
|
||||
Status int `json:"status" dc:"状态"`
|
||||
}
|
||||
|
||||
func (in *ActivityStatusInp) Filter(ctx context.Context) (err error) {
|
||||
if in.Id <= 0 {
|
||||
err = gerror.New("id不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if in.Status <= 0 {
|
||||
err = gerror.New("状态不能为空")
|
||||
return
|
||||
}
|
||||
|
||||
if !validate.InSlice(consts.StatusSlice, in.Status) {
|
||||
err = gerror.New("状态不正确")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type ActivityStatusModel struct{}
|
@ -11,6 +11,7 @@ import (
|
||||
"hotgo/internal/model/entity"
|
||||
"hotgo/internal/model/input/form"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
@ -18,7 +19,7 @@ import (
|
||||
type LessonUpdateFields struct {
|
||||
Name string `json:"name" dc:"课程名"`
|
||||
Cover string `json:"cover" dc:"封面图"`
|
||||
CategoryId int `json:"categoryId" dc:"所属分类"`
|
||||
CategoryId int64 `json:"categoryId" dc:"所属分类"`
|
||||
Video string `json:"video" dc:"介绍视频"`
|
||||
School string `json:"school" dc:"所属学校"`
|
||||
Description string `json:"description" dc:"课程概述"`
|
||||
@ -30,14 +31,16 @@ type LessonUpdateFields struct {
|
||||
StartTime *gtime.Time `json:"startTime" dc:"开课时间"`
|
||||
EndTime *gtime.Time `json:"endTime" dc:"结课时间"`
|
||||
Question string `json:"question" dc:"常见问题"`
|
||||
UpdatedBy int `json:"updatedBy" dc:"更新人"`
|
||||
UpdatedBy int64 `json:"updatedBy" dc:"更新人"`
|
||||
Difficulty int `json:"difficulty" dc:"课程难度"`
|
||||
Subject string `json:"subject" dc:"所属专题"`
|
||||
}
|
||||
|
||||
// LessonInsertFields 新增课程管理字段过滤
|
||||
type LessonInsertFields struct {
|
||||
Name string `json:"name" dc:"课程名"`
|
||||
Cover string `json:"cover" dc:"封面图"`
|
||||
CategoryId int `json:"categoryId" dc:"所属分类"`
|
||||
CategoryId int64 `json:"categoryId" dc:"所属分类"`
|
||||
Video string `json:"video" dc:"介绍视频"`
|
||||
School string `json:"school" dc:"所属学校"`
|
||||
Description string `json:"description" dc:"课程概述"`
|
||||
@ -49,7 +52,9 @@ type LessonInsertFields struct {
|
||||
StartTime *gtime.Time `json:"startTime" dc:"开课时间"`
|
||||
EndTime *gtime.Time `json:"endTime" dc:"结课时间"`
|
||||
Question string `json:"question" dc:"常见问题"`
|
||||
CreatedBy int `json:"createdBy" dc:"创建人"`
|
||||
CreatedBy int64 `json:"createdBy" dc:"创建人"`
|
||||
Difficulty int `json:"difficulty" dc:"课程难度"`
|
||||
Subject string `json:"subject" dc:"所属专题"`
|
||||
}
|
||||
|
||||
// LessonEditInp 修改/新增课程管理
|
||||
@ -58,6 +63,20 @@ type LessonEditInp struct {
|
||||
}
|
||||
|
||||
func (in *LessonEditInp) Filter(ctx context.Context) (err error) {
|
||||
// 验证课程名
|
||||
if err := g.Validator().Rules("required").Data(in.Name).Messages("课程名不能为空").Run(ctx); err != nil {
|
||||
return err.Current()
|
||||
}
|
||||
|
||||
// 验证封面图
|
||||
if err := g.Validator().Rules("required").Data(in.Cover).Messages("封面图不能为空").Run(ctx); err != nil {
|
||||
return err.Current()
|
||||
}
|
||||
|
||||
// 验证所属分类
|
||||
if err := g.Validator().Rules("required").Data(in.CategoryId).Messages("所属分类不能为空").Run(ctx); err != nil {
|
||||
return err.Current()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@ -77,7 +96,7 @@ type LessonDeleteModel struct{}
|
||||
|
||||
// LessonViewInp 获取指定课程管理信息
|
||||
type LessonViewInp struct {
|
||||
Id int `json:"id" v:"required#id不能为空" dc:"id"`
|
||||
Id int64 `json:"id" v:"required#id不能为空" dc:"id"`
|
||||
}
|
||||
|
||||
func (in *LessonViewInp) Filter(ctx context.Context) (err error) {
|
||||
@ -91,6 +110,7 @@ type LessonViewModel struct {
|
||||
// LessonListInp 获取课程管理列表
|
||||
type LessonListInp struct {
|
||||
form.PageReq
|
||||
Id int64 `json:"id" dc:"id"`
|
||||
Name string `json:"name" dc:"课程名"`
|
||||
School string `json:"school" dc:"所属学校"`
|
||||
}
|
||||
@ -100,22 +120,24 @@ func (in *LessonListInp) Filter(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
type LessonListModel struct {
|
||||
Id int `json:"id" dc:"id"`
|
||||
Id int64 `json:"id" dc:"id"`
|
||||
Name string `json:"name" dc:"课程名"`
|
||||
Cover string `json:"cover" dc:"封面图"`
|
||||
CategoryId int `json:"categoryId" dc:"所属分类"`
|
||||
CategoryId int64 `json:"categoryId" dc:"所属分类"`
|
||||
Video string `json:"video" dc:"介绍视频"`
|
||||
School string `json:"school" dc:"所属学校"`
|
||||
StartTime *gtime.Time `json:"startTime" dc:"开课时间"`
|
||||
EndTime *gtime.Time `json:"endTime" dc:"结课时间"`
|
||||
Difficulty int `json:"difficulty" dc:"课程难度"`
|
||||
Subject string `json:"subject" dc:"所属专题"`
|
||||
}
|
||||
|
||||
// LessonExportModel 导出课程管理
|
||||
type LessonExportModel struct {
|
||||
Id int `json:"id" dc:"id"`
|
||||
Id int64 `json:"id" dc:"id"`
|
||||
Name string `json:"name" dc:"课程名"`
|
||||
Cover string `json:"cover" dc:"封面图"`
|
||||
CategoryId int `json:"categoryId" dc:"所属分类"`
|
||||
CategoryId int64 `json:"categoryId" dc:"所属分类"`
|
||||
Video string `json:"video" dc:"介绍视频"`
|
||||
School string `json:"school" dc:"所属学校"`
|
||||
Description string `json:"description" dc:"课程概述"`
|
||||
@ -127,4 +149,6 @@ type LessonExportModel struct {
|
||||
StartTime *gtime.Time `json:"startTime" dc:"开课时间"`
|
||||
EndTime *gtime.Time `json:"endTime" dc:"结课时间"`
|
||||
Question string `json:"question" dc:"常见问题"`
|
||||
Difficulty int `json:"difficulty" dc:"课程难度"`
|
||||
Subject string `json:"subject" dc:"所属专题"`
|
||||
}
|
@ -8,8 +8,10 @@ package router
|
||||
import (
|
||||
"context"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/internal/controller/api/activity"
|
||||
"hotgo/internal/controller/api/lesson"
|
||||
"hotgo/internal/controller/api/member"
|
||||
"hotgo/internal/controller/api/mycourse"
|
||||
"hotgo/internal/controller/api/pay"
|
||||
"hotgo/internal/controller/api/users"
|
||||
"hotgo/internal/service"
|
||||
@ -32,8 +34,10 @@ func Api(ctx context.Context, group *ghttp.RouterGroup) {
|
||||
|
||||
group.Group(simple.RouterPrefix(ctx, consts.AppApi), func(group *ghttp.RouterGroup) {
|
||||
group.Bind(
|
||||
users.NewV1(), // 前台用户
|
||||
lesson.NewV1(), // 课程
|
||||
users.NewV1(), // 前台用户
|
||||
lesson.NewV1(), // 课程
|
||||
activity.NewV1(), // 活动
|
||||
mycourse.NewV1(), // 我的课程
|
||||
)
|
||||
})
|
||||
}
|
||||
|
13
server/internal/router/genrouter/activity.go
Normal file
13
server/internal/router/genrouter/activity.go
Normal file
@ -0,0 +1,13 @@
|
||||
// Package genrouter
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2025 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
// @AutoGenerate Version 2.17.8
|
||||
package genrouter
|
||||
|
||||
import "hotgo/internal/controller/admin/sys"
|
||||
|
||||
func init() {
|
||||
LoginRequiredRouter = append(LoginRequiredRouter, sys.Activity) // 活动管理
|
||||
}
|
33
server/internal/service/mycourse.go
Normal file
33
server/internal/service/mycourse.go
Normal file
@ -0,0 +1,33 @@
|
||||
// ================================================================================
|
||||
// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
|
||||
// You can delete these comments if you wish manually maintain this interface file.
|
||||
// ================================================================================
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "hotgo/api/api/mycourse/v1"
|
||||
)
|
||||
|
||||
type (
|
||||
IMyCourse interface {
|
||||
// GetList 获取我的课程列表
|
||||
GetList(ctx context.Context, req *v1.MyCourseListReq) (res *v1.MyCourseListRes, err error)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
localMyCourse IMyCourse
|
||||
)
|
||||
|
||||
func MyCourse() IMyCourse {
|
||||
if localMyCourse == nil {
|
||||
panic("implement not found for interface IMyCourse, forgot register?")
|
||||
}
|
||||
return localMyCourse
|
||||
}
|
||||
|
||||
func RegisterMyCourse(i IMyCourse) {
|
||||
localMyCourse = i
|
||||
}
|
@ -20,6 +20,22 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
ISysActivity interface {
|
||||
// Model 活动管理ORM模型
|
||||
Model(ctx context.Context, option ...*handler.Option) *gdb.Model
|
||||
// List 获取活动管理列表
|
||||
List(ctx context.Context, in *sysin.ActivityListInp) (list []*sysin.ActivityListModel, totalCount int, err error)
|
||||
// Export 导出活动管理
|
||||
Export(ctx context.Context, in *sysin.ActivityListInp) (err error)
|
||||
// Edit 修改/新增活动管理
|
||||
Edit(ctx context.Context, in *sysin.ActivityEditInp) (err error)
|
||||
// Delete 删除活动管理
|
||||
Delete(ctx context.Context, in *sysin.ActivityDeleteInp) (err error)
|
||||
// View 获取活动管理指定信息
|
||||
View(ctx context.Context, in *sysin.ActivityViewInp) (res *sysin.ActivityViewModel, err error)
|
||||
// Status 更新活动管理状态
|
||||
Status(ctx context.Context, in *sysin.ActivityStatusInp) (err error)
|
||||
}
|
||||
ISysAddons interface {
|
||||
// List 获取列表
|
||||
List(ctx context.Context, in *sysin.AddonsListInp) (list []*sysin.AddonsListModel, totalCount int, err error)
|
||||
@ -468,6 +484,7 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
localSysActivity ISysActivity
|
||||
localSysAddons ISysAddons
|
||||
localSysAddonsConfig ISysAddonsConfig
|
||||
localSysAttachment ISysAttachment
|
||||
@ -495,6 +512,17 @@ var (
|
||||
localSysUsers ISysUsers
|
||||
)
|
||||
|
||||
func SysActivity() ISysActivity {
|
||||
if localSysActivity == nil {
|
||||
panic("implement not found for interface ISysActivity, forgot register?")
|
||||
}
|
||||
return localSysActivity
|
||||
}
|
||||
|
||||
func RegisterSysActivity(i ISysActivity) {
|
||||
localSysActivity = i
|
||||
}
|
||||
|
||||
func SysAddons() ISysAddons {
|
||||
if localSysAddons == nil {
|
||||
panic("implement not found for interface ISysAddons, forgot register?")
|
||||
|
65
server/storage/data/generate/activity_menu.sql
Normal file
65
server/storage/data/generate/activity_menu.sql
Normal file
@ -0,0 +1,65 @@
|
||||
-- hotgo自动生成菜单权限SQL 通常情况下只在首次生成代码时自动执行一次
|
||||
-- 如需再次执行请先手动删除生成的菜单权限和SQL文件:/Users/guochen/Documents/projects/g031/hotgo/server/storage/data/generate/activity_menu.sql
|
||||
-- Version: 2.17.8
|
||||
-- Date: 2025-07-28 21:16:53
|
||||
-- Link https://github.com/bufanyun/hotgo
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET AUTOCOMMIT = 0;
|
||||
START TRANSACTION;
|
||||
|
||||
--
|
||||
-- 数据库: `hotgo`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- 插入表中的数据 `hg_admin_menu`
|
||||
--
|
||||
|
||||
|
||||
SET @now := now();
|
||||
|
||||
|
||||
-- 菜单目录
|
||||
INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, '0', '活动管理', 'activity', '/activity', 'MenuOutlined', '1', '/activity/index', '', '', 'LAYOUT', '1', '', '0', '0', '', '0', '0', '0', '1', '', '0', '', '1', @now, @now);
|
||||
|
||||
|
||||
SET @dirId = LAST_INSERT_ID();
|
||||
|
||||
|
||||
-- 菜单页面
|
||||
-- 列表
|
||||
INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @dirId, '活动管理列表', 'activityIndex', 'index', '', '2', '', '/activity/list', '', '/activity/index', '1', 'activity', '0', '0', '', '0', '1', '0', '2', CONCAT('tr_', @dirId,' '), '10', '', '1', @now, @now);
|
||||
|
||||
|
||||
SET @listId = LAST_INSERT_ID();
|
||||
|
||||
-- 详情
|
||||
INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '活动管理详情', 'activityView', '', '', '3', '', '/activity/view', '', '', '1', '', '0', '0', '', '0', '1', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '10', '', '1', @now, @now);
|
||||
|
||||
|
||||
-- 菜单按钮
|
||||
|
||||
-- 编辑
|
||||
INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '编辑/新增活动管理', 'activityEdit', '', '', '3', '', '/activity/edit', '', '', '1', '', '0', '0', '', '0', '1', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '20', '', '1', @now, @now);
|
||||
|
||||
|
||||
SET @editId = LAST_INSERT_ID();
|
||||
|
||||
|
||||
-- 删除
|
||||
INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '删除活动管理', 'activityDelete', '', '', '3', '', '/activity/delete', '', '', '1', '', '0', '0', '', '0', '0', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '40', '', '1', @now, @now);
|
||||
|
||||
|
||||
-- 更新状态
|
||||
INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '修改活动管理状态', 'activityStatus', '', '', '3', '', '/activity/status', '', '', '1', '', '0', '0', '', '0', '0', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '50', '', '1', @now, @now);
|
||||
|
||||
|
||||
|
||||
-- 导出
|
||||
INSERT INTO `hg_admin_menu` (`id`, `pid`, `title`, `name`, `path`, `icon`, `type`, `redirect`, `permissions`, `permission_name`, `component`, `always_show`, `active_menu`, `is_root`, `is_frame`, `frame_src`, `keep_alive`, `hidden`, `affix`, `level`, `tree`, `sort`, `remark`, `status`, `created_at`, `updated_at`) VALUES (NULL, @listId, '导出活动管理', 'activityExport', '', '', '3', '', '/activity/export', '', '', '1', '', '0', '0', '', '0', '0', '0', '3', CONCAT('tr_', @dirId, ' tr_', @listId,' '), '70', '', '1', @now, @now);
|
||||
|
||||
|
||||
COMMIT;
|
51
web/src/api/activity/index.ts
Normal file
51
web/src/api/activity/index.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { http, jumpExport } from '@/utils/http/axios';
|
||||
|
||||
// 获取活动管理列表
|
||||
export function List(params) {
|
||||
return http.request({
|
||||
url: '/activity/list',
|
||||
method: 'get',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除/批量删除活动管理
|
||||
export function Delete(params) {
|
||||
return http.request({
|
||||
url: '/activity/delete',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 添加/编辑活动管理
|
||||
export function Edit(params) {
|
||||
return http.request({
|
||||
url: '/activity/edit',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 修改活动管理状态
|
||||
export function Status(params) {
|
||||
return http.request({
|
||||
url: '/activity/status',
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 获取活动管理指定详情
|
||||
export function View(params) {
|
||||
return http.request({
|
||||
url: '/activity/view',
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
// 导出活动管理
|
||||
export function Export(params) {
|
||||
jumpExport('/activity/export', params);
|
||||
}
|
@ -14,6 +14,7 @@
|
||||
@uploadChange="uploadChange"
|
||||
v-model:value="image"
|
||||
v-model:values="images"
|
||||
:maxSize="100"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -52,6 +52,7 @@ export default {
|
||||
'audio/mp4',
|
||||
'video/webm',
|
||||
'video/x-flv',
|
||||
'video/mp4',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
172
web/src/views/activity/edit.vue
Normal file
172
web/src/views/activity/edit.vue
Normal file
@ -0,0 +1,172 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-modal
|
||||
v-model:show="showModal"
|
||||
:mask-closable="false"
|
||||
:show-icon="false"
|
||||
preset="dialog"
|
||||
transform-origin="center"
|
||||
:title="formValue.id > 0 ? '编辑活动管理 #' + formValue.id : '添加活动管理'"
|
||||
:style="{
|
||||
width: dialogWidth,
|
||||
}"
|
||||
>
|
||||
<n-scrollbar style="max-height: 87vh" class="pr-5">
|
||||
<n-spin :show="loading" description="请稍候...">
|
||||
<n-form
|
||||
ref="formRef"
|
||||
:model="formValue"
|
||||
:label-placement="settingStore.isMobile ? 'top' : 'left'"
|
||||
:label-width="100"
|
||||
class="py-4"
|
||||
>
|
||||
<n-grid cols="1 s:1 m:1 l:1 xl:1 2xl:1" responsive="screen">
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动标题" path="title">
|
||||
<n-input placeholder="请输入活动标题" v-model:value="formValue.title" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动介绍" path="introduction">
|
||||
<Editor style="height: 450px" id="introduction" v-model:value="formValue.introduction" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动封面图" path="cover">
|
||||
<UploadImage :maxNumber="1" v-model:value="formValue.cover" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="说明图片" path="imgs">
|
||||
<UploadImage :maxNumber="10" v-model:value="formValue.imgs" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动头图" path="banner">
|
||||
<UploadImage :maxNumber="1" v-model:value="formValue.banner" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动视频" path="video">
|
||||
<UploadFile :maxNumber="1" v-model:value="formValue.video" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动开始时间" path="startTime">
|
||||
<DatePicker v-model:formValue="formValue.startTime" type="datetime" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动结束时间" path="endTime">
|
||||
<DatePicker v-model:formValue="formValue.endTime" type="datetime" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动附件" path="attachment">
|
||||
<UploadFile :maxNumber="10" v-model:value="formValue.attachment" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="活动状态" path="status">
|
||||
<n-select v-model:value="formValue.status" :options="dict.getOptionUnRef('sys_normal_disable')" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
</n-form>
|
||||
</n-spin>
|
||||
</n-scrollbar>
|
||||
<template #action>
|
||||
<n-space>
|
||||
<n-button @click="closeForm">
|
||||
取消
|
||||
</n-button>
|
||||
<n-button type="info" :loading="formBtnLoading" @click="confirmForm">
|
||||
确定
|
||||
</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { Edit, View } from '@/api/activity';
|
||||
import { State, newState } from './model';
|
||||
import Editor from '@/components/Editor/editor.vue';
|
||||
import UploadImage from '@/components/Upload/uploadImage.vue';
|
||||
import UploadFile from '@/components/Upload/uploadFile.vue';
|
||||
import DatePicker from '@/components/DatePicker/datePicker.vue';
|
||||
import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { adaModalWidth } from '@/utils/hotgo';
|
||||
|
||||
const emit = defineEmits(['reloadTable']);
|
||||
const message = useMessage();
|
||||
const settingStore = useProjectSettingStore();
|
||||
const dict = useDictStore();
|
||||
const loading = ref(false);
|
||||
const showModal = ref(false);
|
||||
const formValue = ref<State>(newState(null));
|
||||
const formRef = ref<any>({});
|
||||
const formBtnLoading = ref(false);
|
||||
const dialogWidth = computed(() => {
|
||||
return adaModalWidth(840);
|
||||
});
|
||||
|
||||
// 提交表单
|
||||
function confirmForm(e) {
|
||||
e.preventDefault();
|
||||
formRef.value.validate((errors) => {
|
||||
if (!errors) {
|
||||
formBtnLoading.value = true;
|
||||
Edit(formValue.value)
|
||||
.then((_res) => {
|
||||
message.success('操作成功');
|
||||
closeForm();
|
||||
emit('reloadTable');
|
||||
})
|
||||
.finally(() => {
|
||||
formBtnLoading.value = false;
|
||||
});
|
||||
} else {
|
||||
message.error('请填写完整信息');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭表单
|
||||
function closeForm() {
|
||||
showModal.value = false;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function openModal(state: State) {
|
||||
showModal.value = true;
|
||||
|
||||
// 新增
|
||||
if (!state || state.id < 1) {
|
||||
formValue.value = newState(state);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 编辑
|
||||
loading.value = true;
|
||||
View({ id: state.id })
|
||||
.then((res) => {
|
||||
formValue.value = res;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openModal,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less"></style>
|
225
web/src/views/activity/index.vue
Normal file
225
web/src/views/activity/index.vue
Normal file
@ -0,0 +1,225 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="n-layout-page-header">
|
||||
<n-card :bordered="false" title="活动管理">
|
||||
<!-- 这是由系统生成的CURD表格,你可以将此行注释改为表格的描述 -->
|
||||
</n-card>
|
||||
</div>
|
||||
<n-card :bordered="false" class="proCard">
|
||||
<BasicForm ref="searchFormRef" @register="register" @submit="reloadTable" @reset="reloadTable" @keyup.enter="reloadTable">
|
||||
<template #statusSlot="{ model, field }">
|
||||
<n-input v-model:value="model[field]" />
|
||||
</template>
|
||||
</BasicForm>
|
||||
<BasicTable ref="actionRef" openChecked :columns="columns" :request="loadDataTable" :row-key="(row) => row.id" :actionColumn="actionColumn" :scroll-x="scrollX" :resizeHeightOffset="-10000" :checked-row-keys="checkedIds" @update:checked-row-keys="handleOnCheckedRow">
|
||||
<template #tableTitle>
|
||||
<n-button type="primary" @click="addTable" class="min-left-space" v-if="hasPermission(['/activity/edit'])">
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<PlusOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
添加
|
||||
</n-button>
|
||||
<n-button type="error" @click="handleBatchDelete" class="min-left-space" v-if="hasPermission(['/activity/delete'])">
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<DeleteOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
批量删除
|
||||
</n-button>
|
||||
<n-button type="primary" @click="handleExport" class="min-left-space" v-if="hasPermission(['/activity/export'])">
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<ExportOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
导出
|
||||
</n-button>
|
||||
</template>
|
||||
</BasicTable>
|
||||
</n-card>
|
||||
<Edit ref="editRef" @reloadTable="reloadTable" />
|
||||
<View ref="viewRef" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { h, reactive, ref, computed, onMounted } from 'vue';
|
||||
import { useDialog, useMessage } from 'naive-ui';
|
||||
import { BasicTable, TableAction } from '@/components/Table';
|
||||
import { BasicForm, useForm } from '@/components/Form/index';
|
||||
import { usePermission } from '@/hooks/web/usePermission';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { List, Export, Delete, Status } from '@/api/activity';
|
||||
import { PlusOutlined, ExportOutlined, DeleteOutlined } from '@vicons/antd';
|
||||
import { columns, schemas, loadOptions } from './model';
|
||||
import { adaTableScrollX } from '@/utils/hotgo';
|
||||
import Edit from './edit.vue';
|
||||
import View from './view.vue';
|
||||
|
||||
const dict = useDictStore();
|
||||
const dialog = useDialog();
|
||||
const message = useMessage();
|
||||
const { hasPermission } = usePermission();
|
||||
const actionRef = ref();
|
||||
const searchFormRef = ref<any>({});
|
||||
const editRef = ref();
|
||||
const viewRef = ref();
|
||||
const checkedIds = ref([]);
|
||||
|
||||
const actionColumn = reactive({
|
||||
width: 288,
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
fixed: 'right',
|
||||
render(record: State) {
|
||||
return h(TableAction as any, {
|
||||
style: 'button',
|
||||
actions: [
|
||||
{
|
||||
label: '编辑',
|
||||
onClick: handleEdit.bind(null, record),
|
||||
auth: ['/activity/edit'],
|
||||
},
|
||||
|
||||
{
|
||||
label: '禁用',
|
||||
onClick: handleStatus.bind(null, record, 2),
|
||||
ifShow: () => {
|
||||
return record.status === 1;
|
||||
},
|
||||
auth: ['/activity/status'],
|
||||
},
|
||||
{
|
||||
label: '启用',
|
||||
onClick: handleStatus.bind(null, record, 1),
|
||||
ifShow: () => {
|
||||
return record.status === 2;
|
||||
},
|
||||
auth: ['/activity/status'],
|
||||
},
|
||||
{
|
||||
label: '删除',
|
||||
onClick: handleDelete.bind(null, record),
|
||||
auth: ['/activity/delete'],
|
||||
},
|
||||
],
|
||||
dropDownActions: [
|
||||
{
|
||||
label: '查看详情',
|
||||
key: 'view',
|
||||
auth: ['/activity/view'],
|
||||
},
|
||||
],
|
||||
select: (key) => {
|
||||
if (key === 'view') {
|
||||
return handleView(record);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
const scrollX = computed(() => {
|
||||
return adaTableScrollX(columns, actionColumn.width);
|
||||
});
|
||||
|
||||
const [register, {}] = useForm({
|
||||
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
||||
labelWidth: 80,
|
||||
schemas,
|
||||
});
|
||||
|
||||
// 加载表格数据
|
||||
const loadDataTable = async (res) => {
|
||||
return await List({ ...searchFormRef.value?.formModel, ...res });
|
||||
};
|
||||
|
||||
// 更新选中的行
|
||||
function handleOnCheckedRow(rowKeys) {
|
||||
checkedIds.value = rowKeys;
|
||||
}
|
||||
|
||||
// 重新加载表格数据
|
||||
function reloadTable() {
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
// 添加数据
|
||||
function addTable() {
|
||||
editRef.value.openModal(null);
|
||||
}
|
||||
|
||||
// 编辑数据
|
||||
function handleEdit(record: Recordable) {
|
||||
editRef.value.openModal(record);
|
||||
}
|
||||
|
||||
// 查看详情
|
||||
function handleView(record: Recordable) {
|
||||
viewRef.value.openModal(record);
|
||||
}
|
||||
|
||||
// 单个删除
|
||||
function handleDelete(record: Recordable) {
|
||||
dialog.warning({
|
||||
title: '警告',
|
||||
content: '你确定要删除?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: () => {
|
||||
Delete(record).then((_res) => {
|
||||
message.success('删除成功');
|
||||
reloadTable();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
function handleBatchDelete() {
|
||||
if (checkedIds.value.length < 1){
|
||||
message.error('请至少选择一项要删除的数据');
|
||||
return;
|
||||
}
|
||||
|
||||
dialog.warning({
|
||||
title: '警告',
|
||||
content: '你确定要批量删除?',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: () => {
|
||||
Delete({ id: checkedIds.value }).then((_res) => {
|
||||
checkedIds.value = [];
|
||||
message.success('删除成功');
|
||||
reloadTable();
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// 导出
|
||||
function handleExport() {
|
||||
message.loading('正在导出列表...', { duration: 1200 });
|
||||
Export(searchFormRef.value?.formModel);
|
||||
}
|
||||
|
||||
// 修改状态
|
||||
function handleStatus(record: Recordable, status: number) {
|
||||
Status({ id: record.id, status: status }).then((_res) => {
|
||||
message.success('设为' + dict.getLabel('sys_normal_disable', status) + '成功');
|
||||
setTimeout(() => {
|
||||
reloadTable();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadOptions();
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
133
web/src/views/activity/model.ts
Normal file
133
web/src/views/activity/model.ts
Normal file
@ -0,0 +1,133 @@
|
||||
import { h, ref } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { renderImage, renderOptionTag } from '@/utils';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
|
||||
const dict = useDictStore();
|
||||
|
||||
export class State {
|
||||
public id = 0; // id
|
||||
public title = ''; // 活动标题
|
||||
public introduction = ''; // 活动介绍
|
||||
public cover = ''; // 活动封面图
|
||||
public imgs = ''; // 说明图片
|
||||
public banner = ''; // 活动头图
|
||||
public video = ''; // 活动视频
|
||||
public startTime = ''; // 活动开始时间
|
||||
public endTime = ''; // 活动结束时间
|
||||
public extra = ''; // 扩展字段
|
||||
public attachment = ''; // 活动附件
|
||||
public status = 1; // 活动状态
|
||||
public revision = 0; // 乐观锁
|
||||
public createdBy = 0; // 创建人
|
||||
public createdTime = ''; // 创建时间
|
||||
public updatedBy = 0; // 更新人
|
||||
public updatedTime = ''; // 更新时间
|
||||
|
||||
constructor(state?: Partial<State>) {
|
||||
if (state) {
|
||||
Object.assign(this, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function newState(state: State | Record<string, any> | null): State {
|
||||
if (state !== null) {
|
||||
if (state instanceof State) {
|
||||
return cloneDeep(state);
|
||||
}
|
||||
return new State(state);
|
||||
}
|
||||
return new State();
|
||||
}
|
||||
|
||||
// 表单验证规则
|
||||
|
||||
// 表格搜索表单
|
||||
export const schemas = ref<FormSchema[]>([
|
||||
{
|
||||
field: 'id',
|
||||
component: 'NInputNumber',
|
||||
label: 'id',
|
||||
componentProps: {
|
||||
placeholder: '请输入id',
|
||||
onUpdateValue: (e: any) => {
|
||||
console.log(e);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
component: 'NSelect',
|
||||
label: '活动状态',
|
||||
defaultValue: null,
|
||||
componentProps: {
|
||||
placeholder: '请选择活动状态',
|
||||
options: dict.getOption('sys_normal_disable'),
|
||||
onUpdateValue: (e: any) => {
|
||||
console.log(e);
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
// 表格列
|
||||
export const columns = [
|
||||
{
|
||||
title: 'id',
|
||||
key: 'id',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
},
|
||||
{
|
||||
title: '活动标题',
|
||||
key: 'title',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
},
|
||||
{
|
||||
title: '活动封面图',
|
||||
key: 'cover',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
render(row: State) {
|
||||
return renderImage(row.cover);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '活动头图',
|
||||
key: 'banner',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
render(row: State) {
|
||||
return renderImage(row.banner);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '活动开始时间',
|
||||
key: 'startTime',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
},
|
||||
{
|
||||
title: '活动结束时间',
|
||||
key: 'endTime',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
},
|
||||
{
|
||||
title: '活动状态',
|
||||
key: 'status',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
render(row: State) {
|
||||
return renderOptionTag('sys_normal_disable', row.status);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 加载字典数据选项
|
||||
export function loadOptions() {
|
||||
dict.loadOptions(['sys_normal_disable']);
|
||||
}
|
155
web/src/views/activity/view.vue
Normal file
155
web/src/views/activity/view.vue
Normal file
@ -0,0 +1,155 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-drawer v-model:show="showModal" :width="dialogWidth">
|
||||
<n-drawer-content title="活动管理详情" closable>
|
||||
<n-spin :show="loading" description="请稍候...">
|
||||
<n-descriptions label-placement="left" class="py-2" :column="1">
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
活动标题
|
||||
</template>
|
||||
{{ formValue.title }}
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
活动介绍
|
||||
</template>
|
||||
<span v-html="formValue.introduction"></span>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
活动封面图
|
||||
</template>
|
||||
<n-image style="margin-left: 10px; height: 100px; width: 100px" :src="formValue.cover"/>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
说明图片
|
||||
</template>
|
||||
<n-image-group>
|
||||
<n-space>
|
||||
<span v-for="(item, key) in formValue.imgs" :key="key">
|
||||
<n-image style="margin-left: 10px; height: 100px; width: 100px" :src="item" />
|
||||
</span>
|
||||
</n-space>
|
||||
</n-image-group>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
活动头图
|
||||
</template>
|
||||
<n-image style="margin-left: 10px; height: 100px; width: 100px" :src="formValue.banner"/>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
活动视频
|
||||
</template>
|
||||
<div class="upload-card" v-show="formValue.video !== ''" @click="download(formValue.video)">
|
||||
<div class="upload-card-item" style="height: 100px; width: 100px">
|
||||
<div class="upload-card-item-info">
|
||||
<div class="img-box">
|
||||
<n-avatar :style="fileAvatarCSS">
|
||||
{{ getFileExt(formValue.video) }}
|
||||
</n-avatar>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
活动开始时间
|
||||
</template>
|
||||
{{ formValue.startTime }}
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
活动结束时间
|
||||
</template>
|
||||
{{ formValue.endTime }}
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item>
|
||||
<template #label>
|
||||
活动附件
|
||||
</template>
|
||||
<div class="upload-card">
|
||||
<n-space style="gap: 0px 0px">
|
||||
<div
|
||||
class="upload-card-item"
|
||||
style="height: 100px; width: 100px"
|
||||
v-for="(item, key) in formValue.attachment"
|
||||
:key="key"
|
||||
>
|
||||
<div class="upload-card-item-info">
|
||||
<div class="img-box">
|
||||
<n-avatar :style="fileAvatarCSS" @click="download(item)">
|
||||
{{
|
||||
getFileExt(item)
|
||||
}}
|
||||
</n-avatar>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</n-space>
|
||||
</div>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item label="活动状态">
|
||||
<n-tag :type="dict.getType('sys_normal_disable', formValue.status)" size="small" class="min-left-space">
|
||||
{{ dict.getLabel('sys_normal_disable', formValue.status) }}
|
||||
</n-tag>
|
||||
</n-descriptions-item>
|
||||
</n-descriptions>
|
||||
</n-spin>
|
||||
</n-drawer-content>
|
||||
</n-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { View } from '@/api/activity';
|
||||
import { State, newState } from './model';
|
||||
import { adaModalWidth } from '@/utils/hotgo';
|
||||
import { getFileExt } from '@/utils/urlUtils';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
|
||||
const message = useMessage();
|
||||
const dict = useDictStore();
|
||||
const loading = ref(false);
|
||||
const showModal = ref(false);
|
||||
const formValue = ref(newState(null));
|
||||
const dialogWidth = computed(() => {
|
||||
return adaModalWidth(580);
|
||||
});
|
||||
const fileAvatarCSS = computed(() => {
|
||||
return {
|
||||
'--n-merged-size': `var(--n-avatar-size-override, 80px)`,
|
||||
'--n-font-size': `18px`,
|
||||
};
|
||||
});
|
||||
|
||||
// 下载
|
||||
function download(url: string) {
|
||||
window.open(url);
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function openModal(state: State) {
|
||||
showModal.value = true;
|
||||
loading.value = true;
|
||||
View({ id: state.id })
|
||||
.then((res) => {
|
||||
formValue.value = res;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openModal,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
@ -16,6 +16,7 @@
|
||||
<n-form
|
||||
ref="formRef"
|
||||
:model="formValue"
|
||||
:rules="rules"
|
||||
:label-placement="settingStore.isMobile ? 'top' : 'left'"
|
||||
:label-width="100"
|
||||
class="py-4"
|
||||
@ -91,6 +92,16 @@
|
||||
<Editor style="height: 450px" id="question" v-model:value="formValue.question" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="课程难度" path="difficulty">
|
||||
<n-select v-model:value="formValue.difficulty" :options="dict.getOptionUnRef('lesson_difficulty')" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="所属专题" path="subject">
|
||||
<n-select multiple v-model:value="formValue.subject" :options="dict.getOptionUnRef('lesson_subject')" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
</n-form>
|
||||
</n-spin>
|
||||
@ -113,7 +124,7 @@
|
||||
import { ref, computed } from 'vue';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { Edit, View } from '@/api/lesson';
|
||||
import { State, newState } from './model';
|
||||
import { State, newState, rules } from './model';
|
||||
import UploadImage from '@/components/Upload/uploadImage.vue';
|
||||
import UploadFile from '@/components/Upload/uploadFile.vue';
|
||||
import Editor from '@/components/Editor/editor.vue';
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { h, ref } from 'vue';
|
||||
import { NTag } from 'naive-ui';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { FormSchema } from '@/components/Form';
|
||||
import { isNullObject } from '@/utils/is';
|
||||
import { renderImage, renderOptionTag, renderFile } from '@/utils';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
|
||||
@ -27,6 +29,8 @@ export class State {
|
||||
public createdTime = ''; // 创建时间
|
||||
public updatedBy = 0; // 更新人
|
||||
public updatedTime = ''; // 更新时间
|
||||
public difficulty = null; // 课程难度
|
||||
public subject = null; // 所属专题
|
||||
|
||||
constructor(state?: Partial<State>) {
|
||||
if (state) {
|
||||
@ -46,9 +50,40 @@ export function newState(state: State | Record<string, any> | null): State {
|
||||
}
|
||||
|
||||
// 表单验证规则
|
||||
export const rules = {
|
||||
name: {
|
||||
required: true,
|
||||
trigger: ['blur', 'input'],
|
||||
type: 'string',
|
||||
message: '请输入课程名',
|
||||
},
|
||||
cover: {
|
||||
required: true,
|
||||
trigger: ['blur', 'input'],
|
||||
type: 'string',
|
||||
message: '请输入封面图',
|
||||
},
|
||||
categoryId: {
|
||||
required: true,
|
||||
trigger: ['blur', 'input'],
|
||||
type: 'number',
|
||||
message: '请输入所属分类',
|
||||
},
|
||||
};
|
||||
|
||||
// 表格搜索表单
|
||||
export const schemas = ref<FormSchema[]>([
|
||||
{
|
||||
field: 'id',
|
||||
component: 'NInputNumber',
|
||||
label: 'id',
|
||||
componentProps: {
|
||||
placeholder: '请输入id',
|
||||
onUpdateValue: (e: any) => {
|
||||
console.log(e);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
component: 'NInput',
|
||||
@ -132,9 +167,32 @@ export const columns = [
|
||||
align: 'left',
|
||||
width: -1,
|
||||
},
|
||||
{
|
||||
title: '课程难度',
|
||||
key: 'difficulty',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
render(row: State) {
|
||||
return renderOptionTag('lesson_difficulty', row.difficulty);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '所属专题',
|
||||
key: 'subject',
|
||||
align: 'left',
|
||||
width: -1,
|
||||
render(row: State) {
|
||||
if (isNullObject(row.subject) || !isArray(row.subject)) {
|
||||
return ``;
|
||||
}
|
||||
return row.subject.map((tagKey) => {
|
||||
return renderOptionTag('lesson_subject', row.tagKey)
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 加载字典数据选项
|
||||
export function loadOptions() {
|
||||
dict.loadOptions(['lessonCategoryOption']);
|
||||
dict.loadOptions(['lesson_subject', 'lesson_difficulty', 'lessonCategoryOption']);
|
||||
}
|
@ -97,6 +97,18 @@
|
||||
</template>
|
||||
<span v-html="formValue.question"></span>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item label="课程难度">
|
||||
<n-tag :type="dict.getType('lesson_difficulty', formValue.difficulty)" size="small" class="min-left-space">
|
||||
{{ dict.getLabel('lesson_difficulty', formValue.difficulty) }}
|
||||
</n-tag>
|
||||
</n-descriptions-item>
|
||||
<n-descriptions-item label="所属专题">
|
||||
<template v-for="(item, key) in formValue.subject" :key="key">
|
||||
<n-tag :type="dict.getType('lesson_subject', item)" size="small" class="min-left-space">
|
||||
{{ dict.getLabel('lesson_subject', item) }}
|
||||
</n-tag>
|
||||
</template>
|
||||
</n-descriptions-item>
|
||||
</n-descriptions>
|
||||
</n-spin>
|
||||
</n-drawer-content>
|
||||
|
@ -1,25 +1,13 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-modal
|
||||
v-model:show="showModal"
|
||||
:mask-closable="false"
|
||||
:show-icon="false"
|
||||
preset="dialog"
|
||||
transform-origin="center"
|
||||
:title="formValue.id > 0 ? '编辑课程章节 #' + formValue.id : '添加课程章节'"
|
||||
:style="{
|
||||
<n-modal v-model:show="showModal" :mask-closable="false" :show-icon="false" preset="dialog"
|
||||
transform-origin="center" :title="formValue.id > 0 ? '编辑课程章节 #' + formValue.id : '添加课程章节'" :style="{
|
||||
width: dialogWidth,
|
||||
}"
|
||||
>
|
||||
}">
|
||||
<n-scrollbar style="max-height: 87vh" class="pr-5">
|
||||
<n-spin :show="loading" description="请稍候...">
|
||||
<n-form
|
||||
ref="formRef"
|
||||
:model="formValue"
|
||||
:label-placement="settingStore.isMobile ? 'top' : 'left'"
|
||||
:label-width="100"
|
||||
class="py-4"
|
||||
>
|
||||
<n-form ref="formRef" :model="formValue" :label-placement="settingStore.isMobile ? 'top' : 'left'"
|
||||
:label-width="100" class="py-4">
|
||||
<n-grid cols="1 s:1 m:1 l:1 xl:1 2xl:1" responsive="screen">
|
||||
<n-gi span="1">
|
||||
<n-form-item label="课程id" path="lessonId">
|
||||
@ -28,7 +16,16 @@
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
<n-form-item label="视频url" path="videoUrl">
|
||||
<n-input placeholder="请输入视频url" v-model:value="formValue.videoUrl" />
|
||||
<n-upload
|
||||
:action="`${uploadUrl}${urlPrefix}/upload/video`"
|
||||
:max="1"
|
||||
:show-file-list="false"
|
||||
:headers="uploadHeaders"
|
||||
@finish="handleVideoUpload"
|
||||
@before-upload="handleVideoUploadStart"
|
||||
>
|
||||
<n-button :loading="uploadingVideo">上传视频</n-button>
|
||||
</n-upload>
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi span="1">
|
||||
@ -70,79 +67,111 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { Edit, View } from '@/api/lessonSection';
|
||||
import { State, newState } from './model';
|
||||
import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { adaModalWidth } from '@/utils/hotgo';
|
||||
import { ref, computed, reactive } from 'vue';
|
||||
import { useDictStore } from '@/store/modules/dict';
|
||||
import { Edit, View } from '@/api/lessonSection';
|
||||
import { State, newState } from './model';
|
||||
import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import { adaModalWidth } from '@/utils/hotgo';
|
||||
import { useGlobSetting } from '@/hooks/setting';
|
||||
import { useUserStoreWidthOut } from '@/store/modules/user';
|
||||
|
||||
const emit = defineEmits(['reloadTable']);
|
||||
const message = useMessage();
|
||||
const settingStore = useProjectSettingStore();
|
||||
const dict = useDictStore();
|
||||
const loading = ref(false);
|
||||
const showModal = ref(false);
|
||||
const formValue = ref<State>(newState(null));
|
||||
const formRef = ref<any>({});
|
||||
const formBtnLoading = ref(false);
|
||||
const dialogWidth = computed(() => {
|
||||
return adaModalWidth(840);
|
||||
const globSetting = useGlobSetting();
|
||||
const urlPrefix = globSetting.urlPrefix || '';
|
||||
const { uploadUrl } = globSetting;
|
||||
|
||||
const useUserStore = useUserStoreWidthOut();
|
||||
const uploadHeaders = reactive({
|
||||
Authorization: useUserStore.token,
|
||||
uploadType: 'default',
|
||||
});
|
||||
|
||||
// 提交表单
|
||||
function confirmForm(e) {
|
||||
e.preventDefault();
|
||||
formRef.value.validate((errors) => {
|
||||
if (!errors) {
|
||||
formBtnLoading.value = true;
|
||||
Edit(formValue.value)
|
||||
.then((_res) => {
|
||||
message.success('操作成功');
|
||||
closeForm();
|
||||
emit('reloadTable');
|
||||
})
|
||||
.finally(() => {
|
||||
formBtnLoading.value = false;
|
||||
});
|
||||
} else {
|
||||
message.error('请填写完整信息');
|
||||
}
|
||||
});
|
||||
}
|
||||
const emit = defineEmits(['reloadTable']);
|
||||
const message = useMessage();
|
||||
const settingStore = useProjectSettingStore();
|
||||
const dict = useDictStore();
|
||||
const loading = ref(false);
|
||||
const showModal = ref(false);
|
||||
const formValue = ref<State>(newState(null));
|
||||
const formRef = ref<any>({});
|
||||
const formBtnLoading = ref(false);
|
||||
const dialogWidth = computed(() => {
|
||||
return adaModalWidth(840);
|
||||
});
|
||||
const uploadingVideo = ref(false);
|
||||
|
||||
// 关闭表单
|
||||
function closeForm() {
|
||||
showModal.value = false;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function openModal(state: State) {
|
||||
showModal.value = true;
|
||||
|
||||
// 新增
|
||||
if (!state || state.id < 1) {
|
||||
formValue.value = newState(state);
|
||||
|
||||
return;
|
||||
// 提交表单
|
||||
function confirmForm(e) {
|
||||
e.preventDefault();
|
||||
formRef.value.validate((errors) => {
|
||||
if (!errors) {
|
||||
formBtnLoading.value = true;
|
||||
Edit(formValue.value)
|
||||
.then((_res) => {
|
||||
message.success('操作成功');
|
||||
closeForm();
|
||||
emit('reloadTable');
|
||||
})
|
||||
.finally(() => {
|
||||
formBtnLoading.value = false;
|
||||
});
|
||||
} else {
|
||||
message.error('请填写完整信息');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 编辑
|
||||
loading.value = true;
|
||||
View({ id: state.id })
|
||||
.then((res) => {
|
||||
formValue.value = res;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
// 关闭表单
|
||||
function closeForm() {
|
||||
showModal.value = false;
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function openModal(state: State) {
|
||||
showModal.value = true;
|
||||
|
||||
// 新增
|
||||
if (!state || state.id < 1) {
|
||||
formValue.value = newState(state);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openModal,
|
||||
});
|
||||
// 编辑
|
||||
loading.value = true;
|
||||
View({ id: state.id })
|
||||
.then((res) => {
|
||||
formValue.value = res;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
// 上传完成回调
|
||||
function handleVideoUpload({ file, event }) {
|
||||
uploadingVideo.value = false;
|
||||
let res = event?.target?.response
|
||||
? JSON.parse(event.target.response)
|
||||
: {};
|
||||
if (res.code === 0 && res.data?.path) {
|
||||
formValue.value.videoUrl = res.data.path;
|
||||
message.success('视频上传成功');
|
||||
} else {
|
||||
message.error(res.message || '视频上传失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 上传开始回调
|
||||
function handleVideoUploadStart() {
|
||||
uploadingVideo.value = true;
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
openModal,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less"></style>
|
Loading…
x
Reference in New Issue
Block a user