截流自动化的商城平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

lists.html 15KB

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