mirror of https://github.com/mindoc-org/mindoc.git
commit
0dfaa423e1
|
@ -143,17 +143,22 @@ func (c *DocumentController) Read() {
|
|||
doc.AttachList = attach
|
||||
}
|
||||
|
||||
doc.IncrViewCount(doc.DocumentId)
|
||||
c.Data["ViewCount"] = doc.ViewCount + 1
|
||||
|
||||
if c.IsAjax() {
|
||||
var data struct {
|
||||
DocTitle string `json:"doc_title"`
|
||||
Body string `json:"body"`
|
||||
Title string `json:"title"`
|
||||
Version int64 `json:"version"`
|
||||
ViewCount int `json:"view_count"`
|
||||
}
|
||||
data.DocTitle = doc.DocumentName
|
||||
data.Body = doc.Release
|
||||
data.Title = doc.DocumentName + " - Powered by MinDoc"
|
||||
data.Version = doc.Version
|
||||
data.ViewCount = doc.ViewCount + 1
|
||||
|
||||
c.JsonResult(0, "ok", data)
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ type Document struct {
|
|||
Version int64 `orm:"column(version);type(bigint);" json:"version"`
|
||||
//是否展开子目录:0 否/1 是 /2 空间节点,单击时展开下一级
|
||||
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
||||
ViewCount int `orm:"column(view_count);type(int)" json:"view_count"`
|
||||
AttachList []*Attachment `orm:"-" json:"attach"`
|
||||
}
|
||||
|
||||
|
@ -384,3 +385,11 @@ func (item *Document) Processor() *Document {
|
|||
}
|
||||
return item
|
||||
}
|
||||
|
||||
// 增加阅读次数
|
||||
func (item *Document) IncrViewCount(id int) {
|
||||
o := orm.NewOrm()
|
||||
o.QueryTable(item.TableNameWithPrefix()).Filter("document_id", id).Update(orm.Params{
|
||||
"view_count": orm.ColValue(orm.ColAdd, 1),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ function loadDocument($url, $id, $callback) {
|
|||
$("title").text(data.title);
|
||||
$("#article-title").text(data.doc_title);
|
||||
$("#article-info").text(data.doc_info);
|
||||
$("#view_count").text("阅读次数:" + data.view_count);
|
||||
|
||||
events.trigger('article.open', {$url: $url, $id: $id});
|
||||
|
||||
|
@ -80,6 +81,7 @@ function loadDocument($url, $id, $callback) {
|
|||
var doc_title = res.data.doc_title;
|
||||
var title = res.data.title;
|
||||
var doc_info = res.data.doc_info;
|
||||
var view_count = res.data.view_count;
|
||||
|
||||
$body = body;
|
||||
if (typeof $callback === "function" ) {
|
||||
|
@ -90,6 +92,7 @@ function loadDocument($url, $id, $callback) {
|
|||
$("title").text(title);
|
||||
$("#article-title").text(doc_title);
|
||||
$("#article-info").text(doc_info);
|
||||
$("#view_count").text("阅读次数:" + view_count);
|
||||
|
||||
events.data($id, res.data);
|
||||
|
||||
|
|
|
@ -146,6 +146,7 @@
|
|||
</div>
|
||||
<div class="m-copyright">
|
||||
<p>
|
||||
<div id="view_count">阅读次数:{{.ViewCount}}</div>
|
||||
本文档使用 <a href="https://www.iminho.me" target="_blank">MinDoc</a> 发布
|
||||
</p>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue