StateService.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import VectorType from "../enum/VectorType.js";
  2. import SelectState from "../enum/SelectState.js";
  3. export default class StateService {
  4. constructor() {
  5. this.eventName = null;
  6. this.selectItem = null;
  7. this.focusItem = null;
  8. this.draggingItem = null;
  9. }
  10. getEventName() {
  11. return this.eventName;
  12. }
  13. setEventName(eventName) {
  14. this.eventName = eventName;
  15. }
  16. clearEventName() {
  17. this.eventName = null;
  18. }
  19. // type表示类型,state默认是select,但是有的元素需要知道选中的是哪个顶点
  20. setSelectItem(vectorId, type, state) {
  21. this.selectItem = {};
  22. this.selectItem.vectorId = vectorId;
  23. this.selectItem.type = type;
  24. if (symbolService.isSymbol(type)) {
  25. if (state == SelectState.Select) {
  26. this.selectItem.selectIndex = SelectState.All;
  27. } else {
  28. this.selectItem.selectIndex = state;
  29. }
  30. } else if (componentService.isComponent(type)) {
  31. if (state == SelectState.Select) {
  32. this.selectItem.selectIndex = SelectState.All;
  33. }
  34. } else if (type == VectorType.Tag) {
  35. if (state == SelectState.Select) {
  36. this.selectItem.selectIndex = SelectState.All;
  37. } else {
  38. this.selectItem.selectIndex = state;
  39. }
  40. } else if (furnitureService.isFurniture(type)) {
  41. if (state == SelectState.Select) {
  42. this.selectItem.selectIndex = SelectState.All;
  43. }
  44. }
  45. }
  46. getSelectItem() {
  47. return this.selectItem;
  48. }
  49. clearSelectItem() {
  50. this.selectItem = null;
  51. }
  52. getDraggingItem() {
  53. return this.draggingItem;
  54. }
  55. setDraggingItem(draggingItem) {
  56. this.draggingItem = draggingItem;
  57. }
  58. clearDraggingItem() {
  59. this.draggingItem = null;
  60. }
  61. getFocusItem() {
  62. return this.focusItem;
  63. }
  64. setFocusItem(focusItem) {
  65. this.focusItem = focusItem;
  66. }
  67. clearFocusItem() {
  68. this.focusItem = null;
  69. }
  70. clearItems() {
  71. this.selectItem = null;
  72. this.focusItem = null;
  73. this.draggingItem = null;
  74. }
  75. }
  76. const stateService = new StateService();
  77. export { stateService };