修改已发布动态的可见度

pull/106/head
orzi! 3 years ago
parent 5d5d60efeb
commit 2a527202c0

@ -34,6 +34,7 @@ type DataService interface {
DeletePost(post *model.Post) error
LockPost(post *model.Post) error
StickPost(post *model.Post) error
VisibilityPost(post *model.Post) error
GetPostByID(id int64) (*model.Post, error)
GetPosts(conditions *model.ConditionsT, offset, limit int) ([]*model.Post, error)
MergePosts(posts []*model.Post) ([]*model.PostFormated, error)

@ -39,6 +39,10 @@ func (d *dataServant) StickPost(post *model.Post) error {
return nil
}
func (d *dataServant) VisibilityPost(post *model.Post) error {
return post.Update(d.engine)
}
func (d *dataServant) GetPostByID(id int64) (*model.Post, error) {
post := &model.Post{
Model: &model.Model{

@ -288,6 +288,42 @@ func StickPost(c *gin.Context) {
})
}
func VisibilityPost(c *gin.Context) {
param := service.PostVisibilityReq{}
response := app.NewResponse(c)
valid, errs := app.BindAndValid(c, &param)
if !valid {
logrus.Errorf("app.BindAndValid errs: %v", errs)
response.ToErrorResponse(errcode.InvalidParams.WithDetails(errs.Errors()...))
return
}
user, _ := c.Get("USER")
// 获取Post
postFormated, err := service.GetPost(param.ID)
if err != nil {
logrus.Errorf("service.GetPost err: %v\n", err)
response.ToErrorResponse(errcode.GetPostFailed)
return
}
if postFormated.UserID != user.(*model.User).ID && !user.(*model.User).IsAdmin {
response.ToErrorResponse(errcode.NoPermission)
return
}
err = service.VisibilityPost(param.ID, param.Visibility)
if err != nil {
logrus.Errorf("service.LockPost err: %v\n", err)
response.ToErrorResponse(errcode.LockPostFailed)
return
}
response.ToResponse(gin.H{
"visibility": param.Visibility,
})
}
func GetPostTags(c *gin.Context) {
param := service.PostTagsReq{}
response := app.NewResponse(c)

@ -167,6 +167,9 @@ func NewRouter() *gin.Engine {
// 置顶动态
privApi.POST("/post/stick", api.StickPost)
// 修改动态可见度
privApi.POST("/post/visibility", api.VisibilityPost)
// 发布动态评论
privApi.POST("/post/comment", api.CreatePostComment)

@ -51,6 +51,11 @@ type PostStickReq struct {
ID int64 `json:"id" binding:"required"`
}
type PostVisibilityReq struct {
ID int64 `json:"id" binding:"required"`
Visibility model.PostVisibleT `json:"visibility"`
}
type PostStarReq struct {
ID int64 `json:"id" binding:"required"`
}
@ -214,6 +219,19 @@ func StickPost(id int64) error {
return nil
}
func VisibilityPost(id int64, visibility model.PostVisibleT) error {
post, _ := ds.GetPostByID(id)
// 修改可见度
post.Visibility = visibility
err := ds.VisibilityPost(post)
if err != nil {
return err
}
return nil
}
func GetPostStar(postID, userID int64) (*model.PostStar, error) {
return ds.GetUserPostStar(postID, userID)
}

@ -108,6 +108,15 @@ export const stickPost = (data: NetParams.PostStickPost): Promise<NetReq.PostSti
});
};
/** 置顶/取消置顶动态 */
export const visibilityPost = (data: NetParams.PostVisibilityPost): Promise<NetReq.PostVisibilityPost> => {
return request({
method: 'post',
url: '/v1/post/visibility',
data
});
};
/** 发布动态评论 */
export const createComment = (data: NetParams.PostCreateComment): Promise<NetReq.PostCreateComment> => {
return request({

@ -297,7 +297,7 @@ const fileQueue = ref<UploadFileInfo[]>([]);
const imageContents = ref<Item.CommentItemProps[]>([]);
const videoContents = ref<Item.CommentItemProps[]>([]);
const attachmentContents = ref<Item.AttachmentProps[]>([]);
const visitType = ref(0)
const visitType = ref<0 | 1 | 2>(0)
const visibilities = [{value: 0, label: "公开"}, {value: 1, label: "私密"}, {value: 2, label: "好友可见"}]
const uploadGateway = import.meta.env.VITE_HOST + '/v1/attachment';

@ -110,6 +110,21 @@
negative-text="取消"
@positive-click="execStickAction"
/>
<!-- -->
<n-modal
v-model:show="showVisibilityModal"
:mask-closable="false"
preset="dialog"
title="提示"
:content="
'' +
(tempVisibility == 0 ? '' : (tempVisibility == 1 ? '' : '')) +
''
"
positive-text="确认"
negative-text="取消"
@positive-click="execVisibilityAction"
/>
</template>
<div v-if="post.texts.length > 0">
<span
@ -201,7 +216,9 @@ import {
deletePost,
lockPost,
stickPost,
visibilityPost
} from '@/api/post';
import type { DropdownOption } from 'naive-ui';
const store = useStore();
const router = useRouter();
@ -216,7 +233,9 @@ const props = withDefaults(
const showDelModal = ref(false);
const showLockModal = ref(false);
const showStickModal = ref(false);
const showVisibilityModal = ref(false);
const loading = ref(false);
const tempVisibility = ref<0 | 1 | 2>(0);
const emit = defineEmits<{
(e: 'reload'): void;
@ -265,7 +284,7 @@ const post = computed({
});
const adminOptions = computed(() => {
let options = [
let options: DropdownOption[] = [
{
label: '',
key: 'delete',
@ -295,6 +314,34 @@ const adminOptions = computed(() => {
});
}
}
if (post.value.visibility === 0) {
options.push({
label: '',
key: 'vpublic',
children: [
{ label: '', key: 'vprivate' }
, { label: '', key: 'vfriend' }
]
})
} else if (post.value.visibility === 1) {
options.push({
label: '',
key: 'vprivate',
children: [
{ label: '', key: 'vpublic' }
, { label: '', key: 'vfriend' }
]
})
} else {
options.push({
label: '',
key: 'vfriend',
children: [
{ label: '', key: 'vpublic' }
, { label: '', key: 'vprivate' }
]
})
}
return options;
});
@ -333,16 +380,34 @@ const doClickText = (e: MouseEvent, id: number) => {
goPostDetail(id);
};
const handlePostAction = (
item: 'delete' | 'lock' | 'unlock' | 'stick' | 'unstick'
item: 'delete' | 'lock' | 'unlock' | 'stick' | 'unstick' | 'vpublic' | 'vprivate' | 'vfriend'
) => {
if (item === 'delete') {
showDelModal.value = true;
}
if (item === 'lock' || item === 'unlock') {
showLockModal.value = true;
}
if (item === 'stick' || item === 'unstick') {
showStickModal.value = true;
switch (item) {
case 'delete':
showDelModal.value = true;
break;
case 'lock':
case 'unlock':
showLockModal.value = true;
break;
case 'stick':
case 'unstick':
showStickModal.value = true;
break;
case 'vpublic':
tempVisibility.value = 0;
showVisibilityModal.value = true;
break;
case 'vprivate':
tempVisibility.value = 1;
showVisibilityModal.value = true;
break;
case 'vfriend':
tempVisibility.value = 2;
showVisibilityModal.value = true;
break;
default:
break;
}
};
const execDelAction = () => {
@ -393,6 +458,19 @@ const execStickAction = () => {
loading.value = false;
});
};
const execVisibilityAction = () => {
visibilityPost({
id: post.value.id,
visibility: tempVisibility.value
})
.then((res) => {
emit('reload');
window.$message.success('');
})
.catch((err) => {
loading.value = false;
});
};
const handlePostStar = () => {
postStar({
id: post.value.id,

@ -124,6 +124,12 @@ declare module NetParams {
id: number
}
interface PostVisibilityPost {
id: number,
/** 可见性 0公开 1私密 2好友可见 */
visibility: 0 | 1 | 2
}
interface PostGetPostStar {
id: number
}

@ -116,6 +116,11 @@ declare module NetReq {
top_status: 0 | 1
}
interface PostVisibilityPost {
/** 可见性 0公开 1私密 2好友可见 */
visibility_status: 0 | 1 | 2
}
interface PostGetPostStar {
status: boolean
}

Loading…
Cancel
Save