Commit f085c875 by Duanbj

修改管理员内部文章相关逻辑,加入获取和删除内部文章的代码,修改相关css

parent 17c52334
...@@ -192,19 +192,21 @@ svg{ ...@@ -192,19 +192,21 @@ svg{
} }
.title{ .title{
width:60%; width:60%;
font-size:20px; font-size:18px;
text-align: left; text-align: left;
} }
#articles{ #articles{
position: relative; position: relative;
} }
#articleList{ #articleList{
position:absolute; /* position:absolute;
width:50%; width:50%; */
margin-bottom: 0;
} }
.lastStep{ .lastStep{
width:30px; width:30px;
height:30px; height:30px;
margin-top: 12px;
} }
#writenoticeLi>a{ #writenoticeLi>a{
color:black; color:black;
...@@ -216,19 +218,21 @@ svg{ ...@@ -216,19 +218,21 @@ svg{
text-align: center; text-align: center;
font-size:24px; font-size:24px;
font-weight: bold; font-weight: bold;
float: left;
} }
#authorName{ #authorName{
width:100%; width:100%;
height:30px; height:30px;
margin-top:10px; margin-top:10px;
line-height: 30px; padding-right: 5%;
text-align: right; text-align: right;
font-style: italic; font-style: italic;
} }
#content{ #content{
width:100%; width:100%;
margin-top:50px; margin-top:50px;
background-color: #eaeaea; /* background-color: #eaeaea; */
padding: 20px;
} }
#addScore{ #addScore{
......
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
<!--内部文章管理--> <!--内部文章管理-->
<div id="privateArtadmin" class="userlist" style="border:1px solid #000;"> <div id="privateArtadmin" class="userlist" style="border:1px solid #000;">
<span id="user_score_List" style="color:#ff9800" >内部文章</span> <span id="user_score_List" style="color:#ff9800" >内部文章</span>
<table class="table tableList"> <table class="table tableList" id="articleList">
<thead> <thead>
</thead> </thead>
<tbody> <tbody>
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
<div id="articleView" class="hide" > <div id="articleView" class="hide" >
<button class="lastStep" onclick="returnToList()"><?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1541063213171" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2135" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M939.880137 487.72513l-782.215258 0 358.804922-318.92975c12.389168-11.011798 13.505595-29.980825 2.492774-42.369993-11.011798-12.386098-29.977755-13.505595-42.367947-2.492774L64.602344 490.13911c-6.407943 5.693676-10.073426 13.858636-10.073426 22.430872s3.665483 16.737196 10.073426 22.430872l411.993309 366.204449c5.717212 5.083785 12.83533 7.580652 19.925818 7.580652 8.274454 0 16.514115-3.403516 22.442128-10.07445 11.011798-12.387122 9.896394-31.357172-2.492774-42.367947L169.687704 548.100196 939.880137 548.100196c16.57449 0 30.011524-13.613042 30.011524-30.187533S956.454628 487.72513 939.880137 487.72513z" p-id="2136" fill="#FF9800"></path></svg></button> <button class="lastStep" onclick="returnToList()"><?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1541063213171" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2135" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M939.880137 487.72513l-782.215258 0 358.804922-318.92975c12.389168-11.011798 13.505595-29.980825 2.492774-42.369993-11.011798-12.386098-29.977755-13.505595-42.367947-2.492774L64.602344 490.13911c-6.407943 5.693676-10.073426 13.858636-10.073426 22.430872s3.665483 16.737196 10.073426 22.430872l411.993309 366.204449c5.717212 5.083785 12.83533 7.580652 19.925818 7.580652 8.274454 0 16.514115-3.403516 22.442128-10.07445 11.011798-12.387122 9.896394-31.357172-2.492774-42.367947L169.687704 548.100196 939.880137 548.100196c16.57449 0 30.011524-13.613042 30.011524-30.187533S956.454628 487.72513 939.880137 487.72513z" p-id="2136" fill="#FF9800"></path></svg></button>
<div id="artTitle"><h1></h1></div> <div id="artTitle"></div>
<div id="authorName"></div> <div id="authorName"></div>
<div id="content"></div> <div id="content"></div>
</div> </div>
...@@ -242,49 +242,57 @@ ...@@ -242,49 +242,57 @@
$("#articleView").addClass("hide"); $("#articleView").addClass("hide");
} }
function getArticle (articleID){ function getArticle (articleID){
console.log('articleID', articleID);
$.ajax({ $.ajax({
url:'/index/', url: '/operator/',
type:'get', type: 'get',
data:{ data: {
"articleID":articleID, "articleID": articleID,
"actiontype": '5',
'csrfmiddlewaretoken': '{{ csrf_token }}' 'csrfmiddlewaretoken': '{{ csrf_token }}'
}, },
success:function(response){ success:function(response){
{#var result = $.parseJSON(response);#} // {#var result = $.parseJSON(response);#}
var result=response; var result=response;
if(result["success"]){
$("#articleList").addClass("hide"); $("#articleList").addClass("hide");
$("#articleView").removeClass("hide"); $("#articleView").removeClass("hide");
var converter = new showdown.Converter(); var converter = new showdown.Converter();
var content = converter.makeHtml(result["content"]); var content = converter.makeHtml(result["content"]);
console.log('content', articleID, content, result["content"]);
$("#content").empty(); $("#content").empty();
$("#content").append(content); $("#content").append(content);
$("#artTitle").empty(); $("#artTitle").empty();
$("#artTitle").append(result["title"]); $("#artTitle").append(result["title"]);
$("#authorName").empty(); $("#authorName").empty();
$("#authorName").append(result["authorname"]); $("#authorName").append(result["authorname"]);
} else {
alert(result["warning"])
}
}, },
error:function (xhr) { error:function (xhr) {
console.error('something went wrong...'); console.error('something went wrong...',xhr);
} }
}) })
} }
function deleteArt(thisbtn){ function deleteArt(thisbtn){
var title = thisbtn.parentElement.firstElementChild.innerHTML; var title = thisbtn.parentElement.parentElement.firstElementChild.firstElementChild.innerHTML;
var res = confirm('确定要删除"'+title+'"吗?该操作不可撤销。')
if(!res) return;
$.ajax({ $.ajax({
url:'/index/', url: '/operator/',
type:'post', type: 'post',
data:{ data: {
"title":title, "title": title,
"actiontype": '6',
'csrfmiddlewaretoken': '{{ csrf_token }}' 'csrfmiddlewaretoken': '{{ csrf_token }}'
}, },
success:function(response){ success:function(response){
if (response["warning"]=="文章删除成功"){ if (response["warning"]=="删除成功"){
thisbtn.parentElement.parentElement.remove(); thisbtn.parentElement.parentElement.remove();
}else{
alert(response["warning"]);
} }
alert(response["warning"]);
}, },
error:function (xhr) { error:function (xhr) {
console.error('something went wrong...'); console.error('something went wrong...');
......
...@@ -328,6 +328,10 @@ def operator(request): ...@@ -328,6 +328,10 @@ def operator(request):
if request.is_ajax(): if request.is_ajax():
# 判断操作类型 # 判断操作类型
actiontype = request.POST.get('actiontype') actiontype = request.POST.get('actiontype')
if request.method == 'POST':
actiontype = request.POST.get('actiontype')
elif request.method == 'GET':
actiontype = request.GET.get('actiontype')
# 创建用户 # 创建用户
if actiontype == '0': if actiontype == '0':
username = request.POST.get('username') username = request.POST.get('username')
...@@ -415,4 +419,36 @@ def operator(request): ...@@ -415,4 +419,36 @@ def operator(request):
except ObjectDoesNotExist: except ObjectDoesNotExist:
message["warning"] = "2" message["warning"] = "2"
return HttpResponse(json.dumps(message), content_type='application/json') return HttpResponse(json.dumps(message), content_type='application/json')
# 查看内部文章
if actiontype == '5':
try:
articleID = request.GET.get('articleID')
arti = Articles.objects.get(articleID=articleID)
message["success"] = True
message["content"]=arti.content
message["title"]=arti.title
authorID = arti.authorID
author = User.objects.get(userID=authorID)
message["authorname"]=author.name
return HttpResponse(json.dumps(message), content_type='application/json')
except ObjectDoesNotExist:
message["success"] = False
message["warning"] = "文章不存在"
return HttpResponse(json.dumps(message), content_type='application/json')
# 查看内部文章
if actiontype == '6':
title = request.POST.get('title')
try:
delrestlt = Articles.objects.filter(title=title).delete()
print("delrestlt", title, delrestlt)
message["warning"] = "删除成功"
return HttpResponse(json.dumps(message), content_type='application/json')
except:
message["warning"]="删除出错"
return HttpResponse(json.dumps(message), content_type='application/json')
return render('admin.html', locals()) return render('admin.html', locals())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment