From e5c084417dd2cf01f6c2fbc9c74cb78f29cfc9c9 Mon Sep 17 00:00:00 2001 From: livisky <262248861@qq.com> Date: Sat, 18 Feb 2017 16:20:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=90=8E=E7=9A=84=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/static/admin/js/admin/content.js | 270 ++++++++++++++------------- 1 file changed, 136 insertions(+), 134 deletions(-) diff --git a/www/static/admin/js/admin/content.js b/www/static/admin/js/admin/content.js index 38344c7..4c4d518 100644 --- a/www/static/admin/js/admin/content.js +++ b/www/static/admin/js/admin/content.js @@ -1,181 +1,183 @@ /** * Created by livi on 16/4/19. */ - $('.add-img-btn2 input[type="file"]').on('change', function () { - var $this = $(this); - var addimgBtn=$this.parent(); +$('.add-img-btn2 input[type="file"]').on('change', function() { + var $this = $(this); + var addimgBtn = $this.parent(); - if($this.val()){ - $this.upload({ - url: '/admin/content/uploadfile', - data:{__CSRF__:G_csrf}, - success: function (result) { - if (result) { - $("#editor").html(result.articlehtml); - var ainfo=result.ainfo||{}; - $(".title").val(ainfo.title); - $(".author").val(ainfo.author); - $(".keywords").val(ainfo.keywords); - $(".abstract").val(encodeHTMLContent(ainfo.abstract)); + if ($this.val()) { + $this.upload({ + url: '/admin/content/uploadfile', + data: { __CSRF__: G_csrf }, + success: function(result) { + if (result) { + $("#editor").html(result.articlehtml); + var ainfo = result.ainfo || {}; + $(".title").val(ainfo.title); + $(".author").val(ainfo.author); + $(".keywords").val(ainfo.keywords); + $(".abstract").val(encodeHTMLContent(ainfo.abstract)); - var pic =ainfo.thumbnail; - var totop=ainfo.totop; - var torecom=ainfo.torecom; - var topicrecom=ainfo.topicrecom; + var pic = ainfo.thumbnail; + var totop = ainfo.totop; + var torecom = ainfo.torecom; + var topicrecom = ainfo.topicrecom; - function tocheck(el,item){ - if(item===1){ - $(el).attr("checked",true); - } - } - function encodeHTMLContent(str) { - if(str){ - return str.replace(/"/g, '"').replace(/'/g,"'s"); - } - } - tocheck($("#totop"),totop); - tocheck($("#torecom"),torecom); - tocheck($("#topicrecom"),topicrecom); - if(result.errno>=0){ - alert(result.errmsg) + function tocheck(el, item) { + if (item === 1) { + $(el).attr("checked", true); } + } - } else { + function encodeHTMLContent(str) { + if (str) { + return str.replace(/"/g, '"').replace(/'/g, "'s"); + } + } + tocheck($("#totop"), totop); + tocheck($("#torecom"), torecom); + tocheck($("#topicrecom"), topicrecom); + if (result.errno >= 0) { alert(result.errmsg) } - }, - error: function (code, xhr, status, error) { - console.log(error ? ('上传失败: ' + error) : "上传失败"); + + } else { + alert(result.errmsg) } - }); - } - }); + }, + error: function(code, xhr, status, error) { + console.log(error ? ('上传失败: ' + error) : "上传失败"); + } + }); + } +}); - //上传缩略图 - $('.add-img-btn input[type="file"]').on('change', function () { - var $this = $(this); - var addimgBtn=$this.parent(); +//上传缩略图 +$('.add-img-btn input[type="file"]').on('change', function() { + var $this = $(this); + var addimgBtn = $this.parent(); - if($this.val()){ - $this.upload({ - url: '/admin/content/upload', - data:{__CSRF__:G_csrf}, - success: function (result) { - if (result) { - $("#picUrl").val(result.path); - $('.show-img-upload .add-img-btn').css("background-image",'url('+result.path+')') - } else { - console.log('上传失败'); - } - }, - error: function (code, xhr, status, error) { - console.log(error ? ('上传失败: ' + error) : "上传失败"); + if ($this.val()) { + $this.upload({ + url: '/admin/content/upload', + data: { __CSRF__: G_csrf }, + success: function(result) { + if (result) { + $("#picUrl").val(result.path); + $('.show-img-upload .add-img-btn').css("background-image", 'url(' + result.path + ')') + .css("background-size", 'cover'); + } else { + console.log('上传失败'); } - }); - } - }); + }, + error: function(code, xhr, status, error) { + console.log(error ? ('上传失败: ' + error) : "上传失败"); + } + }); + } +}); - //预览/发布文章 - $(function(){ - //预览文章 - $("#previewArticle").on('click',function(){ - var pid=$(this).attr("pid"); - if(pid===""){ - dosubmit('/admin/content/doadd',0,function(json){ - if(json.errno===0){ - $("#previewArticle").attr("pid",json.data.id); - $("#addArticle").attr("pid",json.data.id); - window.open("/preview/"+json.data.id,"_blank"); +//预览/发布文章 +$(function() { + //预览文章 + $("#previewArticle").on('click', function() { + var pid = $(this).attr("pid"); + if (pid === "") { + dosubmit('/admin/content/doadd', 0, function(json) { + if (json.errno === 0) { + $("#previewArticle").attr("pid", json.data.id); + $("#addArticle").attr("pid", json.data.id); + window.open("/preview/" + json.data.id, "_blank"); } }); - }else{ + } else { //更新文章状态 - dosubmit('/admin/content/doadd/',0,function(json){ - if(json.errno===0){ - window.open("/preview/"+pid,"_blank"); + dosubmit('/admin/content/doadd/', 0, function(json) { + if (json.errno === 0) { + window.open("/preview/" + pid, "_blank"); } }) } }) //发布文章 - $("#addArticle").on('click',function(){ - var pid=$(this).attr("pid"); - if(pid===""){ + $("#addArticle").on('click', function() { + var pid = $(this).attr("pid"); + if (pid === "") { //直接发布 - dosubmit('/admin/content/doadd',1,function(json){ - if(json.errno===0){ + dosubmit('/admin/content/doadd', 1, function(json) { + if (json.errno === 0) { alert("发布成功!"); - $("#previewArticle").attr("pid",json.data.id); - $("#addArticle").attr("pid",json.data.id); - window.location.href='/admin/content'; - }else{ + $("#previewArticle").attr("pid", json.data.id); + $("#addArticle").attr("pid", json.data.id); + window.location.href = '/admin/content'; + } else { alert(json.errmsg) } }) - }else{ + } else { //更新文章状态 - dosubmit('/admin/content/doadd/',1,function(json){ - if(json.errno===0){ + dosubmit('/admin/content/doadd/', 1, function(json) { + if (json.errno === 0) { alert("发布成功!"); - window.location.href='/admin/content'; - }else{ + window.location.href = '/admin/content'; + } else { alert(json.errmsg) } }) } }) //公用方法 - var dosubmit=function(httpUrl,ispublished,callback){ - var totopVal=$("#totop").is(':checked') ? 1 : 0; - var torecomVal=$("#torecom").is(':checked') ? 1 : 0; - var topicrecomVal=$("#topicrecom").is(':checked') ? 1 : 0; - var topicrecomVal=$("#topicrecom").is(':checked') ? 1 : 0; - var allowcommentVal=$("#allowcomment").is(':checked') ? 1 : 0; - var flag_aVal=$("#flag_a").is(':checked') ? 1 : 0; - var flag_bVal=$("#flag_b").is(':checked') ? 1 : 0; - var flag_cVal=$("#flag_c").is(':checked') ? 1 : 0; - var flag_dVal=$("#flag_d").is(':checked') ? 1 : 0; - var html = editor.$txt.html(); - var content = $.trim(html); - var newData={ - id:$("#previewArticle").attr("pid"), - title:$(".title").val(), - abstract:$("#abstract").val(), - content:content, - picurl:$("#picUrl").val(), - author:$("#author").val(), - createtime:new Date(), - totop:totopVal, - torecom:torecomVal, - topicrecom:topicrecomVal, - flag_a:flag_aVal, - flag_b:flag_bVal, - flag_c:flag_cVal, - flag_d:flag_dVal, - tag:$("#tagselect").val(), - item:$("#itemselect").val(), - keywords:$("#keywords").val(), - from:$(".from").val(), - allowcomment:allowcommentVal, - ispublished:ispublished, - __CSRF__:G_csrf + var dosubmit = function(httpUrl, ispublished, callback) { + var totopVal = $("#totop").is(':checked') ? 1 : 0; + var torecomVal = $("#torecom").is(':checked') ? 1 : 0; + var topicrecomVal = $("#topicrecom").is(':checked') ? 1 : 0; + var topicrecomVal = $("#topicrecom").is(':checked') ? 1 : 0; + var allowcommentVal = $("#allowcomment").is(':checked') ? 1 : 0; + var flag_aVal = $("#flag_a").is(':checked') ? 1 : 0; + var flag_bVal = $("#flag_b").is(':checked') ? 1 : 0; + var flag_cVal = $("#flag_c").is(':checked') ? 1 : 0; + var flag_dVal = $("#flag_d").is(':checked') ? 1 : 0; + var html = editor.$txt.html(); + var content = $.trim(html); + var newData = { + id: $("#previewArticle").attr("pid"), + title: $(".title").val(), + abstract: $("#abstract").val(), + content: content, + picurl: $("#picUrl").val(), + author: $("#author").val(), + createtime: new Date(), + totop: totopVal, + torecom: torecomVal, + topicrecom: topicrecomVal, + flag_a: flag_aVal, + flag_b: flag_bVal, + flag_c: flag_cVal, + flag_d: flag_dVal, + tag: $("#tagselect").val(), + item: $("#itemselect").val(), + keywords: $("#keywords").val(), + from: $(".from").val(), + allowcomment: allowcommentVal, + ispublished: ispublished, + __CSRF__: G_csrf - } - $.ajax({ - url:httpUrl, - data:newData, - type:'POST', - success:callback - }) } + $.ajax({ + url: httpUrl, + data: newData, + type: 'POST', + success: callback + }) + } var editor = new wangEditor('editor'); editor.config.uploadParams = { - __CSRF__:G_csrf + __CSRF__: G_csrf }; editor.config.emotions = { 'default': { @@ -188,4 +190,4 @@ // 表情 editor.create(); -}) +}) \ No newline at end of file