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

221 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:#545b62;background:#fff}
  17. ul{margin:0;padding:0;list-style:none}
  18. input[type=radio],input[type=checkbox]{margin:0;height:auto;box-shadow:none;outline:none;vertical-align:text-top}
  19. button+button{margin-left:10px}
  20. #wrap{padding:10px}
  21. #topbar{padding:10px 0;border-bottom:1px solid #ccc;text-align:right}
  22. #topbar button{display:inline-block;border:0;padding:.25rem .5rem;line-height:1.5;font-size:12px;color:#fff;background:#28a745;border-color:#28a745;border-radius:.25rem;transition:all .6s;text-align:center}
  23. .topbar button+.topbar button{margin-left:10px}
  24. #topbar button:focus{background:#006829;border-color:#005b24;box-shadow:0 0 0 0.2rem rgba(38,159,86,.5);outline:none}
  25. #file_list{display:grid;grid-gap:10px;grid-template-columns:repeat(auto-fill,minmax(160px,1fr));padding-top:10px}
  26. #file_list:empty:after{content:'可以直接拖拽文件到这里'}
  27. #file_list li{position:relative;display:block;vertical-align:top;padding:10px;border-radius:.25rem}
  28. #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}
  29. #file_list li:hover{background:#f8f8f8}
  30. #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}
  31. #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}
  32. #file_list li .namebox{padding:10px;display:flex;justify-content:center;align-items:flex-start}
  33. #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}
  34. #file_list li .tools{display:none;position:absolute;bottom:12px;right:10px;z-index:99}
  35. #file_list li:hover .tools{display:block}
  36. #file_list li .tools .remove{cursor:pointer}
  37. #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)}
  38. </style>
  39. </head>
  40. <body>
  41. <div id="wrap">
  42. <div id="topbar">
  43. <label><input type="checkbox" name="isWater" id="isWater" <?php if ($photo_markup == '1') echo "checked";?>> 是否水印</label>
  44. <button class="addfile">添加文件</button>
  45. <button class="upall">全部上传</button>
  46. <button class="removeall">清空列表</button>
  47. </div>
  48. <ul id="file_list"></ul>
  49. </div>
  50. <script>
  51. var axupimgs={};
  52. axupimgs.res = [];//存放本地文件的数组
  53. var blobInfo = {file:null}
  54. blobInfo.blob = function(){return this.file;}
  55. var upload_handler = async(blobInfo, succFun, failFun)=>{
  56. var file = blobInfo.blob();
  57. formData = new FormData();
  58. formData.append('upload', file, file.name);
  59. if (document.querySelector('#isWater').checked) {
  60. formData.append('needwatermark', 1);
  61. } else {
  62. //formData.append('needwatermark', 0);
  63. }
  64. let res = await fetch('select_images_post.php', {
  65. method: 'POST',
  66. body: formData
  67. });
  68. let data = await res.json();
  69. succFun(data.url);
  70. };
  71. var upload_base_path = axupimgs.images_upload_base_path;
  72. //为列表添加排序
  73. function reSort(){
  74. document.querySelectorAll('#file_list li').forEach((el,i)=>{
  75. el.setAttribute('data-num',i);
  76. });
  77. }
  78. function isFileImage(file) {
  79. return file && file['type'].split('/')[0] === 'image';
  80. }
  81. function addList(files){
  82. var files_sum = files.length;
  83. var vDom = document.createDocumentFragment();
  84. for(let i=0;i<files_sum;i++){
  85. let file = files[i];
  86. if (!isFileImage(file)) {
  87. alert("选择非图片文件无法上传")
  88. return;
  89. }
  90. let blobUrl = window.URL.createObjectURL(file)
  91. axupimgs.res.push({file:file,blobUrl:blobUrl,url:''});
  92. let li = document.createElement('li');
  93. li.setAttribute('class','up-no');
  94. li.setAttribute('data-time',file.lastModified);
  95. 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>';
  96. vDom.appendChild(li);
  97. }
  98. document.querySelector('#file_list').appendChild(vDom);
  99. //reSort();
  100. }
  101. //清空列表
  102. document.querySelector('#topbar .removeall').addEventListener('click',()=>{
  103. axupimgs.res=[]
  104. document.querySelectorAll('#file_list li').forEach((el,i)=>{
  105. el.parentNode.removeChild(el)
  106. });
  107. });
  108. //拖拽添加
  109. document.addEventListener('dragover', (e)=>{
  110. e.stopPropagation();
  111. e.preventDefault();
  112. e.dataTransfer.dropEffect = 'copy';
  113. });
  114. document.addEventListener('drop', (e)=>{
  115. e.stopPropagation();
  116. e.preventDefault();
  117. if(!e.dataTransfer.files){return false;}
  118. var dropfiles = e.dataTransfer.files;
  119. if(!(dropfiles.length>0)){return false;}
  120. var exts=axupimgs.axupimgs_filetype.replace(/(\s)+/g,'').toLowerCase().split(',');
  121. var files=[];
  122. for( let file of dropfiles ){
  123. ext = file.name.split('.');
  124. ext = '.'+ext[ext.length-1];
  125. for(let s of exts){
  126. if(s==ext){
  127. files.push(file);
  128. break;
  129. }
  130. }
  131. }
  132. if(files.length>0){ addList(files) }
  133. });
  134. //添加文件
  135. document.querySelector('#topbar .addfile').addEventListener('click',()=>{
  136. var input = document.createElement('input');
  137. input.setAttribute('type', 'file');
  138. input.setAttribute('multiple', 'multiple');
  139. input.setAttribute('accept', axupimgs.axupimgs_filetype);
  140. input.click();
  141. input.onchange = function() {
  142. var files = this.files;
  143. addList(files);
  144. }
  145. });
  146. var file_i = 0;
  147. function upAllFiles(n){
  148. var len = axupimgs.res.length;
  149. file_i = n;
  150. if(len == n){
  151. file_i=0;
  152. document.querySelector('#topbar .upall').innerText='全部上传';
  153. //返回
  154. console.log(axupimgs.res);
  155. axupimgs.res.forEach((v,k)=>{
  156. let addonHTML = `<img src='${v.url}'/>`;
  157. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  158. })
  159. window.close();
  160. return true;
  161. }
  162. if( axupimgs.res[n].url!='' ){
  163. n++;
  164. upAllFiles(n)
  165. } else {
  166. blobInfo.file=axupimgs.res[n].file;
  167. blobInfo.isWater = document.querySelector('#isWater').checked;
  168. upload_handler(blobInfo,function(url){
  169. if(upload_base_path){
  170. if(upload_base_path.slice(-1)=='/' && url.substr(0,1)=='/' ){
  171. url = upload_base_path + url.slice(1);
  172. }else if(upload_base_path.slice(-1)!='/' && url.substr(0,1)!='/' ){
  173. url = upload_base_path + '/' + url;
  174. } else {
  175. url = upload_base_path + url;
  176. }
  177. }
  178. axupimgs.res[file_i].url = url;
  179. filename = url.split('/').pop();
  180. var li = document.querySelectorAll('#file_list li')[file_i];
  181. li.setAttribute('class','up-over');
  182. li.querySelector('.namebox span').innerText = filename;
  183. n++
  184. upAllFiles(n);
  185. },function(err){
  186. document.querySelector('#topbar .upall').innerText='全部上传';
  187. document.querySelectorAll('#file_list li.up-now').forEach((el,i)=>{
  188. el.setAttribute('class','up-no');
  189. });
  190. alert(err);
  191. });
  192. }
  193. }
  194. document.querySelector('#topbar .upall').addEventListener('click',(e)=>{
  195. if(e.target.innerText!='全部上传'){return false;}
  196. if(axupimgs.res.length>0){
  197. document.querySelectorAll('#file_list li.up-no').forEach((el,i)=>{
  198. el.classList ? el.classList.add('up-now') : el.className+=' up-now';
  199. });
  200. e.target.innerText='上传中';
  201. upAllFiles(0);
  202. }
  203. });
  204. var observ_flist = new MutationObserver( (muList,observe)=>{
  205. if(muList[0].addedNodes.length>0){
  206. muList[0].addedNodes.forEach((el)=>{
  207. el.querySelector('.remove').addEventListener('click',(e)=>{
  208. var li = e.target.parentNode.parentNode;
  209. var n = li.getAttribute('data-num');
  210. var el = document.querySelectorAll('#file_list li')[n];
  211. el.parentNode.removeChild(el);
  212. axupimgs.res.splice(n,1);
  213. });
  214. });
  215. }
  216. reSort();
  217. });
  218. observ_flist.observe(document.querySelector('#file_list'),{childList:true});
  219. </script>
  220. </body>
  221. </html>