Compare commits

...

10 Commits

Author SHA1 Message Date
8c1c0f10be build: 修改外部配置文件 2025-03-23 12:46:13 +08:00
02ad0f93dc v5.1.0 发布 2025-03-23 12:35:08 +08:00
a06132a4c2 模版更新 2025-03-23 11:50:44 +08:00
f043ddff42 style: 代码格式化 2025-03-23 11:49:23 +08:00
328bd55587 feat: AI自动生成小说封面图片 2025-03-23 11:46:12 +08:00
04fc8e878a fix: 修复升级v5.0.0导致图片上传失败的问题
- 当使用 `$.ajax`发起异步请求时 ,设置`dataType: "json"`会在请求头中自动添加`Accept: application/json`,表示客户端期望服务器返回`JSON`格式的数据。
- 当使用 `$.ajaxFileUpload` 上传文件时,它的行为与`$.ajax`不同,不会自动修改`Accept`请求头,即使设置了`dataType: "json"` `$.ajaxFileUpload`也不会在请求头中添加`Accept: application/json`。

Spring Boot 默认返回`JSON`格式的响应,但它支持内容协商,它会根据客户端请求的`Accept`头来决定返回的响应格式。如果浏览器发送的请求中
`Accept`头包含`application/xml`,并且 Spring Boot 支持`XML`格式响应的话,Spring Boot 会返`XML`格式的响应。但 Spring Boot 默认不支持`XML`格式的响应,当升级`Sharding-JDBC `版本后,自动引入了`jackson-dataformat-xml`依赖,才开始支持`XML`格式的响应,由于`$.ajaxFileUpload`上传文件的默认`Accept`头包含`application/xml`,所以需要在后端上传文件接口处明确指定返回的数据类型为`application/json`。
2025-03-23 09:28:01 +08:00
970ad407f1 perf: AI内容生成失败提醒 2025-03-23 06:44:31 +08:00
f8079f443a Update README.md 2025-03-21 13:14:01 +08:00
75a4c3002b 合并 5.0.x 分支 2025-03-21 12:07:21 +08:00
99f2a15990 build: 创建 GitHub Actions 工作流自动发布版本 2025-03-20 12:21:45 +08:00
17 changed files with 326 additions and 186 deletions

View File

