ResizeHandler.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import store from '@/store'
  2. import { unix2Date } from '@/utils/Foundation'
  3. const { body } = document
  4. const WIDTH = 992 // refer to Bootstrap's responsive design
  5. export default {
  6. watch: {
  7. $route(route) {
  8. if (this.device === 'mobile' && this.sidebar.opened) {
  9. store.dispatch('app/closeSideBar', { withoutAnimation: false })
  10. }
  11. }
  12. },
  13. beforeMount() {
  14. window.addEventListener('resize', this.$_resizeHandler)
  15. },
  16. beforeDestroy() {
  17. window.removeEventListener('resize', this.$_resizeHandler)
  18. },
  19. mounted() {
  20. const isMobile = this.$_isMobile()
  21. if (isMobile) {
  22. store.dispatch('app/toggleDevice', 'mobile')
  23. store.dispatch('app/closeSideBar', { withoutAnimation: true })
  24. }
  25. },
  26. methods: {
  27. // use $_ for mixins properties
  28. // https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
  29. $_isMobile() {
  30. const rect = body.getBoundingClientRect()
  31. return rect.width - 1 < WIDTH
  32. },
  33. $_resizeHandler() {
  34. if (!document.hidden) {
  35. const isMobile = this.$_isMobile()
  36. store.dispatch('app/toggleDevice', isMobile ? 'mobile' : 'desktop')
  37. if (isMobile) {
  38. store.dispatch('app/closeSideBar', { withoutAnimation: true })
  39. }
  40. }
  41. },
  42. // 以下方法提供给ag-grid使用
  43. numberParser(text) {
  44. console.log(text)
  45. return true
  46. },
  47. textCustomComparator(filter, value, text) {
  48. return true
  49. },
  50. hashValueGetter(params) {
  51. return params.node.rowIndex + 1
  52. },
  53. dateValueFormatter(params) {
  54. return unix2Date(params.value)
  55. },
  56. dateCustomComparator(valueA, valueB, nodeA, nodeB, isInverted) {
  57. console.log('a', new Date(valueA))
  58. if (valueB === null) {
  59. return 0
  60. }
  61. const cellDate = new Date(valueB)
  62. const day = cellDate.getDate()
  63. const month = cellDate.getMonth()
  64. const year = cellDate.getFullYear()
  65. const cellDateMidNight = new Date(year, month, day)
  66. console.log('b', cellDateMidNight)
  67. if (new Date(valueA) < cellDateMidNight) {
  68. return 1
  69. } else if (new Date(valueA) > cellDateMidNight) {
  70. return -1
  71. } else {
  72. return 0
  73. }
  74. }
  75. }
  76. }