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.

69 lines
2.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. import Sortable from "sortablejs";
  2. import { putapi } from "@/api/api";
  3. //拖拽组件初始化
  4. function rowDrop(aa, tableData, isshow, cb) {
  5. const tbody = document.querySelector(aa); //".el-table__body-wrapper tbody"
  6. console.log("tableDatatableData", tableData, isshow, this);
  7. Sortable.create(tbody, {
  8. handle: ".move",
  9. animation: 300,
  10. onEnd({ newIndex, oldIndex }) {
  11. cb();
  12. const currRow = tableData.splice(oldIndex, 1)[0];
  13. tableData.splice(newIndex, 0, currRow);
  14. tableData.map((item, index) => {
  15. if (index == newIndex && index == oldIndex) {
  16. // console.log(item, "新数据");
  17. } else if (index == oldIndex) {
  18. } else if (index == newIndex) {
  19. }
  20. });
  21. console.log(tableData);
  22. console.log(tableData.map((item) => item.displayOrder));
  23. },
  24. });
  25. }
  26. //拖拽排序确定方法
  27. //确定拖拽
  28. // function aassertion() {
  29. // const result = [];
  30. // this.tableData.forEach((item, index) => {
  31. // // index 从0开始的, displayOrder从大到小排
  32. // console.log(item.id);
  33. // console.log(index);
  34. // // const currentDisplayOrder = this.tableData.length -1
  35. // const currentDisplayOrder = this.initTableData[index].displayOrder;
  36. // if (item.displayOrder != currentDisplayOrder) {
  37. // // 如果它的displayOrder和它当前所在的位置不同代表挪动过位置
  38. // result.push({ id: item.id, displayOrder: currentDisplayOrder });
  39. // }
  40. // });
  41. // conlusiondraganddrop({ itemList: result }).then((res) => {
  42. // console.log("操作成功");
  43. // this.isshow = true;
  44. // this.getlist();
  45. // });
  46. // }
  47. function assertions(tableData, initTableData) {
  48. const result = [];
  49. tableData.forEach((item, index) => {
  50. // index 从0开始的, displayOrder从大到小排
  51. console.log(item.id);
  52. console.log(index);
  53. // const currentDisplayOrder = this.tableData.length -1
  54. const currentDisplayOrder = initTableData[index].displayOrder;
  55. if (item.displayOrder != currentDisplayOrder) {
  56. // 如果它的displayOrder和它当前所在的位置不同代表挪动过位置
  57. result.push({ id: item.id, displayOrder: currentDisplayOrder });
  58. }
  59. console.log("currentDisplayOrder", currentDisplayOrder);
  60. console.log("item", item);
  61. });
  62. // putapi(url, { itemList: result }).then((res) => {
  63. // console.log("操作成功");
  64. // this.isshow = true;
  65. // this.getlist();
  66. // });
  67. }
  68. export { rowDrop, assertions };