No Description
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.

article_download_edit.htm 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. <div class="item-from-flex">
  2. <div class="item-flex-l">
  3. <div class="item-tit">下载限制:</div>
  4. <div class="item-con">
  5. <div class="select">
  6. <select name="arc_level_id" id="arc_level_id">
  7. </select>
  8. </div>
  9. </div>
  10. </div>
  11. <div class="item-flex-r"> <i class="el-icon-arrow-right"></i> </div>
  12. </div>
  13. <div class="item-from-flex">
  14. <div class="item-flex-l">
  15. <div class="item-tit">上传文件:</div>
  16. <div class="item-con">
  17. <div class="layui-upload" id="download-layui-upload">
  18. <button type="button" class="addr_y none" id="buttonList">选择多文件</button>
  19. <label><input type="checkbox" value="1" onclick="ClickRemoteFile(this);">远程地址</label>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="item-from-flex pt0">
  25. <div class="layui-upload-list mt0" style="overflow: auto;">
  26. <div class="layui-upload-list mt0">
  27. <table class="layui-table article-download-table mt0">
  28. <thead>
  29. <tr>
  30. <th>文件名</th>
  31. <th class="th_server_name" style="display: none;">服务器名称</th>
  32. <th class="th_server_size">大小</th>
  33. <th class="th_server_state">状态</th>
  34. <th>操作</th>
  35. </tr>
  36. </thead>
  37. <tbody id="demoList">
  38. </tbody>
  39. </table>
  40. </div>
  41. <div style="display: none;" id='ClickRemoteFile'>
  42. <div id='Template20210507'></div>
  43. <a class="add_download" onclick="GetTemplateAddr(2);">+添加远程地址</a>
  44. </div>
  45. <button style="display:none;" type="button" class="layui-btn" id="buttonListAction">批量重传</button>
  46. </div>
  47. </div>
  48. <script type="text/javascript">
  49. var admin_id = "{$Think.session.users_id|default='1'}";
  50. var t2_1598602098 = '';
  51. function search_mouseover(th) {
  52. var sinput_id = $(th).attr('data-sinput_id');
  53. $('#search_keywords_list_'+sinput_id).show();
  54. try{
  55. clearTimeout(t2_1598602098);
  56. }catch(e){}
  57. }
  58. function search_mouseout(th) {
  59. var sinput_id = $(th).attr('data-sinput_id');
  60. var setFunc = $("#search_keywords_list_"+sinput_id).hide();
  61. t2_1598602098 = setTimeout('"'+setFunc+'"', 1000);
  62. }
  63. function select_sname(th) {
  64. var sinput_id = $(th).attr('data-sinput_id');
  65. var sname = $(th).attr('data-sname');
  66. $("#"+sinput_id).val(sname);
  67. }
  68. function searchServername(th) {
  69. var sinput_id = $(th).attr('id');
  70. $.ajax({
  71. type: "POST",
  72. url: "{:url('Download/search_servername')}",
  73. data: {keyword:'',_ajax:1},
  74. dataType: 'json',
  75. cache: false,
  76. success: function (res) {
  77. if(res.code == 1){
  78. if (res.data.length > 0) {
  79. var html='';
  80. res.data.forEach(function(i,e) {
  81. var e_num = e+1;
  82. html += '<a href="javascript:void(0);" onclick="select_sname(this);" onmouseover="search_mouseover(this);" onmouseout="search_mouseout(this);" data-sname="'+i+'" data-sinput_id="'+sinput_id+'" style="cursor: pointer;">';
  83. html += '<div class="number c'+e_num+'">'+e_num+'</div>';
  84. html += '<div class="hottxt">'+i+'</div>';
  85. html += '</a>';
  86. });
  87. $('#search_keywords_list_'+sinput_id).html(html).show();
  88. } else {
  89. $('#search_keywords_list_'+sinput_id).hide();
  90. }
  91. } else {
  92. $('#search_keywords_list_'+sinput_id).hide();
  93. }
  94. }
  95. });
  96. }
  97. function round_num() {
  98. var num = '';
  99. for(var i=0;i<3;i++)
  100. {
  101. num+=Math.floor(Math.random()*10);
  102. }
  103. return num;
  104. }
  105. function judgeExt(ext) {
  106. var extArr = [];
  107. extArr = type20210507.split("|");
  108. var ext = ext.replace(".","");
  109. return extArr.indexOf(ext);
  110. }
  111. function cos_download__upload() {
  112. var cosFileObj = document.getElementById("cosFile").files;
  113. var formData = new FormData();
  114. formData.append('file_num', cosFileObj.length);
  115. for (var i = 0; i < cosFileObj.length; i++) {
  116. var file = cosFileObj[i];
  117. var fileName = file.name;
  118. var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
  119. var ext = judgeExt(fileExt);
  120. if (ext > -1) {
  121. // 追加显示在页面上
  122. var timestamp = new Date().getTime() + '-' + Math.ceil(Math.random()*100);
  123. var append_html = '';
  124. append_html += '<tr>';
  125. append_html += '<td>'+ file.name +'</td>';
  126. if (1 == servername_use20210507){
  127. append_html += '<td class="th_server_name">';
  128. } else {
  129. append_html += '<td class="th_server_name" style="display: none;">';
  130. }
  131. append_html += '<input type="text" name="fileupload[server_name][]" value="腾讯云服务器" id="severname_qiniuyun_'+i+'" onclick="searchServername(this);" autocomplete="off">';
  132. append_html += '<div class="help-hot-list" style="display: none;" id="search_keywords_list_severname_qiniuyun_'+i+'"></div>';
  133. append_html += '</td>';
  134. append_html += '<td class="th_server_size">'+ (file.size/1014).toFixed(1) +' KB</td>';
  135. append_html += '<td class="th_server_state" id="upload-'+ timestamp +'">上传腾讯云…请稍等</td>';
  136. append_html += '<td><button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" style="line-height:unset;height: unset;" onclick="DeleteFile(this);">移除</button>';
  137. append_html += '</td>';
  138. append_html += '</tr>';
  139. $("#demoList").append(append_html);
  140. // 表单提交数据
  141. formData.append('file_' + [i], cosFileObj[i]);
  142. formData.append('file_mime_' + [i], file.type);
  143. formData.append('file_name_' + [i], file.name);
  144. formData.append('file_size_' + [i], file.size);
  145. formData.append('file_ext_' + [i], fileExt);
  146. formData.append('file_tdid_' + [i], "#upload-" + timestamp);
  147. } else {
  148. showErrorMsg('不支持选中的文件格式,仅支持' + type20210507);
  149. }
  150. }
  151. // 上传提示
  152. layer.msg('上传腾讯云……&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font id="upgrade_backup_speed">0.01</font>%,请勿刷新', {icon: 1, time: 3600000, shade: [0.2]});
  153. layer.load(3, {shade: [0.1,'#fff']});
  154. $.ajax({
  155. type: 'post',
  156. url : "{:url('plugins/Cos/cos_multiple_upload')}",
  157. data: formData,
  158. contentType: false,
  159. processData: false,
  160. dataType: 'json',
  161. xhr: function () {
  162. myXhr = $.ajaxSettings.xhr();
  163. if (myXhr.upload) {
  164. myXhr.upload.addEventListener('progress', function(e) {
  165. var curr = e.loaded;
  166. var total = e.total;
  167. var process = parseInt(curr / total * 100);
  168. process = 100 == process ? 99 : process;
  169. $('#upgrade_backup_speed').html(process);
  170. });
  171. }
  172. return myXhr;
  173. },
  174. success: function(res) {
  175. layer.closeAll();
  176. try {
  177. if (1 == res.code) {
  178. var file_url = res.data.file_url;
  179. $.each(file_url, function(i, item) {
  180. var html = '';
  181. html += '<input type="hidden" name="fileupload[file_url][]" value="'+ file_url[i] +'">';
  182. html += '<input type="hidden" name="fileupload[file_mime][]" value="'+ res.data.file_mime[i] +'">';
  183. html += '<input type="hidden" name="fileupload[file_name][]" value="'+ res.data.file_name[i] +'">';
  184. html += '<input type="hidden" name="fileupload[file_size][]" value="'+ res.data.file_size[i] +'">';
  185. html += '<input type="hidden" name="fileupload[file_ext][]" value="'+ res.data.file_ext[i] +'">';
  186. $(res.data.file_tdid[i]).html('<span style="color: #5FB878;">上传成功</span>' + html);
  187. });
  188. } else {
  189. showErrorAlert('接口超时,部分上传腾讯云失败,请移除未上传成功的文件重新上传。');
  190. }
  191. } catch(e) {}
  192. },
  193. error: function(e){
  194. layer.closeAll();
  195. showErrorAlert(e.responseText);
  196. }
  197. });
  198. }
  199. function qny_download__upload() {
  200. var arr = [];
  201. for(var i = 0 ;i<document.getElementById("qnyFile").files.length;i++){
  202. file=document.getElementById("qnyFile").files[i];
  203. var fileName = file.name;
  204. var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
  205. var ext = judgeExt(fileExt);
  206. if (ext>-1) {
  207. var timestamp = new Date().getTime()+'-'+ Math.ceil(Math.random()*100);
  208. arr[i] = timestamp;
  209. var append_html = '';
  210. append_html += '<tr id="upload-'+ timestamp +'">';
  211. append_html += '<td>'+ file.name +'</td>';
  212. if (1 == servername_use20210507){
  213. append_html += '<td class="th_server_name">';
  214. }else{
  215. append_html += '<td class="th_server_name" style="display: none;">';
  216. }
  217. append_html += '<input type="text" name="fileupload[server_name][]" value="七牛云服务器" id="severname_qiniuyun_'+i+'" onclick="searchServername(this);" autocomplete="off">';
  218. append_html += '<div class="help-hot-list" style="display: none;" id="search_keywords_list_severname_qiniuyun_'+i+'"></div>';
  219. append_html += '</td>';
  220. append_html += '<td class="th_server_size">'+ (file.size/1014).toFixed(1) +' KB</td>';
  221. append_html += '<td class="th_server_state">等待上传</td>';
  222. append_html += '<td><button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" style="line-height:unset;height: unset;" onclick="DeleteFile(this);">移除</button>';
  223. append_html += '</td>';
  224. append_html += '</tr>';
  225. $("#demoList").append(append_html);
  226. }else{
  227. showErrorMsg('不支持选中的文件格式,仅支持'+type20210507);
  228. }
  229. }
  230. var date = new Date();
  231. var y = date.getFullYear();
  232. var m = date.getMonth() + 1;
  233. m = m < 10 ? '0' + m : m;
  234. var d = date.getDate();
  235. d = d < 10 ? ('0' + d) : d;
  236. $.ajax({
  237. type: 'POST',
  238. url: "{:url('plugins/Qiniuyun/qiniu_upload')}",
  239. data: {_ajax:1,down:1},
  240. dataType: "JSON",
  241. success: function(res1){
  242. if (1 == res1.code){
  243. var token = res1.data.token;
  244. for(var i = 0 ;i<document.getElementById("qnyFile").files.length;i++) {
  245. file = document.getElementById("qnyFile").files[i];
  246. var fileName = file.name;
  247. var formData = new FormData();
  248. formData.append('token', token);
  249. formData.append('file', file);
  250. var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
  251. var num = round_num();
  252. var name = 'U'+admin_id+'-'+ new Date().getTime()+num+ fileExt;
  253. fileName = res1.data.filePath + y + m + d + "/"+ name;
  254. formData.append('key', fileName);
  255. var tr = $("#upload-" + arr[i]);
  256. new Promise(function() {
  257. var tr = $("#upload-" + arr[i]);
  258. var file_mime = file.type;
  259. var file_name = file.name;
  260. var file_size = file.size;
  261. var file_ext = fileExt;
  262. $.ajax({
  263. url: res1.data.uphost,
  264. type: 'POST',
  265. dataType: 'JSON',
  266. data: formData,
  267. timeout: 1200000,
  268. // async: false,
  269. cache: false,
  270. processData: false,
  271. contentType: false,
  272. xhr: function () {
  273. myXhr = $.ajaxSettings.xhr();
  274. if (myXhr.upload) {
  275. myXhr.upload.addEventListener('progress', function (e) {
  276. var curr = e.loaded;
  277. var total = e.total;
  278. process = parseInt(curr / total * 100);
  279. tr.children("td").eq(3).text('上传中...' + process + "%");
  280. });
  281. }
  282. return myXhr;
  283. },
  284. success: function (res2) {
  285. var video_url = res1.data.domain + "/" + res2.key;
  286. //
  287. var html = '';
  288. html += '<input type="hidden" name="fileupload[file_url][]" value="'+ video_url +'">';
  289. html += '<input type="hidden" name="fileupload[file_mime][]" value="'+ file_mime +'">';
  290. html += '<input type="hidden" name="fileupload[file_name][]" value="'+ file_name +'">';
  291. html += '<input type="hidden" name="fileupload[file_ext][]" value="'+ file_ext +'">';
  292. html += '<input type="hidden" name="fileupload[file_size][]" value="'+ file_size +'">';
  293. var tds = tr.children();
  294. tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>');
  295. tds.eq(4).html('<span class="layui-btn layui-btn-xs layui-btn-danger" style="line-height:unset;height: unset;" onclick="DeleteFile(this);">移除</span>'+html);
  296. },
  297. error: function (e) {
  298. showErrorMsg(e.responseText);
  299. return false;
  300. }
  301. });
  302. })
  303. }
  304. }else{
  305. showErrorMsg(res1.msg);
  306. }
  307. },
  308. error: function(e){
  309. showErrorMsg(e.responseText);
  310. }
  311. });
  312. }
  313. function oss_download__upload() {
  314. var arr = [];
  315. for(var i = 0 ;i<document.getElementById("ossFile").files.length;i++){
  316. file=document.getElementById("ossFile").files[i];
  317. var fileName = file.name;
  318. var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
  319. var ext = judgeExt(fileExt);
  320. if (ext>-1) {
  321. //此时取出这个文件进行处理,这里只是显示文件名
  322. var timestamp = new Date().getTime() + '-' + Math.ceil(Math.random()*100);
  323. arr[i] = timestamp;
  324. var append_html = '';
  325. append_html += '<tr id="upload-'+ timestamp +'">';
  326. append_html += '<td>'+ file.name +'</td>';
  327. if (1 == servername_use20210507){
  328. append_html += '<td class="th_server_name">';
  329. }else{
  330. append_html += '<td class="th_server_name" style="display: none;">';
  331. }
  332. append_html += '<input type="text" name="fileupload[server_name][]" value="阿里云服务器" id="severname_qiniuyun_'+i+'" onclick="searchServername(this);" autocomplete="off">';
  333. append_html += '<div class="help-hot-list" style="display: none;" id="search_keywords_list_severname_qiniuyun_'+i+'"></div>';
  334. append_html += '</td>';
  335. append_html += '<td class="th_server_size">'+ (file.size/1014).toFixed(1) +' KB</td>';
  336. append_html += '<td class="th_server_state">等待上传</td>';
  337. append_html += '<td><button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" style="line-height:unset;height: unset;" onclick="DeleteFile(this);">移除</button>';
  338. append_html += '</td>';
  339. append_html += '</tr>';
  340. $("#demoList").append(append_html);
  341. }else{
  342. showErrorMsg('不支持选中的文件格式,仅支持'+type20210507);
  343. }
  344. }
  345. var date = new Date();
  346. var y = date.getFullYear();
  347. var m = date.getMonth() + 1;
  348. m = m < 10 ? '0' + m : m;
  349. var d = date.getDate();
  350. d = d < 10 ? ('0' + d) : d;
  351. $.ajax({
  352. type: 'POST',
  353. url : "{:url('plugins/AliyunOss/oss_upload')}",
  354. data: {_ajax:1,down:1},
  355. dataType: "JSON",
  356. success: function(res1){
  357. if (1 == res1.code){
  358. var accessid = res1.data.accessid;
  359. var policy = res1.data.policy;
  360. var signature = res1.data.signature;
  361. var filePath = res1.data.filePath;
  362. for(var i = 0 ;i<document.getElementById("ossFile").files.length;i++) {
  363. file = document.getElementById("ossFile").files[i];
  364. var fileName = file.name;
  365. var request = new FormData();
  366. request.append("OSSAccessKeyId",accessid);
  367. request.append("policy",policy);
  368. request.append("Signature",signature);
  369. request.append("success_action_status",201);
  370. var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
  371. var num = round_num();
  372. //存储文件名
  373. var name = 'U'+admin_id+'-'+ new Date().getTime()+num+ fileExt;
  374. fileName = filePath + y + m + d + "/"+ name;
  375. request.append("key", fileName);
  376. request.append('file', file);
  377. var tr = $("#upload-" + arr[i]);
  378. new Promise(function() {
  379. var tr = $("#upload-" + arr[i]);
  380. var file_mime = file.type;
  381. var file_name = file.name;
  382. var file_size = file.size;
  383. var file_ext = fileExt;
  384. $.ajax({
  385. url: res1.data.host,
  386. data: request,
  387. processData: false,
  388. cache: false,
  389. contentType: false,
  390. dataType: 'xml',
  391. type : 'post',
  392. xhr: function () {
  393. myXhr = $.ajaxSettings.xhr();
  394. if (myXhr.upload) {
  395. myXhr.upload.addEventListener('progress', function (e) {
  396. var curr = e.loaded;
  397. var total = e.total;
  398. process = parseInt(curr / total * 100);
  399. tr.children("td").eq(3).text('上传中...' + process + "%");
  400. });
  401. }
  402. return myXhr;
  403. },
  404. success: function (res2) {
  405. var res = $(res2).find('PostResponse');
  406. if (res) {
  407. var key = res.find('Key').text();
  408. var video_url = res1.data.domain + "/" + key;
  409. var html = '';
  410. html += '<input type="hidden" name="fileupload[file_url][]" value="' + video_url + '">';
  411. html += '<input type="hidden" name="fileupload[file_mime][]" value="' + file_mime + '">';
  412. html += '<input type="hidden" name="fileupload[file_name][]" value="' + file_name + '">';
  413. html += '<input type="hidden" name="fileupload[file_ext][]" value="' + file_ext + '">';
  414. html += '<input type="hidden" name="fileupload[file_size][]" value="' + file_size + '">';
  415. var tds = tr.children();
  416. tds.eq(3).html('<span style="color: #5FB878;">上传成功</span>');
  417. tds.eq(4).html('<span class="layui-btn layui-btn-xs layui-btn-danger" style="line-height:unset;height: unset;" onclick="DeleteFile(this);">移除</span>' + html);
  418. }
  419. },
  420. error: function (e) {
  421. showErrorMsg(e.responseText);
  422. return false;
  423. }
  424. });
  425. })
  426. }
  427. }else{
  428. showErrorMsg(res1.msg);
  429. }
  430. },
  431. error: function(e){
  432. showErrorMsg(e.responseText);
  433. }
  434. });
  435. }
  436. // 远程/本地上传文件切换
  437. function ClickRemoteFile(obj)
  438. {
  439. if ($(obj).is(':checked')) {
  440. var length = $(".template_div20210507").length;
  441. if (0 == length){
  442. var template_div20210507_html = '';
  443. for (var i=1;i<4;i++) {
  444. template_div20210507_html += '<div class="template_div20210507"><div style=" display: block; margin-bottom: 5px; ">远程地址'+i+':<input type="text" name="remote_file[]" value="" placeholder="http://" style="width: 250px;"></div>\n' ;
  445. $.each(attr_field20210507, function (index, value) {
  446. var field_use_style = '';
  447. if(1 != value.field_use){
  448. field_use_style = ' style="display: none;" ';
  449. }
  450. if('server_name' == value.field_name){
  451. template_div20210507_html += '<span class="ey_'+value.field_name+'" '+field_use_style+'>\n' +
  452. '<span class="title_'+value.field_name+'">'+value.field_title+'</span>:' +
  453. '<input type="text" name="'+value.field_name+'[]" id="'+value.field_name+'_remote_'+i+'" style="width: 80px;" onclick="searchServername(this);" autocomplete="off" value="'+default_servername20210507+'" >\n' +
  454. '<div class="help-hot-list remote-hot-list" style="display: none;" data-test_val="5434" id="search_keywords_list_'+value.field_name+'_remote_'+i+'"></div>\n' +
  455. '</span>\n' ;
  456. }else{
  457. template_div20210507_html += '<span class="ey_'+value.field_name+'" '+field_use_style+'>\n' +
  458. '<span class="title_'+value.field_name+'">'+value.field_title+'</span>:' +
  459. '<input type="text" name="'+value.field_name+'[]" id="'+value.field_name+'_remote_'+i+'" style="width: 80px;"></span>\n' ;
  460. }
  461. });
  462. template_div20210507_html += '</div>';
  463. }
  464. $("#Template20210507").html(template_div20210507_html);
  465. }
  466. $('#ClickRemoteFile').show();
  467. } else {
  468. $('#ClickRemoteFile').hide();
  469. }
  470. }
  471. // 获取模板属性数据
  472. function GetTemplateAddr(num){
  473. if (!num) {
  474. num = 1;
  475. }
  476. $.ajax({
  477. url: "{:url('Download/get_template', ['_ajax'=>1])}",
  478. data: {num:num},
  479. type:'post',
  480. dataType:'json',
  481. success: function(res){
  482. // 拼装模板属性并追加
  483. AddTemplateAddr(num,res.data);
  484. },
  485. });
  486. }
  487. // 删除对应的文件及文件信息
  488. function DeleteFile(obj){
  489. var filenames = $(obj).next().val();
  490. $(obj).parent().parent().remove();
  491. if (filenames) {
  492. var type20210507 = $('#download-layui-upload').attr('data-type');
  493. var url = '';
  494. if ('qny' == type20210507) {
  495. url = "{:url('plugins/Qiniuyun/deleteQny')}";
  496. }else if ('oss' == type20210507) {
  497. url = "{:url('plugins/AliyunOss/deleteOss')}";
  498. }else if ('cos' == type20210507) {
  499. url = "{:url('plugins/Cos/deleteCos')}";
  500. }else{
  501. url = "{:url('user/Uploadify/del_local')}";
  502. }
  503. $.ajax({
  504. type: 'GET',
  505. url: url,
  506. data: {_ajax: 1, filenames: filenames},
  507. success: function (res1) {
  508. }
  509. });
  510. }
  511. }
  512. // 拼装模板属性并追加
  513. function AddTemplateAddr(num,data){
  514. if (!num) {
  515. num = 1;
  516. }
  517. var SerialNum = $('#Template20210507 div.template_div20210507').length;
  518. var default_servername = default_servername20210507;
  519. var html_div = [];
  520. if (num > 1) {
  521. for (var i = 0; i < num; i++) {
  522. SerialNum++;
  523. html_div +=['<div class="template_div20210507"><div style=" display: block; margin-bottom: 5px; ">远程地址'+SerialNum+':<input type="text" name="remote_file[]" value="" placeholder="http://" style="width: 250px;"></div> '];
  524. if (data) {
  525. for (var j = 0; j < data.length; j++) {
  526. if (data[j]['field_name'] == 'server_name') {
  527. if (data[j]['field_use'] == 1){
  528. html_div += ['<span class="ey_' + data[j]['field_name'] + '"> '];
  529. }else {
  530. html_div += ['<span style="display:none;" class="ey_' + data[j]['field_name'] + '"> '];
  531. }
  532. html_div +=['<span class="title_'+data[j]['field_name']+'"> '+data[j]['field_title']+'</span>:<input type="text" name="'+data[j]['field_name']+'[]" id="'+data[j]['field_name']+'_remote_'+SerialNum+'" style="width: 80px;" onclick="searchServername(this);" autocomplete="off" value="'+default_servername+'">'+
  533. '<div class="help-hot-list" style="display: none;" id="search_keywords_list_'+data[j]['field_name']+'_remote_'+SerialNum+'"></div>'+
  534. '</span>'];
  535. }else{
  536. if (data[j]['field_use'] == 1){
  537. html_div += ['<span class="ey_' + data[j]['field_name'] + '"> '];
  538. }else {
  539. html_div += ['<span style="display:none;" class="ey_' + data[j]['field_name'] + '"> '];
  540. }
  541. html_div +=['<span class="title_'+data[j]['field_name']+'"> '+data[j]['field_title']+'</span>:<input type="text" name="'+data[j]['field_name']+'[]" id="'+data[j]['field_name']+'_'+SerialNum+'" style="width: 80px;"></span>'];
  542. }
  543. }
  544. }
  545. html_div +=['</div>'];
  546. }
  547. }else{
  548. SerialNum++;
  549. html_div +=
  550. ['<div class="template_div20210507"><div style=" display: block; margin-bottom: 5px; ">远程地址'+SerialNum+':<input type="text" name="remote_file[]" value="" placeholder="http://" style="width: 250px;"></div>'];
  551. if (data) {
  552. for (var j = 0; j < data.length; j++) {
  553. if (data[j]['field_name'] == 'server_name') {
  554. if (data[j]['field_use'] == 1){
  555. html_div += ['<span class="ey_' + data[j]['field_name'] + '"> '];
  556. }else {
  557. html_div += ['<span style="display:none;" class="ey_' + data[j]['field_name'] + '"> '];
  558. }
  559. html_div +=['<span class="title_'+data[j]['field_name']+'"> '+data[j]['field_title']+'</span>:<input type="text" name="'+data[j]['field_name']+'[]" id="'+data[j]['field_name']+'_remote_'+SerialNum+'" style="width: 80px;" onclick="searchServername(this);" autocomplete="off" value="'+default_servername+'">'+
  560. '<div class="help-hot-list" style="display: none;" id="search_keywords_list_'+data[j]['field_name']+'_remote_'+SerialNum+'"></div>'+
  561. '</span>'];
  562. }else{
  563. if (data[j]['field_use'] == 1){
  564. html_div += ['<span class="ey_' + data[j]['field_name'] + '"> '];
  565. }else {
  566. html_div += ['<span style="display:none;" class="ey_' + data[j]['field_name'] + '"> '];
  567. }
  568. html_div +=['<span class="title_'+data[j]['field_name']+'"> '+data[j]['field_title']+'</span>:<input type="text" name="'+data[j]['field_name']+'[]" id="'+data[j]['field_name']+'_'+SerialNum+'" style="width: 80px;"></span>'];
  569. }
  570. }
  571. }
  572. html_div += ['</div>'];
  573. }
  574. // 追加html
  575. $('#Template20210507').append(html_div);
  576. }
  577. // 文件上传JS
  578. layui.use('upload', function(){
  579. var $ = layui.jquery,upload = layui.upload;
  580. // 多文件列表示例
  581. var demoListView = $('#demoList'),uploadListIns = upload.render({
  582. elem: '#buttonList',
  583. url: "{:url('user/Uploadify/DownloadUploadFile')}",
  584. accept: 'file',
  585. exts: type20210507,
  586. multiple: true,
  587. auto: true,
  588. bindAction: '#buttonListAction',
  589. choose: function(obj){
  590. // 将每次选择的文件追加到文件队列
  591. var files = this.files = obj.pushFile();
  592. // 读取本地文件
  593. obj.preview(function(index, file, result){
  594. if (1 == servername_use20210507) {
  595. var tr = $(
  596. [
  597. '<tr id="upload-' + index + '">',
  598. '<td>' + file.name + '</td>',
  599. '<td class="th_server_name"><input type="text" name="fileupload[server_name][]" value="'+default_servername20210507+'" id="severname_local_' + index + '" onclick="searchServername(this);" autocomplete="off">',
  600. '<div class="help-hot-list" style="display: none;" id="search_keywords_list_severname_local_' + index + '"></div>',
  601. '</td>',
  602. '<td class="th_server_size">' + (file.size / 1014).toFixed(1) + ' KB</td>',
  603. '<td class="th_server_state">等待上传</td>',
  604. '<td>',
  605. // '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>',
  606. '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" style="line-height:unset;height: unset;">移除</button>',
  607. '</td>',
  608. '</tr>'
  609. ].join(''));
  610. }else{
  611. var tr = $(
  612. [
  613. '<tr id="upload-' + index + '">',
  614. '<td>' + file.name + '</td>',
  615. '<td class="th_server_name" style="display: none;"><input type="text" name="fileupload[server_name][]" value="'+default_servername20210507+'" id="severname_local_' + index + '" onclick="searchServername(this);" autocomplete="off">',
  616. '<div class="help-hot-list" style="display: none;" id="search_keywords_list_severname_local_' + index + '"></div>',
  617. '</td>',
  618. '<td class="th_server_size">' + (file.size / 1014).toFixed(1) + ' KB</td>',
  619. '<td class="th_server_state">等待上传</td>',
  620. '<td>',
  621. // '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>',
  622. '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" style="line-height:unset;height: unset;">移除</button>',
  623. '</td>',
  624. '</tr>'
  625. ].join(''));
  626. }
  627. // 单个重传
  628. tr.find('.demo-reload').on('click', function(){
  629. obj.upload(index, file);
  630. });
  631. // 删除
  632. tr.find('.demo-delete').on('click', function(){
  633. // 删除对应的文件
  634. delete files[index];
  635. tr.remove();
  636. // 清空 input file 值,以免删除后出现同名文件不可选
  637. uploadListIns.config.elem.next()[0].value = '';
  638. });
  639. demoListView.append(tr);
  640. });
  641. },
  642. done: function(res, index, upload){
  643. if(res.code == 1){
  644. // 上传成功
  645. var html = '';
  646. html += '<input type="hidden" name="fileupload[file_url][]" value="'+res.file_url+'">';
  647. html += '<input type="hidden" name="fileupload[file_mime][]" value="'+res.file_mime+'">';
  648. html += '<input type="hidden" name="fileupload[file_name][]" value="'+res.file_name+'">';
  649. html += '<input type="hidden" name="fileupload[file_ext][]" value="'+res.file_ext+'">';
  650. html += '<input type="hidden" name="fileupload[file_size][]" value="'+res.file_size+'">';
  651. html += '<input type="hidden" name="fileupload[uhash][]" value="'+res.uhash+'">';
  652. html += '<input type="hidden" name="fileupload[md5file][]" value="'+res.md5file+'">';
  653. var tr = demoListView.find('tr#upload-'+ index),
  654. tds = tr.children();
  655. tds.eq(0).html(res.file_name);
  656. tds.eq(3).html('<span style="color: #5FB878;white-space: nowrap;">'+res.msg+'</span>');
  657. tds.eq(4).html('<span class="layui-btn layui-btn-xs layui-btn-danger" style="line-height:unset;height: unset;" onclick="DeleteFile(this);">移除</span>'+html);
  658. // 清空操作
  659. return delete this.files[index];// 删除文件队列已经上传成功的文件
  660. }
  661. this.error(res, index, upload);
  662. },
  663. error: function(res, index, upload){
  664. var tr = demoListView.find('tr#upload-'+ index),
  665. tds = tr.children();
  666. tds.eq(3).html('<span style="color: #FF5722;white-space: nowrap;">'+res.msg+'</span>');
  667. }
  668. });
  669. });
  670. </script>