Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1fe06e7

Browse files
committed
图书功能开发完成
1 parent 1097646 commit 1fe06e7

File tree

4 files changed

+115
-224
lines changed

4 files changed

+115
-224
lines changed

src/http/controller/book.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,7 @@ func (BookController) ReadList(ctx echo.Context) error {
8484
"next_id": nextId,
8585
}
8686

87-
// 获取当前用户喜欢对象信息
88-
me, ok := ctx.Get("user").(*model.Me)
89-
var likeFlags map[int]int
90-
if ok {
91-
likeFlags, _ = logic.DefaultLike.FindUserLikeObjects(ctx, me.Uid, model.TypeBook, books[0].Id, nextId)
92-
}
93-
94-
return render(ctx, "books/list.html", map[string]interface{}{"books": books, "activeBooks": "active", "page": pageInfo, "likeflags": likeFlags})
87+
return render(ctx, "books/list.html", map[string]interface{}{"books": books, "activeBooks": "active", "page": pageInfo})
9588
}
9689

9790
// Detail 图书详细页

static/css/book.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.books { margin-top: 10px; padding: 5px 0; }
2+
.book { overflow: hidden; clear: both; padding: 0 15px; }
3+
.book .meta-num { max-width: 100px; margin-top: 10.5px; }
4+
.book h4 { color: #474747; }
5+
.book h4 a {color: #474747;text-decoration: none;overflow: hidden;}
6+
.book h4 a:hover { color: #DB6D4C; }
7+
.book .stats { background: #eeeeee; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; margin: 0; padding: 5px; text-align: center; }
8+
.book .stats .votes { color: #555555; }
9+
.stats strong { display: block; font-size: 140%; font-weight: bold; }
10+
.stats .answered { color: #ffffff; background-color: #7e91bd; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; padding: 4px 0; margin: 0; }
11+
.views-orange { color: #ee7711; padding-top: 4px; text-align: center;}
12+
.author-date { color: #999; font-size: 13px; }
13+
.author-date a { color: #999; text-decoration: none; }
14+
.author-date a:hover { color: #DB6D4C; }
15+
16+
.book .desc { margin-top: 5px; font-size: 14px; }
17+
.book .desc a { text-decoration: none; color: #3d5998; }
18+
.book .desc a:hover { color: #DB6D4C; }
19+
20+
.book .book-cover-box { margin-top: 10.5px; }
21+
.book .book-cover-box a { position: relative; overflow: visible; margin: 5px 0; width: 120px; margin-right: .6em; float: right; }
22+
.book .book-cover-box img { width: 100%; border: 1px solid #fff; box-shadow: 1px 1px 6px rgba(0, 0, 0, 0.7); -webkit-box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.7); -moz-box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7); display: block; max-width: 100%; vertical-align: middle; }
23+
24+
hr { margin: 18px 0; border: 0; border-top: 1px solid #555555; border-bottom: 1px solid #ffffff; clear: both; }
25+
hr.dashed { border-top: 1px dashed #999999; }
26+
27+
.book-header .lang { font-size: 13px; }
28+
.book-like { margin-top: 16px; }
29+
.book-like .like { text-align: center; }
30+
.book-like .like strong { line-height: 1.2em; display: block; color: #555555; font-weight: bold; font-size: 32px; line-height: 50px; }
31+
.book-like .like a { text-decoration: none; color: #3d5998; }
32+
.book-sales { text-align: center; }

template/books/detail.html

Lines changed: 78 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,97 @@
1-
{{define "title"}}{{.article.Title}} {{end}}
2-
{{define "seo"}}<meta name="keywords" content="{{.article.Title}}, Go语言博客文章, Go语言博文, Go语言, Golang, Go中文社区,Golang中文社区, Go语言社区, Go语言学习园地">
3-
<meta name="description" content="{{substring .article.Txt 200 ""}}">{{end}}
1+
{{define "title"}}{{.book.Name}} {{end}}
2+
{{define "seo"}}<meta name="keywords" content="{{.book.Name}}, Go语言图书, Go语言, Golang, Go中文社区,Golang中文社区, Go语言社区, Go语言学习园地,Go语言中文网">
3+
<meta name="description" content="{{substring .book.Desc 200 ""}}">{{end}}
44
{{define "content"}}
55
<div class="row banner">
66
</div>
77
<div class="row">
88
<div class="col-lg-9 col-md-8 col-sm-7">
99
<ol class="breadcrumb">
1010
<li><a href="/"><i class="glyphicon glyphicon-home"></i> 首页</a></li>
11-
<li><a href="/articles">网友博文</a></li>
12-
<li class="active">{{.article.Title}}</li>
11+
<li><a href="/books">图书</a></li>
12+
<li class="active">{{.book.Name}}</li>
1313
</ol>
1414
<div class="page box_white">
15-
<div class="title text-center">
16-
<h1 id="title" data-id="{{.article.Id}}">
17-
{{.article.Title}}
18-
{{if .me}}
19-
{{if or (eq .me.Username .article.Author) .me.IsRoot}}
20-
<button id="edit" type="button" class="btn btn-primary btn-xs">编辑</button>
15+
<div class="row book">
16+
<div class="col-lg-2 col-md-2">
17+
<div class="book-cover-col">
18+
<div class="book-cover-box wide">
19+
<a href="{{.book.Cover}}" style="float: none;">
20+
<img src="{{.book.Cover}}" class="bookcover">
21+
</a>
22+
<span class="ebook"></span>
23+
</div>
24+
{{if .book.Price}}
25+
<div class="book-sales">
26+
<b>¥ {{.book.Price}}</b>
27+
</div>
2128
{{end}}
22-
{{end}}
23-
</h1>
24-
</div>
25-
<div class="meta">
26-
<div class="p-author">
27-
<i class="glyphicon glyphicon-calendar"></i>
28-
<span title="发布日期">{{.article.PubDate}}</span>&nbsp;
29-
<i class="glyphicon glyphicon-user"></i>
30-
{{if .article.IsSelf}}
31-
<a href="/user/{{.article.Author}}">{{.article.Author}}</a>
32-
{{else}}
33-
{{noescape .article.Author}}
34-
{{end}}
29+
<div class="book-like">
30+
<div class="like">
31+
<a class="share-btn like-btn {{if .likeflag}}hadlike{{end}}" href="javascript:;" title="{{if .likeflag}}取消推荐{{else}}推荐{{end}}" data-objid="{{.book.Id}}" data-objtype="1" data-flag="{{.likeflag}}">{{if .likeflag}}取消推荐{{else}}推荐{{end}}</a>
32+
<strong>{{.book.Likenum}}</strong>
33+
</div>
34+
</div>
35+
</div>
3536
</div>
36-
<!-- p-author END -->
37-
38-
<div class="p-comment text-right">
39-
<span class="view" title="阅读数">
40-
<i class="glyphicon glyphicon-eye-open"></i>
41-
阅读 <span>{{.article.Viewnum}}</span> 次&nbsp;
42-
</span>
43-
<span class="like" title="喜欢人数">
44-
<i class="glyphicon glyphicon-heart"></i>
45-
<span class="likenum">{{.article.Likenum}}</span> 人喜欢&nbsp;
46-
</span>
47-
<a href="/articles/{{.article.Id}}#commentForm" title="我要评论"><i class="glyphicon glyphicon-comment"></i> <span class="cmtnum">{{.article.Cmtnum}}</span> 条评论</a>&nbsp;
48-
<a class="favorite collect {{if .hadcollect}}hadlike{{end}}" href="#" title="{{if .hadcollect}}取消收藏{{else}}稍后再读{{end}}" data-objid="{{.article.Id}}" data-objtype="1" data-collect="{{.hadcollect}}">
49-
<i class="glyphicon glyphicon-star{{if eq .hadcollect 0}}-empty{{end}}"></i> 收藏
50-
</a>
51-
</div>
52-
<!-- p-comment END -->
53-
</div>
54-
<div class="tags">
55-
{{if .article.Tags}}
56-
{{$tags := explode .article.Tags ","}}
57-
<ul class="list-inline">
58-
{{range $tag := $tags}}
59-
<li><a href="/search?q={{$tag}}&f=tag" title="{{$tag}}">{{$tag}}</a></li>
37+
<div class="col-lg-10 col-md-10">
38+
<div class="book-header">
39+
<h3>{{.book.Name}}<span class="lang">({{if .book.Lang}}英文版{{else}}中文版{{end}})</span></h3>
40+
{{if .book.Ename}}
41+
<small>英文书名:<strong>{{.book.Ename}}</strong></small>
42+
{{end}}
43+
</div>
44+
<div class="meta" style="margin: 0;">
45+
<div class="p-author">
46+
<i class="glyphicon glyphicon-calendar"></i>
47+
<span title="发布日期">{{.book.PubDate}}</span>&nbsp;
48+
<i class="glyphicon glyphicon-user"></i>
49+
{{.book.Author}} (作者)  
50+
{{if .book.Translator}}
51+
{{.book.Translator}} (译者)
52+
{{end}}
53+
</div>
54+
<!-- p-author END -->
55+
56+
<div class="p-comment text-right">
57+
<span class="view" title="阅读数">
58+
<i class="glyphicon glyphicon-eye-open"></i>
59+
阅读 <span>{{.book.Viewnum}}</span> 次&nbsp;
60+
</span>
61+
<a href="/book/{{.book.Id}}#commentForm" title="我要评论"><i class="glyphicon glyphicon-comment"></i> <span class="cmtnum">{{.book.Cmtnum}}</span> 条评论</a>
62+
</div>
63+
<!-- p-comment END -->
64+
</div>
65+
<div class="tags" style="margin: 0;">
66+
<ul class="list-inline">
67+
{{if .book.OnlineUrl}}
68+
<li><a href="{{.book.OnlineUrl}}" target="_blank">在线阅读</a></li>
69+
{{end}}
70+
{{if .book.DownloadUrl}}
71+
<li><a href="{{.book.DownloadUrl}}" target="_blank">下载</a></li>
72+
{{end}}
73+
{{if .book.BuyUrl}}
74+
<li><a href="{{.book.BuyUrl}}" target="_blank">去购买</a></li>
75+
{{end}}
76+
</ul>
77+
</div>
78+
<div class="desc">
79+
{{.book.Desc}}
80+
</div>
81+
{{if .book.Catalogue}}
82+
<div class="catalogue">
83+
{{.book.Catalogue}}
84+
</div>
6085
{{end}}
61-
</ul>
62-
{{end}}
63-
</div>
64-
<!-- tags END -->
65-
<div id="myeditor" class="content article-entry">
66-
{{noescape .article.Content}}
67-
</div>
68-
<!-- content END -->
69-
{{if not .article.IsSelf}}
70-
<div class="row orig-info">
71-
<p>本文来自:<a href="/wr?u=http://{{.article.Domain}}" target="_blank" title="{{.article.Name}}">{{.article.Name}}</a></p>
72-
<p>感谢作者:{{noescape .article.Author}}</p>
73-
<p>查看原文:<a href="/wr?u={{.article.Url}}" target="_blank" title="{{.article.Title}}">{{.article.Title}}</a></p>
74-
</div>
75-
{{end}}
76-
<div class="active row">
77-
<div class="mark-like-btn col-md-8">
78-
<a class="share-btn like-btn {{if .likeflag}}hadlike{{end}}" href="javascript:;" title="{{if .likeflag}}取消喜欢{{else}}我喜欢{{end}}" data-objid="{{.article.Id}}" data-objtype="1" data-flag="{{.likeflag}}">
79-
<i class="glyphicon glyphicon-heart-empty"></i><span class="likenum">{{.article.Likenum}}</span>人喜欢
80-
</a>
81-
<a class="share-btn collect {{if .hadcollect}}hadlike{{end}}" href="javascript:;" title="{{if .hadcollect}}取消收藏{{else}}稍后再读{{end}}" data-objid="{{.article.Id}}" data-objtype="1" data-collect="{{.hadcollect}}">
82-
<i class="glyphicon glyphicon-star-empty"></i>收藏
83-
</a>
8486
</div>
8587
</div>
86-
87-
<!--百度推荐-->
88-
<div id="hm_t_45501" style="margin:0 auto;max-width:790px;"></div>
8988

90-
<div class="row prev-next">
91-
{{if .prev}}<div><a href="/articles/{{.prev.Id}}" title="{{.prev.Title}}">« </a>上一篇: <a href="/articles/{{.prev.Id}}" title="{{.prev.Title}}">{{.prev.Title}}</a></div>{{end}}
92-
{{if .next}}<div><a href="/articles/{{.next.Id}}" title="{{.next.Title}}">» </a>下一篇: <a href="/articles/{{.next.Id}}" title="{{.next.Title}}">{{.next.Title}}</a></div>{{end}}
93-
</div>
89+
<hr class="dashed">
90+
9491
<!-- 评论 -->
95-
<div class="page-comment" data-objid="{{.article.Id}}" data-objtype="1" {{if .me}}data-username="{{.me.Username}}" data-uid="{{.me.Uid}}" data-avatar="{{gravatar .me.Avatar .me.Email 48 .is_https}}"{{end}}>
92+
<div class="page-comment" data-objid="{{.book.Id}}" data-objtype="1" {{if .me}}data-username="{{.me.Username}}" data-uid="{{.me.Uid}}" data-avatar="{{gravatar .me.Avatar .me.Email 48 .is_https}}"{{end}}>
9693
<div class="words hide">
97-
<h3><span class="cmtnum">{{.article.Cmtnum}}</span>条评论</h3>
94+
<h3><span class="cmtnum">{{.book.Cmtnum}}</span>条评论</h3>
9895
<ul class="list-unstyled">
9996
</ul>
10097
</div>
@@ -112,12 +109,6 @@ <h2>文章点评:</h2>
112109
</div>
113110
</div>
114111
<div class="col-lg-3 col-md-4 col-sm-5">
115-
<div class="row box_white sidebar">
116-
<div class="sb-content text-center" style="margin-top: 15px;">
117-
<a href="/articles/new" class="btn btn-default">撰写文章</a>
118-
</div>
119-
</div>
120-
121112
<div class="row box_white sidebar">
122113
<div class="top">
123114
<ul class="list-inline text-center">
@@ -168,25 +159,15 @@ <h3 class="title"><i class="glyphicon glyphicon-fire"></i>&nbsp;<a href="/projec
168159

169160
</div>
170161

171-
<template id="content_tpl">
172-
{{noescape .article.Content}}
173-
</template>
174-
175162
{{end}}
176163
{{define "css"}}
164+
<link rel="stylesheet" type="text/css" href="/static/css/book.css"></link>
177165
<link href="/static/css/highlight/default.css" media="screen" rel="stylesheet" type="text/css">
178166
<link href="/static/css/syntax_highlight/shCore.css" media="screen" rel="stylesheet" type="text/css">
179167
<link href="/static/css/syntax_highlight/shCoreDefault.css" media="screen" rel="stylesheet" type="text/css">
180-
{{if .article.Css}}
181-
<link href="{{.article.Css}}" media="screen" rel="stylesheet" type="text/css">
182-
{{end}}
183-
{{if .article.IsSelf}}
184-
<link href="/static/css/prism.css" media="screen" rel="stylesheet" type="text/css">
185-
{{end}}
186168
<link href="/static/css/jquery.atwho.min.css" media="screen" rel="stylesheet" type="text/css">
187169
{{end}}
188170
{{define "js"}}
189-
<script type="text/javascript" src="//cdn.ckeditor.com/4.6.2/standard-all/ckeditor.js"></script>
190171
<script type="text/javascript" src="/static/js/libs/jquery.autogrowtextarea.min.js"></script>
191172
<script type="text/javascript" src="/static/js/libs/marked.min.js"></script>
192173
<script type="text/javascript" src="/static/js/libs/highlight.min.js"></script>
@@ -199,12 +180,6 @@ <h3 class="title"><i class="glyphicon glyphicon-fire"></i>&nbsp;<a href="/projec
199180
<script type="text/javascript" src="/static/js/libs/plupload.full.min.js"></script>
200181
<script type="text/javascript" src="/static/js/comment.js?v=1.1"></script>
201182
<script type="text/javascript" src="/static/js/puploader.js?v=1.0"></script>
202-
{{if .article.IsSelf}}
203-
<script type="text/javascript">
204-
$('code[class*="language-"]').parent('pre').addClass('line-numbers');
205-
</script>
206-
<script type="text/javascript" src="/static/js/prism.js"></script>
207-
{{end}}
208183
<script type="text/javascript">
209184
// 需要加载的侧边栏
210185
SG.SIDE_BARS = [
@@ -219,95 +194,9 @@ <h3 class="title"><i class="glyphicon glyphicon-fire"></i>&nbsp;<a href="/projec
219194
$('.need-autogrow').autoGrow();
220195

221196
loadComments();
222-
223-
// 文章链接,在本站的 iframe 中打开
224-
$('#wrapper .content').on('mousedown', 'a', function(evt){
225-
var url = $(this).attr('href');
226-
// $(this).attr('href', '/wr?u='+url);
227-
$(this).attr('href', url);
228-
$(this).attr('target', '_blank');
229-
});
230197
});
231198
</script>
232199
<script type="text/javascript" src="/static/ckeditor/config.js"></script>
233-
<script type="text/javascript">
234-
$(function(){
235-
CKEDITOR.plugins.addExternal('prism', '/static/ckeditor/plugins/prism/', 'plugin.js');
236-
$('#edit').on('click', function(){
237-
var txt = $(this).text();
238-
if (txt == '编辑') {
239-
$('#myeditor').attr('contenteditable', true);
240-
$('#myeditor').html($('#content_tpl').html());
241-
if (!CKEDITOR.instances.myeditor) {
242-
MyEditorConfig.extraPlugins = MyEditorExtraPlugins+',prism,sourcedialog';
243-
MyEditorConfig.toolbarGroups = [
244-
{ name: 'undo' },
245-
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
246-
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align' ] },
247-
{ name: 'links' },
248-
{ name: 'insert' },
249-
{ name: 'styles' },
250-
{ name: 'document', groups: [ 'mode', 'document' ] }
251-
];
252-
MyEditorConfig.removeButtons = 'Anchor,SpecialChar,HorizontalRule,Table,Styles,Subscript,Superscript';
253-
CKEDITOR.inline( 'myeditor', MyEditorConfig );
254-
}
255-
256-
$(this).text('完成');
257-
} else {
258-
if (CKEDITOR.instances.myeditor) {
259-
var content = CKEDITOR.instances.myeditor.getData();
260-
modify(content);
261-
262-
CKEDITOR.instances.myeditor.destroy();
263-
264-
Prism.highlightAll();
265-
}
266-
267-
$('#myeditor').attr('contenteditable', false);
268-
$(this).text('编辑');
269-
}
270-
});
271-
272-
CKEDITOR.on('instanceReady', function(evt, editor) {
273-
$('#myeditor').find('.cke_widget_element').each(function(){
274-
$(this).addClass('line-numbers').css('background-color', '#000');
275-
});
276-
});
277-
278-
function modify(content)
279-
{
280-
var url = '/articles/modify',
281-
data = { id: $('#title').data('id'), content:content };
282-
283-
$.ajax({
284-
type: "post",
285-
url: url,
286-
data: data,
287-
dataType: 'json',
288-
success: function(data){
289-
if(data.ok){
290-
if (typeof data.msg != "undefined") {
291-
comTip(data.msg);
292-
} else {
293-
comTip("修改成功!");
294-
}
295-
}else{
296-
comTip(data.error);
297-
}
298-
},
299-
complete:function(xmlReq, textStatus){
300-
},
301-
error:function(xmlReq, textStatus, errorThrown){
302-
if (xmlReq.status == 403) {
303-
comTip("没有修改权限");
304-
}
305-
}
306-
});
307-
}
308-
});
309-
310-
</script>
311200
<script>
312201
var baiduImagePlus = {
313202
noLogo:true,

0 commit comments

Comments
 (0)