Helper.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. export default class Helper {
  2. getChildren(all, parent) {
  3. let _this = this,
  4. arr = [],
  5. isBreak = false,
  6. firstTr;
  7. all.each(function (_, v) {
  8. // 过滤非tr标签
  9. if (! _this.isTr(v) || isBreak) return;
  10. firstTr || (firstTr = $(v));
  11. // 非连续的子节点
  12. if (firstTr && ! _this.isChildren(parent, firstTr)) {
  13. return;
  14. }
  15. if (_this.isChildren(parent, v)) {
  16. arr.push(v)
  17. } else {
  18. isBreak = true;
  19. }
  20. });
  21. return arr;
  22. }
  23. swapable(_o, depth) {
  24. if (
  25. _o
  26. && _o.length
  27. && depth === this.getDepth(_o)
  28. ) {
  29. return true
  30. }
  31. }
  32. sibling(all, depth) {
  33. let _this = this,
  34. next;
  35. all.each(function (_, v) {
  36. if (_this.getDepth(v) === depth && ! next && _this.isTr(v)) {
  37. next = $(v);
  38. }
  39. });
  40. return next;
  41. }
  42. isChildren(parent, child) {
  43. return this.getDepth(child) > this.getDepth(parent);
  44. }
  45. getDepth(v) {
  46. return parseInt($(v).data('depth') || 0);
  47. }
  48. isTr(v) {
  49. return $(v).prop('tagName').toLocaleLowerCase() === 'tr'
  50. }
  51. }