国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
10KB

  1. <?php
  2. require_once(dirname(__FILE__)."/config.php");
  3. include(DEDEDATA.'/mark/inc_photowatermark_config.php');
  4. ?>
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta charset="utf-8">
  9. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  10. <meta name="viewport" content="user-scalable=no,width=device-width,initial-scale=1.0,maximum-scale=1.0">
  11. <meta name="apple-mobile-web-app-capable" content="yes">
  12. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  13. <meta name="format-detection" content="telephone=no">
  14. <title>插入多图</title>
  15. <link rel="stylesheet" href="../../static/web/font/css/font-awesome.min.css">
  16. <style>body{margin:0;line-height:1.6;font:12px Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;color:#545b62;background:#fff}ul{margin:0;padding:0;list-style:none}input[type=radio],input[type=checkbox]{margin:0;height:auto;outline:none;box-shadow:none;vertical-align:text-top}button+button{margin-left:10px}#wrap{padding:10px}#topbar{padding:10px 0;border-bottom:1px solid #ccc;text-align:right}#topbar button{display:inline-block;padding:.25rem .65rem;line-height:1.6;font-size:12px;color:#fff;background:#1eb867;border-color:#1eb867;border-radius:.5rem;border:0;transition:all .5s;text-align:center}.topbar button+.topbar button{margin-left:10px}#topbar button:focus{background:#006829;border-color:#005b24;box-shadow:0 .125rem .25rem rgba(0,0,0,.075);outline:none}#file_list{display:grid;grid-gap:10px;grid-template-columns:repeat(auto-fill,minmax(160px,1fr));padding-top:10px}#file_list:empty:after{content:'拖拽图片到此处上传'}#file_list li{display:block;position:relative;padding:10px;vertical-align:top;border-radius:.5rem}#file_list li.up-now:after{content:'';display:block;position:absolute;top:0;left:0;width:100%;height:100%;background:rgba(255,255,255,0.8) url(../../static/web/img/loadinglit.gif)center center no-repeat;border-radius:.5rem;z-index:999}#file_list li:hover{background:#f5f5f5}#file_list li .picbox{display:flex;flex:0 0 auto;position:relative;padding-top:90%;width:100%;align-items:center;justify-content:center;overflow:hidden}#file_list li .picbox img{display:block;max-width:100%;max-height:100%;position:absolute;top:50%;left:50%;transform:translateX(-50%) translateY(-50%);border-radius:.5rem}#file_list li .namebox{display:flex;padding:10px;justify-content:center;align-items:flex-start}#file_list li.up-over .picbox:after{position:absolute;bottom:10px;right:0;font-family:'FontAwesome';font-size:18px;color:#1eb867;content:'\f058';z-index:9}#file_list li .tools{display:none;position:absolute;bottom:12px;right:10px;z-index:99}#file_list li:hover .tools{display:block}#file_list li .tools .remove{cursor:pointer}#file_list li .tools .remove:after{font-family:'FontAwesome';font-size:18px;color:#dc3545;content:'\f1f8'}</style>
  17. </head>
  18. <body>
  19. <div id="wrap">
  20. <div id="topbar">
  21. <label><input type="checkbox" name="isWater" id="isWater" <?php if ($photo_markup == '1') echo "checked";?>> 是否水印</label>
  22. <button class="addfile">添加图片</button>
  23. <button class="removeall">清空图片</button>
  24. <button class="upall">全部上传</button>
  25. </div>
  26. <ul id="file_list"></ul>
  27. </div>
  28. <script>
  29. var axupimgs={};
  30. axupimgs.res = [];//存放本地文件的数组
  31. var blobInfo = {file:null}
  32. blobInfo.blob = function(){return this.file;}
  33. var upload_handler = async(blobInfo, succFun, failFun)=>{
  34. var file = blobInfo.blob();
  35. formData = new FormData();
  36. formData.append('upload', file, file.name);
  37. formData.append('format', "json");
  38. if (document.querySelector('#isWater').checked) {
  39. formData.append('needwatermark', 1);
  40. } else {
  41. //formData.append('needwatermark', 0);
  42. }
  43. let res = await fetch('select_images_post.php', {
  44. method: 'POST',
  45. body: formData
  46. });
  47. let data = await res.json();
  48. if (typeof data.msg !== 'undefined' && data.msg !== '') {
  49. alert(data.msg)
  50. return;
  51. }
  52. succFun(data.url);
  53. };
  54. var upload_base_path = axupimgs.images_upload_base_path;
  55. //为列表添加排序
  56. function reSort(){
  57. document.querySelectorAll('#file_list li').forEach((el,i)=>{
  58. el.setAttribute('data-num',i);
  59. });
  60. }
  61. function isFileImage(file) {
  62. return file && file['type'].split('/')[0] === 'image';
  63. }
  64. function addList(files) {
  65. var files_sum = files.length;
  66. var vDom = document.createDocumentFragment();
  67. for (let i=0;i<files_sum;i++) {
  68. let file = files[i];
  69. if (!isFileImage(file)) {
  70. alert("选择非图片文件无法上传")
  71. return;
  72. }
  73. let blobUrl = window.URL.createObjectURL(file)
  74. axupimgs.res.push({file:file,blobUrl:blobUrl,url:''});
  75. let li = document.createElement('li');
  76. li.setAttribute('class','up-no');
  77. li.setAttribute('data-time',file.lastModified);
  78. li.innerHTML='<div class="picbox"><img src="'+blobUrl+'"></div><div class="namebox"><span>'+file.name+'</span></div><div class="tools"><a class="remove"></a></div>';
  79. vDom.appendChild(li);
  80. }
  81. document.querySelector('#file_list').appendChild(vDom);
  82. //reSort();
  83. }
  84. //清空列表
  85. document.querySelector('#topbar .removeall').addEventListener('click',()=>{
  86. axupimgs.res=[]
  87. document.querySelectorAll('#file_list li').forEach((el,i)=>{
  88. el.parentNode.removeChild(el)
  89. });
  90. });
  91. //拖拽添加
  92. document.addEventListener('dragover', (e)=>{
  93. e.stopPropagation();
  94. e.preventDefault();
  95. e.dataTransfer.dropEffect = 'copy';
  96. });
  97. document.addEventListener('drop', (e)=>{
  98. e.stopPropagation();
  99. e.preventDefault();
  100. if (!e.dataTransfer.files){return false;}
  101. var dropfiles = e.dataTransfer.files;
  102. if (!(dropfiles.length>0)){return false;}
  103. var exts='.png,.gif,.jpg,.jpeg'.replace(/(\s)+/g,'').toLowerCase().split(',');
  104. var files=[];
  105. for ( let file of dropfiles ) {
  106. ext = file.name.split('.');
  107. ext = '.'+ext[ext.length-1];
  108. for (let s of exts) {
  109. if (s==ext){
  110. files.push(file);
  111. break;
  112. }
  113. }
  114. }
  115. if (files.length>0){ addList(files) }
  116. });
  117. //添加文件
  118. document.querySelector('#topbar .addfile').addEventListener('click',()=>{
  119. var input = document.createElement('input');
  120. input.setAttribute('type', 'file');
  121. input.setAttribute('multiple', 'multiple');
  122. input.setAttribute('accept', axupimgs.axupimgs_filetype);
  123. input.click();
  124. input.onchange = function() {
  125. var files = this.files;
  126. addList(files);
  127. }
  128. });
  129. var file_i = 0;
  130. function upAllFiles(n){
  131. var len = axupimgs.res.length;
  132. file_i = n;
  133. if (len == n){
  134. file_i=0;
  135. document.querySelector('#topbar .upall').innerText='全部上传';
  136. //返回
  137. axupimgs.res.forEach((v,k)=>{
  138. let addonHTML = `<img src='${v.url}'/>`;
  139. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  140. })
  141. window.close();
  142. return true;
  143. }
  144. if ( axupimgs.res[n].url!='' ){
  145. n++;
  146. upAllFiles(n)
  147. } else {
  148. blobInfo.file=axupimgs.res[n].file;
  149. blobInfo.isWater = document.querySelector('#isWater').checked;
  150. upload_handler(blobInfo,function(url){
  151. if (upload_base_path){
  152. if (upload_base_path.slice(-1)=='/' && url.substr(0,1)=='/' ){
  153. url = upload_base_path + url.slice(1);
  154. }else if (upload_base_path.slice(-1)!='/' && url.substr(0,1)!='/' ){
  155. url = upload_base_path + '/' + url;
  156. } else {
  157. url = upload_base_path + url;
  158. }
  159. }
  160. axupimgs.res[file_i].url = url;
  161. filename = url.split('/').pop();
  162. var li = document.querySelectorAll('#file_list li')[file_i];
  163. li.setAttribute('class','up-over');
  164. li.querySelector('.namebox span').innerText = filename;
  165. n++
  166. upAllFiles(n);
  167. },function(err){
  168. document.querySelector('#topbar .upall').innerText='全部上传';
  169. document.querySelectorAll('#file_list li.up-now').forEach((el,i)=>{
  170. el.setAttribute('class','up-no');
  171. });
  172. alert(err);
  173. });
  174. }
  175. }
  176. document.querySelector('#topbar .upall').addEventListener('click',(e)=>{
  177. if (e.target.innerText!='全部上传'){return false;}
  178. if (axupimgs.res.length>0){
  179. document.querySelectorAll('#file_list li.up-no').forEach((el,i)=>{
  180. el.classList ? el.classList.add('up-now') : el.className+=' up-now';
  181. });
  182. e.target.innerText='上传中';
  183. upAllFiles(0);
  184. }
  185. });
  186. var observ_flist = new MutationObserver( (muList,observe)=>{
  187. if (muList[0].addedNodes.length>0){
  188. muList[0].addedNodes.forEach((el)=>{
  189. el.querySelector('.remove').addEventListener('click',(e)=>{
  190. var li = e.target.parentNode.parentNode;
  191. var n = li.getAttribute('data-num');
  192. var el = document.querySelectorAll('#file_list li')[n];
  193. el.parentNode.removeChild(el);
  194. axupimgs.res.splice(n,1);
  195. });
  196. });
  197. }
  198. reSort();
  199. });
  200. observ_flist.observe(document.querySelector('#file_list'),{childList:true});
  201. </script>
  202. </body>
  203. </html>