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

tree.js 4.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /** layui-v2.4.1 MIT License By https://www.layui.com */
  2. ;layui.define("jquery", function (e) {
  3. "use strict";
  4. var o = layui.$, a = layui.hint(), i = "layui-tree-enter", r = function (e) {
  5. this.options = e
  6. }, t = {
  7. arrow: ["", ""],
  8. checkbox: ["", ""],
  9. radio: ["", ""],
  10. branch: ["", ""],
  11. leaf: ""
  12. };
  13. r.prototype.init = function (e) {
  14. var o = this;
  15. e.addClass("layui-box layui-tree"), o.options.skin && e.addClass("layui-tree-skin-" + o.options.skin), o.tree(e), o.on(e)
  16. }, r.prototype.tree = function (e, a) {
  17. var i = this, r = i.options, n = a || r.nodes;
  18. layui.each(n, function (a, n) {
  19. var l = n.children && n.children.length > 0,
  20. c = o('<ul class="' + (n.spread ? "layui-show" : "") + '"></ul>'),
  21. s = o(["<li " + (n.spread ? 'data-spread="' + n.spread + '"' : "") + ">", function () {
  22. return l ? '<i class="layui-icon layui-tree-spread">' + (n.spread ? t.arrow[1] : t.arrow[0]) + "</i>" : ""
  23. }(), function () {
  24. return r.check ? '<i class="layui-icon layui-tree-check">' + ("checkbox" === r.check ? t.checkbox[0] : "radio" === r.check ? t.radio[0] : "") + "</i>" : ""
  25. }(), function () {
  26. return '<a href="' + (n.href || "javascript:;") + '" ' + (r.target && n.href ? 'target="' + r.target + '"' : "") + ">" + ('<i class="layui-icon layui-tree-' + (l ? "branch" : "leaf") + '">' + (l ? n.spread ? t.branch[1] : t.branch[0] : t.leaf) + "</i>") + ("<cite>" + (n.name || "未命名") + "</cite></a>")
  27. }(), "</li>"].join(""));
  28. l && (s.append(c), i.tree(c, n.children)), e.append(s), "function" == typeof r.click && i.click(s, n), i.spread(s, n), r.drag && i.drag(s, n)
  29. })
  30. }, r.prototype.click = function (e, o) {
  31. var a = this, i = a.options;
  32. e.children("a").on("click", function (e) {
  33. layui.stope(e), i.click(o)
  34. })
  35. }, r.prototype.spread = function (e, o) {
  36. var a = this, i = (a.options, e.children(".layui-tree-spread")), r = e.children("ul"), n = e.children("a"),
  37. l = function () {
  38. e.data("spread") ? (e.data("spread", null), r.removeClass("layui-show"), i.html(t.arrow[0]), n.find(".layui-icon").html(t.branch[0])) : (e.data("spread", !0), r.addClass("layui-show"), i.html(t.arrow[1]), n.find(".layui-icon").html(t.branch[1]))
  39. };
  40. r[0] && (i.on("click", l), n.on("dblclick", l))
  41. }, r.prototype.on = function (e) {
  42. var a = this, r = a.options, t = "layui-tree-drag";
  43. e.find("i").on("selectstart", function (e) {
  44. return !1
  45. }), r.drag && o(document).on("mousemove", function (e) {
  46. var i = a.move;
  47. if (i.from) {
  48. var r = (i.to, o('<div class="layui-box ' + t + '"></div>'));
  49. e.preventDefault(), o("." + t)[0] || o("body").append(r);
  50. var n = o("." + t)[0] ? o("." + t) : r;
  51. n.addClass("layui-show").html(i.from.elem.children("a").html()), n.css({
  52. left: e.pageX + 10,
  53. top: e.pageY + 10
  54. })
  55. }
  56. }).on("mouseup", function () {
  57. var e = a.move;
  58. e.from && (e.from.elem.children("a").removeClass(i), e.to && e.to.elem.children("a").removeClass(i), a.move = {}, o("." + t).remove())
  59. })
  60. }, r.prototype.move = {}, r.prototype.drag = function (e, a) {
  61. var r = this, t = (r.options, e.children("a")), n = function () {
  62. var t = o(this), n = r.move;
  63. n.from && (n.to = {item: a, elem: e}, t.addClass(i))
  64. };
  65. t.on("mousedown", function () {
  66. var o = r.move;
  67. o.from = {item: a, elem: e}
  68. }), t.on("mouseenter", n).on("mousemove", n).on("mouseleave", function () {
  69. var e = o(this), a = r.move;
  70. a.from && (delete a.to, e.removeClass(i))
  71. })
  72. }, e("tree", function (e) {
  73. var i = new r(e = e || {}), t = o(e.elem);
  74. return t[0] ? void i.init(t) : a.error("layui.tree 没有找到" + e.elem + "元素")
  75. })
  76. });