842a12bcdedef11439fcdeb0b3d75529dfd3c6be.svn-base 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. calculFunc: colType.availableFunc[0],
  33. Type: col.Type,
  34. availableFunc: colType.availableFunc.map(func => {
  35. return {
  36. name: sqlFunc[func],
  37. func
  38. }
  39. })
  40. }
  41. this.state.caculCols.splice(index, 1, caculCol)
  42. },
  43. deleteCaculColAction(col) {
  44. if (this.debug) console.log('deleteCaculColAction triggered with', col)
  45. const index = this.state.caculCols.findIndex(c => c.Column === col.Column)
  46. this.state.caculCols.splice(index, 1)
  47. },
  48. setCaculColsAction(caculCols) {
  49. if (this.debug) console.log('setCaculColsAction triggered')
  50. this.state.caculCols = caculCols
  51. },
  52. // allCols action
  53. setAllColsAction(allCols) {
  54. if (this.debug) console.log('setAllColsAction triggered width', allCols)
  55. this.state.allCols = allCols
  56. }
  57. }
  58. export default store