8d83573a7ef4ac58260cb8e809682648c6f9b455.svn-base 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. deleteCaculColAction(col) {
  45. if (this.debug) console.log('deleteCaculColAction triggered with', col)
  46. const index = this.state.caculCols.findIndex(c => c.Column === col.Column)
  47. this.state.caculCols.splice(index, 1)
  48. },
  49. setCaculColsAction(caculCols) {
  50. if (this.debug) console.log('setCaculColsAction triggered')
  51. this.state.caculCols = caculCols
  52. },
  53. // allCols action
  54. setAllColsAction(allCols) {
  55. if (this.debug) console.log('setAllColsAction triggered width', allCols)
  56. this.state.allCols = allCols
  57. }
  58. }
  59. export default store