Skip to content

Commit

Permalink
修改上传图片后的样式
Browse files Browse the repository at this point in the history
  • Loading branch information
livisky committed Feb 18, 2017
1 parent e1682c7 commit e5c0844
Showing 1 changed file with 136 additions and 134 deletions.
270 changes: 136 additions & 134 deletions www/static/admin/js/admin/content.js
Original file line number Diff line number Diff line change
@@ -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': {
Expand All @@ -188,4 +190,4 @@
// 表情
editor.create();

})
})

0 comments on commit e5c0844

Please sign in to comment.