Forráskód Böngészése

临时解决阅读页面js报错'menuSetting undefined'

gsw945 2 éve
szülő
commit
725b6ac24e
4 módosított fájl, 29 hozzáadás és 20 törlés
  1. 9 2
      controllers/DocumentController.go
  2. 1 0
      go.mod
  3. 1 0
      go.sum
  4. 18 18
      views/document/default_read.tpl

+ 9 - 2
controllers/DocumentController.go

@@ -65,8 +65,8 @@ func (c *DocumentController) Index() {
 			selected = doc.DocumentId
 			c.Data["Title"] = doc.DocumentName
 			c.Data["Content"] = template.HTML(doc.Release)
-
 			c.Data["Description"] = utils.AutoSummary(doc.Release, 120)
+			c.Data["FoldSetting"] = "first"
 
 			if bookResult.IsDisplayComment {
 				// 获取评论、分页
@@ -78,6 +78,7 @@ func (c *DocumentController) Index() {
 	} else {
 		c.Data["Title"] = i18n.Tr(c.Lang, "blog.summary")
 		c.Data["Content"] = template.HTML(blackfriday.Run([]byte(bookResult.Description)))
+		c.Data["FoldSetting"] = "closed"
 	}
 
 	tree, err := models.NewDocument().CreateDocumentTreeForHtml(bookResult.BookId, selected)
@@ -230,6 +231,12 @@ func (c *DocumentController) Read() {
 	c.Data["Title"] = doc.DocumentName
 	c.Data["Content"] = template.HTML(doc.Release)
 	c.Data["ViewCount"] = doc.ViewCount
+	c.Data["FoldSetting"] = "closed"
+	if doc.IsOpen == 1 {
+		c.Data["FoldSetting"] = "open"
+	} else if doc.IsOpen == 2 {
+		c.Data["FoldSetting"] = "empty"
+	}
 }
 
 // 编辑文档
@@ -1148,7 +1155,7 @@ func (c *DocumentController) DeleteHistory() {
 	c.JsonResult(0, "ok")
 }
 
-//通过文档历史恢复文档
+// 通过文档历史恢复文档
 func (c *DocumentController) RestoreHistory() {
 	c.Prepare()
 

+ 1 - 0
go.mod

@@ -10,6 +10,7 @@ require (
 	github.com/go-ldap/ldap/v3 v3.4.4
 	github.com/howeyc/fsnotify v0.9.0
 	github.com/kardianos/service v1.2.1
+	github.com/lib/pq v1.10.5
 	github.com/lifei6671/gocaptcha v0.2.0
 	github.com/mattn/go-runewidth v0.0.13
 	github.com/mattn/go-sqlite3 v1.14.15

+ 1 - 0
go.sum

@@ -188,6 +188,7 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/lib/pq v1.10.5 h1:J+gdV2cUmX7ZqL2B0lFcW0m+egaHC2V3lpO8nWxyYiQ=
+github.com/lib/pq v1.10.5/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
 github.com/lifei6671/gocaptcha v0.2.0 h1:CwMjGitq5MsYtWODQhlphdl7WhDdD243y1O2d3l8yFU=
 github.com/lifei6671/gocaptcha v0.2.0/go.mod h1:mcUWn1eB+kHOBHLQdmWAQ83bhEGrFTnGMqRCY7sFgUc=
 github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=

+ 18 - 18
views/document/default_read.tpl

@@ -315,39 +315,39 @@ $(function () {
     });
 
     window.menuControl = true;
-    // window.menuSetting = "open" ;
-    if (menuSetting == 'open' || menuSetting == 'first') {
+    window.foldSetting = '{{.FoldSetting}}';
+    if (foldSetting == 'open' || foldSetting == 'first') {
         $('#handlerMenuShow').find('span').text('{{i18n .Lang "doc.fold"}}');
         $('#handlerMenuShow').find('i').attr("class","fa fa-angle-down");
-        if (menuSetting == 'open') {
-            window.jsTree.jstree().open_all()
+        if (foldSetting == 'open') {
+            window.jsTree.jstree().open_all();
         }
-        if (menuSetting == 'first') {
-            window.jsTree.jstree('close_all')
+        if (foldSetting == 'first') {
+            window.jsTree.jstree('close_all');
             var $target = $('.jstree-container-ul').children('li').filter(function(index){
                 if($(this).attr('aria-expanded')==false||$(this).attr('aria-expanded')){
-                    return $(this)
+                    return $(this);
                 }else{
-                    delete $(this)
+                    delete $(this);
                 }
-            })
-            $target.children('i').trigger('click')
+            });
+            $target.children('i').trigger('click');
         }
     } else {
         menuControl = false;
-        window.jsTree.jstree('close_all')
+        window.jsTree.jstree('close_all');
     }
     $('#handlerMenuShow').on('click', function(){
         if(menuControl){
-            $(this).find('span').text('{{i18n .Lang "doc.expand"}}')
-            $(this).find('i').attr("class","fa fa-angle-left")
-            window.menuControl = false
-            window.jsTree.jstree('close_all')
+            $(this).find('span').text('{{i18n .Lang "doc.expand"}}');
+            $(this).find('i').attr("class","fa fa-angle-left");
+            window.menuControl = false;
+            window.jsTree.jstree('close_all');
         }else{
             window.menuControl = true
-            $(this).find('span').text('{{i18n .Lang "doc.fold"}}')
-            $(this).find('i').attr("class","fa fa-angle-down")
-            window.jsTree.jstree().open_all()
+            $(this).find('span').text('{{i18n .Lang "doc.fold"}}');
+            $(this).find('i').attr("class","fa fa-angle-down");
+            window.jsTree.jstree().open_all();
         }
     });