Skip to content

Commit

Permalink
Perf: 项目优化 (#958)
Browse files Browse the repository at this point in the history
* feat: 首页项目拖拽排序功能

* feat: 增加首页项目拖拽排序增加只能管理员进行, 排序失败元素回到原本位置

* perf: 新建文章以后直接进入到编辑文章页面

* perf: 优化文档打开时或刷新时样式闪动问题

* perf: 优化表格样式

* feat: 支持上传视频功能

* feat: 视频样式调整

* feat: 直接粘贴视频上传功能

* perf: 优化markdown目录显示

* feat: 项目配置新增是否开启打印功能

* perf: 优化模型自动更新表字段

* perf: 创建项目时增加选择编辑器功能

* perf: 优化cherry-markdown 菜单栏
  • Loading branch information
Zzhenping committed Jul 8, 2024
1 parent 1ea9221 commit 532dcce
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 33 deletions.
5 changes: 5 additions & 0 deletions commands/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func RegisterModel() {
gob.Register(models.Document{})
gob.Register(models.Template{})
//migrate.RegisterMigration()
err := orm.RunSyncdb("default", false, true)
if err != nil {
logs.Error("注册Model失败 ->", err)
os.Exit(1)
}
}

// RegisterLogger 注册日志
Expand Down
1 change: 1 addition & 0 deletions conf/lang/en-us.ini
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ next = next
no = no
edit_title = Edit Blog
private_blog_tips = Private blog, please enter password to access
print_text = Enable Printing

[doc]
modify_doc = Modify Document
Expand Down
1 change: 1 addition & 0 deletions conf/lang/zh-cn.ini
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ next = 下一篇
no = 无
edit_title = 编辑文章
private_blog_tips = 加密文章,请输入密码访问
print_text = 开启打印

[doc]
modify_doc = 修改文档
Expand Down
12 changes: 10 additions & 2 deletions controllers/BookController.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (c *BookController) Setting() {
if book.PrivateToken != "" {
book.PrivateToken = conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)
}

c.Data["Model"] = book

}
Expand Down Expand Up @@ -153,6 +154,7 @@ func (c *BookController) SaveBook() {
isUseFirstDocument := strings.TrimSpace(c.GetString("is_use_first_document")) == "on"
autoSave := strings.TrimSpace(c.GetString("auto_save")) == "on"
itemId, _ := c.GetInt("itemId")
pringState := strings.TrimSpace(c.GetString("print_state")) == "on"

if strings.Count(description, "") > 500 {
c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_desc_tips"))
Expand Down Expand Up @@ -211,6 +213,11 @@ func (c *BookController) SaveBook() {
} else {
book.AutoSave = 0
}
if pringState {
book.PrintSate = 1
} else {
book.PrintSate = 0
}
if err := book.Update(); err != nil {
c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed"))
}
Expand Down Expand Up @@ -456,6 +463,7 @@ func (c *BookController) Create() {
description := strings.TrimSpace(c.GetString("description", ""))
privatelyOwned, _ := strconv.Atoi(c.GetString("privately_owned"))
commentStatus := c.GetString("comment_status")
editor := c.GetString("editor")
itemId, _ := c.GetInt("itemId")

if bookName == "" {
Expand Down Expand Up @@ -522,6 +530,7 @@ func (c *BookController) Create() {
book.CommentCount = 0
book.PrivatelyOwned = privatelyOwned
book.CommentStatus = commentStatus

book.Identify = identify
book.DocCount = 0
book.MemberId = c.Member.MemberId
Expand All @@ -531,8 +540,7 @@ func (c *BookController) Create() {
book.IsDownload = 1
book.AutoRelease = 0
book.ItemId = itemId

book.Editor = "markdown"
book.Editor = editor
book.Theme = "default"

if err := book.Insert(c.Lang); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion models/BookModel.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ type Book struct {
//是否使用第一篇文章项目为默认首页,0 否/1 是
IsUseFirstDocument int `orm:"column(is_use_first_document);type(int);default(0);description(是否使用第一篇文章项目为默认首页,0 否/1 是)" json:"is_use_first_document"`
//是否开启自动保存:0 否/1 是
AutoSave int `orm:"column(auto_save);type(tinyint);default(0);description(是否开启自动保存:0 否/1 是)" json:"auto_save"`
AutoSave int `orm:"column(auto_save);type(tinyint);default(0);description(是否开启自动保存:0 否/1 是)" json:"auto_save"`
PrintSate int `orm:"column(print_state);type(tinyint);default(1);description(启用打印:0 否/1 是)" json:"print_state"`
}

func (book *Book) String() string {
Expand Down
2 changes: 2 additions & 0 deletions models/BookResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type BookResult struct {
IsDisplayComment bool `json:"is_display_comment"`
IsDownload bool `json:"is_download"`
AutoSave bool `json:"auto_save"`
PrintState bool `json:"print_state"`
Lang string
}

Expand Down Expand Up @@ -213,6 +214,7 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
m.HistoryCount = book.HistoryCount
m.IsDownload = book.IsDownload == 0
m.AutoSave = book.AutoSave == 1
m.PrintState = book.PrintSate == 1
m.ItemId = book.ItemId
m.RoleId = conf.BookRoleNoSpecific

Expand Down
50 changes: 26 additions & 24 deletions static/cherry/cherry-markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,7 @@ div[data-type=codeBlock] .token.inserted {
}

.cherry[data-toolbar-theme=dark] .cherry-insert-table-menu-item.active {
background-color: #d7e6fe;
background-color: #4b4b4b;
}

.cherry-dropdown {
Expand Down Expand Up @@ -2692,25 +2692,26 @@ div[data-type=codeBlock] .token.inserted {
}

[data-toolbar-theme=dark] .cherry-dropdown {
background: #20304b;
background: #ffffff;
}

[data-toolbar-theme=dark] .cherry-dropdown .cherry-dropdown-item {
background: transparent;
color: #d7e6fe;
color: #4b4b4b;
}

[data-toolbar-theme=dark] .cherry-dropdown .cherry-dropdown-item:hover {
background: rgba(255, 255, 255, 0.1);
color: #fff;
background: #e4e4e4;
color: #0a001f;
transition: all .3s;
}

.cherry-toolbar {
position: relative;
display: flex;
justify-content: space-between;
padding: 0 20px;
height: 48px;
height: 34px;
font-size: 16px;
line-height: 2.3;
flex-basis: 100%;
Expand All @@ -2720,6 +2721,7 @@ div[data-type=codeBlock] .token.inserted {
box-shadow: 0 0 10px rgba(128, 145, 165, 0.2);
background: white;
overflow: hidden;
align-items: center;
}

.cherry-toolbar .icon-loading.loading {
Expand All @@ -2742,25 +2744,25 @@ div[data-type=codeBlock] .token.inserted {
}

[data-toolbar-theme=dark] .cherry-toolbar {
background: #20304b;
background: #ffffff;
box-shadow: 0 0 10px rgba(128, 145, 165, 0.2);
}

[data-toolbar-theme=dark] .cherry-toolbar .cherry-toolbar-button {
color: #d7e6fe;
color: #4b4b4b;
background: transparent;
}

[data-toolbar-theme=dark] .cherry-toolbar .cherry-toolbar-button:hover {
color: #fff;
background: rgba(255, 255, 255, 0.1);
color: #0a001f;
transition: all .3s;
background: #e4e4e4;
}

.cherry-toolbar .toolbar-left,
.cherry-toolbar .toolbar-right {
display: flex;
align-items: center;
height: 48px;
overflow: hidden;
}

Expand Down Expand Up @@ -2935,12 +2937,12 @@ div[data-type=codeBlock] .token.inserted {
}

[data-toolbar-theme=dark] .cherry-bubble {
border-color: #20304b;
background: #20304b;
border-color: #ffffff;
background: #ffffff;
}

[data-toolbar-theme=dark] .cherry-bubble .cherry-toolbar-button {
color: #d7e6fe;
color: #4b4b4b;
background: transparent;
}

Expand All @@ -2950,15 +2952,15 @@ div[data-type=codeBlock] .token.inserted {
}

[data-toolbar-theme=dark] .cherry-bubble .cherry-bubble-top {
border-bottom-color: #20304b;
border-bottom-color: #ffffff;
}

[data-toolbar-theme=dark] .cherry-bubble .cherry-bubble-bottom {
border-top-color: #20304b;
border-top-color: #ffffff;
}

[data-toolbar-theme=dark] .cherry-bubble .cherry-toolbar-button:hover {
border-color: #20304b;
border-color: #ffffff;
}

.cherry-switch-paste .switch-btn--bg {
Expand Down Expand Up @@ -3012,15 +3014,15 @@ div[data-type=codeBlock] .token.inserted {
}

[data-toolbar-theme=dark] .cherry-switch-paste[data-type=text] .cherry-text-btn {
color: #d7e6fe;
color: #4b4b4b;
}

[data-toolbar-theme=dark] .cherry-switch-paste[data-type=text] .cherry-md-btn {
color: #fff;
}

[data-toolbar-theme=dark] .cherry-switch-paste[data-type=md] .cherry-md-btn {
color: #d7e6fe;
color: #4b4b4b;
}

[data-toolbar-theme=dark] .cherry-switch-paste[data-type=md] .cherry-text-btn {
Expand Down Expand Up @@ -3192,7 +3194,7 @@ div[data-type=codeBlock] .token.inserted {
}

.cherry-editor .cm-s-default .cm-url {
background: #d7e6fe;
background: #4b4b4b;
font-family: "Menlo", "Liberation Mono", "Consolas", "DejaVu Sans Mono", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace;
font-size: 0.9em;
}
Expand Down Expand Up @@ -3347,7 +3349,7 @@ div[data-type=codeBlock] .token.inserted {
}

[data-toolbar-theme=dark] .cherry-color-wrap h3 {
color: #d7e6fe;
color: #4b4b4b;
}

.cherry-color-wrap .cherry-color-text {
Expand Down Expand Up @@ -3522,7 +3524,7 @@ div[data-type=codeBlock] .token.inserted {
.cherry.theme__dark .cherry-floatmenu .cherry-toolbar-button,
.cherry.theme__dark .cherry-bubble .cherry-toolbar-button,
.cherry.theme__dark .cherry-sidebar .cherry-toolbar-button {
color: #d7e6fe;
color: #4b4b4b;
}

.cherry.theme__dark .cherry-toolbar .cherry-toolbar-button:hover,
Expand All @@ -3547,7 +3549,7 @@ div[data-type=codeBlock] .token.inserted {
}

.cherry.theme__dark .cherry-dropdown .cherry-dropdown-item {
color: #d7e6fe;
color: #4b4b4b;
}

.cherry.theme__dark .cherry-dropdown .cherry-dropdown-item:hover {
Expand All @@ -3561,7 +3563,7 @@ div[data-type=codeBlock] .token.inserted {
}

.cherry.theme__dark .cherry-dropdown.cherry-color-wrap h3 {
color: #d7e6fe;
color: #4b4b4b;
}

.cherry.theme__dark .cherry-dropdown.cherry-color-wrap .cherry-color-item {
Expand Down
12 changes: 6 additions & 6 deletions static/cherry/cherry-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -22792,7 +22792,7 @@

var $lineNum = Math.max(0, lineNum);
this.jumpToLine($lineNum, endLine, percent);
Logger.log('滚动预览区域,左侧应scroll to ', $lineNum);
// Logger.log('滚动预览区域,左侧应scroll to ', $lineNum);
}
/**
*
Expand Down Expand Up @@ -42219,7 +42219,7 @@

{
// 生产环境屏蔽
Logger.log('markdown引擎渲染了:', str);
// Logger.log('markdown引擎渲染了:', str);
}
}

Expand Down Expand Up @@ -56924,7 +56924,7 @@

onScroll = function onScroll() {
if (_this2.applyingDomChanges) {
Logger.log(new Date(), 'sync scroll locked');
// Logger.log(new Date(), 'sync scroll locked');
return;
}

Expand Down Expand Up @@ -57253,13 +57253,13 @@
return obj[index].sign;
});
var res = myersDiff.doDiff();
Logger.log(res);
// Logger.log(res);
this.$dealWithMyersDiffResult(res, oldHtmlList.list, newHtmlList.list, domContainer);
} else if (newHtmlList.list.length && !oldHtmlList.list.length) {
var _context8;

// 全新增
Logger.log('add all');
// Logger.log('add all');

forEach$3(_context8 = newHtmlList.list).call(_context8, function (piece) {
domContainer.appendChild(piece.dom);
Expand All @@ -57268,7 +57268,7 @@
var _context9;

// 全删除
Logger.log('delete all');
// Logger.log('delete all');

forEach$3(_context9 = oldHtmlList.list).call(_context9, function (piece) {
domContainer.removeChild(piece.dom);
Expand Down
19 changes: 19 additions & 0 deletions views/book/index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,25 @@
</div>
<div class="clearfix"></div>
</div>
<!--选择编辑器模式-->
<div class="form-group">
<label>{{i18n $.Lang "blog.text_editor"}}</label>
<div class="col-lg-20">
<label class="radio-inline">
<input type="radio" name="editor" value="markdown"> Markdown
</label>
<label class="radio-inline">
<input type="radio" name="editor" checked value="cherry_markdown"> Markdown (cherry)
</label>
<label class="radio-inline">
<input type="radio" name="editor" value="new_html"> Html (Quill)
</label>
<label class="radio-inline">
<input type="radio" name="editor" value="html"> Html (wangEditor)
</label>
</div>
<div class="clearfix"></div>
</div>
</div>
<div class="pull-right text-center" style="width: 235px;">
<canvas id="bookCover" height="230px" width="170px"><img src="{{cdnimg "/static/images/book.jpg"}}"> </canvas>
Expand Down
9 changes: 9 additions & 0 deletions views/book/setting.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@
</div>
{{end}}

<div class="form-group">
<label for="autoRelease">{{i18n $.Lang "blog.print_text"}}</label>
<div class="controls">
<div class="switch switch-small" data-on="primary" data-off="info">
<input type="checkbox" id="autoSave" name="print_state"{{if .Model.PrintState }} checked{{end}} data-size="small" placeholder="{{i18n $.Lang "blog.print_text"}}">
</div>
</div>
</div>

<div class="form-group">
<label for="autoRelease">{{i18n $.Lang "blog.auto_publish"}}</label>
<div class="controls">
Expand Down
2 changes: 2 additions & 0 deletions views/document/default_read.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
</div>
{{end}}
{{end}}
{{if .Model.PrintState}}
<a href="javascript:window.print();" id="printSinglePage" class="btn btn-default" style="margin-right: 10px;"><i class="fa fa-print"></i> {{i18n .Lang "doc.print"}}</a>
{{end}}
<div class="dropdown pull-right" style="margin-right: 10px;">
{{if eq .Model.PrivatelyOwned 0}}
{{if .Model.IsEnableShare}}
Expand Down

0 comments on commit 532dcce

Please sign in to comment.