file.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  7. <title>文件管理</title>
  8. <link rel="stylesheet" href="../../assets/libs/layui/css/layui.css"/>
  9. <link rel="stylesheet" href="../../assets/module/admin.css?v=315"/>
  10. <!--[if lt IE 9]>
  11. <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  12. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  13. <![endif]-->
  14. <style>
  15. /* 文件列表item */
  16. .file-choose-list-item {
  17. position: relative;
  18. display: inline-block;
  19. vertical-align: top;
  20. padding: 8px 8px;
  21. margin: 5px 0;
  22. cursor: pointer;
  23. }
  24. .file-choose-list-item:hover {
  25. background-color: #F7F7F7;
  26. }
  27. /* 文件列表图片 */
  28. .file-choose-list-item-img {
  29. width: 90px;
  30. height: 90px;
  31. background-repeat: no-repeat;
  32. background-position: center;
  33. background-size: cover;
  34. border-radius: 3px;
  35. overflow: hidden;
  36. position: relative;
  37. background-color: #eee;
  38. }
  39. .file-choose-list-item-img.img-icon {
  40. background-size: inherit;
  41. background-color: transparent;
  42. }
  43. .file-choose-list-item.active .file-choose-list-item-img:after {
  44. content: "";
  45. position: absolute;
  46. left: 0;
  47. top: 0;
  48. bottom: 0;
  49. right: 0;
  50. background: rgba(0, 0, 0, 0.3);
  51. }
  52. /* 文件列表名称 */
  53. .file-choose-list-item-name {
  54. width: 90px;
  55. overflow: hidden;
  56. text-overflow: ellipsis;
  57. white-space: nowrap;
  58. color: #333;
  59. font-size: 12px;
  60. text-align: center;
  61. margin-top: 12px;
  62. }
  63. /* 文件列表复选框 */
  64. .file-choose-list-item-ck {
  65. position: absolute;
  66. right: 8px;
  67. top: 8px;
  68. }
  69. .file-choose-list-item-ck .layui-form-checkbox {
  70. padding: 0;
  71. }
  72. /* 文件列表操作菜单 */
  73. .file-choose-oper-menu {
  74. background-color: #fff;
  75. position: absolute;
  76. left: 8px;
  77. top: 8px;
  78. border-radius: 2px;
  79. box-shadow: 0px 0px 10px rgba(0, 0, 0, .15);
  80. transition: all .3s;
  81. overflow: hidden;
  82. transform: scale(0);
  83. transform-origin: left top;
  84. visibility: hidden;
  85. }
  86. .file-choose-oper-menu.show {
  87. transform: scale(1);
  88. visibility: visible;
  89. }
  90. /* 文件列表操作菜单item */
  91. .file-choose-oper-menu-item {
  92. color: #555;
  93. padding: 6px 5px;
  94. font-size: 14px;
  95. min-width: 70px;
  96. text-align: center;
  97. cursor: pointer;
  98. display: block;
  99. }
  100. .file-choose-oper-menu-item:hover {
  101. background-color: #eee;
  102. }
  103. /** 文件列表为空时样式 */
  104. .file-choose-empty {
  105. text-align: center;
  106. color: #999;
  107. padding: 50px 0;
  108. }
  109. .file-choose-empty .layui-icon {
  110. font-size: 60px;
  111. display: block;
  112. margin-bottom: 8px;
  113. }
  114. </style>
  115. </head>
  116. <body>
  117. <!-- 加载动画 -->
  118. <div class="page-loading">
  119. <div class="ball-loader">
  120. <span></span><span></span><span></span><span></span>
  121. </div>
  122. </div>
  123. <!-- 正文开始 -->
  124. <div class="layui-fluid">
  125. <div class="layui-card">
  126. <div class="layui-card-body layui-text" style="color: #333;">
  127. 以下是静态页面,后台集成示例参考
  128. <a href="https://gitee.com/whvse/easy-fs" target="_blank">获取源码</a>
  129. </div>
  130. </div>
  131. <div class="layui-card">
  132. <div class="layui-card-header">当前位置:<span id="tv-current-position">/</span></div>
  133. <div class="layui-card-body">
  134. <div>
  135. <button id="file-btn-back" class="layui-btn layui-btn-sm layui-btn-primary icon-btn">
  136. <i class="layui-icon">&#xe65c;</i>返回上级
  137. </button>
  138. <button id="file-btn-refresh" class="layui-btn layui-btn-sm layui-btn-primary icon-btn">
  139. <i class="layui-icon">&#xe669;</i>刷新
  140. </button>
  141. <button id="file-btn-upload" class="layui-btn layui-btn-sm layui-btn-normal icon-btn">
  142. <i class="layui-icon">&#xe681;</i>上传文件
  143. </button>
  144. <button id="file-btn-choose" class="layui-btn layui-btn-sm layui-btn-primary icon-btn"
  145. style="margin-left: 10px;">
  146. <i class="layui-icon">&#xe634;</i>弹窗选择
  147. </button>
  148. </div>
  149. <div id="file-list-group"></div>
  150. </div>
  151. </div>
  152. </div>
  153. <!-- js部分 -->
  154. <script type="text/javascript" src="../../assets/libs/layui/layui.js"></script>
  155. <script type="text/javascript" src="../../assets/js/common.js?v=315"></script>
  156. </body>
  157. <script>
  158. layui.use(['jquery', 'layer', 'element', 'upload', 'admin', 'util', 'fileChoose'], function () {
  159. var $ = layui.jquery;
  160. var layer = layui.layer;
  161. var element = layui.element;
  162. var upload = layui.upload;
  163. var admin = layui.admin;
  164. var util = layui.util;
  165. var fileChoose = layui.fileChoose;
  166. var dataList = [];
  167. // 渲染列表
  168. function renderList(dir) {
  169. dir || (dir = $('#tv-current-position').text());
  170. layer.load(2);
  171. $.get('../../json/files.json', {
  172. dir: dir
  173. }, function (res) {
  174. layer.closeAll('loading');
  175. dataList = res.data;
  176. var htmlStr = fileChoose.renderList({
  177. data: dataList,
  178. menu: [{
  179. name: '预览',
  180. event: 'preview'
  181. }, {
  182. name: '复制',
  183. event: 'copy'
  184. }, {
  185. name: '<span style="color: red;">删除</span>',
  186. event: 'del'
  187. }]
  188. });
  189. $('#file-list-group').html(htmlStr);
  190. }, 'json');
  191. }
  192. renderList();
  193. // 列表点击事件
  194. $(document).off('click.fclip').on('click.fclip', '#file-list-group .file-choose-list-item', function (e) {
  195. var item = dataList[$(this).data('index')];
  196. if (item.isDir) { // 是否是文件夹
  197. var cDir = $('#tv-current-position').text();
  198. cDir += (cDir == '/' ? item.name : ('/' + item.name));
  199. $('#tv-current-position').text(cDir);
  200. renderList(cDir);
  201. } else {
  202. var $cMenu = $(this).find('.file-choose-oper-menu');
  203. $('.file-choose-oper-menu').not($cMenu).removeClass('show');
  204. $cMenu.toggleClass('show');
  205. e.stopPropagation();
  206. }
  207. });
  208. // 点击空白隐藏下拉框
  209. $(document).off('click.fclomp').on('click.fclomp', function (e) {
  210. $('.file-choose-oper-menu').removeClass('show');
  211. });
  212. // 菜单事件监听
  213. $(document).off('click.fclomip').on('click.fclomip', '#file-list-group .file-choose-oper-menu-item', function () {
  214. var event = $(this).data('event');
  215. var dataIndex = $(this).parent().parent().data('index');
  216. if (event == 'del') { // 删除
  217. layer.confirm('确定要删除此文件吗?', {shade: .1}, function () {
  218. layer.msg('操作成功', {icon: 1});
  219. renderList();
  220. });
  221. } else if (event == 'preview') {
  222. window.open(dataList[dataIndex].url);
  223. } else {
  224. layer.msg('点击了' + event + ',索引' + dataIndex, {icon: 1});
  225. }
  226. });
  227. // 刷新
  228. $('#file-btn-refresh').click(function () {
  229. renderList();
  230. });
  231. // 返回上级
  232. $('#file-btn-back').click(function () {
  233. var cDir = $('#tv-current-position').text();
  234. if (cDir != '/') {
  235. cDir = cDir.substring(0, cDir.lastIndexOf('/'));
  236. cDir || (cDir = '/');
  237. $('#tv-current-position').text(cDir);
  238. renderList(cDir);
  239. }
  240. });
  241. // 上传
  242. upload.render({
  243. elem: '#file-btn-upload',
  244. accept: 'file'
  245. });
  246. // 弹窗选择
  247. $('#file-btn-choose').click(function () {
  248. fileChoose.open({
  249. fileUrl: '',
  250. listUrl: '../../json/files.json',
  251. num: 3,
  252. dialog: {
  253. offset: '60px'
  254. },
  255. onChoose: function (urls) {
  256. layer.msg('你选择了:' + JSON.stringify(urls), {icon: 1});
  257. }
  258. });
  259. });
  260. });
  261. </script>
  262. </html>