up
This commit is contained in:
@@ -30,3 +30,15 @@
|
||||
### 注意事项
|
||||
- GORM AutoMigrate 会自动添加新字段
|
||||
- 前端颜色选择与日程类型联动
|
||||
|
||||
## 修复:calendar/events jsonErr
|
||||
|
||||
**问题**:`fromGetCalendarEvents` 的 `start/end` 是 `*time.Time` 类型,无法直接解析字符串格式的日期。
|
||||
|
||||
**修复**:改为直接用类型断言解析字符串,用 `time.Parse("2006-01-02", ...)` 解析。
|
||||
|
||||
## 优化:BgColor 弃用,前端根据 ScheduleType 渲染颜色
|
||||
|
||||
**前端**:添加 `getColorByScheduleType()` 函数,`getEvents` 中使用 scheduleType 映射颜色。
|
||||
|
||||
**后端**:只存储 ScheduleType,不处理颜色逻辑。颜色完全由前端 `colorOptions` 控制。
|
||||
|
||||
@@ -325,11 +325,23 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
r.POST("/calendar/events", func(ctx *gin.Context) {
|
||||
isAuth, _, data := AuthenticationAuthority(ctx)
|
||||
if isAuth {
|
||||
var from fromGetCalendarEvents
|
||||
if err := mapstructure.Decode(data, &from); err == nil {
|
||||
// 直接从 data 中解析,避免 float64 → uint 类型问题
|
||||
calendarIDRaw, ok := data["calendar_id"].(float64)
|
||||
if !ok || calendarIDRaw == 0 {
|
||||
ReturnJson(ctx, "jsonErr", nil)
|
||||
return
|
||||
}
|
||||
calendarID := uint(calendarIDRaw)
|
||||
|
||||
// 解析日期字符串
|
||||
startStr, _ := data["start"].(string)
|
||||
endStr, _ := data["end"].(string)
|
||||
startDate, _ := time.Parse("2006-01-02", startStr)
|
||||
endDate, _ := time.Parse("2006-01-02", endStr)
|
||||
|
||||
var events []TabCalendarEvent
|
||||
models.DB.Where("calendar_id = ? AND start_date <= ? AND end_date >= ? AND deleted_at IS NULL",
|
||||
from.CalendarID, from.End, from.Start).Find(&events)
|
||||
calendarID, &endDate, &startDate).Find(&events)
|
||||
|
||||
// 为事件添加编辑权限标识
|
||||
var relist []map[string]interface{}
|
||||
@@ -342,9 +354,6 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
ReturnJson(ctx, "apiOK", gin.H{"list": relist})
|
||||
} else {
|
||||
ReturnJson(ctx, "jsonErr", nil)
|
||||
}
|
||||
} else {
|
||||
ReturnJson(ctx, "userCookieError", nil)
|
||||
}
|
||||
@@ -373,7 +382,6 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
startStr, _ := data["start"].(string)
|
||||
endStr, _ := data["end"].(string)
|
||||
title, _ := data["title"].(string)
|
||||
color, _ := data["color"].(string)
|
||||
remark, _ := data["remark"].(string)
|
||||
isPublic, _ := data["is_public"].(bool)
|
||||
scheduleType, _ := data["schedule_type"].(string)
|
||||
@@ -391,13 +399,9 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
StartDate: &startDate,
|
||||
EndDate: &endDate,
|
||||
ScheduleType: scheduleType,
|
||||
BgColor: color,
|
||||
IsPublic: isPublic,
|
||||
Remark: remark,
|
||||
}
|
||||
if event.BgColor == "" {
|
||||
event.BgColor = calendar.Color
|
||||
}
|
||||
|
||||
if models.DB.Create(&event).Error == nil {
|
||||
// 记录日志
|
||||
@@ -444,7 +448,6 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
startStr, _ := data["start"].(string)
|
||||
endStr, _ := data["end"].(string)
|
||||
title, _ := data["title"].(string)
|
||||
color, _ := data["color"].(string)
|
||||
remark, _ := data["remark"].(string)
|
||||
isPublic, _ := data["is_public"].(bool)
|
||||
scheduleType, _ := data["schedule_type"].(string)
|
||||
@@ -460,16 +463,9 @@ func ApiCalendar(r *gin.RouterGroup) {
|
||||
StartDate: &startDate,
|
||||
EndDate: &endDate,
|
||||
ScheduleType: scheduleType,
|
||||
BgColor: color,
|
||||
IsPublic: isPublic,
|
||||
Remark: remark,
|
||||
}
|
||||
if newEvent.BgColor == "" {
|
||||
// 获取日历颜色
|
||||
var calendar TabCalendar
|
||||
models.DB.Where("id = ?", oldEvent.CalendarID).First(&calendar)
|
||||
newEvent.BgColor = calendar.Color
|
||||
}
|
||||
|
||||
if models.DB.Model(&oldEvent).Updates(&newEvent).Error == nil {
|
||||
// 记录日志
|
||||
|
||||
@@ -119,6 +119,12 @@ function selectColor(colorValue) {
|
||||
}
|
||||
}
|
||||
|
||||
// 根据日程类型获取颜色
|
||||
function getColorByScheduleType(scheduleType) {
|
||||
const found = colorOptions.value.find(c => c.type === scheduleType)
|
||||
return found ? found.value : "#3788d9" // 默认蓝色
|
||||
}
|
||||
|
||||
// 日期转后端格式:YYYY-MM-DD 00:00:00
|
||||
function toDatetime(dateStr) {
|
||||
return dateStr ? dateStr + " 00:00:00" : ""
|
||||
@@ -220,7 +226,7 @@ async function getEvents() {
|
||||
end: item.StartDate === item.EndDate
|
||||
? item.EndDate
|
||||
: DateUtils.toCalendarEnd(item.EndDate),
|
||||
backgroundColor: item.BgColor,
|
||||
backgroundColor: getColorByScheduleType(item.ScheduleType),
|
||||
borderColor: item.ID === pageData.value.seleEventID ? "#000000" : "#F7F7F7",
|
||||
allDay: true,
|
||||
extendedProps: {
|
||||
|
||||
Reference in New Issue
Block a user