文档首页.
()
| 155 | |
| 156 | // 文档首页. |
| 157 | func (this *DocumentController) Index() { |
| 158 | identify := this.Ctx.Input.Param(":key") |
| 159 | if identify == "" { |
| 160 | this.Abort("404") |
| 161 | } |
| 162 | |
| 163 | token := this.GetString("token") |
| 164 | if len(strings.TrimSpace(this.GetString("with-password"))) > 0 { |
| 165 | this.indexWithPassword() |
| 166 | return |
| 167 | } |
| 168 | |
| 169 | tab := strings.ToLower(this.GetString("tab")) |
| 170 | |
| 171 | bookResult := isReadable(identify, token, this) |
| 172 | if bookResult.BookId == 0 { //没有阅读权限 |
| 173 | this.Redirect(beego.URLFor("HomeController.Index"), 302) |
| 174 | return |
| 175 | } |
| 176 | |
| 177 | this.TplName = "document/intro.html" |
| 178 | bookResult.Lang = utils.GetLang(bookResult.Lang) |
| 179 | this.Data["Book"] = bookResult |
| 180 | |
| 181 | switch tab { |
| 182 | case "comment", "score": |
| 183 | default: |
| 184 | tab = "default" |
| 185 | } |
| 186 | this.Data["ExistWeCode"] = strings.TrimSpace(models.GetOptionValue("DOWNLOAD_WECODE", "")) != "" |
| 187 | this.Data["Qrcode"] = new(models.Member).GetQrcodeByUid(bookResult.MemberId) |
| 188 | this.Data["MyScore"] = new(models.Score).BookScoreByUid(this.Member.MemberId, bookResult.BookId) |
| 189 | this.Data["Tab"] = tab |
| 190 | if beego.AppConfig.DefaultBool("showWechatCode", false) && bookResult.PrivatelyOwned == 0 { |
| 191 | wechatCode := models.NewWechatCode() |
| 192 | go wechatCode.CreateWechatCode(bookResult.BookId) //如果已经生成了小程序码,则不会再生成 |
| 193 | this.Data["Wxacode"] = wechatCode.GetCode(bookResult.BookId) |
| 194 | } |
| 195 | |
| 196 | //当前默认展示1000条评论(暂时先默认1000条) |
| 197 | comments, _ := new(models.Comments).Comments(1, 1000, models.CommentOpt{BookId: bookResult.BookId, Status: []int{1}, WithoutDocComment: true}) |
| 198 | |
| 199 | this.Data["Comments"] = comments |
| 200 | this.Data["Menu"], _ = new(models.Document).GetMenuTop(bookResult.BookId) |
| 201 | title := "《" + bookResult.BookName + "》" |
| 202 | if tab == "comment" { |
| 203 | title = "点评 - " + title |
| 204 | } |
| 205 | this.GetSeoByPage("book_info", map[string]string{ |
| 206 | "title": title, |
| 207 | "keywords": bookResult.Label, |
| 208 | "description": bookResult.Description, |
| 209 | }) |
| 210 | this.Data["RelateBooks"] = models.NewRelateBook().Lists(bookResult.BookId) |
| 211 | this.Data["Versions"] = models.NewVersion().GetPublicVersionItems(bookResult.Identify) |
| 212 | } |
| 213 | |
| 214 | // 文档首页. |
nothing calls this directly
no test coverage detected