mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-23 14:40:49 +08:00
Compare commits
42 Commits
feature/me
...
codex-5yja
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9554030054 | ||
|
|
d4677a5799 | ||
|
|
99644046fc | ||
|
|
22c9bd7d39 | ||
|
|
3fc6929075 | ||
|
|
4eed6889d6 | ||
|
|
959b0f6a48 | ||
|
|
91ffacc335 | ||
|
|
4969a759aa | ||
|
|
81e3a80d35 | ||
|
|
d717ce03c1 | ||
|
|
66035447a8 | ||
|
|
fa1148bc4e | ||
|
|
f60f184c84 | ||
|
|
06ffb180fe | ||
|
|
1b892828f1 | ||
|
|
1aa88ab0fe | ||
|
|
86126699d3 | ||
|
|
a6a07b9bda | ||
|
|
d8b3c68150 | ||
|
|
318b481c4b | ||
|
|
7338b891db | ||
|
|
eb18dc8e94 | ||
|
|
aec5321f89 | ||
|
|
2e658f37a4 | ||
|
|
7ccb2a44e3 | ||
|
|
0fa08e2260 | ||
|
|
38a49f7414 | ||
|
|
fb89c9fb25 | ||
|
|
e9458f5419 | ||
|
|
2d87c8f23d | ||
|
|
cb281e4030 | ||
|
|
fe84e3f2fa | ||
|
|
c307732696 | ||
|
|
a29bf7d860 | ||
|
|
27393c15f2 | ||
|
|
c91a787f29 | ||
|
|
6096712291 | ||
|
|
6d20addcde | ||
|
|
d8f9fd670c | ||
|
|
5ebe739917 | ||
|
|
022edc866a |
116
CONTRIBUTING.md
Normal file
116
CONTRIBUTING.md
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
#### **⚠️注意:仅想修改前端的朋友可不用部署后端服务**
|
||||||
|
|
||||||
|
## 如何部署
|
||||||
|
|
||||||
|
> Step1 先克隆仓库
|
||||||
|
|
||||||
|
```shell
|
||||||
|
git clone https://github.com/nagisa77/OpenIsle.git
|
||||||
|
cd OpenIsle
|
||||||
|
```
|
||||||
|
|
||||||
|
> Step2 后端部署
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cd backend
|
||||||
|
```
|
||||||
|
|
||||||
|
以IDEA编辑器为例,IDEA打开backend文件夹。
|
||||||
|
|
||||||
|
- 设置VM Option,最好运行在其他端口,非8080,这里设置8081
|
||||||
|
|
||||||
|
```shell
|
||||||
|
-Dserver.port=8081
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- 设置jdk版本为java 17
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- 本机配置MySQL服务(网上很多教程,忽略)
|
||||||
|
- 设置环境变量.env 文件 或.properties 文件(二选一)
|
||||||
|
|
||||||
|
1. 环境变量文件生成
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cp open-isle.env.example open-isle.env
|
||||||
|
```
|
||||||
|
|
||||||
|
修改环境变量,留下需要的,比如你要开发Google登录业务,就需要谷歌相关的变量,数据库是一定要的
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
应用环境文件, 选择刚刚的`open-isle.env`
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2. 直接修改 .properities 文件
|
||||||
|
|
||||||
|
位置src/main/application.properties, 数据库需要修改标红处,其他按需修改
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
处理完环境问题直接跑起来就能通了
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> Step3 前端部署
|
||||||
|
|
||||||
|
前端可以依赖本机部署的后端,也可以直接调用线上的后端接口
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cd ../frontend_nuxt/
|
||||||
|
```
|
||||||
|
|
||||||
|
copy环境.env文件
|
||||||
|
|
||||||
|
```shell
|
||||||
|
cp .env.staging.example .env
|
||||||
|
```
|
||||||
|
|
||||||
|
1. 依赖本机部署的后端:打开本文件夹,修改.env 修改为瞄准本机后端端口
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
; 本地部署后端
|
||||||
|
NUXT_PUBLIC_API_BASE_URL=https://127.0.0.1:8081
|
||||||
|
; 预发环境后端
|
||||||
|
; NUXT_PUBLIC_API_BASE_URL=https://staging.open-isle.com
|
||||||
|
; 生产环境后端
|
||||||
|
; NUXT_PUBLIC_API_BASE_URL=https://www.open-isle.com
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 依赖预发环境后台环境
|
||||||
|
|
||||||
|
**(⚠️强烈推荐只部署前端的朋友使用该环境)**
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
; 本地部署后端
|
||||||
|
; NUXT_PUBLIC_API_BASE_URL=https://127.0.0.1:8081
|
||||||
|
; 预发环境后端
|
||||||
|
NUXT_PUBLIC_API_BASE_URL=https://staging.open-isle.com
|
||||||
|
; 生产环境后端
|
||||||
|
; NUXT_PUBLIC_API_BASE_URL=https://www.open-isle.com
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 依赖线上后台环境
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
; 本地部署后端
|
||||||
|
; NUXT_PUBLIC_API_BASE_URL=https://127.0.0.1:8081
|
||||||
|
; 预发环境后端
|
||||||
|
; NUXT_PUBLIC_API_BASE_URL=https://staging.open-isle.com
|
||||||
|
; 生产环境后端
|
||||||
|
NUXT_PUBLIC_API_BASE_URL=https://www.open-isle.com
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# 安装依赖
|
||||||
|
npm install --verbose
|
||||||
|
|
||||||
|
# 运行前端服务
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
如此一来,浏览器访问 http://127.0.0.1:3000 即可访问前端页面
|
||||||
37
README.md
37
README.md
@@ -1,45 +1,18 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="OpenIsle" src="https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/image.png" width="200">
|
<img alt="OpenIsle" src="https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/image.png" width="200">
|
||||||
<br><br>
|
<br>
|
||||||
高效的开源社区前后端端平台
|
高效的开源社区前后端端平台
|
||||||
<br><br>
|
<br><br><br>
|
||||||
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square"></a>
|
<img alt="Image" src="https://openisle-1307107697.cos.accelerate.myqcloud.com/dynamic_assert/22752cfac5a04a9c90c41995b9f55fed.png" width="1200">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## 💡 简介
|
## 💡 简介
|
||||||
|
|
||||||
OpenIsle 是一个使用 Spring Boot 和 Vue 3 构建的全栈开源社区平台,提供用户注册、登录、贴文发布、评论交互等完整功能,可用于项目社区或直接打造自主社区站点。
|
OpenIsle 是一个使用 Spring Boot 和 Vue 3 构建的全栈开源社区平台,提供用户注册、登录、贴文发布、评论交互等完整功能,可用于项目社区或直接打造自主社区站点。
|
||||||
|
|
||||||
## 🚧 开发
|
## 🚧 开发 & 部署
|
||||||
|
|
||||||
### 后端
|
详细见 [Contributing](https://github.com/nagisa77/OpenIsle?tab=contributing-ov-file)
|
||||||
|
|
||||||
1. 确保安装 JDK 17 及 Maven
|
|
||||||
2. 信息配置修改 `src/main/resources/application.properties`,或通过环境变量设置数据库等参数
|
|
||||||
3. 执行 `mvn clean package` 生成包,之后使用 `java -jar target/openisle-0.0.1-SNAPSHOT.jar`启动,或在开发时直接使用 `mvn spring-boot:run`
|
|
||||||
|
|
||||||
### 前端
|
|
||||||
|
|
||||||
1. 进入前端目录
|
|
||||||
```bash
|
|
||||||
cd frontend_nuxt
|
|
||||||
```
|
|
||||||
2. 安装依赖
|
|
||||||
```bash
|
|
||||||
npm install
|
|
||||||
```
|
|
||||||
3. 启动开发服务
|
|
||||||
```bash
|
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
生产版本使用如下命令编译:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
会在 `.output` 目录生成文件,配合线上网站方式部署
|
|
||||||
|
|
||||||
## ✨ 项目特点
|
## ✨ 项目特点
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,16 @@ public class PostController {
|
|||||||
postService.deletePost(id, auth.getName());
|
postService.deletePost(id, auth.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/close")
|
||||||
|
public PostSummaryDto close(@PathVariable Long id, Authentication auth) {
|
||||||
|
return postMapper.toSummaryDto(postService.closePost(id, auth.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/{id}/reopen")
|
||||||
|
public PostSummaryDto reopen(@PathVariable Long id, Authentication auth) {
|
||||||
|
return postMapper.toSummaryDto(postService.reopenPost(id, auth.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ResponseEntity<PostDetailDto> getPost(@PathVariable Long id, Authentication auth) {
|
public ResponseEntity<PostDetailDto> getPost(@PathVariable Long id, Authentication auth) {
|
||||||
String viewer = auth != null ? auth.getName() : null;
|
String viewer = auth != null ? auth.getName() : null;
|
||||||
|
|||||||
@@ -32,5 +32,6 @@ public class PostSummaryDto {
|
|||||||
private PostType type;
|
private PostType type;
|
||||||
private LotteryDto lottery;
|
private LotteryDto lottery;
|
||||||
private boolean rssExcluded;
|
private boolean rssExcluded;
|
||||||
|
private boolean closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ public class PostMapper {
|
|||||||
dto.setStatus(post.getStatus());
|
dto.setStatus(post.getStatus());
|
||||||
dto.setPinnedAt(post.getPinnedAt());
|
dto.setPinnedAt(post.getPinnedAt());
|
||||||
dto.setRssExcluded(post.getRssExcluded() == null || post.getRssExcluded());
|
dto.setRssExcluded(post.getRssExcluded() == null || post.getRssExcluded());
|
||||||
|
dto.setClosed(post.isClosed());
|
||||||
|
|
||||||
List<ReactionDto> reactions = reactionService.getReactionsForPost(post.getId())
|
List<ReactionDto> reactions = reactionService.getReactionsForPost(post.getId())
|
||||||
.stream()
|
.stream()
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ public enum NotificationType {
|
|||||||
POST_REVIEW_REQUEST,
|
POST_REVIEW_REQUEST,
|
||||||
/** Your post under review was approved or rejected */
|
/** Your post under review was approved or rejected */
|
||||||
POST_REVIEWED,
|
POST_REVIEWED,
|
||||||
|
/** An administrator deleted your post */
|
||||||
|
POST_DELETED,
|
||||||
/** A subscribed post received a new comment */
|
/** A subscribed post received a new comment */
|
||||||
POST_UPDATED,
|
POST_UPDATED,
|
||||||
/** Someone subscribed to your post */
|
/** Someone subscribed to your post */
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ public class Post {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private PostType type = PostType.NORMAL;
|
private PostType type = PostType.NORMAL;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private boolean closed = false;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
private LocalDateTime pinnedAt;
|
private LocalDateTime pinnedAt;
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ public class CommentService {
|
|||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
Post post = postRepository.findById(postId)
|
Post post = postRepository.findById(postId)
|
||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||||
|
if (post.isClosed()) {
|
||||||
|
throw new IllegalStateException("Post closed");
|
||||||
|
}
|
||||||
Comment comment = new Comment();
|
Comment comment = new Comment();
|
||||||
comment.setAuthor(author);
|
comment.setAuthor(author);
|
||||||
comment.setPost(post);
|
comment.setPost(post);
|
||||||
@@ -94,6 +97,9 @@ public class CommentService {
|
|||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
Comment parent = commentRepository.findById(parentId)
|
Comment parent = commentRepository.findById(parentId)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Comment not found"));
|
.orElseThrow(() -> new IllegalArgumentException("Comment not found"));
|
||||||
|
if (parent.getPost().isClosed()) {
|
||||||
|
throw new IllegalStateException("Post closed");
|
||||||
|
}
|
||||||
Comment comment = new Comment();
|
Comment comment = new Comment();
|
||||||
comment.setAuthor(author);
|
comment.setAuthor(author);
|
||||||
comment.setPost(parent.getPost());
|
comment.setPost(parent.getPost());
|
||||||
|
|||||||
@@ -512,6 +512,30 @@ public class PostService {
|
|||||||
return postRepository.save(post);
|
return postRepository.save(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Post closePost(Long id, String username) {
|
||||||
|
Post post = postRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||||
|
User user = userRepository.findByUsername(username)
|
||||||
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
|
if (!user.getId().equals(post.getAuthor().getId()) && user.getRole() != Role.ADMIN) {
|
||||||
|
throw new IllegalArgumentException("Unauthorized");
|
||||||
|
}
|
||||||
|
post.setClosed(true);
|
||||||
|
return postRepository.save(post);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Post reopenPost(Long id, String username) {
|
||||||
|
Post post = postRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||||
|
User user = userRepository.findByUsername(username)
|
||||||
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
|
if (!user.getId().equals(post.getAuthor().getId()) && user.getRole() != Role.ADMIN) {
|
||||||
|
throw new IllegalArgumentException("Unauthorized");
|
||||||
|
}
|
||||||
|
post.setClosed(false);
|
||||||
|
return postRepository.save(post);
|
||||||
|
}
|
||||||
|
|
||||||
@org.springframework.transaction.annotation.Transactional
|
@org.springframework.transaction.annotation.Transactional
|
||||||
public Post updatePost(Long id,
|
public Post updatePost(Long id,
|
||||||
String username,
|
String username,
|
||||||
@@ -555,7 +579,9 @@ public class PostService {
|
|||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||||
User user = userRepository.findByUsername(username)
|
User user = userRepository.findByUsername(username)
|
||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("User not found"));
|
||||||
if (!user.getId().equals(post.getAuthor().getId()) && user.getRole() != Role.ADMIN) {
|
User author = post.getAuthor();
|
||||||
|
boolean adminDeleting = !user.getId().equals(author.getId()) && user.getRole() == Role.ADMIN;
|
||||||
|
if (!user.getId().equals(author.getId()) && user.getRole() != Role.ADMIN) {
|
||||||
throw new IllegalArgumentException("Unauthorized");
|
throw new IllegalArgumentException("Unauthorized");
|
||||||
}
|
}
|
||||||
for (Comment c : commentRepository.findByPostAndParentIsNullOrderByCreatedAtAsc(post)) {
|
for (Comment c : commentRepository.findByPostAndParentIsNullOrderByCreatedAtAsc(post)) {
|
||||||
@@ -572,7 +598,12 @@ public class PostService {
|
|||||||
future.cancel(false);
|
future.cancel(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String title = post.getTitle();
|
||||||
postRepository.delete(post);
|
postRepository.delete(post);
|
||||||
|
if (adminDeleting) {
|
||||||
|
notificationService.createNotification(author, NotificationType.POST_DELETED,
|
||||||
|
null, null, null, user, null, title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public java.util.List<Post> getPostsByIds(java.util.List<Long> ids) {
|
public java.util.List<Post> getPostsByIds(java.util.List<Long> ids) {
|
||||||
|
|||||||
@@ -61,6 +61,58 @@ class PostServiceTest {
|
|||||||
verify(postRepo).delete(post);
|
verify(postRepo).delete(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deletePostByAdminNotifiesAuthor() {
|
||||||
|
PostRepository postRepo = mock(PostRepository.class);
|
||||||
|
UserRepository userRepo = mock(UserRepository.class);
|
||||||
|
CategoryRepository catRepo = mock(CategoryRepository.class);
|
||||||
|
TagRepository tagRepo = mock(TagRepository.class);
|
||||||
|
LotteryPostRepository lotteryRepo = mock(LotteryPostRepository.class);
|
||||||
|
NotificationService notifService = mock(NotificationService.class);
|
||||||
|
SubscriptionService subService = mock(SubscriptionService.class);
|
||||||
|
CommentService commentService = mock(CommentService.class);
|
||||||
|
CommentRepository commentRepo = mock(CommentRepository.class);
|
||||||
|
ReactionRepository reactionRepo = mock(ReactionRepository.class);
|
||||||
|
PostSubscriptionRepository subRepo = mock(PostSubscriptionRepository.class);
|
||||||
|
NotificationRepository notificationRepo = mock(NotificationRepository.class);
|
||||||
|
PostReadService postReadService = mock(PostReadService.class);
|
||||||
|
ImageUploader imageUploader = mock(ImageUploader.class);
|
||||||
|
TaskScheduler taskScheduler = mock(TaskScheduler.class);
|
||||||
|
EmailSender emailSender = mock(EmailSender.class);
|
||||||
|
ApplicationContext context = mock(ApplicationContext.class);
|
||||||
|
|
||||||
|
PostService service = new PostService(postRepo, userRepo, catRepo, tagRepo, lotteryRepo,
|
||||||
|
notifService, subService, commentService, commentRepo,
|
||||||
|
reactionRepo, subRepo, notificationRepo, postReadService,
|
||||||
|
imageUploader, taskScheduler, emailSender, context, PublishMode.DIRECT);
|
||||||
|
when(context.getBean(PostService.class)).thenReturn(service);
|
||||||
|
|
||||||
|
Post post = new Post();
|
||||||
|
post.setId(1L);
|
||||||
|
post.setTitle("T");
|
||||||
|
post.setContent("");
|
||||||
|
User author = new User();
|
||||||
|
author.setId(2L);
|
||||||
|
author.setRole(Role.USER);
|
||||||
|
post.setAuthor(author);
|
||||||
|
|
||||||
|
User admin = new User();
|
||||||
|
admin.setId(1L);
|
||||||
|
admin.setRole(Role.ADMIN);
|
||||||
|
|
||||||
|
when(postRepo.findById(1L)).thenReturn(Optional.of(post));
|
||||||
|
when(userRepo.findByUsername("admin")).thenReturn(Optional.of(admin));
|
||||||
|
when(commentRepo.findByPostAndParentIsNullOrderByCreatedAtAsc(post)).thenReturn(List.of());
|
||||||
|
when(reactionRepo.findByPost(post)).thenReturn(List.of());
|
||||||
|
when(subRepo.findByPost(post)).thenReturn(List.of());
|
||||||
|
when(notificationRepo.findByPost(post)).thenReturn(List.of());
|
||||||
|
|
||||||
|
service.deletePost(1L, "admin");
|
||||||
|
|
||||||
|
verify(notifService).createNotification(eq(author), eq(NotificationType.POST_DELETED), isNull(),
|
||||||
|
isNull(), isNull(), eq(admin), isNull(), eq("T"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createPostRespectsRateLimit() {
|
void createPostRespectsRateLimit() {
|
||||||
PostRepository postRepo = mock(PostRepository.class);
|
PostRepository postRepo = mock(PostRepository.class);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<GlobalPopups />
|
<GlobalPopups />
|
||||||
|
<ConfirmDialog />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
import HeaderComponent from '~/components/HeaderComponent.vue'
|
import HeaderComponent from '~/components/HeaderComponent.vue'
|
||||||
import MenuComponent from '~/components/MenuComponent.vue'
|
import MenuComponent from '~/components/MenuComponent.vue'
|
||||||
import GlobalPopups from '~/components/GlobalPopups.vue'
|
import GlobalPopups from '~/components/GlobalPopups.vue'
|
||||||
|
import ConfirmDialog from '~/components/ConfirmDialog.vue'
|
||||||
import { useIsMobile } from '~/utils/screen'
|
import { useIsMobile } from '~/utils/screen'
|
||||||
|
|
||||||
const isMobile = useIsMobile()
|
const isMobile = useIsMobile()
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.vditor-toolbar--pin {
|
.vditor-toolbar--pin {
|
||||||
top: var(--header-height) !important;
|
top: calc(var(--header-height) + 1px) !important;
|
||||||
|
z-index: 2000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.vditor-panel {
|
.vditor-panel {
|
||||||
@@ -183,7 +184,7 @@ body {
|
|||||||
font-family: 'Maple Mono', monospace;
|
font-family: 'Maple Mono', monospace;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
white-space: no-wrap;
|
white-space: break-spaces;
|
||||||
background-color: var(--code-highlight-background-color);
|
background-color: var(--code-highlight-background-color);
|
||||||
color: var(--text-color);
|
color: var(--text-color);
|
||||||
}
|
}
|
||||||
|
|||||||
65
frontend_nuxt/components/BaseSwitch.vue
Normal file
65
frontend_nuxt/components/BaseSwitch.vue
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<template>
|
||||||
|
<label class="switch">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
:checked="modelValue"
|
||||||
|
@change="$emit('update:modelValue', $event.target.checked)"
|
||||||
|
/>
|
||||||
|
<span class="slider"></span>
|
||||||
|
</label>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
defineProps({
|
||||||
|
modelValue: { type: Boolean, default: false },
|
||||||
|
})
|
||||||
|
|
||||||
|
defineEmits(['update:modelValue'])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.switch {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
width: 40px;
|
||||||
|
height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.switch input {
|
||||||
|
opacity: 0;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider {
|
||||||
|
position: absolute;
|
||||||
|
cursor: pointer;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: #ccc;
|
||||||
|
transition: 0.2s;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider:before {
|
||||||
|
position: absolute;
|
||||||
|
content: '';
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
left: 2px;
|
||||||
|
bottom: 2px;
|
||||||
|
background-color: white;
|
||||||
|
transition: 0.2s;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + .slider {
|
||||||
|
background-color: var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + .slider:before {
|
||||||
|
transform: translateX(20px);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
getEditorTheme as getEditorThemeUtil,
|
getEditorTheme as getEditorThemeUtil,
|
||||||
getPreviewTheme as getPreviewThemeUtil,
|
getPreviewTheme as getPreviewThemeUtil,
|
||||||
} from '~/utils/vditor'
|
} from '~/utils/vditor'
|
||||||
|
import '~/assets/global.css'
|
||||||
import LoginOverlay from '~/components/LoginOverlay.vue'
|
import LoginOverlay from '~/components/LoginOverlay.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
v-if="showEditor"
|
v-if="showEditor"
|
||||||
@submit="submitReply"
|
@submit="submitReply"
|
||||||
:loading="isWaitingForReply"
|
:loading="isWaitingForReply"
|
||||||
:disabled="!loggedIn"
|
:disabled="!loggedIn || postClosed"
|
||||||
:show-login-overlay="!loggedIn"
|
:show-login-overlay="!loggedIn"
|
||||||
:parent-user-name="comment.userName"
|
:parent-user-name="comment.userName"
|
||||||
/>
|
/>
|
||||||
@@ -76,6 +76,7 @@
|
|||||||
:level="level + 1"
|
:level="level + 1"
|
||||||
:default-show-replies="item.openReplies"
|
:default-show-replies="item.openReplies"
|
||||||
:post-author-id="postAuthorId"
|
:post-author-id="postAuthorId"
|
||||||
|
:post-closed="postClosed"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</BaseTimeline>
|
</BaseTimeline>
|
||||||
@@ -122,6 +123,10 @@ const props = defineProps({
|
|||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
postClosed: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['deleted'])
|
const emit = defineEmits(['deleted'])
|
||||||
@@ -148,6 +153,7 @@ const toggleReplies = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const toggleEditor = () => {
|
const toggleEditor = () => {
|
||||||
|
if (props.postClosed) return
|
||||||
showEditor.value = !showEditor.value
|
showEditor.value = !showEditor.value
|
||||||
if (showEditor.value) {
|
if (showEditor.value) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -213,6 +219,10 @@ const deleteComment = async () => {
|
|||||||
}
|
}
|
||||||
const submitReply = async (parentUserName, text, clear) => {
|
const submitReply = async (parentUserName, text, clear) => {
|
||||||
if (!text.trim()) return
|
if (!text.trim()) return
|
||||||
|
if (props.postClosed) {
|
||||||
|
toast.error('帖子已关闭')
|
||||||
|
return
|
||||||
|
}
|
||||||
isWaitingForReply.value = true
|
isWaitingForReply.value = true
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
if (!token) {
|
if (!token) {
|
||||||
|
|||||||
71
frontend_nuxt/components/ConfirmDialog.vue
Normal file
71
frontend_nuxt/components/ConfirmDialog.vue
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<template>
|
||||||
|
<BasePopup :visible="visible" @close="onCancel">
|
||||||
|
<div class="confirm-dialog" role="dialog" aria-modal="true">
|
||||||
|
<h3 class="confirm-title">{{ title }}</h3>
|
||||||
|
<p class="confirm-message">{{ message }}</p>
|
||||||
|
<div class="confirm-actions">
|
||||||
|
<div class="cancel-button" @click="onCancel">取消</div>
|
||||||
|
<div class="confirm-button" @click="onConfirm">确认</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</BasePopup>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import BasePopup from '~/components/BasePopup.vue'
|
||||||
|
import { useConfirm } from '~/composables/useConfirm'
|
||||||
|
|
||||||
|
const { visible, title, message, onConfirm, onCancel } = useConfirm()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.confirm-dialog {
|
||||||
|
padding: 20px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.confirm-title {
|
||||||
|
margin-top: 0;
|
||||||
|
font-size: 18px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.confirm-message {
|
||||||
|
margin: 16px 0 20px;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: var(--text-secondary, #666);
|
||||||
|
}
|
||||||
|
.confirm-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
.confirm-button,
|
||||||
|
.cancel-button {
|
||||||
|
min-width: 88px;
|
||||||
|
height: 36px;
|
||||||
|
padding: 0 14px;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
}
|
||||||
|
.confirm-button {
|
||||||
|
background: var(--primary-color);
|
||||||
|
color: #fff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.confirm-button:hover {
|
||||||
|
background: var(--primary-color-hover);
|
||||||
|
}
|
||||||
|
.cancel-button {
|
||||||
|
background: transparent;
|
||||||
|
color: var(--primary-color);
|
||||||
|
border-color: currentColor;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.cancel-button:hover {
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -95,7 +95,6 @@ const closeMilkTeaPopup = () => {
|
|||||||
if (!process.client) return
|
if (!process.client) return
|
||||||
localStorage.setItem('milkTeaActivityPopupShown', 'true')
|
localStorage.setItem('milkTeaActivityPopupShown', 'true')
|
||||||
showMilkTeaPopup.value = false
|
showMilkTeaPopup.value = false
|
||||||
checkNotificationSetting()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkNotificationSetting = async () => {
|
const checkNotificationSetting = async () => {
|
||||||
@@ -108,7 +107,6 @@ const closeNotificationPopup = () => {
|
|||||||
if (!process.client) return
|
if (!process.client) return
|
||||||
localStorage.setItem('notificationSettingPopupShown', 'true')
|
localStorage.setItem('notificationSettingPopupShown', 'true')
|
||||||
showNotificationPopup.value = false
|
showNotificationPopup.value = false
|
||||||
checkNewMedals()
|
|
||||||
}
|
}
|
||||||
const checkNewMedals = async () => {
|
const checkNewMedals = async () => {
|
||||||
if (!process.client) return
|
if (!process.client) return
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
getEditorTheme as getEditorThemeUtil,
|
getEditorTheme as getEditorThemeUtil,
|
||||||
getPreviewTheme as getPreviewThemeUtil,
|
getPreviewTheme as getPreviewThemeUtil,
|
||||||
} from '~/utils/vditor'
|
} from '~/utils/vditor'
|
||||||
|
import '~/assets/global.css'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'PostEditor',
|
name: 'PostEditor',
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ import { computed, onMounted, ref, watch } from 'vue'
|
|||||||
import { toast } from '~/main'
|
import { toast } from '~/main'
|
||||||
import { authState, getToken } from '~/utils/auth'
|
import { authState, getToken } from '~/utils/auth'
|
||||||
import { reactionEmojiMap } from '~/utils/reactions'
|
import { reactionEmojiMap } from '~/utils/reactions'
|
||||||
|
import { useReactionTypes } from '~/composables/useReactionTypes'
|
||||||
|
|
||||||
|
const { reactionTypes, initialize } = useReactionTypes()
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue'])
|
||||||
@@ -66,30 +70,6 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const reactions = ref(props.modelValue)
|
const reactions = ref(props.modelValue)
|
||||||
const reactionTypes = ref([])
|
|
||||||
|
|
||||||
let cachedTypes = null
|
|
||||||
const fetchTypes = async () => {
|
|
||||||
if (cachedTypes) return cachedTypes
|
|
||||||
try {
|
|
||||||
const token = getToken()
|
|
||||||
const res = await fetch(`${API_BASE_URL}/api/reaction-types`, {
|
|
||||||
headers: { Authorization: token ? `Bearer ${token}` : '' },
|
|
||||||
})
|
|
||||||
if (res.ok) {
|
|
||||||
cachedTypes = await res.json()
|
|
||||||
} else {
|
|
||||||
cachedTypes = []
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
cachedTypes = []
|
|
||||||
}
|
|
||||||
return cachedTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
reactionTypes.value = await fetchTypes()
|
|
||||||
})
|
|
||||||
|
|
||||||
const counts = computed(() => {
|
const counts = computed(() => {
|
||||||
const c = {}
|
const c = {}
|
||||||
@@ -200,6 +180,10 @@ const toggleReaction = async (type) => {
|
|||||||
toast.error('操作失败')
|
toast.error('操作失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await initialize()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -253,7 +237,7 @@ const toggleReaction = async (type) => {
|
|||||||
|
|
||||||
.make-reaction-item {
|
.make-reaction-item {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 10px;
|
padding: 4px;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
|
|||||||
52
frontend_nuxt/composables/useConfirm.ts
Normal file
52
frontend_nuxt/composables/useConfirm.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// composables/useConfirm.ts
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
// 全局单例(SPA 下即可;Nuxt/SSR 下见文末“SSR 提醒”)
|
||||||
|
const visible = ref(false)
|
||||||
|
const title = ref('')
|
||||||
|
const message = ref('')
|
||||||
|
|
||||||
|
let resolver: ((ok: boolean) => void) | null = null
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
visible.value = false
|
||||||
|
title.value = ''
|
||||||
|
message.value = ''
|
||||||
|
resolver = null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useConfirm() {
|
||||||
|
/**
|
||||||
|
* 打开确认框,返回 Promise<boolean>
|
||||||
|
* - 确认 => resolve(true)
|
||||||
|
* - 取消/关闭 => resolve(false)
|
||||||
|
* 若并发调用,以最后一次为准(更简单直观)
|
||||||
|
*/
|
||||||
|
const confirm = (t: string, m: string) => {
|
||||||
|
title.value = t
|
||||||
|
message.value = m
|
||||||
|
visible.value = true
|
||||||
|
return new Promise<boolean>((resolve) => {
|
||||||
|
resolver = resolve
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const onConfirm = () => {
|
||||||
|
resolver?.(true)
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
const onCancel = () => {
|
||||||
|
resolver?.(false)
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
visible,
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
confirm,
|
||||||
|
onConfirm,
|
||||||
|
onCancel,
|
||||||
|
}
|
||||||
|
}
|
||||||
52
frontend_nuxt/composables/useReactionTypes.js
Normal file
52
frontend_nuxt/composables/useReactionTypes.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
const reactionTypes = ref([])
|
||||||
|
let isLoading = false
|
||||||
|
let isInitialized = false
|
||||||
|
|
||||||
|
export function useReactionTypes() {
|
||||||
|
const config = useRuntimeConfig()
|
||||||
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
|
|
||||||
|
const fetchReactionTypes = async () => {
|
||||||
|
if (isInitialized || isLoading) {
|
||||||
|
reactionTypes.value = [...(window.reactionTypes || [])]
|
||||||
|
return reactionTypes.value
|
||||||
|
}
|
||||||
|
|
||||||
|
isLoading = true
|
||||||
|
try {
|
||||||
|
const token = getToken()
|
||||||
|
const res = await fetch(`${API_BASE_URL}/api/reaction-types`, {
|
||||||
|
headers: { Authorization: token ? `Bearer ${token}` : '' },
|
||||||
|
})
|
||||||
|
if (res.ok) {
|
||||||
|
reactionTypes.value = await res.json()
|
||||||
|
window.reactionTypes = [...reactionTypes.value]
|
||||||
|
isInitialized = true
|
||||||
|
} else {
|
||||||
|
reactionTypes.value = []
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch reaction types:', error)
|
||||||
|
reactionTypes.value = []
|
||||||
|
} finally {
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
return reactionTypes.value
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialize = async () => {
|
||||||
|
if (!isInitialized) {
|
||||||
|
await fetchReactionTypes()
|
||||||
|
}
|
||||||
|
return reactionTypes.value
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
reactionTypes: readonly(reactionTypes),
|
||||||
|
fetchReactionTypes,
|
||||||
|
initialize,
|
||||||
|
isInitialized: readonly(isInitialized)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -535,6 +535,7 @@ const sanitizeDescription = (text) => stripMarkdown(text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
.article-item-description {
|
.article-item-description {
|
||||||
|
max-width: 100%;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: gray;
|
color: gray;
|
||||||
|
|||||||
@@ -33,15 +33,13 @@
|
|||||||
<div v-if="selectedTab === 'control'">
|
<div v-if="selectedTab === 'control'">
|
||||||
<div class="message-control-container">
|
<div class="message-control-container">
|
||||||
<div class="message-control-title">通知设置</div>
|
<div class="message-control-title">通知设置</div>
|
||||||
<div class="message-control-push-item-container">
|
<div class="message-control-item-container">
|
||||||
<div
|
<div v-for="pref in notificationPrefs" :key="pref.type" class="message-control-item">
|
||||||
v-for="pref in notificationPrefs"
|
<div class="message-control-item-label">{{ formatType(pref.type) }}</div>
|
||||||
:key="pref.type"
|
<BaseSwitch
|
||||||
class="message-control-push-item"
|
:model-value="pref.enabled"
|
||||||
:class="{ select: pref.enabled }"
|
@update:modelValue="(val) => togglePref(pref, val)"
|
||||||
@click="togglePref(pref)"
|
/>
|
||||||
>
|
|
||||||
{{ formatType(pref.type) }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -495,6 +493,24 @@
|
|||||||
已被管理员拒绝
|
已被管理员拒绝
|
||||||
</NotificationContainer>
|
</NotificationContainer>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="item.type === 'POST_DELETED'">
|
||||||
|
<NotificationContainer :item="item" :markRead="markRead">
|
||||||
|
管理员
|
||||||
|
<template v-if="item.fromUser">
|
||||||
|
<NuxtLink
|
||||||
|
class="notif-content-text"
|
||||||
|
@click="markRead(item.id)"
|
||||||
|
:to="`/users/${item.fromUser.id}`"
|
||||||
|
>
|
||||||
|
{{ item.fromUser.username }}
|
||||||
|
</NuxtLink>
|
||||||
|
</template>
|
||||||
|
删除了您的帖子
|
||||||
|
<span class="notif-content-text">
|
||||||
|
{{ stripMarkdownLength(item.content, 100) }}
|
||||||
|
</span>
|
||||||
|
</NotificationContainer>
|
||||||
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<NotificationContainer :item="item" :markRead="markRead">
|
<NotificationContainer :item="item" :markRead="markRead">
|
||||||
{{ formatType(item.type) }}
|
{{ formatType(item.type) }}
|
||||||
@@ -524,7 +540,7 @@ import {
|
|||||||
fetchNotifications,
|
fetchNotifications,
|
||||||
fetchUnreadCount,
|
fetchUnreadCount,
|
||||||
isLoadingMessage,
|
isLoadingMessage,
|
||||||
markRead,
|
markNotificationRead,
|
||||||
notifications,
|
notifications,
|
||||||
markAllRead,
|
markAllRead,
|
||||||
hasMore,
|
hasMore,
|
||||||
@@ -532,6 +548,7 @@ import {
|
|||||||
updateNotificationPreference,
|
updateNotificationPreference,
|
||||||
} from '~/utils/notification'
|
} from '~/utils/notification'
|
||||||
import TimeManager from '~/utils/time'
|
import TimeManager from '~/utils/time'
|
||||||
|
import BaseSwitch from '~/components/BaseSwitch.vue'
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
@@ -564,10 +581,10 @@ const fetchPrefs = async () => {
|
|||||||
notificationPrefs.value = await fetchNotificationPreferences()
|
notificationPrefs.value = await fetchNotificationPreferences()
|
||||||
}
|
}
|
||||||
|
|
||||||
const togglePref = async (pref) => {
|
const togglePref = async (pref, value) => {
|
||||||
const ok = await updateNotificationPreference(pref.type, !pref.enabled)
|
const ok = await updateNotificationPreference(pref.type, value)
|
||||||
if (ok) {
|
if (ok) {
|
||||||
pref.enabled = !pref.enabled
|
pref.enabled = value
|
||||||
await fetchNotifications({
|
await fetchNotifications({
|
||||||
page: page.value,
|
page: page.value,
|
||||||
size: pageSize,
|
size: pageSize,
|
||||||
@@ -579,6 +596,14 @@ const togglePref = async (pref) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const markRead = async (id) => {
|
||||||
|
markNotificationRead(id)
|
||||||
|
if (selectedTab.value === 'unread') {
|
||||||
|
const index = notifications.value.findIndex((n) => n.id === id)
|
||||||
|
if (index !== -1) notifications.value.splice(index, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const approve = async (id, nid) => {
|
const approve = async (id, nid) => {
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
if (!token) return
|
if (!token) return
|
||||||
@@ -647,6 +672,8 @@ const formatType = (t) => {
|
|||||||
return '抽奖中奖了'
|
return '抽奖中奖了'
|
||||||
case 'LOTTERY_DRAW':
|
case 'LOTTERY_DRAW':
|
||||||
return '抽奖已开奖'
|
return '抽奖已开奖'
|
||||||
|
case 'POST_DELETED':
|
||||||
|
return '帖子被删除'
|
||||||
default:
|
default:
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
@@ -818,26 +845,21 @@ onActivated(async () => {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-control-push-item-container {
|
.message-control-item-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: column;
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-control-push-item {
|
.message-control-item {
|
||||||
font-size: 14px;
|
display: flex;
|
||||||
margin-bottom: 5px;
|
align-items: center;
|
||||||
padding: 8px 16px;
|
justify-content: space-between;
|
||||||
border: 1px solid var(--normal-border-color);
|
max-width: 200px;
|
||||||
border-radius: 10px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.message-control-push-item.select {
|
.message-control-item-label {
|
||||||
background-color: var(--primary-color);
|
font-size: 14px;
|
||||||
color: white;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
|
|||||||
@@ -15,8 +15,9 @@
|
|||||||
<div class="article-title-container-right">
|
<div class="article-title-container-right">
|
||||||
<div v-if="status === 'PENDING'" class="article-pending-button">审核中</div>
|
<div v-if="status === 'PENDING'" class="article-pending-button">审核中</div>
|
||||||
<div v-if="status === 'REJECTED'" class="article-block-button">已拒绝</div>
|
<div v-if="status === 'REJECTED'" class="article-block-button">已拒绝</div>
|
||||||
|
<div v-if="closed" class="article-closed-button">已关闭</div>
|
||||||
<div
|
<div
|
||||||
v-if="loggedIn && !isAuthor && !subscribed"
|
v-if="!closed && loggedIn && !isAuthor && !subscribed"
|
||||||
class="article-subscribe-button"
|
class="article-subscribe-button"
|
||||||
@click="subscribePost"
|
@click="subscribePost"
|
||||||
>
|
>
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="loggedIn && !isAuthor && subscribed"
|
v-if="!closed && loggedIn && !isAuthor && subscribed"
|
||||||
class="article-unsubscribe-button"
|
class="article-unsubscribe-button"
|
||||||
@click="unsubscribePost"
|
@click="unsubscribePost"
|
||||||
>
|
>
|
||||||
@@ -167,11 +168,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="closed" class="post-close-container">该帖子已关闭,内容仅供阅读,无法进行互动</div>
|
||||||
|
|
||||||
<ClientOnly>
|
<ClientOnly>
|
||||||
<CommentEditor
|
<CommentEditor
|
||||||
@submit="postComment"
|
@submit="postComment"
|
||||||
:loading="isWaitingPostingComment"
|
:loading="isWaitingPostingComment"
|
||||||
:disabled="!loggedIn"
|
:disabled="!loggedIn || closed"
|
||||||
:show-login-overlay="!loggedIn"
|
:show-login-overlay="!loggedIn"
|
||||||
:parent-user-name="author.username"
|
:parent-user-name="author.username"
|
||||||
/>
|
/>
|
||||||
@@ -196,6 +199,7 @@
|
|||||||
:level="0"
|
:level="0"
|
||||||
:default-show-replies="item.openReplies"
|
:default-show-replies="item.openReplies"
|
||||||
:post-author-id="author.id"
|
:post-author-id="author.id"
|
||||||
|
:post-closed="closed"
|
||||||
@deleted="onCommentDeleted"
|
@deleted="onCommentDeleted"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
@@ -232,7 +236,16 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, onBeforeUnmount, nextTick, watch, watchEffect } from 'vue'
|
import {
|
||||||
|
ref,
|
||||||
|
computed,
|
||||||
|
onMounted,
|
||||||
|
onBeforeUnmount,
|
||||||
|
nextTick,
|
||||||
|
watch,
|
||||||
|
watchEffect,
|
||||||
|
onActivated,
|
||||||
|
} from 'vue'
|
||||||
import VueEasyLightbox from 'vue-easy-lightbox'
|
import VueEasyLightbox from 'vue-easy-lightbox'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import CommentItem from '~/components/CommentItem.vue'
|
import CommentItem from '~/components/CommentItem.vue'
|
||||||
@@ -251,6 +264,8 @@ import { useRouter } from 'vue-router'
|
|||||||
import { useIsMobile } from '~/utils/screen'
|
import { useIsMobile } from '~/utils/screen'
|
||||||
import Dropdown from '~/components/Dropdown.vue'
|
import Dropdown from '~/components/Dropdown.vue'
|
||||||
import { ClientOnly } from '#components'
|
import { ClientOnly } from '#components'
|
||||||
|
import { useConfirm } from '~/composables/useConfirm'
|
||||||
|
const { confirm } = useConfirm()
|
||||||
|
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
const API_BASE_URL = config.public.apiBaseUrl
|
const API_BASE_URL = config.public.apiBaseUrl
|
||||||
@@ -267,6 +282,7 @@ const tags = ref([])
|
|||||||
const postReactions = ref([])
|
const postReactions = ref([])
|
||||||
const comments = ref([])
|
const comments = ref([])
|
||||||
const status = ref('PUBLISHED')
|
const status = ref('PUBLISHED')
|
||||||
|
const closed = ref(false)
|
||||||
const pinnedAt = ref(null)
|
const pinnedAt = ref(null)
|
||||||
const rssExcluded = ref(false)
|
const rssExcluded = ref(false)
|
||||||
const isWaitingPostingComment = ref(false)
|
const isWaitingPostingComment = ref(false)
|
||||||
@@ -349,7 +365,12 @@ const articleMenuItems = computed(() => {
|
|||||||
const items = []
|
const items = []
|
||||||
if (isAuthor.value || isAdmin.value) {
|
if (isAuthor.value || isAdmin.value) {
|
||||||
items.push({ text: '编辑文章', onClick: () => editPost() })
|
items.push({ text: '编辑文章', onClick: () => editPost() })
|
||||||
items.push({ text: '删除文章', color: 'red', onClick: () => deletePost() })
|
items.push({ text: '删除文章', color: 'red', onClick: deletePost })
|
||||||
|
if (closed.value) {
|
||||||
|
items.push({ text: '重新打开帖子', onClick: () => reopenPost() })
|
||||||
|
} else {
|
||||||
|
items.push({ text: '关闭帖子', onClick: () => closePost() })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isAdmin.value) {
|
if (isAdmin.value) {
|
||||||
if (pinnedAt.value) {
|
if (pinnedAt.value) {
|
||||||
@@ -485,6 +506,7 @@ watchEffect(() => {
|
|||||||
postReactions.value = data.reactions || []
|
postReactions.value = data.reactions || []
|
||||||
subscribed.value = !!data.subscribed
|
subscribed.value = !!data.subscribed
|
||||||
status.value = data.status
|
status.value = data.status
|
||||||
|
closed.value = data.closed
|
||||||
pinnedAt.value = data.pinnedAt
|
pinnedAt.value = data.pinnedAt
|
||||||
rssExcluded.value = data.rssExcluded
|
rssExcluded.value = data.rssExcluded
|
||||||
postTime.value = TimeManager.format(data.createdAt)
|
postTime.value = TimeManager.format(data.createdAt)
|
||||||
@@ -544,6 +566,10 @@ const onSliderInput = (e) => {
|
|||||||
|
|
||||||
const postComment = async (parentUserName, text, clear) => {
|
const postComment = async (parentUserName, text, clear) => {
|
||||||
if (!text.trim()) return
|
if (!text.trim()) return
|
||||||
|
if (closed.value) {
|
||||||
|
toast.error('帖子已关闭')
|
||||||
|
return
|
||||||
|
}
|
||||||
console.debug('Posting comment', { postId, text })
|
console.debug('Posting comment', { postId, text })
|
||||||
isWaitingPostingComment.value = true
|
isWaitingPostingComment.value = true
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
@@ -682,24 +708,62 @@ const includeRss = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const closePost = async () => {
|
||||||
|
const token = getToken()
|
||||||
|
if (!token) return
|
||||||
|
const res = await fetch(`${API_BASE_URL}/api/posts/${postId}/close`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
})
|
||||||
|
if (res.ok) {
|
||||||
|
closed.value = true
|
||||||
|
toast.success('已关闭')
|
||||||
|
await refreshPost()
|
||||||
|
} else {
|
||||||
|
toast.error('操作失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const reopenPost = async () => {
|
||||||
|
const token = getToken()
|
||||||
|
if (!token) return
|
||||||
|
const res = await fetch(`${API_BASE_URL}/api/posts/${postId}/reopen`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
})
|
||||||
|
if (res.ok) {
|
||||||
|
closed.value = false
|
||||||
|
toast.success('已重新打开')
|
||||||
|
await refreshPost()
|
||||||
|
} else {
|
||||||
|
toast.error('操作失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const editPost = () => {
|
const editPost = () => {
|
||||||
navigateTo(`/posts/${postId}/edit`, { replace: true })
|
navigateTo(`/posts/${postId}/edit`, { replace: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
const deletePost = async () => {
|
const deletePost = async () => {
|
||||||
const token = getToken()
|
try {
|
||||||
if (!token) {
|
const ok = await confirm('删除帖子', '此操作不可恢复,确认要删除吗?')
|
||||||
toast.error('请先登录')
|
if (!ok) return
|
||||||
return
|
const token = getToken()
|
||||||
}
|
if (!token) {
|
||||||
const res = await fetch(`${API_BASE_URL}/api/posts/${postId}`, {
|
toast.error('请先登录')
|
||||||
method: 'DELETE',
|
return
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
}
|
||||||
})
|
const res = await fetch(`${API_BASE_URL}/api/posts/${postId}`, {
|
||||||
if (res.ok) {
|
method: 'DELETE',
|
||||||
toast.success('已删除')
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
navigateTo('/', { replace: true })
|
})
|
||||||
} else {
|
if (res.ok) {
|
||||||
|
toast.success('已删除')
|
||||||
|
navigateTo('/', { replace: true })
|
||||||
|
} else {
|
||||||
|
toast.error('操作失败')
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
toast.error('操作失败')
|
toast.error('操作失败')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -812,7 +876,7 @@ const gotoProfile = () => {
|
|||||||
navigateTo(`/users/${author.value.id}`, { replace: true })
|
navigateTo(`/users/${author.value.id}`, { replace: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
const initPage = async () => {
|
||||||
await fetchComments()
|
await fetchComments()
|
||||||
const hash = location.hash
|
const hash = location.hash
|
||||||
const id = hash.startsWith('#comment-') ? hash.substring('#comment-'.length) : null
|
const id = hash.startsWith('#comment-') ? hash.substring('#comment-'.length) : null
|
||||||
@@ -820,6 +884,14 @@ onMounted(async () => {
|
|||||||
updateCurrentIndex()
|
updateCurrentIndex()
|
||||||
window.addEventListener('scroll', updateCurrentIndex)
|
window.addEventListener('scroll', updateCurrentIndex)
|
||||||
jumpToHashComment()
|
jumpToHashComment()
|
||||||
|
}
|
||||||
|
|
||||||
|
onActivated(async () => {
|
||||||
|
await initPage()
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await initPage()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -845,6 +917,10 @@ onMounted(async () => {
|
|||||||
width: calc(85% - 40px);
|
width: calc(85% - 40px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.info-content-text p code {
|
||||||
|
padding: 2px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
.post-page-scroller-container {
|
.post-page-scroller-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -868,6 +944,18 @@ onMounted(async () => {
|
|||||||
gap: 10px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-close-container {
|
||||||
|
padding: 40px;
|
||||||
|
margin-top: 15px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-color);
|
||||||
|
background-color: var(--background-color);
|
||||||
|
border: 1px dashed var(--normal-border-color);
|
||||||
|
border-radius: 10px;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
.scroller {
|
.scroller {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
@@ -982,6 +1070,7 @@ onMounted(async () => {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.article-closed-button,
|
||||||
.article-subscribe-button-text,
|
.article-subscribe-button-text,
|
||||||
.article-unsubscribe-button-text {
|
.article-unsubscribe-button-text {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@@ -1024,6 +1113,15 @@ onMounted(async () => {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.article-closed-button {
|
||||||
|
background-color: var(--background-color);
|
||||||
|
color: gray;
|
||||||
|
border: 1px solid gray;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
.article-title {
|
.article-title {
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
|||||||
@@ -38,10 +38,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="form-row switch-row">
|
<div class="form-row switch-row">
|
||||||
<div class="setting-title">毛玻璃效果</div>
|
<div class="setting-title">毛玻璃效果</div>
|
||||||
<label class="switch">
|
<BaseSwitch v-model="frosted" />
|
||||||
<input type="checkbox" v-model="frosted" />
|
|
||||||
<span class="slider"></span>
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="role === 'ADMIN'" class="admin-section">
|
<div v-if="role === 'ADMIN'" class="admin-section">
|
||||||
@@ -76,6 +73,7 @@ import { ref, onMounted, watch } from 'vue'
|
|||||||
import AvatarCropper from '~/components/AvatarCropper.vue'
|
import AvatarCropper from '~/components/AvatarCropper.vue'
|
||||||
import BaseInput from '~/components/BaseInput.vue'
|
import BaseInput from '~/components/BaseInput.vue'
|
||||||
import Dropdown from '~/components/Dropdown.vue'
|
import Dropdown from '~/components/Dropdown.vue'
|
||||||
|
import BaseSwitch from '~/components/BaseSwitch.vue'
|
||||||
import { toast } from '~/main'
|
import { toast } from '~/main'
|
||||||
import { fetchCurrentUser, getToken, setToken } from '~/utils/auth'
|
import { fetchCurrentUser, getToken, setToken } from '~/utils/auth'
|
||||||
import { frostedState, setFrosted } from '~/utils/frosted'
|
import { frostedState, setFrosted } from '~/utils/frosted'
|
||||||
@@ -318,51 +316,6 @@ const save = async () => {
|
|||||||
max-width: 200px;
|
max-width: 200px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.switch {
|
|
||||||
position: relative;
|
|
||||||
display: inline-block;
|
|
||||||
width: 40px;
|
|
||||||
height: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.switch input {
|
|
||||||
opacity: 0;
|
|
||||||
width: 0;
|
|
||||||
height: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider {
|
|
||||||
position: absolute;
|
|
||||||
cursor: pointer;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
background-color: #ccc;
|
|
||||||
transition: 0.2s;
|
|
||||||
border-radius: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.slider:before {
|
|
||||||
position: absolute;
|
|
||||||
content: '';
|
|
||||||
height: 16px;
|
|
||||||
width: 16px;
|
|
||||||
left: 2px;
|
|
||||||
bottom: 2px;
|
|
||||||
background-color: white;
|
|
||||||
transition: 0.2s;
|
|
||||||
border-radius: 50%;
|
|
||||||
}
|
|
||||||
|
|
||||||
input:checked + .slider {
|
|
||||||
background-color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
input:checked + .slider:before {
|
|
||||||
transform: translateX(20px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.profile-section {
|
.profile-section {
|
||||||
margin-bottom: 30px;
|
margin-bottom: 30px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
class="signup-page-button-primary"
|
class="signup-page-button-primary"
|
||||||
@click="sendVerification"
|
@click="sendVerification"
|
||||||
>
|
>
|
||||||
<div class="signup-page-button-text">验证邮箱</div>
|
<div class="signup-page-button-text">验证并注册</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="signup-page-button-primary disabled">
|
<div v-else class="signup-page-button-primary disabled">
|
||||||
<div class="signup-page-button-text">
|
<div class="signup-page-button-text">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js/lib/common'
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
const theme =
|
const theme =
|
||||||
document.documentElement.dataset.theme ||
|
document.documentElement.dataset.theme ||
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const iconMap = {
|
|||||||
LOTTERY_WIN: 'fas fa-trophy',
|
LOTTERY_WIN: 'fas fa-trophy',
|
||||||
LOTTERY_DRAW: 'fas fa-bullhorn',
|
LOTTERY_DRAW: 'fas fa-bullhorn',
|
||||||
MENTION: 'fas fa-at',
|
MENTION: 'fas fa-at',
|
||||||
|
POST_DELETED: 'fas fa-trash',
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchUnreadCount() {
|
export async function fetchUnreadCount() {
|
||||||
@@ -158,7 +159,7 @@ function createFetchNotifications() {
|
|||||||
...n,
|
...n,
|
||||||
src: n.comment.author.avatar,
|
src: n.comment.author.avatar,
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/users/${n.comment.author.id}`, { replace: true })
|
navigateTo(`/users/${n.comment.author.id}`, { replace: true })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -168,7 +169,7 @@ function createFetchNotifications() {
|
|||||||
emoji: reactionEmojiMap[n.reactionType],
|
emoji: reactionEmojiMap[n.reactionType],
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
if (n.fromUser) {
|
if (n.fromUser) {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -180,7 +181,19 @@ function createFetchNotifications() {
|
|||||||
icon: n.fromUser ? undefined : iconMap[n.type],
|
icon: n.fromUser ? undefined : iconMap[n.type],
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
if (n.fromUser) {
|
if (n.fromUser) {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
|
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else if (n.type === 'POST_DELETED') {
|
||||||
|
arr.push({
|
||||||
|
...n,
|
||||||
|
src: n.fromUser ? n.fromUser.avatar : null,
|
||||||
|
icon: n.fromUser ? undefined : iconMap[n.type],
|
||||||
|
iconClick: () => {
|
||||||
|
if (n.fromUser) {
|
||||||
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -191,7 +204,7 @@ function createFetchNotifications() {
|
|||||||
icon: iconMap[n.type],
|
icon: iconMap[n.type],
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
if (n.post) {
|
if (n.post) {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/posts/${n.post.id}`)
|
navigateTo(`/posts/${n.post.id}`)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -201,7 +214,7 @@ function createFetchNotifications() {
|
|||||||
...n,
|
...n,
|
||||||
src: n.comment.author.avatar,
|
src: n.comment.author.avatar,
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/users/${n.comment.author.id}`, { replace: true })
|
navigateTo(`/users/${n.comment.author.id}`, { replace: true })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -211,7 +224,7 @@ function createFetchNotifications() {
|
|||||||
icon: iconMap[n.type],
|
icon: iconMap[n.type],
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
if (n.fromUser) {
|
if (n.fromUser) {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -222,7 +235,7 @@ function createFetchNotifications() {
|
|||||||
icon: iconMap[n.type],
|
icon: iconMap[n.type],
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
if (n.fromUser) {
|
if (n.fromUser) {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
navigateTo(`/users/${n.fromUser.id}`, { replace: true })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -237,7 +250,7 @@ function createFetchNotifications() {
|
|||||||
icon: iconMap[n.type],
|
icon: iconMap[n.type],
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
if (n.post) {
|
if (n.post) {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/posts/${n.post.id}`, { replace: true })
|
navigateTo(`/posts/${n.post.id}`, { replace: true })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -249,7 +262,7 @@ function createFetchNotifications() {
|
|||||||
icon: n.fromUser ? undefined : iconMap[n.type],
|
icon: n.fromUser ? undefined : iconMap[n.type],
|
||||||
iconClick: () => {
|
iconClick: () => {
|
||||||
if (n.post) {
|
if (n.post) {
|
||||||
markRead(n.id)
|
markNotificationRead(n.id)
|
||||||
navigateTo(`/posts/${n.post.id}`, { replace: true })
|
navigateTo(`/posts/${n.post.id}`, { replace: true })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -277,7 +290,7 @@ function createFetchNotifications() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const markRead = async (id) => {
|
const markNotificationRead = async (id) => {
|
||||||
if (!id) return
|
if (!id) return
|
||||||
const n = notifications.value.find((n) => n.id === id)
|
const n = notifications.value.find((n) => n.id === id)
|
||||||
if (!n || n.read) return
|
if (!n || n.read) return
|
||||||
@@ -319,7 +332,7 @@ function createFetchNotifications() {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
fetchNotifications,
|
fetchNotifications,
|
||||||
markRead,
|
markNotificationRead,
|
||||||
notifications,
|
notifications,
|
||||||
isLoadingMessage,
|
isLoadingMessage,
|
||||||
markAllRead,
|
markAllRead,
|
||||||
@@ -329,7 +342,7 @@ function createFetchNotifications() {
|
|||||||
|
|
||||||
export const {
|
export const {
|
||||||
fetchNotifications,
|
fetchNotifications,
|
||||||
markRead,
|
markNotificationRead,
|
||||||
notifications,
|
notifications,
|
||||||
isLoadingMessage,
|
isLoadingMessage,
|
||||||
markAllRead,
|
markAllRead,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import Vditor from 'vditor'
|
|||||||
import { getToken, authState } from './auth'
|
import { getToken, authState } from './auth'
|
||||||
import { searchUsers, fetchFollowings, fetchAdmins } from './user'
|
import { searchUsers, fetchFollowings, fetchAdmins } from './user'
|
||||||
import { tiebaEmoji } from './tiebaEmoji'
|
import { tiebaEmoji } from './tiebaEmoji'
|
||||||
import '~/assets/global.css'
|
|
||||||
|
|
||||||
export function getEditorTheme() {
|
export function getEditorTheme() {
|
||||||
return document.documentElement.dataset.theme === 'dark' ? 'dark' : 'classic'
|
return document.documentElement.dataset.theme === 'dark' ? 'dark' : 'classic'
|
||||||
|
|||||||
Reference in New Issue
Block a user