upload.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="renderer" content="webkit">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <title>SmartShop Manage System</title>
  8. {load href="__PUBLIC__/base/base.css,__PUBLIC__/admin/style.css,__PUBLIC__/js/do.js,__PUBLIC__/js/package.js,__PUBLIC__/admin/common.js" /}
  9. </head>
  10. <style type="text/css">
  11. html,body{margin:10px;}
  12. ul.gallery{display: flex;flex-wrap:wrap;}
  13. ul.gallery li{height:100px;width:100px;border: 1px solid #DDDDDD;margin:3px;padding: 5px;line-height: 30px;overflow:hidden;text-align: center;}
  14. ul.gallery li:first-child {border-width:1px;}
  15. ul.gallery li a{display:block;text-align: center;padding-top:15px;height: 90px;}
  16. ul.gallery li i{font-size:50px;}
  17. ul.gallery li img{width:88px;}
  18. ul.gallery li:hover,ul.gallery li.current{padding: 4px; border: 2px dotted #7CA3C1;background-color:transparent;}
  19. #uploader{margin-top:30px;}
  20. .uploader-list .file-item {position: relative;}
  21. .uploader-list .file-item .error {position:absolute;padding: 5px 0;background: rgba(255,255,255,0.5);margin-bottom: 0;text-indent: 0;bottom: 0;text-align:center;color:red;left:0;right:0;}
  22. </style>
  23. <body>
  24. <div id="main">
  25. <div class="tabs">
  26. <ul class="tab_menu"><li class="current">本地文件</li><li>文件库</li><li>网络文件</li></ul>
  27. <div class="tab_box">
  28. <div class="box1">
  29. <div class="fn-clear"><ul id="fileList" class="uploader-list gallery"></ul></div>
  30. <div id="uploader" class="fn-tac m10"><div id="upButton">选择本地文件</div></div>
  31. </div>
  32. <div class="box2 hide">
  33. <ul class="gallery fn-clear">
  34. {volist name="$lists.backpath" id="vo"}<li><a href="{:url('system/admin.common/upload',['path'=>$vo.path,'input'=>$input,'tab'=>1])}"><i class="iconfont icon-arrowleft"></i><br />{$vo.name}</a></li>{/volist}
  35. {volist name="$lists.folder" id="folder"}<li><a href="{:url('system/admin.common/upload',['path'=>$folder.path,'input'=>$input,'tab'=>1])}"><i class="iconfont icon-wallet_icon"></i><br />{$folder.name} </a></li>{/volist}
  36. {volist name="$lists.file" id="file"}<li class="getfile" data-src="{$file[0]}"><img src="{$file[0]}"></li>{/volist}
  37. </ul>
  38. </div>
  39. <div class="box3 hide">
  40. <table class="formtable">
  41. <tr><th>网络文件URL:</th><td><input class="input w500" type="text" id="imgurl" name="imgurl" value="" /></td></tr>
  42. <tr><th></th><td><input type="button" value="确定" class="button button-blue" onclick="setNetImg()"/></td></tr>
  43. </table>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. <script type="text/javascript">
  50. Do('layer','upload','tab',function(){
  51. saveImage();
  52. var $list = $("#fileList");
  53. var thumbnailWidth = 120;
  54. var thumbnailHeight = 120;
  55. var uploader = WebUploader.create({
  56. swf: '{__PUBLIC__}js/Plug-in/uploader/Uploader.swf',
  57. pick: '#upButton',auto: true,compress:false,fileVal:'upfile',fileNumLimit:10,
  58. server:'{:url("system/admin.common/upload")}',
  59. accept: {title: 'Images',extensions: 'gif,jpg,jpeg,bmp,png,mp3',mimeTypes: 'image/jpg,image/jpeg,image/png,audio/mpeg'}
  60. });
  61. //当有文件添加进来的时候
  62. uploader.on( 'fileQueued', function( file ) {
  63. var $li = $('<li id="' + file.id + '" class="file-item thumbnail">' + '<img></li>'),
  64. $img = $li.find('img');
  65. $list.append($li);
  66. uploader.makeThumb( file, function( error, src ) {
  67. if (error) {
  68. $img.replaceWith('<span>不能预览</span>');
  69. return;
  70. }
  71. $img.attr( 'src', src );
  72. },thumbnailWidth, thumbnailHeight );
  73. });
  74. //上传完毕
  75. uploader.on( 'uploadSuccess', function(file,data ) {
  76. if(data.error == 1){
  77. var $li = $('#'+file.id ),$error = $li.find('div.error');
  78. if (!$error.length) {
  79. $error = $('<div class="error"></div>').appendTo($li);
  80. }
  81. $error.text(data.message);
  82. }else{
  83. $( '#'+file.id ).addClass('upload-state-done');
  84. $( '#'+file.id ).addClass('getfile');
  85. $( '#'+file.id ).attr("data-src",data.url);
  86. saveImage();
  87. }
  88. });
  89. // 文件上传失败,显示上传出错。
  90. uploader.on('uploadError', function( file ) {
  91. var $li = $('#'+file.id ),
  92. $error = $li.find('div.error');
  93. if (!$error.length) {
  94. $error = $('<div class="error"></div>').appendTo($li);
  95. }
  96. $error.text('上传失败');
  97. });
  98. //完成上传完了,成功或者失败,先删除进度条。
  99. uploader.on( 'uploadComplete', function( file ) {
  100. $('#'+file.id ).find('.progress').remove();
  101. });
  102. //{if $tab}设置当前Tab
  103. $(".tab_menu > li").each(function(i){
  104. $(".tab_menu > li").removeClass('current');
  105. $('.tab_menu > li:eq(1)').addClass('current');
  106. $('.box1').addClass('hide');
  107. $('.box2').removeClass('hide');
  108. });
  109. //{/if}设置当前Tab
  110. $(".gallery >li").each(function(){
  111. $(this).on("click",function(){
  112. $(".gallery >li").removeClass('current');
  113. $(this).addClass("current");
  114. })
  115. })
  116. //TABS切换
  117. $('.tabs').Tabs({event:'click',callback:function(rel){
  118. uploader.refresh();
  119. }});
  120. })
  121. function saveImage(){
  122. var index = parent.layer.getFrameIndex(window.name);
  123. $('.getfile').click(function(){
  124. parent.$("#"+$('body').attr("class"))[0].contentWindow.{$input?$input:'setImg'}($(this).attr('data-src'));
  125. {$close?"parent.layer.msg('设置成功')":"parent.layer.close(index)"}
  126. });
  127. }
  128. function setNetImg(){
  129. var index = parent.layer.getFrameIndex(window.name);
  130. var imgpath = $("#imgurl").val();
  131. var re = /^(http|ftp|https):\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))+(\/\S*)+\.(jpg|png|bmp|gif|mp3)/;
  132. if(!re.test(imgpath)){
  133. parent.layer.alert('地址必须以http开头,以jpg,png,bmp,gif,mp3结束');
  134. }else{
  135. parent.$("#"+$('body').attr("class"))[0].contentWindow.{$input?$input:'setImg'}(imgpath);
  136. {$close?"parent.layer.msg('设置成功')":"parent.layer.close(index)"}
  137. }
  138. }
  139. </script>
  140. </body>
  141. </html>