Skip to content

Commit

Permalink
feat: 完成帖子创作页面,完成帖子详细页面
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx committed Apr 7, 2024
1 parent 5f25b0a commit 5404f90
Show file tree
Hide file tree
Showing 20 changed files with 426 additions and 2,538 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

## 2024-04-07

### ✨ Features | 新功能

* 完成帖子创作页面

* 完成帖子详细页面

## 2024-04-06

### ✨ Features | 新功能
Expand Down
20 changes: 0 additions & 20 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,6 @@ const routes: RouteRecordRaw[] = [
path: '/notification',
component: () => import('../views/notification/notification.vue'),
},
{
path: '/posts',
component: () => import('../views/posts/posts.vue'),
},
{
path: '/post/:postId',
component: () => import('../views/posts/post.vue'),
},
{
path: '/write/',
component: () => import('../views/posts/write.vue'),
},
{
path: '/write/preview',
component: () => import('../views/posts/preview.vue'),
},
{
path: '/write/modify/:postId',
component: () => import('../views/posts/modify.vue'),
},
{
path: '/manage',
component: () => import('../views/manage/manage.vue'),
Expand Down
11 changes: 10 additions & 1 deletion src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export enum NotificationType {
Comment = 5
}

export enum PostStatusType {
Public = 1,
Private = 2,
Draft = 3
}


// -----------------------------------------URL-------------------------------------------------------------------------

export const DeleteRelationUrl = "/relation/deleteRelation"
Expand All @@ -68,18 +75,20 @@ export const UpdateUserUrl = "/content/updateUser"
export const UpdatePostUrl = "/content/updatePost"
export const GetUserDetailUrl = "/content/getUserDetail"
export const GetPrivateFilesUrl = "/content/getPrivateFiles"

export const AskDownloadFileUrl = "/content/askDownloadFile"
export const EmptyRecycleBinUrl = "/content/emptyRecycleBin"
export const GetRecycleBinFilesUrl = "/content/getRecycleBinFiles"
export const GetLatestRecommendUrl = "/content/getLatestRecommend"
export const GetRecommendByUserUrl = "/content/getRecommendByUser"
export const GetRecommendByItemUrl = "/content/getRecommendByItem"
export const GetPopularRecommendUrl = "/content/getPopularRecommend"
export const CompletelyRemoveFileUrl = "/content/completelyRemoveFile"
export const RecoverRecycleBinFileUrl = "/content/recoverRecycleBinFile"
export const UpdateFileUrl = "/content/updateFile"
export const AskUploadFileUrl = "/content/askUploadFile"

export const GetTagListUrl = "/label/getLabels"

export const QQLoginUrl = "/auth/qqLogin"
export const RegisterUrl = "/auth/register"
export const SendEmailUrl = "/auth/sendEmail"
Expand Down
32 changes: 32 additions & 0 deletions src/utils/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ export type Post = {
userName: string
}

export type PostDetail = {
title: string,
text: string,
status: number,
url: string,
author: {
userId: string,
name: string,
url: string
},
tags: [],
viewCount: number,
likeCount: number,
commentCount: number,
shareCount: number,
collectCount: number,
liked: boolean,
collected: boolean,
createTime: number,
updateTime: number
}

export type HotPost = {
postId: string
title: string
Expand All @@ -55,6 +77,7 @@ export type Zone = {
export type Tag = {
tagId: string,
zoneId: string,
subZoneId: string,
value: string,
}

Expand All @@ -67,4 +90,13 @@ export type Notification = {
toUserId: string
type: number
createTime: number
}

export type PostInfo = {
title: string
text: string
url: string
tags: Tag[]
status: number,
isSure: boolean
}
136 changes: 124 additions & 12 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@

import {CreateRelation, DeleteRelation} from "@/utils/api";
import {
CreatePostUrl,
GetLatestRecommendUrl,
GetPopularRecommendUrl,
GetRecommendByUserUrl,
GetPopularRecommendUrl, GetPostUrl, GetRecommendByItemUrl,
GetRecommendByUserUrl, GetTagListUrl, GetZonesUrl, PostStatusType,
RelationType,
TargetType
} from "@/utils/consts";
import type {HotUser, Post, User} from "@/utils/type";
import {get} from "@/utils/request";
import type {HotUser, Post, PostDetail, PostInfo, Tag, User, Zone} from "@/utils/type";
import {get, post} from "@/utils/request";
import {ref} from "vue";

export const turnTime = (time: number) => {
const date = new Date(time);
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}`;
export const turnTime = (time: number | undefined) => {
if (time) {
const date = new Date(time);
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}`;
} else {
return ""
}
}

export const unFollowHotUser = (user: HotUser) => {
Expand Down Expand Up @@ -158,4 +163,111 @@ const getRecommendUrl = (mainClassify: string, classifyNum: number) => {
url.value = `${GetRecommendByUserUrl}?category=${classifyNum}`
}
return url.value
}

export const getPostDetail = async (postId: string) => {
const postDetail = ref<PostDetail>()
await get(false, `${GetPostUrl}?postId=${postId}`, )
.then((res:any) => {
postDetail.value = {
title: res.title,
text: res.text,
status: res.status,
url: res.url,
author: {
userId: res.author.userId,
name: res.author.name,
url: res.author.url
},
tags: res.tags,
viewCount: res.viewCount,
likeCount: res.likeCount,
commentCount: res.commentCount,
shareCount: res.shareCount,
collectCount: res.collectCount,
liked: res.liked,
collected: res.collected,
createTime: res.createTime,
updateTime: res.updateTime
}
})
return postDetail.value
}

export const getPostRecommendByPostId = async (postId: string) => {
const postList = ref<Post[]>([])
await get(false, `${GetRecommendByItemUrl}?itemId=${postId}&category=${TargetType.Post}`)
.then((res: any) => {
postList.value = res.recommends.posts.map((post: any) => ({
postId: post.postId,
title: post.title,
text: post.text,
url: post.url,
tags: post.tags,
likeCount: post.likeCount,
commentCount: post.commentCount,
liked: post.liked,
userName: post.userName
}))
})
return postList.value
}


// 获取分区列表
export const getZoneList = async (fatherId: string, limit: number, offset: number) => {
const zoneList = ref<Zone[]>([])
await get(false, `${GetZonesUrl}?fatherId=${fatherId}&limit=${limit}&offset${offset}`)
.then((res: any) => {
if (res.zones) {
zoneList.value = res.zones.map((zone: any) => ({
zoneId: zone.id,
value: zone.value,
}))
}
})
return zoneList.value
}

export const getTagList = async(key: string, zoneId: string, subZoneId: string) =>{
const tagsList = ref<Tag[]>([])
await get(false, `${GetTagListUrl}?key=${key}&zone=${zoneId}&subZone=${subZoneId}`).then((res: any) => {
tagsList.value = res.labels.map((tag: any) => ({
tagId: tag.labelId,
zoneId: tag.zone,
subZoneId: tag.subZone,
value: tag.value,
}))
})
return tagsList.value
}

export const createPost = async (postInfo: PostInfo): Promise<any> => {
const tags = postInfo.tags.map((tag: Tag) => ({
tagId: tag.tagId,
zoneId: tag.subZoneId
}))
console.log(postInfo.tags, tags)
return await post(true, CreatePostUrl, {
title: postInfo.title,
text: postInfo.text,
url: postInfo.url,
tags: tags,
status: postInfo.status,
isSure: postInfo.isSure
})
}

export const getPostStatus = (status: string) => {
console.log(status)
switch (status) {
case 'public':
return PostStatusType.Public
case 'private':
return PostStatusType.Private
case 'draft':
return PostStatusType.Draft
default:
return 0
}
}
10 changes: 4 additions & 6 deletions src/views/home/show-recommend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
<div class="post-content">{{ htmlToText(post.userName + ": " + post.text) }}</div>
</div>
</section>
<PostDetail
:information="post"
class="footer"
></PostDetail>
<!-- <PostDetail -->
<!-- :information="post"-->
<!-- class="footer"-->
<!-- ></PostDetail>-->
</div>
</div>
<div class="user-box" v-show="props.classify === 'user'">
Expand Down Expand Up @@ -78,13 +78,11 @@


<script setup lang="ts">
import PostDetail from '../posts/post-information.vue'
import {onMounted, ref, watch} from 'vue'
import type {Post, User} from "@/utils/type";
import {followUser, getPostRecommend, getUserRecommend, unFollowUser} from "@/utils/utils";
import {TargetType} from "@/utils/consts";
import {useStore} from "@/store";
const store = useStore()
const props = defineProps<{
classify: string,
Expand Down
Loading

0 comments on commit 5404f90

Please sign in to comment.