c1c329ec35e279fef39e573b24d05f91ef955d5c.svn-base 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { trimColType } from '@/utils/buildSentence'
  2. import { sqlFunc } from '@/utils/configs'
  3. const store = {
  4. debug: process.env.NODE_ENV === 'development',
  5. state: {
  6. dimensions: [],
  7. caculCols: [],
  8. caculCols2: [],
  9. allCols: []
  10. },
  11. // dimensions actions
  12. addDimensionAction(col) {
  13. if (this.debug) console.log('adddimensionAction triggered with', col)
  14. col.isDimension = true
  15. },
  16. deleteDimensionAction(col) {
  17. if (this.debug) console.log('deleteDimensionAction triggered with', col)
  18. const index = this.state.dimensions.findIndex(c => c.Column === col.Column)
  19. this.state.dimensions[index].isDimension = false
  20. this.state.dimensions.splice(index, 1)
  21. },
  22. setDimensionsAction(dimensions) {
  23. if (this.debug) console.log('setDimensionsAction triggered')
  24. this.state.dimensions = dimensions
  25. },
  26. // caculCols actions
  27. addCaculColAction(col) {
  28. if (this.debug) console.log('addCaculColAction triggered with', col)
  29. const colType = trimColType(col.Type)
  30. const index = this.state.caculCols.findIndex(item => item.Column === col.Column)
  31. const caculCol = {
  32. Column: col.Column,
  33. Comment: col.Comment,
  34. calculFunc: colType.availableFunc[0],
  35. Type: col.Type,
  36. availableFunc: colType.availableFunc.map(func => {
  37. return {
  38. name: sqlFunc[func],
  39. func
  40. }
  41. })
  42. }
  43. this.state.caculCols.splice(index, 1, caculCol)
  44. },
  45. addCaculColAction2(col) {
  46. if (this.debug) console.log('addCaculColAction2 triggered with', col)
  47. const colType = trimColType(col.Type)
  48. const index = this.state.caculCols2.findIndex(item => item.Column === col.Column)
  49. const caculCol2 = {
  50. Column: col.Column,
  51. Comment: col.Comment,
  52. calculFunc: colType.availableFunc[0],
  53. Type: col.Type,
  54. availableFunc: colType.availableFunc.map(func => {
  55. return {
  56. name: sqlFunc[func],
  57. func
  58. }
  59. })
  60. }
  61. this.state.caculCols2.splice(index, 1, caculCol2)
  62. },
  63. deleteCaculColAction(col) {
  64. if (this.debug) console.log('deleteCaculColAction triggered with', col)
  65. const index = this.state.caculCols.findIndex(c => c.Column === col.Column)
  66. this.state.caculCols.splice(index, 1)
  67. },
  68. deleteCaculColAction2(col) {
  69. if (this.debug) console.log('deleteCaculColAction2 triggered with', col)
  70. const index2 = this.state.caculCols2.findIndex(c => c.Column === col.Column)
  71. this.state.caculCols2.splice(index2, 1)
  72. },
  73. setCaculColsAction(caculCols) {
  74. if (this.debug) console.log('setCaculColsAction triggered')
  75. this.state.caculCols = caculCols
  76. },
  77. setCaculColsAction2(caculCols) {
  78. if (this.debug) console.log('setCaculColsAction2 triggered')
  79. this.state.caculCols2 = caculCols
  80. },
  81. // allCols action
  82. setAllColsAction(allCols) {
  83. if (this.debug) console.log('setAllColsAction triggered width', allCols)
  84. this.state.allCols = allCols
  85. }
  86. }
  87. export default store