From 8183c8ebddc5c9b1ed16c55e3fe6946f020d88bc Mon Sep 17 00:00:00 2001 From: alimy Date: Tue, 15 Apr 2025 18:47:42 +0800 Subject: [PATCH] web source add biome to format/chec code --- web/.gitignore | 1 + web/biome.json | 30 + web/package.json | 3 + web/public/sw.js | 19 +- web/src/App.vue | 20 +- web/src/api/auth.ts | 60 +- web/src/api/post.ts | 176 ++-- web/src/api/site.ts | 6 +- web/src/api/user.ts | 188 ++-- web/src/components/auth.vue | 208 ++-- web/src/components/comment-item.vue | 127 +-- web/src/components/compose-comment.vue | 293 +++--- web/src/components/compose-reply.vue | 153 +-- web/src/components/compose.vue | 532 +++++----- web/src/components/contact-item.vue | 85 +- web/src/components/follow-item.vue | 186 ++-- web/src/components/main-nav.vue | 79 +- web/src/components/message-item.vue | 333 ++++--- web/src/components/message-skeleton.vue | 13 +- web/src/components/mobile-post-item.vue | 406 ++++---- web/src/components/post-attachment.vue | 92 +- web/src/components/post-detail.vue | 883 +++++++++-------- web/src/components/post-image.vue | 13 +- web/src/components/post-item.vue | 406 ++++---- web/src/components/post-link.vue | 13 +- web/src/components/post-skeleton.vue | 13 +- web/src/components/post-video.vue | 16 +- web/src/components/reply-item.vue | 125 +-- web/src/components/rightbar.vue | 151 +-- web/src/components/sidebar.vue | 314 +++--- web/src/components/tag-item.vue | 249 +++-- web/src/components/whisper-add-friend.vue | 46 +- web/src/components/whisper.vue | 46 +- web/src/main.ts | 24 +- web/src/router/index.ts | 110 +-- web/src/shims-vue.d.ts | 28 +- web/src/store/index.ts | 50 +- web/src/types/Item.d.ts | 20 +- web/src/types/NetParams.d.ts | 12 +- web/src/types/NetReq.d.ts | 4 +- web/src/utils/content.ts | 24 +- web/src/utils/count.ts | 4 +- web/src/utils/formatTime.ts | 22 +- web/src/utils/isZipFile.ts | 86 +- web/src/utils/request.ts | 73 +- web/src/utils/scrollToTop.ts | 31 +- web/src/views/404.vue | 6 +- web/src/views/Anouncement.vue | 6 +- web/src/views/Collection.vue | 153 +-- web/src/views/Contacts.vue | 101 +- web/src/views/Following.vue | 202 ++-- web/src/views/Home.vue | 667 +++++++------ web/src/views/Messages.vue | 452 ++++----- web/src/views/Post.vue | 312 +++--- web/src/views/Profile.vue | 661 ++++++------- web/src/views/Setting.vue | 565 +++++------ web/src/views/Topic.vue | 78 +- web/src/views/User.vue | 1082 +++++++++++---------- web/src/views/Wallet.vue | 146 ++- web/src/vuex.d.ts | 22 +- web/tsconfig.json | 35 +- web/vite.config.ts | 22 +- 62 files changed, 5281 insertions(+), 5002 deletions(-) create mode 100644 web/biome.json diff --git a/web/.gitignore b/web/.gitignore index 37fd5405..bd2c292f 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -23,6 +23,7 @@ dist-ssr *.sln *.sw? +bun.lock yarn.lock package-lock.json components.d.ts diff --git a/web/biome.json b/web/biome.json new file mode 100644 index 00000000..78a8d9f7 --- /dev/null +++ b/web/biome.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "organizeImports": { + "enabled": true + }, + "vcs": { + "enabled": true, + "clientKind": "git", + "useIgnoreFile": true + }, + "formatter": { + "indentStyle": "space" + }, + "javascript": { + "formatter": { + "quoteStyle": "single" + } + }, + "css": { + "parser": { + "cssModules": true + } + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + } +} diff --git a/web/package.json b/web/package.json index 9c699ca4..03cc1b95 100644 --- a/web/package.json +++ b/web/package.json @@ -6,6 +6,8 @@ "dev": "vite", "build": "vite build", "preview": "vite preview", + "check": "biome check --write", + "format": "biome format --write", "tauri": "tauri" }, "dependencies": { @@ -32,6 +34,7 @@ "vuex": "^4.1.0" }, "devDependencies": { + "@biomejs/biome": "^1.9.4", "@tauri-apps/cli": "^1.5.10", "@types/node": "^22.14.1", "@types/qrcode": "^1.5.5", diff --git a/web/public/sw.js b/web/public/sw.js index aeee59a0..b58dcd83 100644 --- a/web/public/sw.js +++ b/web/public/sw.js @@ -1,10 +1,9 @@ -self.addEventListener("install", (event) => { - event.waitUntil((async () => {})()); - }); - - self.addEventListener("activate", (event) => { - event.waitUntil((async () => {})()); - }); - - self.addEventListener("fetch", (event) => {}); - \ No newline at end of file +self.addEventListener('install', (event) => { + event.waitUntil((async () => {})()); +}); + +self.addEventListener('activate', (event) => { + event.waitUntil((async () => {})()); +}); + +self.addEventListener('fetch', (event) => {}); diff --git a/web/src/App.vue b/web/src/App.vue index 36b9ec92..1beb2978 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -52,18 +52,20 @@ const store = useStore(); const theme = computed(() => (store.state.theme === 'dark' ? darkTheme : null)); function loadSiteProfile() { - store.commit('loadDefaultSiteProfile'); - if (import.meta.env.VITE_USE_WEB_PROFILE.toLowerCase() === "true") { - getSiteProfile().then((res) => { - store.commit('updateSiteProfile', res); - }).catch((err) => { - console.log(err); - }); - } + store.commit('loadDefaultSiteProfile'); + if (import.meta.env.VITE_USE_WEB_PROFILE.toLowerCase() === 'true') { + getSiteProfile() + .then((res) => { + store.commit('updateSiteProfile', res); + }) + .catch((err) => { + console.log(err); + }); + } } onMounted(() => { - loadSiteProfile(); + loadSiteProfile(); }); diff --git a/web/src/api/auth.ts b/web/src/api/auth.ts index 4d5a066d..536b30d6 100644 --- a/web/src/api/auth.ts +++ b/web/src/api/auth.ts @@ -1,39 +1,47 @@ import { request } from '@/utils/request'; /** 用户登录 */ -export const userLogin = (params: NetParams.AuthUserLogin): Promise => { - return request({ - method: 'post', - url: '/v1/auth/login', - data: params, - }); +export const userLogin = ( + params: NetParams.AuthUserLogin, +): Promise => { + return request({ + method: 'post', + url: '/v1/auth/login', + data: params, + }); }; /** 注册用户 */ -export const userRegister = (params: NetParams.AuthUserRegister): Promise => { - return request({ - method: 'post', - url: '/v1/auth/register', - data: params, - }); +export const userRegister = ( + params: NetParams.AuthUserRegister, +): Promise => { + return request({ + method: 'post', + url: '/v1/auth/register', + data: params, + }); }; /** 用户信息 */ -export const userInfo = (token: NetParams.AuthUserInfo = ""): Promise => { - return request({ - method: 'get', - url: '/v1/user/info', - headers: { - Authorization: `Bearer ${token}`, - }, - }); +export const userInfo = ( + token: NetParams.AuthUserInfo = '', +): Promise => { + return request({ + method: 'get', + url: '/v1/user/info', + headers: { + Authorization: `Bearer ${token}`, + }, + }); }; /** 修改用户密码,该接口暂时未使用 */ -export const updateUserPassword = (data: NetParams.AuthUpdateUserPassword): Promise => { - return request({ - method: 'post', - url: '/v1/api/user/password', - data, - }); +export const updateUserPassword = ( + data: NetParams.AuthUpdateUserPassword, +): Promise => { + return request({ + method: 'post', + url: '/v1/api/user/password', + data, + }); }; diff --git a/web/src/api/post.ts b/web/src/api/post.ts index 54a8b75f..f870e225 100644 --- a/web/src/api/post.ts +++ b/web/src/api/post.ts @@ -1,320 +1,320 @@ -import { request } from "@/utils/request"; +import { request } from '@/utils/request'; /** 获取动态列表 */ export const getPosts = ( - params: NetParams.PostGetPosts + params: NetParams.PostGetPosts, ): Promise => { return request({ - method: "get", - url: "/v1/posts", + method: 'get', + url: '/v1/posts', params, }); }; /** 获取标签列表 */ export const getTags = ( - params: NetParams.PostGetTags + params: NetParams.PostGetTags, ): Promise => { return request({ - method: "get", - url: "/v1/tags", + method: 'get', + url: '/v1/tags', params, }); }; /** 获取动态详情 */ export const getPost = ( - params: NetParams.PostGetPost + params: NetParams.PostGetPost, ): Promise => { return request({ - method: "get", - url: "/v1/post", + method: 'get', + url: '/v1/post', params, }); }; /** 获取动态点赞状态 */ export const getPostStar = ( - params: NetParams.PostPostStar + params: NetParams.PostPostStar, ): Promise => { return request({ - method: "get", - url: "/v1/post/star", + method: 'get', + url: '/v1/post/star', params, }); }; /** 动态点赞 */ export const postStar = ( - data: NetParams.PostPostStar + data: NetParams.PostPostStar, ): Promise => { return request({ - method: "post", - url: "/v1/post/star", + method: 'post', + url: '/v1/post/star', data, }); }; /** 获取动态收藏状态 */ export const getPostCollection = ( - params: NetParams.PostGetPostCollection + params: NetParams.PostGetPostCollection, ): Promise => { return request({ - method: "get", - url: "/v1/post/collection", + method: 'get', + url: '/v1/post/collection', params, }); }; /** 动态收藏 */ export const postCollection = ( - data: NetParams.PostPostCollection + data: NetParams.PostPostCollection, ): Promise => { return request({ - method: "post", - url: "/v1/post/collection", + method: 'post', + url: '/v1/post/collection', data, }); }; /** 获取动态评论列表 */ export const getPostComments = ( - params: NetParams.PostGetPostComments + params: NetParams.PostGetPostComments, ): Promise => { return request({ - method: "get", - url: "/v1/post/comments", + method: 'get', + url: '/v1/post/comments', params, }); }; /** 获取联系人列表 */ export const getContacts = ( - params: NetParams.GetContacts + params: NetParams.GetContacts, ): Promise => { return request({ - method: "get", - url: "/v1/user/contacts", + method: 'get', + url: '/v1/user/contacts', params, }); }; /** 获取联系人列表 */ export const getIndexTrends = ( - params: NetParams.IndexTrendsReq + params: NetParams.IndexTrendsReq, ): Promise => { return request({ - method: "get", - url: "/v1/trends/index", + method: 'get', + url: '/v1/trends/index', params, }); }; /** 发布动态 */ export const createPost = ( - data: NetParams.PostCreatePost + data: NetParams.PostCreatePost, ): Promise => { return request({ - method: "post", - url: "/v1/post", + method: 'post', + url: '/v1/post', data, }); }; /** 删除动态 */ export const deletePost = ( - data: NetParams.PostDeletePost + data: NetParams.PostDeletePost, ): Promise => { return request({ - method: "delete", - url: "/v1/post", + method: 'delete', + url: '/v1/post', data, }); }; /** 锁定/解锁动态 */ export const lockPost = ( - data: NetParams.PostLockPost + data: NetParams.PostLockPost, ): Promise => { return request({ - method: "post", - url: "/v1/post/lock", + method: 'post', + url: '/v1/post/lock', data, }); }; /** 置顶/取消置顶动态 */ export const stickPost = ( - data: NetParams.PostStickPost + data: NetParams.PostStickPost, ): Promise => { return request({ - method: "post", - url: "/v1/post/stick", + method: 'post', + url: '/v1/post/stick', data, }); }; /** 设为亮点/取消亮点动态 */ export const highlightPost = ( - data: NetParams.PostHighlightPost + data: NetParams.PostHighlightPost, ): Promise => { return request({ - method: "post", - url: "/v1/post/highlight", + method: 'post', + url: '/v1/post/highlight', data, }); }; /** 置顶/取消置顶动态 */ export const visibilityPost = ( - data: NetParams.PostVisibilityPost + data: NetParams.PostVisibilityPost, ): Promise => { return request({ - method: "post", - url: "/v1/post/visibility", + method: 'post', + url: '/v1/post/visibility', data, }); }; /** 点赞评论 */ export const thumbsUpTweetComment = ( - data: NetParams.PostTweetCommentThumbs + data: NetParams.PostTweetCommentThumbs, ): Promise => { return request({ - method: "post", - url: "/v1/tweet/comment/thumbsup", + method: 'post', + url: '/v1/tweet/comment/thumbsup', data, }); }; /** 点踩评论 */ export const thumbsDownTweetComment = ( - data: NetParams.PostTweetCommentThumbs + data: NetParams.PostTweetCommentThumbs, ): Promise => { return request({ - method: "post", - url: "/v1/tweet/comment/thumbsdown", + method: 'post', + url: '/v1/tweet/comment/thumbsdown', data, }); }; /** 点赞评论回复 */ export const thumbsUpTweetReply = ( - data: NetParams.PostTweetReplyThumbs + data: NetParams.PostTweetReplyThumbs, ): Promise => { return request({ - method: "post", - url: "/v1/tweet/reply/thumbsup", + method: 'post', + url: '/v1/tweet/reply/thumbsup', data, }); }; /** 点踩评论回复 */ export const thumbsDownTweetReply = ( - data: NetParams.PostTweetReplyThumbs + data: NetParams.PostTweetReplyThumbs, ): Promise => { return request({ - method: "post", - url: "/v1/tweet/reply/thumbsdown", + method: 'post', + url: '/v1/tweet/reply/thumbsdown', data, }); }; /** 发布动态评论 */ export const createComment = ( - data: NetParams.PostCreateComment + data: NetParams.PostCreateComment, ): Promise => { return request({ - method: "post", - url: "/v1/post/comment", + method: 'post', + url: '/v1/post/comment', data, }); }; /** 删除评论 */ export const deleteComment = ( - data: NetParams.PostDeleteComment + data: NetParams.PostDeleteComment, ): Promise => { return request({ - method: "delete", - url: "/v1/post/comment", + method: 'delete', + url: '/v1/post/comment', data, }); }; /** 精选评论 */ export const highlightComment = ( - data: NetParams.PostHighlightComment + data: NetParams.PostHighlightComment, ): Promise => { return request({ - method: "post", - url: "/v1/post/comment/highlight", + method: 'post', + url: '/v1/post/comment/highlight', data, }); }; /** 发布评论回复 */ export const createCommentReply = ( - data: NetParams.PostCreateCommentReply + data: NetParams.PostCreateCommentReply, ): Promise => { return request({ - method: "post", - url: "/v1/post/comment/reply", + method: 'post', + url: '/v1/post/comment/reply', data, }); }; /** 删除评论回复 */ export const deleteCommentReply = ( - data: NetParams.PostDeleteCommentReply + data: NetParams.PostDeleteCommentReply, ): Promise => { return request({ - method: "delete", - url: "/v1/post/comment/reply", + method: 'delete', + url: '/v1/post/comment/reply', data, }); }; /** 置顶/取消置顶话题 */ export const stickTopic = ( - data: NetParams.PostStickTopic + data: NetParams.PostStickTopic, ): Promise => { return request({ - method: "post", - url: "/v1/topic/stick", + method: 'post', + url: '/v1/topic/stick', data, }); }; /** 置顶/取消置顶话题 */ export const pinTopic = ( - data: NetParams.PostPinTopic + data: NetParams.PostPinTopic, ): Promise => { return request({ - method: "post", - url: "/v1/topic/pin", + method: 'post', + url: '/v1/topic/pin', data, }); }; /** 关注话题 */ export const followTopic = ( - data: NetParams.PostFollowTopic + data: NetParams.PostFollowTopic, ): Promise => { return request({ - method: "post", - url: "/v1/topic/follow", + method: 'post', + url: '/v1/topic/follow', data, }); }; /** 取消关注话题 */ export const unfollowTopic = ( - data: NetParams.PostUnfollowTopic + data: NetParams.PostUnfollowTopic, ): Promise => { return request({ - method: "post", - url: "/v1/topic/unfollow", + method: 'post', + url: '/v1/topic/unfollow', data, }); }; diff --git a/web/src/api/site.ts b/web/src/api/site.ts index f3680b00..4fdf6207 100644 --- a/web/src/api/site.ts +++ b/web/src/api/site.ts @@ -1,9 +1,9 @@ -import { request } from "@/utils/request"; +import { request } from '@/utils/request'; /** 获取站点概要信息 */ export const getSiteProfile = (): Promise => { return request({ - method: "get", - url: "/v1/site/profile", + method: 'get', + url: '/v1/site/profile', }); }; diff --git a/web/src/api/user.ts b/web/src/api/user.ts index 34d5aed2..b9996c64 100644 --- a/web/src/api/user.ts +++ b/web/src/api/user.ts @@ -1,12 +1,12 @@ -import { request } from "@/utils/request"; +import { request } from '@/utils/request'; /** 获取验证码 */ export const getCaptcha = ( - params: NetParams.UserGetCaptcha = {} + params: NetParams.UserGetCaptcha = {}, ): Promise => { return request({ - method: "get", - url: "/v1/captcha", + method: 'get', + url: '/v1/captcha', params, }); }; @@ -18,8 +18,8 @@ export const getCaptcha = ( */ export const sendCaptcha = (data: any) => { return request({ - method: "post", - url: "/v1/captcha", + method: 'post', + url: '/v1/captcha', data, }); }; @@ -30,11 +30,11 @@ export const sendCaptcha = (data: any) => { * @returns Promise */ export const sendUserWhisper = ( - data: NetParams.UserWhisper + data: NetParams.UserWhisper, ): Promise => { return request({ - method: "post", - url: "/v1/user/whisper", + method: 'post', + url: '/v1/user/whisper', data, }); }; @@ -45,11 +45,11 @@ export const sendUserWhisper = ( * @returns Promise */ export const requestingFriend = ( - data: NetParams.RequestingFriend + data: NetParams.RequestingFriend, ): Promise => { return request({ - method: "post", - url: "/v1/friend/requesting", + method: 'post', + url: '/v1/friend/requesting', data, }); }; @@ -60,33 +60,33 @@ export const requestingFriend = ( * @returns Promise */ export const addFriend = ( - data: NetParams.AddFriend + data: NetParams.AddFriend, ): Promise => { return request({ - method: "post", - url: "/v1/friend/add", + method: 'post', + url: '/v1/friend/add', data, }); }; // 关注 用户 export const followUser = ( - data: NetParams.FollowUserReq + data: NetParams.FollowUserReq, ): Promise => { return request({ - method: "post", - url: "/v1/user/follow", + method: 'post', + url: '/v1/user/follow', data, }); }; // 取消关注 用户 export const unfollowUser = ( - data: NetParams.UnfollowUserReq + data: NetParams.UnfollowUserReq, ): Promise => { return request({ - method: "post", - url: "/v1/user/unfollow", + method: 'post', + url: '/v1/user/unfollow', data, }); }; @@ -97,11 +97,11 @@ export const unfollowUser = ( * @returns Promise */ export const getUserFollows = ( - params: NetParams.GetUserFollows + params: NetParams.GetUserFollows, ): Promise => { return request({ - method: "get", - url: "/v1/user/follows", + method: 'get', + url: '/v1/user/follows', params, }); }; @@ -112,11 +112,11 @@ export const getUserFollows = ( * @returns Promise */ export const getUserFollowings = ( - params: NetParams.GetUserFollowings + params: NetParams.GetUserFollowings, ): Promise => { return request({ - method: "get", - url: "/v1/user/followings", + method: 'get', + url: '/v1/user/followings', params, }); }; @@ -127,11 +127,11 @@ export const getUserFollowings = ( * @returns Promise */ export const rejectFriend = ( - data: NetParams.RejectFriend + data: NetParams.RejectFriend, ): Promise => { return request({ - method: "post", - url: "/v1/friend/reject", + method: 'post', + url: '/v1/friend/reject', data, }); }; @@ -142,11 +142,11 @@ export const rejectFriend = ( * @returns Promise */ export const deleteFriend = ( - data: NetParams.DeleteFriend + data: NetParams.DeleteFriend, ): Promise => { return request({ - method: "post", - url: "/v1/friend/delete", + method: 'post', + url: '/v1/friend/delete', data, }); }; @@ -157,11 +157,11 @@ export const deleteFriend = ( * @returns Promise */ export const getContacts = ( - data: NetParams.GetContacts + data: NetParams.GetContacts, ): Promise => { return request({ - method: "post", - url: "/v1/user/contacts", + method: 'post', + url: '/v1/user/contacts', data, }); }; @@ -172,11 +172,11 @@ export const getContacts = ( * @returns Promise */ export const bindUserPhone = ( - data: NetParams.UserBindUserPhone + data: NetParams.UserBindUserPhone, ): Promise => { return request({ - method: "post", - url: "/v1/user/phone", + method: 'post', + url: '/v1/user/phone', data, }); }; @@ -187,33 +187,33 @@ export const bindUserPhone = ( * @returns Promise */ export const activateUser = ( - data: NetParams.UserActivation + data: NetParams.UserActivation, ): Promise => { return request({ - method: "post", - url: "/v1/user/activate", + method: 'post', + url: '/v1/user/activate', data, }); }; /** 更改密码 */ export const changePassword = ( - data: NetParams.UserChangePassword + data: NetParams.UserChangePassword, ): Promise => { return request({ - method: "post", - url: "/v1/user/password", + method: 'post', + url: '/v1/user/password', data, }); }; /** 更改昵称 */ export const changeNickname = ( - data: NetParams.UserChangeNickname + data: NetParams.UserChangeNickname, ): Promise => { return request({ - method: "post", - url: "/v1/user/nickname", + method: 'post', + url: '/v1/user/nickname', data, }); }; @@ -225,30 +225,30 @@ export const changeNickname = ( */ export const changeAvatar = (data: any) => { return request({ - method: "post", - url: "/v1/user/avatar", + method: 'post', + url: '/v1/user/avatar', data, }); }; /** 获取未读消息数 */ export const getUnreadMsgCount = ( - params: NetParams.UserGetUnreadMsgCount = {} + params: NetParams.UserGetUnreadMsgCount = {}, ): Promise => { return request({ - method: "get", - url: "/v1/user/msgcount/unread", + method: 'get', + url: '/v1/user/msgcount/unread', params, }); }; /** 获取消息列表 */ export const getMessages = ( - params: NetParams.UserGetMessages + params: NetParams.UserGetMessages, ): Promise => { return request({ - method: "get", - url: "/v1/user/messages", + method: 'get', + url: '/v1/user/messages', params, }); }; @@ -259,11 +259,11 @@ export const getMessages = ( * @returns Promise */ export const readMessage = ( - data: NetParams.ReadMessageReq + data: NetParams.ReadMessageReq, ): Promise => { return request({ - method: "post", - url: "/v1/user/message/read", + method: 'post', + url: '/v1/user/message/read', data, }); }; @@ -274,51 +274,51 @@ export const readMessage = ( */ export const readAllMessage = (): Promise => { return request({ - method: "post", - url: "/v1/user/message/readall", + method: 'post', + url: '/v1/user/message/readall', }); }; /** 获取收藏列表 */ export const getCollections = ( - params: NetParams.UserGetCollections + params: NetParams.UserGetCollections, ): Promise => { return request({ - method: "get", - url: "/v1/user/collections", + method: 'get', + url: '/v1/user/collections', params, }); }; /** 获取用户基础信息 */ export const getUserProfile = ( - params: NetParams.UserGetUserProfile + params: NetParams.UserGetUserProfile, ): Promise => { return request({ - method: "get", - url: "/v1/user/profile", + method: 'get', + url: '/v1/user/profile', params, }); }; /** 获取用户帖子列表 */ export const getUserPosts = ( - params: NetParams.UserGetUserPosts + params: NetParams.UserGetUserPosts, ): Promise => { return request({ - method: "get", - url: "/v1/user/posts", + method: 'get', + url: '/v1/user/posts', params, }); }; /** 获取账单列表 */ export const getBills = ( - params: NetParams.UserGetBills + params: NetParams.UserGetBills, ): Promise => { return request({ - method: "get", - url: "/v1/user/wallet/bills", + method: 'get', + url: '/v1/user/wallet/bills', params, }); }; @@ -329,11 +329,11 @@ export const getBills = ( * @returns Promise */ export const reqRecharge = ( - data: NetParams.UserReqRecharge + data: NetParams.UserReqRecharge, ): Promise => { return request({ - method: "post", - url: "/v1/user/recharge", + method: 'post', + url: '/v1/user/recharge', data, }); }; @@ -344,11 +344,11 @@ export const reqRecharge = ( * @returns Promise */ export const getRecharge = ( - params: NetParams.UserGetRecharge + params: NetParams.UserGetRecharge, ): Promise => { return request({ - method: "get", - url: "/v1/user/recharge", + method: 'get', + url: '/v1/user/recharge', params, }); }; @@ -362,8 +362,8 @@ export const getSuggestUsers = (params: { k: string; }): Promise => { return request({ - method: "get", - url: "/v1/suggest/users", + method: 'get', + url: '/v1/suggest/users', params, }); }; @@ -377,8 +377,8 @@ export const getSuggestTags = (params: { k: string; }): Promise => { return request({ - method: "get", - url: "/v1/suggest/tags", + method: 'get', + url: '/v1/suggest/tags', params, }); }; @@ -389,11 +389,11 @@ export const getSuggestTags = (params: { * @returns Promise */ export const precheckAttachment = ( - params: NetParams.UserPrecheckAttachment + params: NetParams.UserPrecheckAttachment, ): Promise => { return request({ - method: "get", - url: "/v1/attachment/precheck", + method: 'get', + url: '/v1/attachment/precheck', params, }); }; @@ -404,11 +404,11 @@ export const precheckAttachment = ( * @returns Promise */ export const getAttachment = ( - params: NetParams.UserGetAttachment + params: NetParams.UserGetAttachment, ): Promise => { return request({ - method: "get", - url: "/v1/attachment", + method: 'get', + url: '/v1/attachment', params, }); }; @@ -419,11 +419,11 @@ export const getAttachment = ( * @returns Promise */ export const changeUserStatus = ( - data: NetParams.UserStatusReq + data: NetParams.UserStatusReq, ): Promise => { return request({ - method: "post", - url: "/v1/admin/user/status", + method: 'post', + url: '/v1/admin/user/status', data, }); }; @@ -434,7 +434,7 @@ export const changeUserStatus = ( */ export const getSiteInfo = (): Promise => { return request({ - method: "get", - url: "/v1/admin/site/status", + method: 'get', + url: '/v1/admin/site/status', }); }; diff --git a/web/src/components/auth.vue b/web/src/components/auth.vue index 8b348bcd..36a0e019 100644 --- a/web/src/components/auth.vue +++ b/web/src/components/auth.vue @@ -164,134 +164,134 @@ const store = useStore(); const loading = ref(false); const loginRef = ref(); const loginForm = reactive({ - username: '', - password: '', + username: '', + password: '', }); const registerRef = ref(); const registerForm = reactive({ - username: '', - password: '', - repassword: '', + username: '', + password: '', + repassword: '', }); const registerRule = { - username: { - required: true, - message: '请输入账户名', + username: { + required: true, + message: '请输入账户名', + }, + password: { + required: true, + message: '请输入密码', + }, + repassword: [ + { + required: true, + message: '请输入密码', }, - password: { - required: true, - message: '请输入密码', + { + validator: (rule: FormItemRule, value: any) => { + return ( + !!registerForm.password && + registerForm.password.startsWith(value) && + registerForm.password.length >= value.length + ); + }, + message: '两次密码输入不一致', + trigger: 'input', }, - repassword: [ - { - required: true, - message: '请输入密码', - }, - { - validator: (rule: FormItemRule, value: any) => { - return ( - !!registerForm.password && - registerForm.password.startsWith(value) && - registerForm.password.length >= value.length - ); - }, - message: '两次密码输入不一致', - trigger: 'input', - }, - ], + ], }; const handleLogin = (e: Event) => { - e.preventDefault(); - e.stopPropagation(); + e.preventDefault(); + e.stopPropagation(); - loginRef.value?.validate((errors) => { - if (!errors) { - loading.value = true; + loginRef.value?.validate((errors) => { + if (!errors) { + loading.value = true; - userLogin({ - username: loginForm.username, - password: loginForm.password, - }) - .then((res) => { - const token = res?.token || ''; - // 写入用户信息 - localStorage.setItem('PAOPAO_TOKEN', token); + userLogin({ + username: loginForm.username, + password: loginForm.password, + }) + .then((res) => { + const token = res?.token || ''; + // 写入用户信息 + localStorage.setItem('PAOPAO_TOKEN', token); - return userInfo(token); - }) - .then((res) => { - window.$message.success('登录成功'); - loading.value = false; + return userInfo(token); + }) + .then((res) => { + window.$message.success('登录成功'); + loading.value = false; - store.commit('updateUserinfo', res); - store.commit('triggerAuth', false); - store.commit('refresh') - loginForm.username = ''; - loginForm.password = ''; - }) - .catch((err) => { - loading.value = false; - }); - } - }); + store.commit('updateUserinfo', res); + store.commit('triggerAuth', false); + store.commit('refresh'); + loginForm.username = ''; + loginForm.password = ''; + }) + .catch((err) => { + loading.value = false; + }); + } + }); }; const handleRegister = (e: Event) => { - e.preventDefault(); - e.stopPropagation(); + e.preventDefault(); + e.stopPropagation(); - registerRef.value?.validate((errors) => { - if (!errors) { - loading.value = true; + registerRef.value?.validate((errors) => { + if (!errors) { + loading.value = true; - userRegister({ - username: registerForm.username, - password: registerForm.password, - }) - .then((res) => { - return userLogin({ - username: registerForm.username, - password: registerForm.password, - }); - }) - .then((res) => { - const token = res?.token || ''; - // 写入用户信息 - localStorage.setItem('PAOPAO_TOKEN', token); + userRegister({ + username: registerForm.username, + password: registerForm.password, + }) + .then((res) => { + return userLogin({ + username: registerForm.username, + password: registerForm.password, + }); + }) + .then((res) => { + const token = res?.token || ''; + // 写入用户信息 + localStorage.setItem('PAOPAO_TOKEN', token); - return userInfo(token); - }) - .then((res) => { - window.$message.success('注册成功'); - loading.value = false; + return userInfo(token); + }) + .then((res) => { + window.$message.success('注册成功'); + loading.value = false; - store.commit('updateUserinfo', res); - store.commit('triggerAuth', false); - registerForm.username = ''; - registerForm.password = ''; - registerForm.repassword = ''; - }) - .catch((err) => { - loading.value = false; - }); - } - }); + store.commit('updateUserinfo', res); + store.commit('triggerAuth', false); + registerForm.username = ''; + registerForm.password = ''; + registerForm.repassword = ''; + }) + .catch((err) => { + loading.value = false; + }); + } + }); }; onMounted(() => { - const token = localStorage.getItem('PAOPAO_TOKEN') || ''; - if (token) { - userInfo(token) - .then((res) => { - store.commit('updateUserinfo', res); - store.commit('triggerAuth', false); - }) - .catch((err) => { - store.commit('userLogout'); - }); - } else { + const token = localStorage.getItem('PAOPAO_TOKEN') || ''; + if (token) { + userInfo(token) + .then((res) => { + store.commit('updateUserinfo', res); + store.commit('triggerAuth', false); + }) + .catch((err) => { store.commit('userLogout'); - } + }); + } else { + store.commit('userLogout'); + } }); diff --git a/web/src/components/comment-item.vue b/web/src/components/comment-item.vue index 8292b903..f19c323e 100644 --- a/web/src/components/comment-item.vue +++ b/web/src/components/comment-item.vue @@ -142,90 +142,93 @@ const replyAtUsername = ref(''); const replyComposeRef = ref(); const emit = defineEmits<{ - (e: 'reload'): void + (e: 'reload'): void; }>(); -const props = withDefaults(defineProps<{ - comment: Item.CommentProps, - postUserId: number -}>(), {}) +const props = withDefaults( + defineProps<{ + comment: Item.CommentProps; + postUserId: number; + }>(), + {}, +); const comment = computed(() => { - let comment: Item.CommentComponentProps = Object.assign( - { - texts: [], - imgs: [], - }, - props.comment - ); - comment.contents.map((content :any) => { - if (+content.type === 1 || +content.type === 2) { - comment.texts.push(content); - } - if (+content.type === 3) { - comment.imgs.push(content); - } - }); - return comment; + let comment: Item.CommentComponentProps = Object.assign( + { + texts: [], + imgs: [], + }, + props.comment, + ); + comment.contents.map((content: any) => { + if (+content.type === 1 || +content.type === 2) { + comment.texts.push(content); + } + if (+content.type === 3) { + comment.imgs.push(content); + } + }); + return comment; }); const doClickText = (e: MouseEvent, id: number | string) => { - let _target = e.target as any; - if (_target.dataset.detail) { - const d = _target.dataset.detail.split(':'); - if (d.length === 2) { - store.commit('refresh'); - if (d[0] === 'tag') { - window.$message.warning('评论内的无效话题'); - } else { - router.push({ - name: 'user', - query: { - s: d[1], - }, - }); - } - } + let _target = e.target as any; + if (_target.dataset.detail) { + const d = _target.dataset.detail.split(':'); + if (d.length === 2) { + store.commit('refresh'); + if (d[0] === 'tag') { + window.$message.warning('评论内的无效话题'); + } else { + router.push({ + name: 'user', + query: { + s: d[1], + }, + }); + } } + } }; const focusReply = (reply: Item.ReplyProps) => { - replyAtUserID.value = reply.user_id; - replyAtUsername.value = reply.user?.username || ''; - replyComposeRef.value?.switchReply(true); + replyAtUserID.value = reply.user_id; + replyAtUsername.value = reply.user?.username || ''; + replyComposeRef.value?.switchReply(true); }; const reload = () => { - emit('reload'); + emit('reload'); }; const resetReply = () => { - replyAtUserID.value = 0; - replyAtUsername.value = ''; + replyAtUserID.value = 0; + replyAtUsername.value = ''; }; const execDelAction = () => { - deleteComment({ - id: comment.value.id, + deleteComment({ + id: comment.value.id, + }) + .then((_res) => { + window.$message.success('删除成功'); + setTimeout(() => { + reload(); + }, 50); }) - .then((_res) => { - window.$message.success('删除成功'); - setTimeout(() => { - reload(); - }, 50); - }) - .catch((_err) => {}); + .catch((_err) => {}); }; const execHightlightAction = () => { - highlightComment({ - id: comment.value.id, + highlightComment({ + id: comment.value.id, + }) + .then((res) => { + comment.value.is_essence = res.highlight_status; + window.$message.success('操作成功'); + setTimeout(() => { + reload(); + }, 50); }) - .then((res) => { - comment.value.is_essence = res.highlight_status; - window.$message.success("操作成功"); - setTimeout(() => { - reload(); - }, 50); - }) - .catch((_err) => {}); + .catch((_err) => {}); }; diff --git a/web/src/components/compose-comment.vue b/web/src/components/compose-comment.vue index 0d57a3a2..5b6acb7a 100644 --- a/web/src/components/compose-comment.vue +++ b/web/src/components/compose-comment.vue @@ -170,26 +170,24 @@ import { onMounted, computed, ref } from 'vue'; import { useStore } from 'vuex'; import { debounce } from 'lodash'; -import { - ImageOutline, -} from '@vicons/ionicons5'; +import { ImageOutline } from '@vicons/ionicons5'; import { createComment } from '@/api/post'; import { getSuggestUsers } from '@/api/user'; import { parsePostTag } from '@/utils/content'; import type { MentionOption, UploadFileInfo, UploadInst } from 'naive-ui'; const emit = defineEmits<{ - (e: 'post-success'): void; + (e: 'post-success'): void; }>(); const props = withDefaults( - defineProps<{ - lock: number; - postId: number; - }>(), - { - lock: 0, - postId: 0, - } + defineProps<{ + lock: number; + postId: number; + }>(), + { + lock: 0, + postId: 0, + }, ); const store = useStore(); @@ -203,185 +201,194 @@ const uploadRef = ref(); const uploadType = ref('public/image'); const fileQueue = ref([]); const imageContents = ref([]); -const allowUserRegister = ref(import.meta.env.VITE_ALLOW_USER_REGISTER.toLowerCase() === 'true') -const defaultCommentMaxLength = Number(import.meta.env.VITE_DEFAULT_COMMENT_MAX_LENGTH) +const allowUserRegister = ref( + import.meta.env.VITE_ALLOW_USER_REGISTER.toLowerCase() === 'true', +); +const defaultCommentMaxLength = Number( + import.meta.env.VITE_DEFAULT_COMMENT_MAX_LENGTH, +); const uploadGateway = import.meta.env.VITE_HOST + '/v1/attachment'; const uploadToken = computed(() => { - return 'Bearer ' + localStorage.getItem('PAOPAO_TOKEN'); + return 'Bearer ' + localStorage.getItem('PAOPAO_TOKEN'); }); // 加载at用户列表 const loadSuggestionUsers = debounce((k) => { - getSuggestUsers({ - k, - }) - .then((res) => { - let options: MentionOption[] = []; - res.suggest.map((i) => { - options.push({ - label: i, - value: i, - }); - }); - optionsRef.value = options; - loading.value = false; - }) - .catch((err) => { - loading.value = false; + getSuggestUsers({ + k, + }) + .then((res) => { + let options: MentionOption[] = []; + res.suggest.map((i) => { + options.push({ + label: i, + value: i, }); + }); + optionsRef.value = options; + loading.value = false; + }) + .catch((err) => { + loading.value = false; + }); }, 200); const handleSearch = (k: string, prefix: string) => { - if (loading.value) { - return; - } - loading.value = true; - if (prefix === '@') { - loadSuggestionUsers(k); - } + if (loading.value) { + return; + } + loading.value = true; + if (prefix === '@') { + loadSuggestionUsers(k); + } }; const changeContent = (v: string) => { - if (v.length > defaultCommentMaxLength) { - content.value = v.substring(0, defaultCommentMaxLength); - } else { - content.value = v; - } + if (v.length > defaultCommentMaxLength) { + content.value = v.substring(0, defaultCommentMaxLength); + } else { + content.value = v; + } }; const setUploadType = (type: string) => { - uploadType.value = type; + uploadType.value = type; }; const updateUpload = (list: UploadFileInfo[]) => { - for (let i = 0; i < list.length; i++) { - var name = list[i].name; - var basename: string = name.split('.').slice(0, -1).join('.'); - var ext: string = name.split('.').pop()!; - if (basename.length > 30) { - list[i].name = basename.substring(0, 18) + "..." + basename.substring(basename.length-9) + "." + ext; - } + for (let i = 0; i < list.length; i++) { + var name = list[i].name; + var basename: string = name.split('.').slice(0, -1).join('.'); + var ext: string = name.split('.').pop()!; + if (basename.length > 30) { + list[i].name = + basename.substring(0, 18) + + '...' + + basename.substring(basename.length - 9) + + '.' + + ext; } - fileQueue.value = list; + } + fileQueue.value = list; }; const beforeUpload = async (data: any) => { - // 图片类型校验 - if ( - uploadType.value === 'public/image' && - !['image/png', 'image/jpg', 'image/jpeg', 'image/gif'].includes( - (data.file as any).file?.type - ) - ) { - window.$message.warning('图片仅允许 png/jpg/gif 格式'); - return false; - } + // 图片类型校验 + if ( + uploadType.value === 'public/image' && + !['image/png', 'image/jpg', 'image/jpeg', 'image/gif'].includes( + (data.file as any).file?.type, + ) + ) { + window.$message.warning('图片仅允许 png/jpg/gif 格式'); + return false; + } - if ( - uploadType.value === 'image' && - (data.file as any).file?.size > 10485760 - ) { - window.$message.warning('图片大小不能超过10MB'); - return false; - } + if ( + uploadType.value === 'image' && + (data.file as any).file?.size > 10485760 + ) { + window.$message.warning('图片大小不能超过10MB'); + return false; + } - return true; + return true; }; const finishUpload = ({ file, event }: any): any => { - try { - let data = JSON.parse(event.target?.response); + try { + let data = JSON.parse(event.target?.response); - if (data.code === 0) { - if (uploadType.value === 'public/image') { - imageContents.value.push({ - id: file.id, - content: data.data.content, - } as Item.CommentItemProps); - } - } - } catch (error) { - window.$message.error('上传失败'); + if (data.code === 0) { + if (uploadType.value === 'public/image') { + imageContents.value.push({ + id: file.id, + content: data.data.content, + } as Item.CommentItemProps); + } } + } catch (error) { + window.$message.error('上传失败'); + } }; const failUpload = ({ file, event }: any): any => { - try { - let data = JSON.parse(event.target?.response); + try { + let data = JSON.parse(event.target?.response); - if (data.code !== 0) { - let errMsg = data.msg || '上传失败'; - if (data.details && data.details.length > 0) { - data.details.map((detail: string) => { - errMsg += ':' + detail; - }); - } - window.$message.error(errMsg); - } - } catch (error) { - window.$message.error('上传失败'); + if (data.code !== 0) { + let errMsg = data.msg || '上传失败'; + if (data.details && data.details.length > 0) { + data.details.map((detail: string) => { + errMsg += ':' + detail; + }); + } + window.$message.error(errMsg); } + } catch (error) { + window.$message.error('上传失败'); + } }; const removeUpload = ({ file }: any) => { - let idx = imageContents.value.findIndex((item) => item.id === file.id); - if (idx > -1) { - imageContents.value.splice(idx, 1); - } + let idx = imageContents.value.findIndex((item) => item.id === file.id); + if (idx > -1) { + imageContents.value.splice(idx, 1); + } }; const focusComment = () => { - showBtn.value = true; + showBtn.value = true; }; const cancelComment = () => { - showBtn.value = false; - // 置空 - uploadRef.value?.clear(); - fileQueue.value = []; - content.value = ''; - imageContents.value = []; + showBtn.value = false; + // 置空 + uploadRef.value?.clear(); + fileQueue.value = []; + content.value = ''; + imageContents.value = []; }; // 发布动态 const submitPost = () => { - if (content.value.trim().length === 0) { - window.$message.warning('请输入内容哦'); - return; - } + if (content.value.trim().length === 0) { + window.$message.warning('请输入内容哦'); + return; + } - // 解析用户at - let { users } = parsePostTag(content.value); + // 解析用户at + let { users } = parsePostTag(content.value); - const contents = []; - let sort = 100; + const contents = []; + let sort = 100; + contents.push({ + content: content.value, + type: 2, // 文字 + sort, + }); + imageContents.value.map((img) => { + sort++; contents.push({ - content: content.value, - type: 2, // 文字 - sort, - }); - imageContents.value.map((img) => { - sort++; - contents.push({ - content: img.content, - type: 3, // 图片 - sort, - }); + content: img.content, + type: 3, // 图片 + sort, }); + }); - submitting.value = true; - createComment({ - contents, - post_id: props.postId, - users: Array.from(new Set(users)), - }) - .then((res) => { - window.$message.success('发布成功'); - submitting.value = false; - emit('post-success'); + submitting.value = true; + createComment({ + contents, + post_id: props.postId, + users: Array.from(new Set(users)), + }) + .then((res) => { + window.$message.success('发布成功'); + submitting.value = false; + emit('post-success'); - // 置空 - cancelComment(); - }) - .catch((err) => { - submitting.value = false; - }); + // 置空 + cancelComment(); + }) + .catch((err) => { + submitting.value = false; + }); }; const triggerAuth = (key: string) => { - store.commit('triggerAuth', true); - store.commit('triggerAuthKey', key); + store.commit('triggerAuth', true); + store.commit('triggerAuthKey', key); }; diff --git a/web/src/components/compose-reply.vue b/web/src/components/compose-reply.vue index 732acccc..f89cc19c 100644 --- a/web/src/components/compose-reply.vue +++ b/web/src/components/compose-reply.vue @@ -57,103 +57,112 @@ import { ref } from 'vue'; import { useStore } from 'vuex'; import { formatPrettyTime } from '@/utils/formatTime'; -import { createCommentReply, thumbsUpTweetComment, thumbsDownTweetComment } from '@/api/post'; +import { + createCommentReply, + thumbsUpTweetComment, + thumbsDownTweetComment, +} from '@/api/post'; import { InputInst } from 'naive-ui'; import { - ThumbUpTwotone, - ThumbUpOutlined, - ThumbDownTwotone, - ThumbDownOutlined, + ThumbUpTwotone, + ThumbUpOutlined, + ThumbDownTwotone, + ThumbDownOutlined, } from '@vicons/material'; import { YesNoEnum } from '@/utils/IEnum'; -const props = withDefaults(defineProps<{ - comment: Item.CommentProps, - atUserid: number, - atUsername: string, -}>(), { +const props = withDefaults( + defineProps<{ + comment: Item.CommentProps; + atUserid: number; + atUsername: string; + }>(), + { atUserid: 0, - atUsername: '' -}); + atUsername: '', + }, +); const store = useStore(); const emit = defineEmits<{ - (e: 'reload'): void, - (e: 'reset'): void + (e: 'reload'): void; + (e: 'reset'): void; }>(); const inputInstRef = ref(); const showReply = ref(false); const replyContent = ref(''); const submitting = ref(false); -const defaultReplyMaxLength = Number(import.meta.env.VITE_DEFAULT_REPLY_MAX_LENGTH) -const hasThumbsUp = ref(props.comment.is_thumbs_up == YesNoEnum.YES) -const hasThumbsDown = ref(props.comment.is_thumbs_down == YesNoEnum.YES) -const thumbsUpCount = ref(props.comment.thumbs_up_count) +const defaultReplyMaxLength = Number( + import.meta.env.VITE_DEFAULT_REPLY_MAX_LENGTH, +); +const hasThumbsUp = ref(props.comment.is_thumbs_up == YesNoEnum.YES); +const hasThumbsDown = ref(props.comment.is_thumbs_down == YesNoEnum.YES); +const thumbsUpCount = ref(props.comment.thumbs_up_count); const handleThumbsUp = () => { - thumbsUpTweetComment({ - tweet_id: props.comment.post_id, - comment_id: props.comment.id, + thumbsUpTweetComment({ + tweet_id: props.comment.post_id, + comment_id: props.comment.id, + }) + .then((_res) => { + hasThumbsUp.value = !hasThumbsUp.value; + if (hasThumbsUp.value) { + thumbsUpCount.value++; + hasThumbsDown.value = false; + } else { + thumbsUpCount.value--; + } }) - .then((_res) => { - hasThumbsUp.value = !hasThumbsUp.value - if (hasThumbsUp.value) { - thumbsUpCount.value++ - hasThumbsDown.value = false - } else { - thumbsUpCount.value-- - } - }) - .catch((err) => { - console.log(err); - }); + .catch((err) => { + console.log(err); + }); }; const handleThumbsDown = () => { - thumbsDownTweetComment({ - tweet_id: props.comment.post_id, - comment_id: props.comment.id, + thumbsDownTweetComment({ + tweet_id: props.comment.post_id, + comment_id: props.comment.id, + }) + .then((_res) => { + hasThumbsDown.value = !hasThumbsDown.value; + if (hasThumbsDown.value) { + if (hasThumbsUp.value) { + thumbsUpCount.value--; + hasThumbsUp.value = false; + } + } }) - .then((_res) => { - hasThumbsDown.value = !hasThumbsDown.value - if (hasThumbsDown.value) { - if (hasThumbsUp.value) { - thumbsUpCount.value-- - hasThumbsUp.value = false - } - } - }) - .catch((err) => { - console.log(err); - }); + .catch((err) => { + console.log(err); + }); }; const switchReply = (status: boolean) => { - showReply.value = status; - - if (status) { - setTimeout(() => { - inputInstRef.value?.focus(); - }, 10); - } else { - submitting.value = false; - replyContent.value = ''; - emit('reset'); - } + showReply.value = status; + + if (status) { + setTimeout(() => { + inputInstRef.value?.focus(); + }, 10); + } else { + submitting.value = false; + replyContent.value = ''; + emit('reset'); + } }; const submitReply = () => { - submitting.value = true; - createCommentReply({ - comment_id: props.comment.id, - at_user_id: props.atUserid, - content: replyContent.value, + submitting.value = true; + createCommentReply({ + comment_id: props.comment.id, + at_user_id: props.atUserid, + content: replyContent.value, + }) + .then((res) => { + switchReply(false); + window.$message.success('评论成功'); + emit('reload'); }) - .then((res) => { - switchReply(false); - window.$message.success('评论成功'); - emit('reload'); - }) - .catch((err) => { - submitting.value = false; - }); + .catch((err) => { + submitting.value = false; + }); }; defineExpose({ switchReply }); diff --git a/web/src/components/compose.vue b/web/src/components/compose.vue index 1688d645..5c41c254 100644 --- a/web/src/components/compose.vue +++ b/web/src/components/compose.vue @@ -281,11 +281,11 @@ import { debounce } from 'lodash'; import { getSuggestUsers, getSuggestTags } from '@/api/user'; import { - ImageOutline, - VideocamOutline, - AttachOutline, - CompassOutline, - EyeOutline, + ImageOutline, + VideocamOutline, + AttachOutline, + CompassOutline, + EyeOutline, } from '@vicons/ionicons5'; import { createPost } from '@/api/post'; import { parsePostTag } from '@/utils/content'; @@ -294,7 +294,7 @@ import type { MentionOption, UploadFileInfo, UploadInst } from 'naive-ui'; import { VisibilityEnum, PostItemTypeEnum } from '@/utils/IEnum'; const emit = defineEmits<{ - (e: 'post-success', post: Item.PostProps): void; + (e: 'post-success', post: Item.PostProps): void; }>(); const store = useStore(); @@ -315,323 +315,329 @@ const imageContents = ref([]); const videoContents = ref([]); const attachmentContents = ref([]); const visitType = ref(VisibilityEnum.PUBLIC); -const defaultVisitType = ref(VisibilityEnum.PUBLIC) +const defaultVisitType = ref(VisibilityEnum.PUBLIC); -const allowTweetVisibility = ref(import.meta.env.VITE_ALLOW_TWEET_VISIBILITY.toLowerCase() === 'true') +const allowTweetVisibility = ref( + import.meta.env.VITE_ALLOW_TWEET_VISIBILITY.toLowerCase() === 'true', +); const uploadGateway = import.meta.env.VITE_HOST + '/v1/attachment'; const uploadToken = computed(() => { - return 'Bearer ' + localStorage.getItem('PAOPAO_TOKEN'); + return 'Bearer ' + localStorage.getItem('PAOPAO_TOKEN'); }); -const visibilities = computed(()=> { - let res = [ - {value: VisibilityEnum.PUBLIC, label: "公开"}, - {value: VisibilityEnum.PRIVATE, label: "私密"}, - {value: VisibilityEnum.Following, label: "关注可见"}, - ]; - if (store.state.profile.useFriendship) { - res.push({value: VisibilityEnum.FRIEND, label: "好友可见"}); - } - return res; +const visibilities = computed(() => { + let res = [ + { value: VisibilityEnum.PUBLIC, label: '公开' }, + { value: VisibilityEnum.PRIVATE, label: '私密' }, + { value: VisibilityEnum.Following, label: '关注可见' }, + ]; + if (store.state.profile.useFriendship) { + res.push({ value: VisibilityEnum.FRIEND, label: '好友可见' }); + } + return res; }); const switchLink = () => { - showLinkSet.value = !showLinkSet.value; - if (showLinkSet.value && showEyeSet.value) { - showEyeSet.value = false - } + showLinkSet.value = !showLinkSet.value; + if (showLinkSet.value && showEyeSet.value) { + showEyeSet.value = false; + } }; const switchEye = () => { - showEyeSet.value = !showEyeSet.value; - if (showEyeSet.value && showLinkSet.value) { - showLinkSet.value = false - } + showEyeSet.value = !showEyeSet.value; + if (showEyeSet.value && showLinkSet.value) { + showLinkSet.value = false; + } }; // 加载at用户列表 const loadSuggestionUsers = debounce((k) => { - getSuggestUsers({ - k, - }) - .then((res) => { - let options: MentionOption[] = []; - res.suggest.map((i) => { - options.push({ - label: i, - value: i, - }); - }); - optionsRef.value = options; - loading.value = false; - }) - .catch((err) => { - loading.value = false; + getSuggestUsers({ + k, + }) + .then((res) => { + let options: MentionOption[] = []; + res.suggest.map((i) => { + options.push({ + label: i, + value: i, }); + }); + optionsRef.value = options; + loading.value = false; + }) + .catch((err) => { + loading.value = false; + }); }, 200); // 加载推荐tag列表 const loadSuggestionTags = debounce((k) => { - getSuggestTags({ - k, - }) - .then((res) => { - let options: MentionOption[] = []; - res.suggest.map((i) => { - options.push({ - label: i, - value: i, - }); - }); - optionsRef.value = options; - loading.value = false; - }) - .catch((err) => { - loading.value = false; + getSuggestTags({ + k, + }) + .then((res) => { + let options: MentionOption[] = []; + res.suggest.map((i) => { + options.push({ + label: i, + value: i, }); + }); + optionsRef.value = options; + loading.value = false; + }) + .catch((err) => { + loading.value = false; + }); }, 200); const handleSearch = (k: string, prefix: string) => { - if (loading.value) { - return; - } - loading.value = true; - if (prefix === '@') { - loadSuggestionUsers(k); - } else { - loadSuggestionTags(k); - } + if (loading.value) { + return; + } + loading.value = true; + if (prefix === '@') { + loadSuggestionUsers(k); + } else { + loadSuggestionTags(k); + } }; const changeContent = (v: string) => { - if (v.length > store.state.profile.defaultTweetMaxLength) { - content.value = v.substring(0, store.state.profile.defaultTweetMaxLength); - } else { - content.value = v; - } + if (v.length > store.state.profile.defaultTweetMaxLength) { + content.value = v.substring(0, store.state.profile.defaultTweetMaxLength); + } else { + content.value = v; + } }; const setUploadType = (type: string) => { - uploadType.value = type; + uploadType.value = type; }; const updateUpload = (list: UploadFileInfo[]) => { - for (let i = 0; i < list.length; i++) { - var name = list[i].name; - var basename: string = name.split('.').slice(0, -1).join('.'); - var ext: string = name.split('.').pop()!; - if (basename.length > 30) { - list[i].name = basename.substring(0, 18) + "..." + basename.substring(basename.length-9) + "." + ext; - } + for (let i = 0; i < list.length; i++) { + var name = list[i].name; + var basename: string = name.split('.').slice(0, -1).join('.'); + var ext: string = name.split('.').pop()!; + if (basename.length > 30) { + list[i].name = + basename.substring(0, 18) + + '...' + + basename.substring(basename.length - 9) + + '.' + + ext; } - fileQueue.value = list; + } + fileQueue.value = list; }; const beforeUpload = async (data: any) => { - // 图片类型校验 - if ( - uploadType.value === 'public/image' && - !['image/webp', 'image/png', 'image/jpg', 'image/jpeg', 'image/gif'].includes( - data.file.file?.type - ) - ) { - window.$message.warning('图片仅允许 webp/png/jpg/gif 格式'); - return false; - } - - if (uploadType.value === 'image' && data.file.file?.size > 10485760) { - window.$message.warning('图片大小不能超过10MB'); - return false; - } - - // 视频类型校验 - if ( - uploadType.value === 'public/video' && - !['video/mp4', 'video/quicktime'].includes(data.file.file?.type) - ) { - window.$message.warning('视频仅允许 mp4/mov 格式'); - return false; - } - - if ( - uploadType.value === 'public/video' && - data.file.file?.size > 104857600 - ) { - window.$message.warning('视频大小不能超过100MB'); - return false; - } - // 附件类型校验 - if ( - uploadType.value === 'attachment' && !(await isZipFile(data.file.file)) - ) { - window.$message.warning('附件仅允许 zip 格式'); - return false; - } - - if (uploadType.value === 'attachment' && data.file.file?.size > 104857600) { - window.$message.warning('附件大小不能超过100MB'); - return false; - } - - return true; + // 图片类型校验 + if ( + uploadType.value === 'public/image' && + ![ + 'image/webp', + 'image/png', + 'image/jpg', + 'image/jpeg', + 'image/gif', + ].includes(data.file.file?.type) + ) { + window.$message.warning('图片仅允许 webp/png/jpg/gif 格式'); + return false; + } + + if (uploadType.value === 'image' && data.file.file?.size > 10485760) { + window.$message.warning('图片大小不能超过10MB'); + return false; + } + + // 视频类型校验 + if ( + uploadType.value === 'public/video' && + !['video/mp4', 'video/quicktime'].includes(data.file.file?.type) + ) { + window.$message.warning('视频仅允许 mp4/mov 格式'); + return false; + } + + if (uploadType.value === 'public/video' && data.file.file?.size > 104857600) { + window.$message.warning('视频大小不能超过100MB'); + return false; + } + // 附件类型校验 + if (uploadType.value === 'attachment' && !(await isZipFile(data.file.file))) { + window.$message.warning('附件仅允许 zip 格式'); + return false; + } + + if (uploadType.value === 'attachment' && data.file.file?.size > 104857600) { + window.$message.warning('附件大小不能超过100MB'); + return false; + } + + return true; }; const finishUpload = ({ file, event }: any): any => { - try { - let data = JSON.parse(event.target?.response); - - if (data.code === 0) { - if (uploadType.value === 'public/image') { - imageContents.value.push({ - id: file.id, - content: data.data.content, - } as Item.CommentItemProps); - } - if (uploadType.value === 'public/video') { - videoContents.value.push({ - id: file.id, - content: data.data.content, - } as Item.CommentItemProps); - } - if (uploadType.value === 'attachment') { - attachmentContents.value.push({ - id: file.id, - content: data.data.content, - } as Item.AttachmentProps); - } - } - } catch (error) { - window.$message.error('上传失败'); + try { + let data = JSON.parse(event.target?.response); + + if (data.code === 0) { + if (uploadType.value === 'public/image') { + imageContents.value.push({ + id: file.id, + content: data.data.content, + } as Item.CommentItemProps); + } + if (uploadType.value === 'public/video') { + videoContents.value.push({ + id: file.id, + content: data.data.content, + } as Item.CommentItemProps); + } + if (uploadType.value === 'attachment') { + attachmentContents.value.push({ + id: file.id, + content: data.data.content, + } as Item.AttachmentProps); + } } + } catch (error) { + window.$message.error('上传失败'); + } }; const failUpload = ({ file, event }: any): any => { - try { - let data = JSON.parse(event.target?.response); - - if (data.code !== 0) { - let errMsg = data.msg || '上传失败'; - if (data.details && data.details.length > 0) { - data.details.map((detail: string) => { - errMsg += ':' + detail; - }); - } - window.$message.error(errMsg); - } - } catch (error) { - window.$message.error('上传失败'); + try { + let data = JSON.parse(event.target?.response); + + if (data.code !== 0) { + let errMsg = data.msg || '上传失败'; + if (data.details && data.details.length > 0) { + data.details.map((detail: string) => { + errMsg += ':' + detail; + }); + } + window.$message.error(errMsg); } + } catch (error) { + window.$message.error('上传失败'); + } }; const removeUpload = ({ file }: any) => { - let idx = imageContents.value.findIndex((item) => item.id === file.id); - if (idx > -1) { - imageContents.value.splice(idx, 1); - } - idx = videoContents.value.findIndex((item) => item.id === file.id); - if (idx > -1) { - videoContents.value.splice(idx, 1); - } - idx = attachmentContents.value.findIndex((item) => item.id === file.id); - if (idx > -1) { - attachmentContents.value.splice(idx, 1); - } + let idx = imageContents.value.findIndex((item) => item.id === file.id); + if (idx > -1) { + imageContents.value.splice(idx, 1); + } + idx = videoContents.value.findIndex((item) => item.id === file.id); + if (idx > -1) { + videoContents.value.splice(idx, 1); + } + idx = attachmentContents.value.findIndex((item) => item.id === file.id); + if (idx > -1) { + attachmentContents.value.splice(idx, 1); + } }; // 发布动态 const submitPost = () => { - if (content.value.trim().length === 0) { - window.$message.warning('请输入内容哦'); - return; - } + if (content.value.trim().length === 0) { + window.$message.warning('请输入内容哦'); + return; + } - // 解析用户at及tag - let { tags, users } = parsePostTag(content.value); + // 解析用户at及tag + let { tags, users } = parsePostTag(content.value); - const contents = []; - let sort = 100; + const contents = []; + let sort = 100; + contents.push({ + content: content.value, + type: PostItemTypeEnum.TEXT, // 文字 + sort, + }); + + imageContents.value.map((img) => { + sort++; contents.push({ - content: content.value, - type: PostItemTypeEnum.TEXT, // 文字 - sort, + content: img.content, + type: PostItemTypeEnum.IMAGEURL, // 图片 + sort, }); - - imageContents.value.map((img) => { - sort++; - contents.push({ - content: img.content, - type: PostItemTypeEnum.IMAGEURL, // 图片 - sort, - }); + }); + videoContents.value.map((video) => { + sort++; + contents.push({ + content: video.content, + type: PostItemTypeEnum.VIDEOURL, // 视频 + sort, }); - videoContents.value.map((video) => { - sort++; - contents.push({ - content: video.content, - type: PostItemTypeEnum.VIDEOURL, // 视频 - sort, - }); + }); + attachmentContents.value.map((attachment) => { + sort++; + contents.push({ + content: attachment.content, + type: PostItemTypeEnum.ATTACHMENT, // 附件 + sort, }); - attachmentContents.value.map((attachment) => { - sort++; - contents.push({ - content: attachment.content, - type: PostItemTypeEnum.ATTACHMENT, // 附件 - sort, - }); + }); + if (links.value.length > 0) { + links.value.map((link) => { + sort++; + contents.push({ + content: link, + type: PostItemTypeEnum.LINKURL, // 链接 + sort, + }); }); - if (links.value.length > 0) { - links.value.map((link) => { - sort++; - contents.push({ - content: link, - type: PostItemTypeEnum.LINKURL, // 链接 - sort, - }); - }); - } - - submitting.value = true; - createPost({ - contents, - tags: Array.from(new Set(tags)), - users: Array.from(new Set(users)), - attachment_price: +attachmentPrice.value * 100, - visibility: visitType.value + } + + submitting.value = true; + createPost({ + contents, + tags: Array.from(new Set(tags)), + users: Array.from(new Set(users)), + attachment_price: +attachmentPrice.value * 100, + visibility: visitType.value, + }) + .then((res) => { + window.$message.success('发布成功'); + submitting.value = false; + emit('post-success', res); + + // 置空 + showLinkSet.value = false; + showEyeSet.value = false; + uploadRef.value?.clear(); + fileQueue.value = []; + content.value = ''; + links.value = []; + imageContents.value = []; + videoContents.value = []; + attachmentContents.value = []; + visitType.value = defaultVisitType.value; }) - .then((res) => { - window.$message.success('发布成功'); - submitting.value = false; - emit('post-success', res); - - // 置空 - showLinkSet.value = false; - showEyeSet.value = false; - uploadRef.value?.clear(); - fileQueue.value = []; - content.value = ''; - links.value = []; - imageContents.value = []; - videoContents.value = []; - attachmentContents.value = []; - visitType.value = defaultVisitType.value; - }) - .catch((err) => { - submitting.value = false; - }); + .catch((err) => { + submitting.value = false; + }); }; const triggerAuth = (key: string) => { - store.commit('triggerAuth', true); - store.commit('triggerAuthKey', key); + store.commit('triggerAuth', true); + store.commit('triggerAuthKey', key); }; onMounted(() => { - const defaultVisibility = store.state.profile.defaultTweetVisibility - if (store.state.profile.useFriendship && defaultVisibility === 'friend') { - defaultVisitType.value = VisibilityEnum.FRIEND - } else if (defaultVisibility === 'following') { - defaultVisitType.value = VisibilityEnum.Following - } else if (defaultVisibility === 'public') { - defaultVisitType.value = VisibilityEnum.PUBLIC - } else { - defaultVisitType.value = VisibilityEnum.PRIVATE - } - visitType.value = defaultVisitType.value; + const defaultVisibility = store.state.profile.defaultTweetVisibility; + if (store.state.profile.useFriendship && defaultVisibility === 'friend') { + defaultVisitType.value = VisibilityEnum.FRIEND; + } else if (defaultVisibility === 'following') { + defaultVisitType.value = VisibilityEnum.Following; + } else if (defaultVisibility === 'public') { + defaultVisitType.value = VisibilityEnum.PUBLIC; + } else { + defaultVisitType.value = VisibilityEnum.PRIVATE; + } + visitType.value = defaultVisitType.value; }); diff --git a/web/src/components/contact-item.vue b/web/src/components/contact-item.vue index 22db8b38..42a4656a 100644 --- a/web/src/components/contact-item.vue +++ b/web/src/components/contact-item.vue @@ -57,65 +57,64 @@ diff --git a/web/src/components/follow-item.vue b/web/src/components/follow-item.vue index 7908ab97..72c1533c 100644 --- a/web/src/components/follow-item.vue +++ b/web/src/components/follow-item.vue @@ -57,120 +57,122 @@ diff --git a/web/src/components/main-nav.vue b/web/src/components/main-nav.vue index a398e2ee..c9055721 100644 --- a/web/src/components/main-nav.vue +++ b/web/src/components/main-nav.vue @@ -64,57 +64,62 @@ import { onMounted, ref } from 'vue'; import { useStore } from 'vuex'; import { useRouter } from 'vue-router'; -import { useMessage, useOsTheme, DrawerPlacement} from 'naive-ui'; -import { LightModeOutlined, DarkModeOutlined, ChevronLeftRound, DehazeRound } from '@vicons/material'; +import { useMessage, useOsTheme, DrawerPlacement } from 'naive-ui'; +import { + LightModeOutlined, + DarkModeOutlined, + ChevronLeftRound, + DehazeRound, +} from '@vicons/material'; const store = useStore(); const router = useRouter(); -const activeDrawerRef = ref(false) -const placementRef = ref('left') +const activeDrawerRef = ref(false); +const placementRef = ref('left'); const props = withDefaults( - defineProps<{ - title: string; - back?: boolean; - theme?: boolean; - }>(), - { - title: '', - back: false, - theme: true, - } + defineProps<{ + title: string; + back?: boolean; + theme?: boolean; + }>(), + { + title: '', + back: false, + theme: true, + }, ); const switchTheme = (theme: boolean) => { - if (theme) { - localStorage.setItem('PAOPAO_THEME', 'dark'); - store.commit('triggerTheme', 'dark'); - } else { - localStorage.setItem('PAOPAO_THEME', 'light'); - store.commit('triggerTheme', 'light'); - } + if (theme) { + localStorage.setItem('PAOPAO_THEME', 'dark'); + store.commit('triggerTheme', 'dark'); + } else { + localStorage.setItem('PAOPAO_THEME', 'light'); + store.commit('triggerTheme', 'light'); + } }; const goBack = () => { - if (window.history.length <= 1) { - router.push({ - path: '/', - }); - } else { - router.go(-1); - } + if (window.history.length <= 1) { + router.push({ + path: '/', + }); + } else { + router.go(-1); + } }; const activeDrawer = () => { - activeDrawerRef.value = true + activeDrawerRef.value = true; }; onMounted(() => { - if (!localStorage.getItem('PAOPAO_THEME')) { - switchTheme((useOsTheme() as unknown as string) === 'dark'); - } - // 移动端特殊处理 - if (!store.state.desktopModelShow) { - window.$store = store; - window.$message = useMessage(); - } + if (!localStorage.getItem('PAOPAO_THEME')) { + switchTheme((useOsTheme() as unknown as string) === 'dark'); + } + // 移动端特殊处理 + if (!store.state.desktopModelShow) { + window.$store = store; + window.$message = useMessage(); + } }); diff --git a/web/src/components/message-item.vue b/web/src/components/message-item.vue index 796eb93a..a377eb2b 100644 --- a/web/src/components/message-item.vue +++ b/web/src/components/message-item.vue @@ -138,208 +138,237 @@ diff --git a/web/src/components/message-skeleton.vue b/web/src/components/message-skeleton.vue index 3fc83325..1b1c193d 100644 --- a/web/src/components/message-skeleton.vue +++ b/web/src/components/message-skeleton.vue @@ -8,11 +8,14 @@