diff --git a/controllers/base.go b/controllers/base.go index 4aa667ab..c830a790 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -85,7 +85,7 @@ func (c *BaseController) JsonResult(errCode int, errMsg string, data ...interfac } c.Ctx.ResponseWriter.Header().Set("Content-Type", "application/json; charset=utf-8") - + c.Ctx.ResponseWriter.Header().Set("Cache-Control", "no-cache, no-store") io.WriteString(c.Ctx.ResponseWriter, string(returnJSON)) c.StopRun() diff --git a/static/js/kancloud.js b/static/js/kancloud.js index 47d1ddcd..2c5ed9da 100644 --- a/static/js/kancloud.js +++ b/static/js/kancloud.js @@ -24,7 +24,7 @@ function loadDocument($url, $id, $callback) { $("#article-title").text(doc_title); $("#article-info").text(doc_info); - events.trigger('article.open', { $url : $url, $init : false, $id : $id }); + events.trigger('article.open', { $url : $url, $id : $id }); return false; } @@ -52,7 +52,7 @@ function loadDocument($url, $id, $callback) { events.data('doc_title_' + $id, doc_title); events.data('doc_info_' + $id, doc_info); - events.trigger('article.open', { $url : $url, $init : true, $id : $id }); + events.trigger('article.open', { $url : $url, $id : $id }); } else if (res.errcode === 6000) { window.location.href = "/"; } else { @@ -138,11 +138,20 @@ $(function () { // 处理打开事件 events.on('article.open', function (event, $param) { + + var prevState = window.history.state || {}; if ('pushState' in history) { - if ($param.$init === false) { - window.history.replaceState($param, $param.$id, $param.$url); + // if ($param.$init === false) { + // window.history.replaceState($param, $param.$id, $param.$url); + // } else { + // window.history.pushState($param, $param.$id, $param.$url); + // } + + if ($param.$id) { + prevState.$id === $param.$id || window.history.pushState($param, $param.$id, $param.$url); } else { window.history.pushState($param, $param.$id, $param.$url); + window.history.replaceState($param, $param.$id, $param.$url); } } else { window.location.hash = $param.$url; @@ -196,12 +205,15 @@ $(function () { window.onpopstate = function (e) { var $param = e.state; - console.log($param); + if (!$param) return; if($param.hasOwnProperty("$url")) { window.jsTree.jstree().deselect_all(); - window.jsTree.jstree().select_node({ id : $param.$id }); - $param.$init = false; + if ($param.$id) { + window.jsTree.jstree().select_node({ id : $param.$id }); + }else{ + window.location.assign($param.$url); + } // events.trigger('article.open', $param); } else { console.log($param); @@ -209,9 +221,9 @@ $(function () { }; try { var $node = window.jsTree.jstree().get_selected(); - if (typeof $node === "object") { + if ($node instanceof Array && $node.length) { $node = window.jsTree.jstree().get_node({ id: $node[0] }); - events.trigger('article.open', { $url: $node.a_attr.href, $init: true, $id: $node.a_attr.id }); + events.trigger('article.open', { $url: $node.a_attr.href, $id: $node.id }); } } catch (e) { console.log(e); diff --git a/views/book/users.tpl b/views/book/users.tpl index 6e114e24..815eddd2 100644 --- a/views/book/users.tpl +++ b/views/book/users.tpl @@ -43,8 +43,8 @@ {{end}} -
-
+
+
@@ -86,6 +86,11 @@
+