issues: 功能优化和体验优化 (#972)

* pref: 优化小屏幕下 cherry-markdown.css 样式

* fix: 修复 markdown 上传图片功能没有回显链接问题

* fix: #853 修复文章被删除后可以从缓存读取

* feat: #834 增加文章私有状态, 文章分类下不展示私有文章
pull/882/merge
zhanzhenping 2024-07-24 09:20:06 +08:00 committed by GitHub
parent cd9667bba7
commit acf3c46e82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 36 deletions

View File

@ -128,7 +128,7 @@ func (c *BlogController) ManageList() {
pageIndex, _ := c.GetInt("page", 1) pageIndex, _ := c.GetInt("page", 1)
blogList, totalCount, err := models.NewBlog().FindToPager(pageIndex, conf.PageSize, c.Member.MemberId, "") blogList, totalCount, err := models.NewBlog().FindToPager(pageIndex, conf.PageSize, c.Member.MemberId, "all")
if err != nil { if err != nil {
c.ShowErrorPage(500, err.Error()) c.ShowErrorPage(500, err.Error())
@ -168,7 +168,7 @@ func (c *BlogController) ManageSetting() {
if strings.Count(blogExcerpt, "") > 500 { if strings.Count(blogExcerpt, "") > 500 {
c.JsonResult(6008, i18n.Tr(c.Lang, "message.blog_digest_tips")) c.JsonResult(6008, i18n.Tr(c.Lang, "message.blog_digest_tips"))
} }
if blogStatus != "public" && blogStatus != "password" && blogStatus != "draft" { if blogStatus != "private" && blogStatus != "public" && blogStatus != "password" && blogStatus != "draft" {
blogStatus = "public" blogStatus = "public"
} }
if blogStatus == "password" && blogPassword == "" { if blogStatus == "password" && blogPassword == "" {

View File

@ -15,7 +15,7 @@ import (
"github.com/mindoc-org/mindoc/utils" "github.com/mindoc-org/mindoc/utils"
) )
//博文表 // 博文表
type Blog struct { type Blog struct {
BlogId int `orm:"pk;auto;unique;column(blog_id)" json:"blog_id"` BlogId int `orm:"pk;auto;unique;column(blog_id)" json:"blog_id"`
//文章标题 //文章标题
@ -89,7 +89,7 @@ func NewBlog() *Blog {
} }
} }
//根据文章ID查询文章 // 根据文章ID查询文章
func (b *Blog) Find(blogId int) (*Blog, error) { func (b *Blog) Find(blogId int) (*Blog, error) {
o := orm.NewOrm() o := orm.NewOrm()
@ -102,7 +102,7 @@ func (b *Blog) Find(blogId int) (*Blog, error) {
return b.Link() return b.Link()
} }
//从缓存中读取文章 // 从缓存中读取文章
func (b *Blog) FindFromCache(blogId int) (blog *Blog, err error) { func (b *Blog) FindFromCache(blogId int) (blog *Blog, err error) {
key := fmt.Sprintf("blog-id-%d", blogId) key := fmt.Sprintf("blog-id-%d", blogId)
var temp Blog var temp Blog
@ -126,7 +126,7 @@ func (b *Blog) FindFromCache(blogId int) (blog *Blog, err error) {
return return
} }
//查找指定用户的指定文章 // 查找指定用户的指定文章
func (b *Blog) FindByIdAndMemberId(blogId, memberId int) (*Blog, error) { func (b *Blog) FindByIdAndMemberId(blogId, memberId int) (*Blog, error) {
o := orm.NewOrm() o := orm.NewOrm()
@ -139,7 +139,7 @@ func (b *Blog) FindByIdAndMemberId(blogId, memberId int) (*Blog, error) {
return b.Link() return b.Link()
} }
//根据文章标识查询文章 // 根据文章标识查询文章
func (b *Blog) FindByIdentify(identify string) (*Blog, error) { func (b *Blog) FindByIdentify(identify string) (*Blog, error) {
o := orm.NewOrm() o := orm.NewOrm()
@ -151,7 +151,7 @@ func (b *Blog) FindByIdentify(identify string) (*Blog, error) {
return b, nil return b, nil
} }
//获取指定文章的链接内容 // 获取指定文章的链接内容
func (b *Blog) Link() (*Blog, error) { func (b *Blog) Link() (*Blog, error) {
o := orm.NewOrm() o := orm.NewOrm()
//如果是链接文章,则需要从链接的项目中查找文章内容 //如果是链接文章,则需要从链接的项目中查找文章内容
@ -211,14 +211,14 @@ func (b *Blog) Link() (*Blog, error) {
return b, nil return b, nil
} }
//判断指定的文章标识是否存在 // 判断指定的文章标识是否存在
func (b *Blog) IsExist(identify string) bool { func (b *Blog) IsExist(identify string) bool {
o := orm.NewOrm() o := orm.NewOrm()
return o.QueryTable(b.TableNameWithPrefix()).Filter("blog_identify", identify).Exist() return o.QueryTable(b.TableNameWithPrefix()).Filter("blog_identify", identify).Exist()
} }
//保存文章 // 保存文章
func (b *Blog) Save(cols ...string) error { func (b *Blog) Save(cols ...string) error {
o := orm.NewOrm() o := orm.NewOrm()
@ -239,7 +239,7 @@ func (b *Blog) Save(cols ...string) error {
b.Modified = time.Now() b.Modified = time.Now()
_, err = o.Update(b, cols...) _, err = o.Update(b, cols...)
key := fmt.Sprintf("blog-id-%d", b.BlogId) key := fmt.Sprintf("blog-id-%d", b.BlogId)
cache.Delete(key) _ = cache.Delete(key)
} else { } else {
@ -250,7 +250,7 @@ func (b *Blog) Save(cols ...string) error {
return err return err
} }
//过滤文章的危险标签,处理文章外链以及图片. // 过滤文章的危险标签,处理文章外链以及图片.
func (b *Blog) Processor() *Blog { func (b *Blog) Processor() *Blog {
b.BlogRelease = utils.SafetyProcessor(b.BlogRelease) b.BlogRelease = utils.SafetyProcessor(b.BlogRelease)
@ -285,7 +285,7 @@ func (b *Blog) Processor() *Blog {
return b return b
} }
//分页查询文章列表 // 分页查询文章列表
func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string) (blogList []*Blog, totalCount int, err error) { func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string) (blogList []*Blog, totalCount int, err error) {
o := orm.NewOrm() o := orm.NewOrm()
@ -297,10 +297,14 @@ func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string)
if memberId > 0 { if memberId > 0 {
query = query.Filter("member_id", memberId) query = query.Filter("member_id", memberId)
} }
if status != "" { if status != "" && status != "all" {
query = query.Filter("blog_status", status) query = query.Filter("blog_status", status)
} }
if status == "" {
query = query.Filter("blog_status__ne", "private")
}
_, err = query.OrderBy("-order_index", "-blog_id").Offset(offset).Limit(pageSize).All(&blogList) _, err = query.OrderBy("-order_index", "-blog_id").Offset(offset).Limit(pageSize).All(&blogList)
if err != nil { if err != nil {
@ -326,8 +330,11 @@ func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string)
return return
} }
//删除文章 // 删除文章
func (b *Blog) Delete(blogId int) error { func (b *Blog) Delete(blogId int) error {
// 删除文章缓存
key := fmt.Sprintf("blog-id-%d", blogId)
_ = cache.Delete(key)
o := orm.NewOrm() o := orm.NewOrm()
_, err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id", blogId).Delete() _, err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id", blogId).Delete()
@ -337,7 +344,7 @@ func (b *Blog) Delete(blogId int) error {
return err return err
} }
//查询下一篇文章 // 查询下一篇文章
func (b *Blog) QueryNext(blogId int) (*Blog, error) { func (b *Blog) QueryNext(blogId int) (*Blog, error) {
o := orm.NewOrm() o := orm.NewOrm()
blog := NewBlog() blog := NewBlog()
@ -355,7 +362,7 @@ func (b *Blog) QueryNext(blogId int) (*Blog, error) {
return blog, err return blog, err
} }
//查询下一篇文章 // 查询下一篇文章
func (b *Blog) QueryPrevious(blogId int) (*Blog, error) { func (b *Blog) QueryPrevious(blogId int) (*Blog, error) {
o := orm.NewOrm() o := orm.NewOrm()
blog := NewBlog() blog := NewBlog()
@ -373,7 +380,7 @@ func (b *Blog) QueryPrevious(blogId int) (*Blog, error) {
return blog, err return blog, err
} }
//关联文章附件 // 关联文章附件
func (b *Blog) LinkAttach() (err error) { func (b *Blog) LinkAttach() (err error) {
o := orm.NewOrm() o := orm.NewOrm()

View File

@ -6078,3 +6078,15 @@ span.change {
border-radius: 10px !important; border-radius: 10px !important;
background-color: #b3d4fc !important; background-color: #b3d4fc !important;
} }
@media screen and (max-width: 1400px) {
.cherry-toolbar-button {
padding: 0;
}
.cherry-toolbar .toolbar-left {
justify-content: space-between;
width: 95%;
}
}

View File

@ -51,7 +51,7 @@
"<label>" + imageLang.url + "</label>" + "<label>" + imageLang.url + "</label>" +
"<input type=\"text\" data-url />" + (function() { "<input type=\"text\" data-url />" + (function() {
return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" + return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" +
// 3xxx 下行添加multiple=\"multiple\" // 3xxx <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>multiple=\"multiple\"
"<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/jpeg,image/png,image/gif,image/jpg\" multiple=\"multiple\" />" + "<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/jpeg,image/png,image/gif,image/jpg\" multiple=\"multiple\" />" +
"<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" + "<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" +
"</div>" : ""; "</div>" : "";
@ -78,7 +78,7 @@
opacity: settings.dialogMaskOpacity, opacity: settings.dialogMaskOpacity,
backgroundColor: settings.dialogMaskBgColor backgroundColor: settings.dialogMaskBgColor
}, },
// 这里将多图片地址改造后插入文档中 // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD>
buttons: { buttons: {
enter: [lang.buttons.enter, function() { enter: [lang.buttons.enter, function() {
var url = this.find("[data-url]").val(); var url = this.find("[data-url]").val();
@ -88,7 +88,7 @@
alert(imageLang.imageURLEmpty); alert(imageLang.imageURLEmpty);
return false; return false;
} }
// 这里增加循环 // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD>
let arr = url.split(";"); let arr = url.split(";");
var altAttr = (alt !== "") ? " \"" + alt + "\"" : ""; var altAttr = (alt !== "") ? " \"" + alt + "\"" : "";
for (let i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
@ -121,19 +121,19 @@
fileInput.bind("change", function() { fileInput.bind("change", function() {
// 3xxx 20240602 // 3xxx 20240602
// let formData = new FormData(); // let formData = new FormData();
// 获取文本框dom // <EFBFBD><EFBFBD>ȡ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD>dom
// var doc = document.getElementById('doc'); // var doc = document.getElementById('doc');
// 获取上传控件dom // <EFBFBD><EFBFBD>ȡ<EFBFBD>ϴ<EFBFBD><EFBFBD>ؼ<EFBFBD>dom
// var upload = document.getElementById('upload'); // var upload = document.getElementById('upload');
// let files = upload.files; // let files = upload.files;
//遍历文件信息append到formData存储 //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>Ϣappend<EFBFBD><EFBFBD>formData<EFBFBD>
// for (let i = 0; i < files.length; i++) { // for (let i = 0; i < files.length; i++) {
// let file = files[i] // let file = files[i]
// formData.append('files', file) // formData.append('files', file)
// } // }
// 获取文件名 // <EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
// var fileName = upload.files[0].name; // var fileName = upload.files[0].name;
// 获取文件路径 // <EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD>·<EFBFBD><EFBFBD>
// var filePath = upload.value; // var filePath = upload.value;
// doc.value = fileName; // doc.value = fileName;
// 3xxx // 3xxx
@ -161,17 +161,11 @@
var json = (body.innerText) ? body.innerText : ((body.textContent) ? body.textContent : null); var json = (body.innerText) ? body.innerText : ((body.textContent) ? body.textContent : null);
json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")"); json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")");
var url=""; var url="";
for (let i = 0; i < json.length; i++) { if (json.success === 1) {
if (json[i].success === 1) { url=json.url;
if (i==0){
url=json[i].url;
}else{
url=url+";"+json[i].url;
}
} else { } else {
alert(json[i].message); alert(json.message);
} }
}
dialog.find("[data-url]").val(url) dialog.find("[data-url]").val(url)
return false; return false;
}; };

View File

@ -79,9 +79,12 @@
<label class="radio-inline"> <label class="radio-inline">
<input type="radio" {{if eq .Model.BlogStatus "password"}}checked{{end}} name="status" value="password">{{i18n .Lang "blog.encryption"}}<span class="text"></span> <input type="radio" {{if eq .Model.BlogStatus "password"}}checked{{end}} name="status" value="password">{{i18n .Lang "blog.encryption"}}<span class="text"></span>
</label> </label>
<label class="radio-inline">
<input type="radio" {{if eq .Model.BlogStatus "private"}}checked{{end}} name="status" value="private">{{i18n .Lang "blog.private"}}<span class="text"></span>
</label>
</div> </div>
</div> </div>
<div class="form-group"{{if eq .Model.BlogStatus "public"}} style="display: none;"{{end}} id="blogPassword"> <div class="form-group"{{if ne .Model.BlogStatus "password"}} style="display: none;"{{end}} id="blogPassword">
<label>{{i18n .Lang "blog.blog_pwd"}}</label> <label>{{i18n .Lang "blog.blog_pwd"}}</label>
<input type="password" class="form-control" name="password" id="password" placeholder="{{i18n .Lang "blog.blog_pwd"}}" value="{{.Model.Password}}" maxlength="20"> <input type="password" class="form-control" name="password" id="password" placeholder="{{i18n .Lang "blog.blog_pwd"}}" value="{{.Model.Password}}" maxlength="20">
</div> </div>