国内流行的内容管理系统(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.

214 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. <style>
  16. body{margin:0;line-height:1.5;font:12px Helvetica Neue,Helvetica,PingFang SC,Tahoma,Arial,sans-serif;color:#424b51;background:#fff}
  17. ul{margin:0;padding:0;list-style:none}
  18. button+button{margin-left:10px}
  19. #wrap{padding:10px}
  20. #topbar{padding:10px 0;border-bottom:1px solid #ccc;text-align:right}
  21. #topbar button{display:inline-block;border:0;padding:.25rem .5rem;line-height:1.5;font-size:12px;color:#fff;background:#dc3545color:#dc3545;border-color:color:#dc3545;border-radius:.25rem;transition:all .6s;text-align:center}
  22. .topbar button+.topbar button{margin-left:10px}
  23. #topbar button:focus{background:#006829;border-color:#005b24;box-shadow:0 0 0 0.2rem rgba(38,159,86,.5);outline:none}
  24. #file_list{display:grid;grid-gap:10px;grid-template-columns:repeat(auto-fill,minmax(160px,1fr));padding-top:10px}
  25. #file_list:empty:after{content:'可以直接拖拽文件到这里。'}
  26. #file_list li{position:relative;display:block;vertical-align:top;padding:10px;border-radius:.25rem}
  27. #file_list li.up-now:after{content:'';position:absolute;top:0;left:0;display:block;width:100%;height:100%;background:rgba(255,255,255,0.8) url(loading.gif) center center no-repeat;border-radius:.25rem;z-index:999}
  28. #file_list li:hover{background:#f2f2f2}
  29. #file_list li .picbox{display:flex;flex:0 0 auto;justify-content:center;overflow:hidden;position:relative;width:100%;padding-top:90%;align-items:center}
  30. #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:.25rem}
  31. #file_list li .namebox{padding:10px;display:flex;justify-content:center;align-items:flex-start}
  32. #file_list li.up-over .picbox:after{content:url(data:image/svg+xml;%20charset=utf8,%3Csvg%20viewBox%3D%220%200%201024%201024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%3E%3Cpath%20d%3D%22M512%200C229.376%200%200%20229.376%200%20512s229.376%20512%20512%20512%20512-229.376%20512-512S794.624%200%20512%200z%22%20fill%3D%22%234AC711%22%3E%3C%2Fpath%3E%3Cpath%20d%3D%22M855.552%20394.752l-358.4%20358.4a50.9952%2050.9952%200%200%201-72.192%200l-204.8-204.8c-18.944-19.968-18.944-51.2%200-71.168a50.5344%2050.5344%200%200%201%2072.192-1.024L460.8%20644.608l322.048-322.048c19.968-18.944%2051.2-18.944%2071.168%200%2020.48%2019.456%2020.992%2051.712%201.536%2072.192z%22%20fill%3D%22%23FFFFFF%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E);position:absolute;bottom:10px;right:0;z-index:9}
  33. #file_list li .tools{display:none;position:absolute;bottom:12px;right:10px;z-index:99}
  34. #file_list li:hover .tools{display:block}
  35. #file_list li .tools .remove{cursor:pointer}
  36. #file_list li .tools .remove:after{content:url(data:image/svg+xml;%20charset=utf8,%3Csvg%20width=%2224%22%20height=%2224%22%20viewBox=%220%200%2024%2024%22%20xmlns=%22http://www.w3.org/2000/svg%22%3E%3Cpath%20d=%22M17%206h3a1%201%200%200%201%200%202h-1v11a3%203%200%200%201-3%203H8a3%203%200%200%201-3-3V8H4a1%201%200%201%201%200-2h3V5a3%203%200%200%201%203-3h4a3%203%200%200%201%203%203v1zm-2%200V5a1%201%200%200%200-1-1h-4a1%201%200%200%200-1%201v1h6zm2%202H7v11a1%201%200%200%200%201%201h8a1%201%200%200%200%201-1V8zm-8%203a1%201%200%200%201%202%200v6a1%201%200%200%201-2%200v-6zm4%200a1%201%200%200%201%202%200v6a1%201%200%200%201-2%200v-6z%22%3E%3C/path%3E%3C/svg%3E)}
  37. </style>
  38. </head>
  39. <body>
  40. <div id="wrap">
  41. <div id="topbar">
  42. <label><input type="checkbox" name="isWater" id="isWater" <?php if ($photo_markup == '1') echo "checked"; ?>>&nbsp;是否水印&nbsp;</label>
  43. <button class="addfile">添加文件</button>
  44. <button class="upall">全部上传</button>
  45. <button class="removeall">清空列表</button>
  46. </div>
  47. <ul id="file_list"></ul>
  48. </div>
  49. <script>
  50. var axupimgs={};
  51. axupimgs.res = [];//存放本地文件的数组
  52. var blobInfo = {file:null}
  53. blobInfo.blob = function(){return this.file;}
  54. var upload_handler = async(blobInfo, succFun, failFun)=>{
  55. var file = blobInfo.blob();
  56. formData = new FormData();
  57. formData.append('upload', file, file.name);
  58. if (document.querySelector('#isWater').checked) {
  59. formData.append('needwatermark', 1);
  60. } else {
  61. // formData.append('needwatermark', 0);
  62. }
  63. let res = await fetch('select_images_post.php', {
  64. method: 'POST',
  65. body: formData
  66. });
  67. let data = await res.json();
  68. succFun(data.url);
  69. };
  70. var upload_base_path = axupimgs.images_upload_base_path;
  71. //为列表添加排序
  72. function reSort(){
  73. document.querySelectorAll('#file_list li').forEach((el,i)=>{
  74. el.setAttribute('data-num',i);
  75. });
  76. }
  77. function addList(files){
  78. var files_sum = files.length;
  79. var vDom = document.createDocumentFragment();
  80. for(let i=0;i<files_sum;i++){
  81. let file = files[i];
  82. let blobUrl = window.URL.createObjectURL(file)
  83. axupimgs.res.push({file:file,blobUrl:blobUrl,url:''});
  84. let li = document.createElement('li');
  85. li.setAttribute('class','up-no');
  86. li.setAttribute('data-time',file.lastModified);
  87. 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>';
  88. vDom.appendChild(li);
  89. }
  90. document.querySelector('#file_list').appendChild(vDom);
  91. //reSort();
  92. }
  93. //清空列表
  94. document.querySelector('#topbar .removeall').addEventListener('click',()=>{
  95. axupimgs.res=[]
  96. document.querySelectorAll('#file_list li').forEach((el,i)=>{
  97. el.parentNode.removeChild(el)
  98. });
  99. });
  100. //拖拽添加
  101. document.addEventListener('dragover', (e)=>{
  102. e.stopPropagation();
  103. e.preventDefault();
  104. e.dataTransfer.dropEffect = 'copy';
  105. });
  106. document.addEventListener('drop', (e)=>{
  107. e.stopPropagation();
  108. e.preventDefault();
  109. if(!e.dataTransfer.files){return false;}
  110. var dropfiles = e.dataTransfer.files;
  111. if(!(dropfiles.length>0)){return false;}
  112. var exts=axupimgs.axupimgs_filetype.replace(/(\s)+/g,'').toLowerCase().split(',');
  113. var files=[];
  114. for( let file of dropfiles ){
  115. ext = file.name.split('.');
  116. ext = '.'+ext[ext.length-1];
  117. for(let s of exts){
  118. if(s==ext){
  119. files.push(file);
  120. break;
  121. }
  122. }
  123. }
  124. if(files.length>0){ addList(files) }
  125. });
  126. //添加文件
  127. document.querySelector('#topbar .addfile').addEventListener('click',()=>{
  128. var input = document.createElement('input');
  129. input.setAttribute('type', 'file');
  130. input.setAttribute('multiple', 'multiple');
  131. input.setAttribute('accept', axupimgs.axupimgs_filetype);
  132. input.click();
  133. input.onchange = function() {
  134. var files = this.files;
  135. addList(files);
  136. }
  137. });
  138. var file_i = 0;
  139. function upAllFiles(n){
  140. var len = axupimgs.res.length;
  141. file_i = n;
  142. if(len == n){
  143. file_i=0;
  144. document.querySelector('#topbar .upall').innerText='全部上传';
  145. //返回
  146. console.log(axupimgs.res);
  147. axupimgs.res.forEach((v,k)=>{
  148. //window.opener.CKEDITOR.tools.callFunction(k, v);
  149. let addonHTML = `<img src='${v.url}'/>`;
  150. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  151. })
  152. window.close();
  153. return true;
  154. }
  155. if( axupimgs.res[n].url!='' ){
  156. n++;
  157. upAllFiles(n)
  158. } else {
  159. blobInfo.file=axupimgs.res[n].file;
  160. blobInfo.isWater = document.querySelector('#isWater').checked;
  161. upload_handler(blobInfo,function(url){
  162. if(upload_base_path){
  163. if(upload_base_path.slice(-1)=='/' && url.substr(0,1)=='/' ){
  164. url = upload_base_path + url.slice(1);
  165. }else if(upload_base_path.slice(-1)!='/' && url.substr(0,1)!='/' ){
  166. url = upload_base_path + '/' + url;
  167. } else {
  168. url = upload_base_path + url;
  169. }
  170. }
  171. axupimgs.res[file_i].url = url;
  172. filename = url.split('/').pop();
  173. var li = document.querySelectorAll('#file_list li')[file_i];
  174. li.setAttribute('class','up-over');
  175. li.querySelector('.namebox span').innerText = filename;
  176. n++
  177. upAllFiles(n);
  178. },function(err){
  179. document.querySelector('#topbar .upall').innerText='全部上传';
  180. document.querySelectorAll('#file_list li.up-now').forEach((el,i)=>{
  181. el.setAttribute('class','up-no');
  182. });
  183. alert(err);
  184. });
  185. }
  186. }
  187. document.querySelector('#topbar .upall').addEventListener('click',(e)=>{
  188. if(e.target.innerText!='全部上传'){return false;}
  189. if(axupimgs.res.length>0){
  190. document.querySelectorAll('#file_list li.up-no').forEach((el,i)=>{
  191. el.classList ? el.classList.add('up-now') : el.className+=' up-now';
  192. });
  193. e.target.innerText='上传中...';
  194. upAllFiles(0);
  195. }
  196. });
  197. var observ_flist = new MutationObserver( (muList,observe)=>{
  198. if(muList[0].addedNodes.length>0){
  199. muList[0].addedNodes.forEach((el)=>{
  200. el.querySelector('.remove').addEventListener('click',(e)=>{
  201. var li = e.target.parentNode.parentNode;
  202. var n = li.getAttribute('data-num');
  203. var el = document.querySelectorAll('#file_list li')[n];
  204. el.parentNode.removeChild(el);
  205. axupimgs.res.splice(n,1);
  206. });
  207. });
  208. }
  209. reSort();
  210. });
  211. observ_flist.observe(document.querySelector('#file_list'),{childList:true});
  212. </script>
  213. </body>
  214. </html>