删除功能完成
This commit is contained in:
@@ -143,6 +143,63 @@ func ApiSchedule(r *gin.RouterGroup) {
|
||||
|
||||
})
|
||||
|
||||
r.POST("/deleevent", func(ctx *gin.Context) {
|
||||
isAuth, user, data := AuthenticationAuthority(ctx)
|
||||
if isAuth {
|
||||
var from fromAddEvent
|
||||
if err := mapstructure.Decode(data, &from); err == nil {
|
||||
//先从数据库拉取原始event数据
|
||||
oldEvent:=TabSchedule{}
|
||||
if models.DB.Where("id = ?", from.ID).First(&oldEvent).Error==nil{
|
||||
//需要先判断修改权限
|
||||
var isCanEdit=false
|
||||
if slices.Contains(scheduleAdmins,user.ID){ //用户id是管理员
|
||||
isCanEdit = true
|
||||
}
|
||||
if oldEvent.UserID==user.ID{//event是用户创建的
|
||||
isCanEdit = true
|
||||
}
|
||||
if isCanEdit{
|
||||
tosql := TabSchedule{}
|
||||
tosql.DeletedAt.Scan(time.Now())
|
||||
//fmt.Println(tosql)
|
||||
findEvent:=TabSchedule{
|
||||
ID: oldEvent.ID,
|
||||
}
|
||||
if models.DB.Where(&findEvent).Updates(&tosql).Error==nil{
|
||||
//应该修改完了 写日志
|
||||
//把最新数据再读出来
|
||||
models.DB.Where(&findEvent).First(&findEvent)
|
||||
newContent, _ := json.Marshal(findEvent) //转 JSON
|
||||
oldContent, _ := json.Marshal(oldEvent) //转 JSON
|
||||
tosqllog := TabScheduleLog{
|
||||
UserID: user.ID,
|
||||
ScheduleID: oldEvent.ID,
|
||||
ActionType: "delete",
|
||||
NewContent: string(newContent),
|
||||
OldContent: string(oldContent),
|
||||
IP: ctx.ClientIP(),
|
||||
}
|
||||
models.DB.Create(&tosqllog)
|
||||
ReturnJson(ctx, "apiOK", nil)
|
||||
}else{
|
||||
ReturnJson(ctx, "apiErr", nil)
|
||||
}
|
||||
}else{
|
||||
ReturnJson(ctx, "schedule_permission_denied", nil)
|
||||
}
|
||||
}else{
|
||||
ReturnJson(ctx, "schedule_event_not_find", nil)
|
||||
}
|
||||
} else {
|
||||
ReturnJson(ctx, "jsonErr", nil)
|
||||
}
|
||||
} else {
|
||||
ReturnJson(ctx, "userCookieError", nil)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
r.POST("/editevent", func(ctx *gin.Context) {
|
||||
isAuth, user, data := AuthenticationAuthority(ctx)
|
||||
if isAuth {
|
||||
@@ -150,10 +207,8 @@ func ApiSchedule(r *gin.RouterGroup) {
|
||||
var from fromAddEvent
|
||||
if err := mapstructure.Decode(data, &from); err == nil {
|
||||
//先从数据库拉取原始event数据
|
||||
oldEvent:=TabSchedule{
|
||||
ID: from.ID,
|
||||
}
|
||||
if models.DB.Where(&oldEvent).First(&oldEvent).Error==nil{
|
||||
oldEvent:=TabSchedule{}
|
||||
if models.DB.Where("id = ?", from.ID).First(&oldEvent).Error==nil{
|
||||
//需要先判断修改权限
|
||||
var isCanEdit=false
|
||||
if slices.Contains(scheduleAdmins,user.ID){ //用户id是管理员
|
||||
|
||||
@@ -14,4 +14,7 @@ export const scheduleApi = {
|
||||
editEvent(data) {
|
||||
return api.post('/schedule/editevent', data)
|
||||
},
|
||||
deleEvent(data) {
|
||||
return api.post('/schedule/deleevent', data)
|
||||
},
|
||||
}
|
||||
@@ -502,6 +502,34 @@ const getEvents = () => {
|
||||
});
|
||||
};
|
||||
|
||||
//删除event
|
||||
function delEvent(){
|
||||
|
||||
scheduleApi
|
||||
.deleEvent({
|
||||
id:eventData.value.id
|
||||
}).then((r) => {
|
||||
//console.log(r);
|
||||
if (r.errCode == 0) {
|
||||
//前端提交是否错误
|
||||
switch (
|
||||
r.raw.err_code //后端返回是否错误
|
||||
) {
|
||||
case 0:
|
||||
closeEventModal();
|
||||
getEvents();//从新从后端获取最新数据
|
||||
break;
|
||||
default:
|
||||
toast.danger(t("message.server_error"));
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
toast.danger(t("message.server_error"));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 颜色选择处理
|
||||
const selectColor = (colorValue) => {
|
||||
@@ -654,7 +682,7 @@ onMounted(() => {
|
||||
class="modal-footer border-t p-4 flex justify-between items-center flex-shrink-0">
|
||||
|
||||
<div class="flex gap-2">
|
||||
<button v-if="eventData.isEditing" @click="closeEventModal" class="btn px-4 py-2 text-white bg-red-500 hover:bg-red-600 rounded-md
|
||||
<button v-if="eventData.isEditing" @click="delEvent" class="btn px-4 py-2 text-white bg-red-500 hover:bg-red-600 rounded-md
|
||||
disabled:bg-gray-400 disabled:cursor-not-allowed" :disabled="!eventData.isEditable">
|
||||
删除
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user