diff --git a/src/dede/album_add.php b/src/dede/album_add.php index cc56f09b..fab3e577 100755 --- a/src/dede/album_add.php +++ b/src/dede/album_add.php @@ -63,6 +63,7 @@ else if($dopost=='save') if(!isset($formhtml)) $formhtml = 0; if(!isset($formzip)) $formzip = 0; if(!isset($ddisfirst)) $ddisfirst = 0; + if(!isset($albums)) $albums = ""; if(!isset($delzip)) $delzip = 0; if(empty($click)) $click = ($cfg_arc_click=='-1' ? mt_rand(50, 200) : $cfg_arc_click); @@ -117,7 +118,21 @@ else if($dopost=='save') $ddisremote = 0; } $litpic = GetDDImage('none',$picname,$ddisremote); + // 处理新的缩略图上传 + if ($litpic_b64 != "") { + $data = explode( ',', $litpic_b64 ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + // 加水印 + WaterImg($cfg_basedir.$fullUrl, 'up'); + $litpic = $fullUrl; + } //使用第一张图作为缩略图 if($ddisfirst==1 && $litpic=='') { @@ -126,7 +141,21 @@ else if($dopost=='save') $litpic = GetDDImage('ddfirst', $imgurl1, $isrm); } } - + // 处理新的缩略图上传 + if ($litpic_b64 != "") { + $data = explode( ',', $litpic_b64 ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + + // 加水印 + WaterImg($cfg_basedir.$fullUrl, 'up'); + $litpic = $fullUrl; + } //生成文档ID $arcID = GetIndexKey($arcrank,$typeid,$sortrank,$channelid,$senddate,$adminid); @@ -250,6 +279,28 @@ else if($dopost=='save') } } + if ($albums !== "") { + $albumsArr = json_decode(stripslashes( $albums), true); + + for ($i=0; $i <= count($albumsArr) - 1; $i++) { + $album = $albumsArr[$i]; + $data = explode( ',', $album['img'] ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + $info = ''; + $imginfos = GetImageSize($cfg_basedir.$fullUrl, $info); + $v = $fullUrl; + $imginfo = !empty($album['txt']) ? $album['txt'] : ''; + $imgurls .= "{dede:img ddimg='$v' text='$imginfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $v {/dede:img}\r\n"; + } + + } + $imgurls = addslashes($imgurls); //处理body字段自动摘要、自动提取缩略图等 diff --git a/src/dede/album_edit.php b/src/dede/album_edit.php index bbddaaa3..a8f1b8ef 100755 --- a/src/dede/album_edit.php +++ b/src/dede/album_edit.php @@ -73,6 +73,7 @@ else if($dopost=='save') if(!isset($dellink)) $dellink = 0; if(!isset($autolitpic)) $autolitpic = 0; if(!isset($formhtml)) $formhtml = 0; + if(!isset($albums)) $albums = ""; if(!isset($formzip)) $formzip = 0; if(!isset($ddisfirst)) $ddisfirst = 0; if(!isset($delzip)) $delzip = 0; @@ -130,6 +131,21 @@ else if($dopost=='save') $ddisremote = 0; } $litpic = GetDDImage('none', $picname, $ddisremote); + // 处理新的缩略图上传 + if ($litpic_b64 != "") { + $data = explode( ',', $litpic_b64 ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + + // 加水印 + WaterImg($cfg_basedir.$fullUrl, 'up'); + $litpic = $fullUrl; + } //分析body里的内容 $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext'); @@ -329,6 +345,30 @@ else if($dopost=='save') $imgurls .= "{dede:img ddimg='$litpicname' text='$imginfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $v {/dede:img}\r\n"; } } + + if ($albums !== "") { + $albumsArr = json_decode(stripslashes( $albums), true); + + // var_dump($albumsArr);exit; + + for ($i=0; $i <= count($albumsArr) - 1; $i++) { + $album = $albumsArr[$i]; + $data = explode( ',', $album['img'] ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + $info = ''; + $imginfos = GetImageSize($cfg_basedir.$fullUrl, $info); + $v = $fullUrl; + $imginfo = !empty($album['txt']) ? $album['txt'] : ''; + $imgurls .= "{dede:img ddimg='$v' text='$imginfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $v {/dede:img}\r\n"; + } + + } $imgurls = addslashes($imgurls); diff --git a/src/dede/archives_add.php b/src/dede/archives_add.php index fdedefbd..d20c9ad6 100755 --- a/src/dede/archives_add.php +++ b/src/dede/archives_add.php @@ -57,6 +57,7 @@ else if($dopost=='save') $flag = isset($flags) ? join(',',$flags) : ''; $notpost = isset($notpost) && $notpost == 1 ? 1: 0; if(empty($click)) $click = ($cfg_arc_click=='-1' ? mt_rand(50, 200) : $cfg_arc_click); + if(empty($litpic_b64)) $litpic_b64 = ''; if(empty($typeid2)) $typeid2 = 0; if(!isset($autokey)) $autokey = 0; @@ -117,6 +118,21 @@ else if($dopost=='save') $ddisremote = 0; } $litpic = GetDDImage('none',$picname,$ddisremote); + // 处理新的缩略图上传 + if ($litpic_b64 != "") { + $data = explode( ',', $litpic_b64 ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + + // 加水印 + WaterImg($cfg_basedir.$fullUrl, 'up'); + $litpic = $fullUrl; + } //生成文档ID $arcID = GetIndexKey($arcrank,$typeid,$sortrank,$channelid,$senddate,$adminid); diff --git a/src/dede/archives_edit.php b/src/dede/archives_edit.php index 3bbad3b4..5caedda4 100755 --- a/src/dede/archives_edit.php +++ b/src/dede/archives_edit.php @@ -59,6 +59,7 @@ else if($dopost=='save') require_once(DEDEINC.'/oxwindow.class.php'); $flag = isset($flags) ? join(',',$flags) : ''; $notpost = isset($notpost) && $notpost == 1 ? 1: 0; + if(empty($litpic_b64)) $litpic_b64 = ''; if(empty($typeid2)) $typeid2 = 0; if(!isset($autokey)) $autokey = 0; @@ -117,6 +118,22 @@ else if($dopost=='save') $litpic = GetDDImage('none', $picname, $ddisremote); + // 处理新的缩略图上传 + if ($litpic_b64 != "") { + $data = explode( ',', $litpic_b64 ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + + // 加水印 + WaterImg($cfg_basedir.$fullUrl, 'up'); + $litpic = $fullUrl; + } + //分析处理附加表数据 $inadd_f = ''; $inadd_v = ''; diff --git a/src/dede/archives_sg_add.php b/src/dede/archives_sg_add.php index e7e93105..99c42af1 100755 --- a/src/dede/archives_sg_add.php +++ b/src/dede/archives_sg_add.php @@ -77,6 +77,7 @@ else if($dopost=='save') if(empty($flags)) $flag = ''; else $flag = join(',', $flags); $senddate = time(); + if(empty($litpic_b64)) $litpic_b64 = ''; $title = cn_substrR($title,$cfg_title_maxlen); $isremote = (empty($isremote)? 0 : $isremote); $serviterm=empty($serviterm)? "" : $serviterm; @@ -88,7 +89,21 @@ else if($dopost=='save') if(empty($ddisremote)) $ddisremote = 0; $litpic = GetDDImage('none', $picname, $ddisremote); + // 处理新的缩略图上传 + if ($litpic_b64 != "") { + $data = explode( ',', $litpic_b64 ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + // 加水印 + WaterImg($cfg_basedir.$fullUrl, 'up'); + $litpic = $fullUrl; + } //生成文档ID $arcID = GetIndexKey($arcrank, $typeid, $senddate, $channelid, $senddate, $adminid); diff --git a/src/dede/archives_sg_edit.php b/src/dede/archives_sg_edit.php index aa5f9882..8b8ad582 100755 --- a/src/dede/archives_sg_edit.php +++ b/src/dede/archives_sg_edit.php @@ -79,6 +79,7 @@ else if($dopost=='save') $title = cn_substrR($title, $cfg_title_maxlen); $isremote = (empty($isremote)? 0 : $isremote); $serviterm=empty($serviterm)? "" : $serviterm; + if(empty($litpic_b64)) $litpic_b64 = ''; if(!TestPurview('a_Check,a_AccCheck,a_MyCheck')) $arcrank = -1; $adminid = $cuserLogin->getUserID(); @@ -86,7 +87,21 @@ else if($dopost=='save') //处理上传的缩略图 if(empty($ddisremote)) $ddisremote = 0; $litpic = GetDDImage('none', $picname, $ddisremote); - + // 处理新的缩略图上传 + if ($litpic_b64 != "") { + $data = explode( ',', $litpic_b64 ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + + // 加水印 + WaterImg($cfg_basedir.$fullUrl, 'up'); + $litpic = $fullUrl; + } //分析处理附加表数据 $inadd_f = ''; $inadd_v = ''; diff --git a/src/dede/article_add.php b/src/dede/article_add.php index c4746db6..840ce86c 100755 --- a/src/dede/article_add.php +++ b/src/dede/article_add.php @@ -16,6 +16,7 @@ if($dopost!='save') ClearMyAddon(); $channelid = empty($channelid) ? 0 : intval($channelid); $cid = empty($cid) ? 0 : intval($cid); + if(empty($litpic_b64)) $litpic_b64 = ''; if(empty($geturl)) $geturl = ''; @@ -123,6 +124,21 @@ else if($dopost=='save') } $litpic = GetDDImage('none', $picname, $ddisremote); + // 处理新的缩略图上传 + if ($litpic_b64 != "") { + $data = explode( ',', $litpic_b64 ); + $ntime = time(); + $savepath = $ddcfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime); + CreateDir($savepath); + $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999)); + $fullUrl = $fullUrl.".png"; + + file_put_contents($cfg_basedir.$fullUrl, base64_decode( $data[ 1 ] )); + + // 加水印 + WaterImg($cfg_basedir.$fullUrl, 'up'); + $litpic = $fullUrl; + } //生成文档ID $arcID = GetIndexKey($arcrank,$typeid,$sortrank,$channelid,$senddate,$adminid); diff --git a/src/dede/content_list.php b/src/dede/content_list.php index 7a6bb5b5..3ee7d661 100755 --- a/src/dede/content_list.php +++ b/src/dede/content_list.php @@ -101,13 +101,7 @@ if(empty($totalresult) && empty($keyword) && empty($orderby) && empty($flag)) } // 缓存处理 $sql = "SELECT COUNT(*) AS dd FROM `#@__arctiny` $tinyQuery "; - $cachekey = md5($sql); - $arr = GetCache('listcache', $cachekey); - if (empty($arr)) - { - $arr = $dsql->GetOne($sql); - SetCache('listcache', $cachekey, $arr); - } + $arr = $dsql->GetOne($sql); $totalresult = $arr['dd']; } diff --git a/src/dede/css/albumupload.css b/src/dede/css/albumupload.css new file mode 100644 index 00000000..50956eb3 --- /dev/null +++ b/src/dede/css/albumupload.css @@ -0,0 +1,162 @@ +div.flash +{ + width:375px; + -moz-border-radius-topleft:5px; + -webkit-border-top-left-radius:5px; + -moz-border-radius-topright:5px; + -webkit-border-top-right-radius:5px; + -moz-border-radius-bottomleft:5px; + -webkit-border-bottom-left-radius:5px; + -moz-border-radius-bottomright:5px; + -webkit-border-bottom-right-radius:5px; + border-color:#D9E4FF; + margin:10px 5px; +} + +#btnSubmit +{ + margin:0 0 0 155px; +} + +.progressWrapper +{ + width:357px; + overflow:hidden; +} + +.progressContainer +{ + border:solid 1px #E8E8E8; + background-color:#F7F7F7; + overflow:hidden; + margin:5px; + padding:4px; +} + +.message +{ + border:solid 1px #FD9; + background-color:#FFC; + overflow:hidden; + margin:1em 0; + padding:10px 20px; +} + +.red +{ + border:solid 1px #B50000; + background-color:#FFEBEB; +} + +.green +{ + border:solid 1px #DDF0DD; + background-color:#EBFFEB; +} + +.blue +{ + border:solid 1px #CEE2F2; + background-color:#F0F5FF; +} + +.progressName +{ + font-size:8pt; + font-weight:700; + color:#555; + width:323px; + height:14px; + text-align:left; + white-space:nowrap; + overflow:hidden; +} + +.progressBarInProgress,.progressBarComplete,.progressBarError +{ + font-size:0; + width:0; + height:2px; + background-color:blue; + margin-top:2px; +} + +.progressBarComplete +{ + width:100%; + background-color:green; + visibility:hidden; +} + +.progressBarError +{ + width:100%; + background-color:red; + visibility:hidden; +} + +.progressBarStatus +{ + margin-top:2px; + width:337px; + font-size:7pt; + font-family:Arial; + text-align:left; + white-space:nowrap; +} + +a.progressCancel +{ + font-size:0; + display:block; + height:14px; + width:14px; + background-image:url(../images/cancelbutton.gif); + background-repeat:no-repeat; + background-position:-14px 0; + float:right; +} + +a.progressCancel:hover +{ + background-position:0 0; +} + +.swfupload +{ + vertical-align:top; +} + +.albCt +{ + float:left; + width:244px; + height:150px; + margin-right:10px; + margin-bottom:10px; + border:1px dashed #AAD381; + background:#FAFFEE; + text-align:center; + padding:3px; +} + +.albEdit +{ + height:180px; +} + +.picinfo +{ + height:30px; + line-height:30px; + margin:10px 0; +} + +.thumbnails img,.thumbnailsEdit img +{ + margin:5px; +} + +.albCt img { + height: 100px!important; +} \ No newline at end of file diff --git a/src/dede/css/swfupload.css b/src/dede/css/swfupload.css deleted file mode 100755 index 5739a9f2..00000000 --- a/src/dede/css/swfupload.css +++ /dev/null @@ -1 +0,0 @@ -div.flash{width:375px;margin:10px 5px;border-color:#D9E4FF;-moz-border-radius-topleft:5px;-webkit-border-top-left-radius:5px;-moz-border-radius-topright:5px;-webkit-border-top-right-radius:5px;-moz-border-radius-bottomleft:5px;-webkit-border-bottom-left-radius:5px;-moz-border-radius-bottomright:5px;-webkit-border-bottom-right-radius:5px;}#btnSubmit{margin:0 0 0 155px;}.progressWrapper{width:357px;overflow:hidden;}.progressContainer{margin:5px;padding:4px;border:solid 1px #E8E8E8;background-color:#F7F7F7;overflow:hidden;}.message{margin:1em 0;padding:10px 20px;border:solid 1px #FFDD99;background-color:#FFFFCC;overflow:hidden;}.red{border:solid 1px #B50000;background-color:#FFEBEB;}.green{border:solid 1px #DDF0DD;background-color:#EBFFEB;}.blue{border:solid 1px #CEE2F2;background-color:#F0F5FF;}.progressName{font-size:8pt;font-weight:700;color:#555;width:323px;height:14px;text-align:left;white-space:nowrap;overflow:hidden;}.progressBarInProgress,.progressBarComplete,.progressBarError{font-size:0;width:0%;height:2px;background-color:blue;margin-top:2px;}.progressBarComplete{width:100%;background-color:green;visibility:hidden;}.progressBarError{width:100%;background-color:red;visibility:hidden;}.progressBarStatus{margin-top:2px;width:337px;font-size:7pt;font-family:Arial;text-align:left;white-space:nowrap;}a.progressCancel{font-size:0;display:block;height:14px;width:14px;background-image:url(../images/cancelbutton.gif);background-repeat:no-repeat;background-position:-14px 0px;float:right;}a.progressCancel:hover{background-position:0px 0px;}.swfupload{vertical-align:top;}.thumbnails img{margin:5px;}.thumbnailsEdit img{margin:5px;}.albCt{float:left;width:244px;height:150px;margin-right:10px;margin-bottom:10px;padding:3px;border:1px dashed #AAD381;background:#FAFFEE;text-align:center;}.albEdit{height:180px;}.picinfo{margin:10px 0 10px 0;height:30px;line-height:30px;} \ No newline at end of file diff --git a/src/dede/dialog/select_images.php b/src/dede/dialog/select_images.php index 69669e23..a00d27b3 100755 --- a/src/dede/dialog/select_images.php +++ b/src/dede/dialog/select_images.php @@ -114,11 +114,17 @@ function ReturnImg(reimg) window.opener.document.getElementById('div').style.height = '100px'; } else - window.opener.document.getElementById('div').style.backgroundImage = "url("+reimg+")"; + window.opener.document.getElementById('div').style.backgroundImage = "url("+reimg+")"; + } else if(window.opener.document.getElementById('')){ window.opener.document.getElementById('').src = reimg; - } + } + // 适配新的缩略图 + if (window.opener.document.getElementById('litPic')) + { + window.opener.document.getElementById('litPic').src = reimg; + } if(document.all) window.opener=true; } diff --git a/src/dede/js/album.js b/src/dede/js/album.js index 732feca7..d4103a9a 100755 --- a/src/dede/js/album.js +++ b/src/dede/js/album.js @@ -8,16 +8,30 @@ * @link http://www.dedecms.com */ -function checkSubmitAlb(){ - if(document.form1.title.value==''){ - alert("档案标题不能为空!"); + +function checkSubmitAlb() { + if (document.form1.title.value == '') { + alert("档案标题不能为空!"); return false; } - if(document.form1.typeid.value==0){ + if (document.form1.typeid.value == 0) { alert("请选择档案的主类别!"); return false; } document.form1.imagebody.value = $Obj('copyhtml').innerHTML; + + if ($("#thumbnails .albCt").length > 0) { + // 这里从thumbnails中取出图片元素信息 + $("#thumbnails .albCt").each(function(){ + albums.push({ + "img" : $(this).find("img").attr("src"), + "txt" : $(this).find("input").val() + }) + }) + } + + $("#albums").val(JSON.stringify(albums)); + return true; } @@ -44,7 +58,7 @@ function showZipField(formitem,zipid,upid){ $Obj(zipid).style.display = 'block'; $Obj(upid).style.display = 'none'; //$Obj('handfield').style.display = 'none'; - $Obj('formhtml').checked = false; + // $Obj('formhtml').checked = false; $Obj('copyhtml').innerHTML = ''; } else { $Obj(zipid).style.display = 'none'; diff --git a/src/dede/js/main.js b/src/dede/js/main.js index a2fe39ca..c653e890 100755 --- a/src/dede/js/main.js +++ b/src/dede/js/main.js @@ -1,5 +1,3 @@ - \ No newline at end of file +// 生成一个随机ID +function guid() { + function S4() { + return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); + } + return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); +} + +// 显示对话框,动态创建modal并显示,退出自动销毁窗体 +// args是以下结构体 +/* +args = { + title : "", // 标题,默认是MuEMS + footer : "", // 底部按钮,可以自定义按钮 + noClose : false, // 是否显示右上角关闭按钮,默认显示 +} +*/ +// 函数会返回一个modalID,通过这个ID可自已定义一些方法 +// 这里用到了一个展开语法 +// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax +function ShowMsg(content, ...args) { + title = "DedeCMS"; + if (typeof content == "undefined") content = ""; + modalID = guid(); + var footer = ``; + var noClose = false; + + if (args.length == 1) { + // 存在args参数 + if (typeof args[0].title !== 'undefined' && args[0].title != "") { + title = args[0].title; + } + if (typeof args[0].footer !== 'undefined' && args[0].footer != "") { + footer = args[0].footer; + } + if (typeof args[0].noClose !== 'undefined' && args[0].noClose == true) { + noClose = true; + } + } + + footer = footer.replace("~modalID~", modalID); + content = content.replace("~modalID~", modalID); + + var modal = `
`; + $("body").append(modal) + $("#GKModal" + modalID).modal({ + backdrop: 'static', + show: true + }); + $("#GKModal" + modalID).on('hidden.bs.modal', function (e) { + $("#GKModal" + modalID).remove(); + }) + return modalID; +} + +// 隐藏并销毁modal +function CloseModal(modalID) { + $("#" + modalID).modal('hide'); + $("#" + modalID).on('hidden.bs.modal', function (e) { + if ($("#" + modalID).length > 0) { + $("#" + modalID).remove(); + } + }) +} + +// 获取缩略图 +var litpicImgSrc = ""; +var litpicImg = ""; +var currentCID = 0; +var mdlCropperID = ""; +var pubAt = 0; +var optCropper = { + preview: ".pv", + crop: function (e) { + $("#cropWidth").text(Math.round(e.detail.height)); + $("#cropHeight").text(Math.round(e.detail.width)); + var dataUrl = $(this).cropper("getCroppedCanvas") + .toDataURL(); + litpicImg = dataUrl; + $("#litPic").attr("src", litpicImg); + $("#litpic_b64").val(litpicImg); + }, + aspectRatio: 4 / 3, + // 拖动截取缩略图后,截取的缩略图更新到imageItems中 + cropend: function (data) { + // 这里的ID要单独取出来 + var dataUrl = $(this).cropper("getCroppedCanvas") + .toDataURL(); + litpicImg = dataUrl; + $("#litPic").attr("src", litpicImg); + $("#litpic_b64").val(litpicImg); + } +} + +var cropperAspectRatio = { + 0: 16 / 9, + 1: 4 / 3, + 2: 1 / 1, + 3: 2 / 3, + 4: NaN, +} + +function setAspectRatio(ar) { + var opts = optCropper; + opts.aspectRatio = cropperAspectRatio[ar]; + $("#cropImg" + mdlCropperID).cropper('destroy').cropper(opts); +} + +function useDefault(modalID) { + $("#litpic_b64").val(litpicImgSrc); + $("#litPic").attr("src", litpicImgSrc); + CloseModal('GKModal' + modalID); +} + +$(document).ready(function () { + + $("#btnClearAll").click(function (event) { + litpicImgSrc = ""; + litpicImg = ""; + $("#litpic_b64").val(litpicImg); + $("#litPic").attr("src", "../static/defaultpic.gif"); + }) + + // 添加图片 + $("#iptAddImages").change(function (event) { + var files = event.target.files; + for (var i = 0, f; f = files[i]; i++) { + // 如果不是图片忽略 + if (!f.type.match('image.*')) { + continue; + } + + // 将图片渲染到浏览器 + var reader = new FileReader(); + reader.onload = (function (theFile) { + return function (e) { + litpicImgSrc = e.target.result; + SetThumb(litpicImgSrc); + }; + })(f); + reader.readAsDataURL(f); + } + $("#iptAddImages").val(""); + }); + + // 截取缩略图 + function SetThumb(srcURL) { + var footer = + ""; + var optButton = `宽度:px,高度:px
' + optButton + '