提交 c08bf8e2 编写于 作者: yubinCloud's avatar yubinCloud

8-10 增加保存文档内容的功能

上级 bf287ac9
......@@ -2,12 +2,14 @@ package io.github.yubincloud.fairywiki.service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.github.yubincloud.fairywiki.domain.Content;
import io.github.yubincloud.fairywiki.domain.Doc;
import io.github.yubincloud.fairywiki.domain.DocExample;
import io.github.yubincloud.fairywiki.dto.req.DocQueryReqDto;
import io.github.yubincloud.fairywiki.dto.req.DocSaveReqDto;
import io.github.yubincloud.fairywiki.dto.resp.DocQueryRespDto;
import io.github.yubincloud.fairywiki.dto.resp.PageRespDto;
import io.github.yubincloud.fairywiki.mapper.ContentMapper;
import io.github.yubincloud.fairywiki.mapper.DocMapper;
import io.github.yubincloud.fairywiki.utils.CopyUtil;
import io.github.yubincloud.fairywiki.utils.SnowFlake;
......@@ -27,6 +29,9 @@ public class DocService {
@Resource
private DocMapper docMapper;
@Resource
private ContentMapper contentMapper;
@Resource
private SnowFlake snowFlake;
......@@ -69,11 +74,22 @@ public class DocService {
*/
public void save(DocSaveReqDto reqDto) {
Doc docRecord = CopyUtil.copy(reqDto, Doc.class);
Content docContent = CopyUtil.copy(reqDto, Content.class);
if (ObjectUtils.isEmpty(docRecord.getId())) { // 判断 id 是否为空
docRecord.setId(snowFlake.nextId());
// 新增
Long docId = snowFlake.nextId();
docRecord.setId(docId);
docMapper.insertSelective(docRecord);
docContent.setId(docId);
contentMapper.insertSelective(docContent);
} else {
// 更新
docMapper.updateByPrimaryKey(docRecord);
int count = contentMapper.updateByPrimaryKeyWithBLOBs(docContent); // 带大字段的更新
if (count == 0) {
contentMapper.insert(docContent);
}
}
}
......
......@@ -49,6 +49,7 @@ export interface Doc {
sort: number;
viewCount: number;
voteCount: number;
content: string;
}
/**
......
......@@ -187,12 +187,16 @@ export default defineComponent({
// -------- 表单 ---------
const treeSelectData = ref(); // 因为树选择组件的属性状态,会随当前编辑的节点而变化,所以单独声明一个响应式变量
treeSelectData.value = [];
const doc = ref({});
const doc = ref();
doc.value = {};
const modalVisible = ref(false);
const modalLoading = ref(false);
let textEditor: E;
const handleSaveDoc = () => {
modalLoading.value = true;
doc.value.content = textEditor.txt.html();
axios.post("/doc/save", doc.value).then((response) => {
const respData = response.data;
modalLoading.value = false;
......@@ -332,7 +336,7 @@ export default defineComponent({
onMounted(() => {
handleQuery();
const textEditor = new E('#content');
textEditor = new E('#content');
textEditor.config.zIndex = 0;
textEditor.create();
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册