From 9fd28264dd9ec95d9fe0fa42460a27c0538ee355 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Sun, 22 Dec 2024 10:38:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=AB=A0=E8=8A=82?= =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lanyuanxiaoyao/bookstore/Controller.kt | 18 +++++++++++++++++ src/main/resources/static/index.html | 20 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Controller.kt b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Controller.kt index 6d71efe..1ab6587 100644 --- a/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Controller.kt +++ b/src/main/kotlin/com/lanyuanxiaoyao/bookstore/Controller.kt @@ -5,6 +5,7 @@ import jakarta.annotation.Resource import jakarta.transaction.Transactional import org.slf4j.LoggerFactory import org.springframework.data.domain.PageRequest +import org.springframework.data.domain.Sort import org.springframework.web.bind.annotation.* data class PageResponse( @@ -12,6 +13,12 @@ data class PageResponse( val total: Long, ) +data class SingleResponse( + val data: Map, +) { + constructor(e: E): this(mapOf("item" to e)) +} + @RestController @RequestMapping("book") class BookController { @@ -154,6 +161,17 @@ class ChapterController { return chapterRepository.findById(chapterId).orElseThrow().let { ViewItem(it) } } + @GetMapping("show/{chapterId}") + fun show(@PathVariable("chapterId") chapterId: String): SingleResponse { + return SingleResponse( + lineRepository + .findAll({ root, _, builder -> + builder.equal(root.get("chapter").get("chapterId"), chapterId) + }, Sort.by(Sort.Direction.DESC, "sequence")) + .joinToString("\n") { "

${it.text}

" } + ) + } + @Transactional @GetMapping("remove/{chapterId}") fun remove(@PathVariable("chapterId") chapterId: String) { diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index 0de89c7..5e780e4 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -150,6 +150,26 @@ label: '编辑', ...chapterDetailDialog(), }, + { + type: 'action', + label: '阅读', + actionType: 'dialog', + dialog: { + title: '阅读', + size: 'lg', + actions: [], + body: { + type: 'service', + className: 'p-10', + api: '${base}/chapter/show/${chapterId}', + silentPolling: true, + body: { + type: 'tpl', + tpl: '${item|raw}' + } + } + } + }, { type: 'action', label: '导入',