@ -17,7 +17,7 @@
novel-plus 是一个多端PCWAP阅读功能完善的原创文学 CMS
系统由前台门户系统作家后台管理系统平台后台管理系统和爬虫管理系统等多个子系统构成包括小说推荐作品检索小说排行小说阅读小说评论会员中心作家专区等功能支持自定义多模版可拓展的多种小说内容存储方式内置数据库分表存储和
TXT 文本存储阅读主题切换多爬虫源自动采集和更新数据会员充值订阅模式新闻发布和实时统计报表
TXT 文本存储阅读主题切换多爬虫源自动采集和更新数据AI写作会员充值订阅模式新闻发布和实时统计报表
## 项目地址
@ -39,25 +39,25 @@ novel-plus -- 父工程
## 技术选型
| 技术 | 说明
|---------------------| ---------------------------
| Spring Boot | Spring 应用快速开发脚手架
| Spring AI | Spring 官方 AI 框架
| MyBatis | 持久层 ORM 框架
| MyBatis Dynamic SQL | Mybatis 动态 sql
| PageHelper | MyBatis 分页插件
| MyBatis Generator | 持久层代码生成插件
| Sharding-JDBC | 代码层分库分表中间件
| JJWT | JWT 登录支持
| Spring Security | 安全框架
| Apache Shiro | 安全框架
| Redis | 缓存方案
| Aliyun OSS | 阿里云对象存储服务图片存储备选方案
| Lombok | 简化对象封装工具
| Docker | 应用容器引擎
| MySQL | 数据库服务
| Thymeleaf | 模板引擎
| Layui | 前端 UI 框架
| 技术 | 说明
|---------------------|---------------------
| Spring Boot | Spring 应用快速开发脚手架
| Spring AI | Spring 官方 AI 框架
| MyBatis | 持久层 ORM 框架
| MyBatis Dynamic SQL | Mybatis 动态 sql
| PageHelper | MyBatis 分页插件
| MyBatis Generator | 持久层代码生成插件
| Sharding-JDBC | 代码层分库分表中间件
| JJWT | JWT 登录支持
| Spring Security | 安全框架
| Apache Shiro | 安全框架
| Redis | 缓存方案
| Aliyun OSS | 阿里云对象存储服务图片存储备选方案
| Lombok | 简化对象封装工具
| Docker | 应用容器引擎
| MySQL | 数据库服务
| Thymeleaf | 模板引擎
| Layui | 前端 UI 框架
## 项目截图
@ -71,6 +71,42 @@ novel-plus -- 父工程
https://www.bilibili.com/video/BV18e41197xs
## AI 功能
novel-plus 5.x 已集成 Spring 官方最新发布的 Spring AI 框架并推出多项 AI 功能
1. v5.0.0 版本在小说章节发布页面的文本编辑器中集成了多项智能编辑功能包括 AI 扩写缩写续写及文本润色等这些功能的设计灵感来源于百家号文章编辑器中的 AI 助手
2. v5.1.0 版本在小说发布页面新增 AI 生成封面图功能若作家未上传自定义封面图系统将根据小说信息自动生成封面图
目前AI 功能仍处于实验阶段仅实现了基础的核心功能我们非常重视用户的实际使用体验和反馈未来将根据用户需求和使用情况持续优化和调整该功能如果用户反馈积极我们计划进一步开发更高级的
AI 功能例如自动生成有声小说智能情节推荐等以全面提升 novel-plus 的创作能力和用户体验
我们将持续关注 AI 技术的发展并致力于将其与小说创作场景深度融合为用户带来更智能更便捷的创作工具
由于 DeepSeek 官方 API 目前不可用novel-plus 项目默认使用的是第三方[硅基流动](https://cloud.siliconflow.cn/i/DOgMRH9S)
提供的 API采用的 AI 模型有对话模型`deepseek-ai/DeepSeek-R1-Distill-Llama-8B`DeepSeek-R1 的蒸馏版本免费使用和生图模型`Kwai-Kolors/Kolors`快手 Kolors 团队开发的文本到图像生成模型免费使用只需注册一个硅基流动账号创建一个
API 密钥并将其添加到 novel-plus 项目 novel-front 模块的 yaml 配置文件中即可体验 novel-plus 项目的 AI 写作功能
```yaml
spring:
ai:
openai:
image:
enabled: true
base-url: https://api.siliconflow.cn
api-key: sk-rrrupturhdofbiqzjutduuiceecpvfqlnvmgcyiaipbdikoi
options:
model: Kwai-Kolors/Kolors
response_format: URL
api-key: sk-rrrupturhdofbiqzjutduuiceecpvfqlnvmgcyiaipbdikoi
base-url: https://api.siliconflow.cn
chat:
options:
model: deepseek-ai/DeepSeek-R1-Distill-Llama-8B
```
> novel-plus 项目默认使用的都是免费 AI 模型生成效果有限如果对生成内容有更高的要求建议选用付费的 AI 模型
## 增值服务
👉 [了解详情](https://novel.xxyopen.com/service.htm)
@ -95,3 +131,5 @@ https://www.bilibili.com/video/BV18e41197xs
## 免责声明
本项目提供的爬虫工具仅用于采集项目初期的测试数据请勿用于商业盈利 用户使用本系统从事任何违法违规的事情一切后果由用户自行承担作者不承担任何责任

View File

@ -5,7 +5,7 @@
<groupId>com.java2nb</groupId>
<artifactId>novel-admin</artifactId>
<version>5.0.1</version>
<version>5.1.0</version>
<packaging>jar</packaging>
<name>novel-admin</name>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>5.0.1</version>
<version>5.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -18,6 +18,11 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Date;
import java.util.Objects;
@ -125,5 +130,23 @@ public class FileUtil {
}
/**
* 下载文件
*
* @param downloadUrl 下载的URL
* @param savePath 保存的路径
*/
@SneakyThrows
public void downloadFile(String downloadUrl, String savePath) {
Path path = Paths.get(savePath);
Path parentPath = path.getParent();
if (Files.notExists(parentPath)) {
Files.createDirectories(parentPath);
}
URL url = new URL(downloadUrl);
try (InputStream in = url.openStream()) {
Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING);
}
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>5.0.1</version>
<version>5.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>novel</artifactId>
<groupId>com.java2nb</groupId>
<version>5.0.1</version>
<version>5.1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -54,7 +54,14 @@ http:
spring:
ai:
openai:
api-key: sk-nnhjmxuljagcuubbovjztbhkiawqaabzziazeurppinxtgva
image:
enabled: true
base-url: https://api.siliconflow.cn
api-key: sk-rrrupturhdofbiqzjutduuiceecpvfqlnvmgcyiaipbdikoi
options:
model: Kwai-Kolors/Kolors
response_format: URL
api-key: sk-rrrupturhdofbiqzjutduuiceecpvfqlnvmgcyiaipbdikoi
base-url: https://api.siliconflow.cn
chat:
options:

View File

@ -17,6 +17,7 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -61,11 +62,20 @@ public class FileController {
/**
* 图片上传
*
* @return
* - 当使用 `$.ajax`发起异步请求时 ,设置`dataType: "json"`会在请求头中自动添加`Accept: application/json`,表示客户端期望服务器返回
* `JSON`格式的数据。
* - 当使用 `$.ajaxFileUpload` 上传文件时,它的行为与`$.ajax`不同,不会自动修改`Accept`请求头,即使设置了`dataType: "json"`
* `$.ajaxFileUpload`也不会在请求头中添加`Accept: application/json`。
*
* Spring Boot 默认返回`JSON`格式的响应,但它支持内容协商,它会根据客户端请求的`Accept`头来决定返回的响应格式。
* 如果浏览器发送的请求中`Accept`头包含`application/xml`,并且 Spring Boot 支持`XML`格式响应的话Spring Boot 会返回`XML`格式的响应。
* 但 Spring Boot 默认不支持`XML`格式的响应,当升级`Sharding-JDBC `版本后,自动引入了`jackson-dataformat-xml`依赖,才开始支持`XML`格式的响应,
* 由于`$.ajaxFileUpload`上传文件的默认`Accept`头包含`application/xml`,所以需要在后端上传文件接口处明确指定返回的数据类型为`application/json`。
*
*/
@SneakyThrows
@ResponseBody
@PostMapping("/picUpload")
@PostMapping(value = "/picUpload", produces = MediaType.APPLICATION_JSON_VALUE)
RestResult<String> upload(@RequestParam("file") MultipartFile file) {
Date currentDate = new Date();
String savePath =

View File

@ -7,6 +7,7 @@ import com.java2nb.novel.core.cache.CacheService;
import com.java2nb.novel.core.config.BookPriceProperties;
import com.java2nb.novel.core.enums.ResponseStatus;
import com.java2nb.novel.core.utils.Constants;
import com.java2nb.novel.core.utils.FileUtil;
import com.java2nb.novel.core.utils.StringUtil;
import com.java2nb.novel.entity.Book;
import com.java2nb.novel.entity.*;
@ -27,10 +28,16 @@ import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.DateUtils;
import org.mybatis.dynamic.sql.SortSpecification;
import org.mybatis.dynamic.sql.render.RenderingStrategies;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.springframework.ai.image.Image;
import org.springframework.ai.image.ImagePrompt;
import org.springframework.ai.image.ImageResponse;
import org.springframework.ai.openai.OpenAiImageModel;
import org.springframework.ai.openai.OpenAiImageOptions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -39,13 +46,16 @@ import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
import static com.java2nb.novel.mapper.BookCategoryDynamicSqlSupport.bookCategory;
import static com.java2nb.novel.mapper.BookCategoryDynamicSqlSupport.sort;
import static com.java2nb.novel.mapper.BookCommentDynamicSqlSupport.bookComment;
import static com.java2nb.novel.mapper.BookContentDynamicSqlSupport.bookContent;
import static com.java2nb.novel.mapper.BookContentDynamicSqlSupport.content;
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.*;
import static com.java2nb.novel.mapper.BookDynamicSqlSupport.book;
import static com.java2nb.novel.mapper.BookIndexDynamicSqlSupport.bookIndex;
import static com.java2nb.novel.mapper.BookSettingDynamicSqlSupport.bookSetting;
import static org.mybatis.dynamic.sql.SqlBuilder.*;
@ -87,6 +97,10 @@ public class BookServiceImpl implements BookService {
private final BookPriceProperties bookPriceConfig;
private final OpenAiImageModel openAiImageModel;
private final ThreadPoolExecutor threadPoolExecutor;
private final IdWorker idWorker = IdWorker.INSTANCE;
@ -235,7 +249,7 @@ public class BookServiceImpl implements BookService {
BookIndexDynamicSqlSupport.isVip)
.from(bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId));
if("index_num desc".equals(orderBy)){
if ("index_num desc".equals(orderBy)) {
where.orderBy(BookIndexDynamicSqlSupport.indexNum.descending());
}
return bookIndexMapper.selectMany(where
@ -502,6 +516,7 @@ public class BookServiceImpl implements BookService {
@Override
public void addBook(Book book, Long authorId, String penName) {
book.setId(IdWorker.INSTANCE.nextId());
//判断小说名是否存在
if (queryIdByNameAndAuthor(book.getBookName(), penName) != null) {
//该作者发布过此书名的小说
@ -516,7 +531,36 @@ public class BookServiceImpl implements BookService {
book.setCreateTime(new Date());
book.setUpdateTime(book.getCreateTime());
bookMapper.insertSelective(book);
if (Objects.isNull(book.getPicUrl()) || !book.getPicUrl().startsWith(Constants.LOCAL_PIC_PREFIX)) {
// 用户没有上传封面图片AI自动生成封面图片
threadPoolExecutor.execute(() -> {
String prompt = String.format("生成一本小说的封面图片,图片中间显示书名《%s》书名下方显示作者“%s 著”。",
book.getBookName(), book.getAuthorName());
log.debug("prompt:{}", prompt);
ImageResponse response = openAiImageModel.call(
new ImagePrompt(prompt,
OpenAiImageOptions.builder()
.quality("hd")
.height(800)
.width(600).build())
);
Image output = response.getResult().getOutput();
Date currentDate = new Date();
String picUrl = Constants.LOCAL_PIC_PREFIX +
"aiGen/" + DateUtils.formatDate(currentDate, "yyyy") + "/" +
DateUtils.formatDate(currentDate, "MM") + "/" +
DateUtils.formatDate(currentDate, "dd") + "/" + book.getId() + ".png";
FileUtil.downloadFile(output.getUrl(), picSavePath + picUrl);
bookMapper.update(update(BookDynamicSqlSupport.book)
.set(BookDynamicSqlSupport.picUrl)
.equalTo(picUrl)
.set(updateTime)
.equalTo(currentDate)
.where(id, isEqualTo(book.getId()))
.build()
.render(RenderingStrategies.MYBATIS3));
});
}
}
@Override

View File

@ -48,13 +48,17 @@ book:
spring:
ai:
openai:
api-key: sk-nnhjmxuljagcuubbovjztbhkiawqaabzziazeurppinxtgva
image:
enabled: true
base-url: https://api.siliconflow.cn
api-key: sk-jjtixmivxaccndqgkqfkbgkzvmbctdxogcrfbjzfttbouitt
options:
model: Kwai-Kolors/Kolors
response_format: URL
api-key: sk-jjtixmivxaccndqgkqfkbgkzvmbctdxogcrfbjzfttbouitt
base-url: https://api.siliconflow.cn
chat:
options:
model: deepseek-ai/DeepSeek-R1-Distill-Llama-8B

View File

@ -347,8 +347,12 @@
success: function(res){
layer.close(loading);
// 将生成的内容追加到文本末尾
const newText = "\n\n" + res.data; // 添加换行符分隔
typeWriter(textarea, newText); // 使用打字机效果
if(res.code == '200'){
const newText = "\n\nAI生成内容" + res.data; // 添加换行符分隔
typeWriter(textarea, newText); // 使用打字机效果
}else{
layer.msg('AI内容生成失败请稍后重试');
}
},
error: function(){
layer.msg('请求失败,请稍后重试');

View File

@ -51,7 +51,8 @@
</div>
<div class="my_r">
<div id="noContentDiv">
<div class="tc" style="margin-top: 200px"><a href="/author/book_add.html" class="btn_red">创建作品</a></div>
<div class="tc" style="margin-top: 200px"><a href="/author/book_add.html" class="btn_red">创建作品</a>
</div>
</div>
<div class="my_bookshelf" id="hasContentDiv" style="display: none">
@ -142,10 +143,13 @@
<script src="/javascript/common.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
var searchCount = 0;
var timeout;
search(1, 5);
function search(curr, limit) {
searchCount++;
clearTimeout(timeout);
$.ajax({
type: "get",
url: "/author/listBookByPage",
@ -155,6 +159,7 @@
if (data.code == 200) {
var bookList = data.data.list;
if (bookList.length > 0) {
var aiPicGenerating = bookList[0].picUrl == '/images/default.gif'
$("#hasContentDiv").css("display", "block");
$("#noContentDiv").css("display", "none");
var bookListHtml = "";
@ -226,6 +231,12 @@
});
});
if (curr === 1 && aiPicGenerating && searchCount < 10) {
timeout = setTimeout(function () {
search(curr, limit);
}, 3000);
}
}

View File

@ -22,25 +22,19 @@
body {
-webkit-user-select: none; /* Chrome, Safari, Opera */
-webkit-user-select: none; /* Chrome, Safari, Opera */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera, and Firefox */
}
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera, and Firefox */
}
.line-limit-length {
@ -84,16 +78,16 @@
height: 180px;
}
#tipLayer {
display: none;
position: absolute;
background-color: rgba(255, 0, 0, 0.8);
color: white;
padding: 5px 10px;
border-radius: 3px;
cursor: pointer;
z-index: 1000;
}
#tipLayer {
display: none;
position: absolute;
background-color: rgba(255, 0, 0, 0.8);
color: white;
padding: 5px 10px;
border-radius: 3px;
cursor: pointer;
z-index: 1000;
}
</style>
</head>
@ -173,7 +167,7 @@
book.bookDesc = book.bookDesc.replace(/<[^>]+>/g, "").replace(/\s+/g, "").replace(/&nbsp;/g, "");
}
bookListHtml += ("<div id='"+book.bookId+"' onclick='read(\""+book.bookId+"\",\""+book.preContentId+"\")' class=\"item layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
bookListHtml += ("<div id='" + book.bookId + "' onclick='read(\"" + book.bookId + "\",\"" + book.preContentId + "\")' class=\"item layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
" <div class=\"layui-col-xs6 layui-col-sm3 layui-col-md2 layui-col-lg2\" style=\"text-align: center\">\n" +
" <img style='width: 130px;height: 180px' align=\"center\"\n" +
" src=\"" + book.picUrl + "\"/>\n" +
@ -197,40 +191,38 @@
$("#bookList").html(bookListHtml);
$(".item").on('touchstart', function(e) {
var element = $(this);
// 清除可能存在的定时器
clearTimeout(timeout);
isLongPress = false;
$(".item").on('touchstart', function (e) {
var element = $(this);
// 清除可能存在的定时器
clearTimeout(timeout);
isLongPress = false;
// 获取触摸点位置
var touch = e.originalEvent.touches[0];
// 设置一个定时器在500ms后触发可以根据需要调整时间
timeout = setTimeout(function() {
e.preventDefault();
showTip(touch, element);
}, 1000);
}).on('touchend', function(e) {
if (!isLongPress) {
// 如果没有发生长按,则执行点击事件的逻辑
clearTimeout(timeout);
}
}).on('touchmove', function() {
clearTimeout(timeout);
hideTip();
}).on('contextmenu', function(e) {
e.preventDefault();
});
$('#tipLayer').click(function() {
// 点击tips层时删除对应的.item元素
removeFromBookShelf($(this).data('target').attr("id"));
$(this).data('target').remove();
hideTip();
});
// 获取触摸点位置
var touch = e.originalEvent.touches[0];
// 设置一个定时器在500ms后触发可以根据需要调整时间
timeout = setTimeout(function () {
e.preventDefault();
showTip(touch, element);
}, 1000);
}).on('touchend', function (e) {
if (!isLongPress) {
// 如果没有发生长按,则执行点击事件的逻辑
clearTimeout(timeout);
}
}).on('touchmove', function () {
clearTimeout(timeout);
hideTip();
}).on('contextmenu', function (e) {
e.preventDefault();
});
$('#tipLayer').click(function () {
// 点击tips层时删除对应的.item元素
removeFromBookShelf($(this).data('target').attr("id"));
$(this).data('target').remove();
hideTip();
});
layui.use('laypage', function () {
@ -272,7 +264,7 @@ $(".item").on('touchstart', function(e) {
}
function showTip(touchEvent, element) {
isLongPress = true;
isLongPress = true;
// 根据触摸点位置设置弹出层的位置
$('#tipLayer')
.css({
@ -284,7 +276,7 @@ $(".item").on('touchstart', function(e) {
}
function hideTip() {
isLongPress = false;
isLongPress = false;
$('#tipLayer').hide().removeData('target'); // 隐藏tips并清除数据
}
@ -333,11 +325,11 @@ $(".item").on('touchstart', function(e) {
searchByAllCondition(1, 20, keywords);
}
function read(bookId,contentId){
if(isLongPress){
return false;
}
location.href = '/book/'+bookId+"/"+contentId+".html"
function read(bookId, contentId) {
if (isLongPress) {
return false;
}
location.href = '/book/' + bookId + "/" + contentId + ".html"
hideTip();
}
@ -347,19 +339,19 @@ $(".item").on('touchstart', function(e) {
function removeFromBookShelf(bookId) {
$.ajax({
type: "delete",
url: "/user/removeFromBookShelf/" + bookId,
data: {},
dataType: "json",
success: function (data) {
if (data.code == 200) {
$("#shelf" + bookId).remove();
}
}
});
$.ajax({
type: "delete",
url: "/user/removeFromBookShelf/" + bookId,
data: {},
dataType: "json",
success: function (data) {
if (data.code == 200) {
$("#shelf" + bookId).remove();
}
}
});
}
}
</script>

View File

@ -5,7 +5,7 @@
<groupId>com.java2nb</groupId>
<artifactId>novel</artifactId>
<version>5.0.1</version>
<version>5.1.0</version>
<modules>
<module>novel-common</module>
<module>novel-front</module>

View File

@ -347,8 +347,12 @@
success: function(res){
layer.close(loading);
// 将生成的内容追加到文本末尾
const newText = "\n\n" + res.data; // 添加换行符分隔
typeWriter(textarea, newText); // 使用打字机效果
if(res.code == '200'){
const newText = "\n\nAI生成内容" + res.data; // 添加换行符分隔
typeWriter(textarea, newText); // 使用打字机效果
}else{
layer.msg('AI内容生成失败请稍后重试');
}
},
error: function(){
layer.msg('请求失败,请稍后重试');

View File

@ -51,7 +51,8 @@
</div>
<div class="my_r">
<div id="noContentDiv">
<div class="tc" style="margin-top: 200px"><a href="/author/book_add.html" class="btn_red">创建作品</a></div>
<div class="tc" style="margin-top: 200px"><a href="/author/book_add.html" class="btn_red">创建作品</a>
</div>
</div>
<div class="my_bookshelf" id="hasContentDiv" style="display: none">
@ -142,10 +143,13 @@
<script src="/javascript/common.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
var searchCount = 0;
var timeout;
search(1, 5);
function search(curr, limit) {
searchCount++;
clearTimeout(timeout);
$.ajax({
type: "get",
url: "/author/listBookByPage",
@ -155,6 +159,7 @@
if (data.code == 200) {
var bookList = data.data.list;
if (bookList.length > 0) {
var aiPicGenerating = bookList[0].picUrl == '/images/default.gif'
$("#hasContentDiv").css("display", "block");
$("#noContentDiv").css("display", "none");
var bookListHtml = "";
@ -226,6 +231,12 @@
});
});
if (curr === 1 && aiPicGenerating && searchCount < 10) {
timeout = setTimeout(function () {
search(curr, limit);
}, 3000);
}
}

View File

@ -22,25 +22,19 @@
body {
-webkit-user-select: none; /* Chrome, Safari, Opera */
-webkit-user-select: none; /* Chrome, Safari, Opera */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera, and Firefox */
}
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera, and Firefox */
}
.line-limit-length {
@ -84,16 +78,16 @@
height: 180px;
}
#tipLayer {
display: none;
position: absolute;
background-color: rgba(255, 0, 0, 0.8);
color: white;
padding: 5px 10px;
border-radius: 3px;
cursor: pointer;
z-index: 1000;
}
#tipLayer {
display: none;
position: absolute;
background-color: rgba(255, 0, 0, 0.8);
color: white;
padding: 5px 10px;
border-radius: 3px;
cursor: pointer;
z-index: 1000;
}
</style>
</head>
@ -173,7 +167,7 @@
book.bookDesc = book.bookDesc.replace(/<[^>]+>/g, "").replace(/\s+/g, "").replace(/&nbsp;/g, "");
}
bookListHtml += ("<div id='"+book.bookId+"' onclick='read(\""+book.bookId+"\",\""+book.preContentId+"\")' class=\"item layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
bookListHtml += ("<div id='" + book.bookId + "' onclick='read(\"" + book.bookId + "\",\"" + book.preContentId + "\")' class=\"item layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
" <div class=\"layui-col-xs6 layui-col-sm3 layui-col-md2 layui-col-lg2\" style=\"text-align: center\">\n" +
" <img style='width: 130px;height: 180px' align=\"center\"\n" +
" src=\"" + book.picUrl + "\"/>\n" +
@ -197,40 +191,38 @@
$("#bookList").html(bookListHtml);
$(".item").on('touchstart', function(e) {
var element = $(this);
// 清除可能存在的定时器
clearTimeout(timeout);
isLongPress = false;
$(".item").on('touchstart', function (e) {
var element = $(this);
// 清除可能存在的定时器
clearTimeout(timeout);
isLongPress = false;
// 获取触摸点位置
var touch = e.originalEvent.touches[0];
// 设置一个定时器在500ms后触发可以根据需要调整时间
timeout = setTimeout(function() {
e.preventDefault();
showTip(touch, element);
}, 1000);
}).on('touchend', function(e) {
if (!isLongPress) {
// 如果没有发生长按,则执行点击事件的逻辑
clearTimeout(timeout);
}
}).on('touchmove', function() {
clearTimeout(timeout);
hideTip();
}).on('contextmenu', function(e) {
e.preventDefault();
});
$('#tipLayer').click(function() {
// 点击tips层时删除对应的.item元素
removeFromBookShelf($(this).data('target').attr("id"));
$(this).data('target').remove();
hideTip();
});
// 获取触摸点位置
var touch = e.originalEvent.touches[0];
// 设置一个定时器在500ms后触发可以根据需要调整时间
timeout = setTimeout(function () {
e.preventDefault();
showTip(touch, element);
}, 1000);
}).on('touchend', function (e) {
if (!isLongPress) {
// 如果没有发生长按,则执行点击事件的逻辑
clearTimeout(timeout);
}
}).on('touchmove', function () {
clearTimeout(timeout);
hideTip();
}).on('contextmenu', function (e) {
e.preventDefault();
});
$('#tipLayer').click(function () {
// 点击tips层时删除对应的.item元素
removeFromBookShelf($(this).data('target').attr("id"));
$(this).data('target').remove();
hideTip();
});
layui.use('laypage', function () {
@ -272,7 +264,7 @@ $(".item").on('touchstart', function(e) {
}
function showTip(touchEvent, element) {
isLongPress = true;
isLongPress = true;
// 根据触摸点位置设置弹出层的位置
$('#tipLayer')
.css({
@ -284,7 +276,7 @@ $(".item").on('touchstart', function(e) {
}
function hideTip() {
isLongPress = false;
isLongPress = false;
$('#tipLayer').hide().removeData('target'); // 隐藏tips并清除数据
}
@ -333,11 +325,11 @@ $(".item").on('touchstart', function(e) {
searchByAllCondition(1, 20, keywords);
}
function read(bookId,contentId){
if(isLongPress){
return false;
}
location.href = '/book/'+bookId+"/"+contentId+".html"
function read(bookId, contentId) {
if (isLongPress) {
return false;
}
location.href = '/book/' + bookId + "/" + contentId + ".html"
hideTip();
}
@ -347,19 +339,19 @@ $(".item").on('touchstart', function(e) {
function removeFromBookShelf(bookId) {
$.ajax({
type: "delete",
url: "/user/removeFromBookShelf/" + bookId,
data: {},
dataType: "json",
success: function (data) {
if (data.code == 200) {
$("#shelf" + bookId).remove();
}
}
});
$.ajax({
type: "delete",
url: "/user/removeFromBookShelf/" + bookId,
data: {},
dataType: "json",
success: function (data) {
if (data.code == 200) {
$("#shelf" + bookId).remove();
}
}
});
}
}
</script>