5a14fde234b8a779fd9b995b06b5ae03919d2fb3.svn-base 2.9 KB

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