截流自动化的商城平台
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.

lists.html 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. {layout name="layout2" /}
  2. <style>
  3. .layui-tree-main {
  4. width: calc(100% - 50px);
  5. }
  6. .layui-tree-iconClick {
  7. margin: 0 5px 0 10px;
  8. }
  9. .layui-tree-txt {
  10. max-width: calc(100% - 33px);;
  11. overflow: hidden;
  12. white-space: nowrap;
  13. text-overflow: ellipsis;
  14. -o-text-overflow:ellipsis;
  15. }
  16. </style>
  17. <div class="file-manager">
  18. <div id="cate-tree-more" class="cate-tree-more" style="width: 200px"></div>
  19. <div class="gallery">
  20. <div class="layui-card" style="box-shadow:none;">
  21. <div class="layui-card-header">
  22. <button type="button" class="layui-btn layui-btn layui-btn-sm layui-btn-normal layEvent" lay-event="addCate"><i class="layui-icon layui-icon-add-circle"></i> 添加分类</button>
  23. <button type="button" class="layui-btn layui-btn layui-btn-sm layui-btn-normal" id="upload">
  24. <i class="layui-icon layui-icon-upload"></i> {if $type == 10}上传图片{elseif $type == 20}上传视频{else/}上传文件{/if}
  25. </button>
  26. <button type="button" class="layui-btn layui-btn layui-btn-sm layEvent layui-btn layui-btn-warm" lay-event="move" style="margin-left:5px;"><i class="layui-icon layui-icon-water"></i> 移动分类</button>
  27. <button type="button" class="layui-btn layui-btn layui-btn-sm layEvent layui-btn layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i> 删除文件</button>
  28. </div>
  29. <div class="layui-card-body">
  30. <script id="manager" type="text/html">
  31. <ul class="warehouse">
  32. {{# layui.each(d, function(index, item){ }}
  33. <li lay-id="{{item.id}}" lay-href="{{item.uri}}">
  34. <div class="file-icon"><img class="file-image" src="{{item.uri}}"></div>
  35. <div class="file-name"><a href="javascript:">{{item.name}}</a></div>
  36. </li>
  37. {{# }); }}
  38. </ul>
  39. {{# if(d.length === 0){ }}
  40. <div class="empty">
  41. <i class="layui-icon layui-icon-release" style=""></i>
  42. <p>木有数据,请去上传</p>
  43. </div>
  44. {{# } }}
  45. </script>
  46. <div id="view"></div>
  47. <input type="hidden" id="fileUrl" value="">
  48. </div>
  49. </div>
  50. <div style="height:55px;"></div>
  51. <div class="footer">
  52. <button type="button" id="okFile" class="layui-btn layui-btn layui-btn-sm layui-btn-normal">使用选中文件</button>
  53. <div id="page"></div>
  54. </div>
  55. </div>
  56. </div>
  57. <script>
  58. layui.use(["form", "element", "tree", "laytpl", "laypage", "upload"], function() {
  59. var $ = layui.jquery;
  60. var tree = layui.tree;
  61. var laytpl = layui.laytpl;
  62. var laypage = layui.laypage;
  63. var upload = layui.upload;
  64. var category = JSON.parse('{$category|raw}');
  65. var curCid = 0;
  66. var uploadIns = upload.render({
  67. elem: "#upload"
  68. ,url: "{:url('Upload/image')}"
  69. ,accept: "images"
  70. ,exts: "jpg|png|gif|bmp|jpeg|ico"
  71. ,size: 4096
  72. ,data : {
  73. "cid": curCid,
  74. "type": "{$type}"
  75. }
  76. ,number: 20
  77. ,multiple: true
  78. ,done: function (res) {
  79. if (res.code === 1) {
  80. var li = "<li lay-id='"+res.data.id+"' lay-href='"+res.data.uri+"'>\n";
  81. li += "<div class='file-icon'><img class='file-image' src='"+res.data.uri+"'></div>\n"
  82. li += "<div class='file-name'><a href='javascript:'>"+res.data.name+"</a></div>\n";
  83. li += "</li>"
  84. $(".warehouse").prepend(li)
  85. }
  86. layer.msg(res.msg);
  87. }
  88. });
  89. var active = {
  90. getFile: function (cid, page) {
  91. cid = cid === undefined ? 0 : cid;
  92. page = page === undefined ? 1 : page;
  93. var data = {cid:cid, page:page, type: "{$type}"};
  94. var index = layer.load(1, {shade: false});
  95. like.ajax({
  96. url: "{:url('File/lists')}",
  97. type: "GET",
  98. data: data,
  99. success:function(res) {
  100. layer.close(index);
  101. if(res.code === 1) {
  102. active.renderList(res.data.data);
  103. laypage.render({
  104. elem: "page"
  105. ,count: res.data.total
  106. ,curr: res.data.current_page
  107. ,limit: res.data.per_page
  108. ,last: res.data.last_page
  109. ,jump: function (obj, first) {
  110. if (!first) {
  111. active.getFile(cid, obj.curr)
  112. }
  113. }
  114. });
  115. }
  116. }
  117. });
  118. },
  119. renderList: function(data) {
  120. var getTpl = document.getElementById("manager").innerHTML;
  121. var view = document.getElementById('view');
  122. laytpl(getTpl).render(data, function(html){
  123. view.innerHTML = html;
  124. });
  125. },
  126. getChoice: function() {
  127. var ids = [];
  128. var href = [];
  129. $(".warehouse li.on").each(function () {
  130. ids.push($(this).attr("lay-id"));
  131. href.push($(this).attr("lay-href"));
  132. });
  133. return {ids:ids, href:href}
  134. },
  135. move: function () {
  136. var fileData = active.getChoice();
  137. if (fileData.ids.length === 0) {
  138. layer.msg("尚未选择任何文件");
  139. return false;
  140. }
  141. layer.open({
  142. type: 2
  143. ,title: "移动文件"
  144. ,content: "{:url('File/move')}?type={$type}"
  145. ,area: ["400px", "440px"]
  146. ,btn: ["确定", "取消"]
  147. ,yes: function(index, layero){
  148. var iframeWindow = window["layui-layer-iframe" + index];
  149. var submit = layero.find("iframe").contents().find("#addSubmit");
  150. iframeWindow.layui.form.on("submit(addSubmit)", function(data){
  151. data.field["file_ids"] = fileData.ids;
  152. data.field["type"] = "{$type}";
  153. like.ajax({
  154. url: "{:url('File/move')}",
  155. data: data.field,
  156. type: "POST",
  157. success:function(res) {
  158. if(res.code === 1) {
  159. // if (data.field['cid'] !== '0') {
  160. // $(".warehouse li.on").remove();
  161. // }
  162. active.getFile(curCid, 1);
  163. layui.layer.msg(res.msg);
  164. layer.close(index);
  165. }
  166. }
  167. });
  168. });
  169. submit.trigger("click");
  170. return false;
  171. }
  172. });
  173. },
  174. del: function () {
  175. var fileData = active.getChoice();
  176. if (fileData.ids.length === 0) {
  177. layer.msg("尚未选择任何文件");
  178. return false;
  179. }
  180. layer.confirm('确定删除所选文件?', function(index){
  181. like.ajax({
  182. url: "{:url('File/del')}",
  183. data: {file_ids: fileData.ids, type: '{$type}'},
  184. type: "POST",
  185. success:function(res) {
  186. if(res.code === 1) {
  187. active.getFile(curCid, 1);
  188. layui.layer.msg(res.msg);
  189. }
  190. }
  191. });
  192. layer.close(index);
  193. });
  194. },
  195. addCate: function () {
  196. layer.open({
  197. type: 2
  198. ,title: "新增分类"
  199. ,content: "{:url('File/addCate')}"
  200. ,area: ["400px", "400px"]
  201. ,btn: ["确定", "取消"]
  202. ,yes: function(index, layero){
  203. var iframeWindow = window["layui-layer-iframe" + index];
  204. var submit = layero.find("iframe").contents().find("#addSubmit");
  205. iframeWindow.layui.form.on("submit(addSubmit)", function(data){
  206. data.field["type"] = "{$type}";
  207. like.ajax({
  208. url: "{:url('File/addCate')}",
  209. data: data.field,
  210. type: "POST",
  211. success:function(res) {
  212. if(res.code === 1) {
  213. category = res.data;
  214. active.renderTree();
  215. layui.layer.msg(res.msg);
  216. layer.close(index);
  217. }
  218. }
  219. });
  220. });
  221. submit.trigger("click");
  222. }
  223. });
  224. },
  225. editCate: function (obj) {
  226. if (obj.data.id === 0) {
  227. layer.msg("此分类不允许编辑", {icon: 2});
  228. return false;
  229. }
  230. layer.open({
  231. type: 2
  232. ,title: "编辑分类"
  233. ,content: "{:url('File/editCate')}?id="+ obj.data.id + '&&type={$type}'
  234. ,area: ["400px", "400px"]
  235. ,btn: ["确定", "取消"]
  236. ,yes: function(index, layero){
  237. var iframeWindow = window["layui-layer-iframe" + index];
  238. var submit = layero.find("iframe").contents().find("#addSubmit");
  239. iframeWindow.layui.form.on("submit(addSubmit)", function(data){
  240. data.field['id'] = obj.data.id;
  241. data.field["type"] = "{$type}";
  242. like.ajax({
  243. url: "{:url('File/editCate')}",
  244. data: data.field,
  245. type: "POST",
  246. success:function(res) {
  247. if(res.code === 1) {
  248. category = res.data;
  249. active.renderTree();
  250. layui.layer.msg(res.msg);
  251. layer.close(index);
  252. }
  253. }
  254. });
  255. });
  256. submit.trigger("click");
  257. return false;
  258. }
  259. });
  260. },
  261. delCate: function(obj) {
  262. if (obj.data.id === 0) {
  263. layer.msg("此分类不允许删除", {icon: 2});
  264. return false;
  265. }
  266. like.ajax({
  267. url: "{:url('File/delCate')}",
  268. data: {id: obj.data.id, type: "{$type}"},
  269. type: "POST",
  270. success:function(res) {
  271. if(res.code === 1) {
  272. category = res.data;
  273. active.renderTree();
  274. layui.layer.msg(res.msg);
  275. }else{
  276. category = res.data;
  277. active.renderTree();
  278. }
  279. }
  280. });
  281. },
  282. renderTree: function () {
  283. tree.render({
  284. elem: '#cate-tree-more'
  285. ,edit: ['update', 'del']
  286. ,customOperate: false
  287. ,onlyIconControl:true
  288. ,data: category
  289. ,click: function (obj) {
  290. // 节点被点击
  291. var cid = obj.data.id;
  292. var page = 1;
  293. curCid = cid;
  294. active.getFile(cid, page);
  295. uploadIns.reload({
  296. elem: "#upload"
  297. ,url: "{:url('Upload/image')}"
  298. ,data : {
  299. "cid": curCid,
  300. "type": "{$type}"
  301. }
  302. });
  303. }
  304. ,operate: function(obj){
  305. switch (obj.type) {
  306. case "update":
  307. active.editCate(obj);
  308. break;
  309. case "del":
  310. active.delCate(obj);
  311. break;
  312. }
  313. }
  314. });
  315. }
  316. };
  317. like.eventClick(active);
  318. active.renderTree();
  319. active.getFile();
  320. var globalUrls = [];
  321. $(document).on("click", ".warehouse li", function () {
  322. var isExist = $.inArray($(this).attr("lay-href"), globalUrls);
  323. if (isExist >= 0){
  324. globalUrls.splice(isExist, 1);
  325. } else {
  326. globalUrls.push($(this).attr("lay-href"));
  327. }
  328. if ($(this).hasClass("on")) {
  329. $(this).removeClass("on");
  330. } else {
  331. $(this).addClass("on");
  332. }
  333. $('#fileUrl').val(globalUrls.join(','));
  334. });
  335. // 选择图片(用于富文本的图片选择)
  336. // Author: 张无忌
  337. $("#okFile").click(function () {
  338. // var urls = [];
  339. // $(".warehouse li.on").each(function () {
  340. // urls.push($(this).attr("lay-href"));
  341. // });
  342. if (globalUrls.length <= 0) {
  343. parent.layer.msg("请至少选择一张图片");
  344. return false;
  345. }
  346. var index = parent.layer.getFrameIndex(window.name);
  347. parent.layer.close(index);
  348. parent.window.callback && parent.window.callback(globalUrls.reverse());
  349. });
  350. })
  351. </script>