1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import store from '@/store'
- import { unix2Date } from '@/utils/Foundation'
- const { body } = document
- const WIDTH = 992 // refer to Bootstrap's responsive design
- export default {
- watch: {
- $route(route) {
- if (this.device === 'mobile' && this.sidebar.opened) {
- store.dispatch('app/closeSideBar', { withoutAnimation: false })
- }
- }
- },
- beforeMount() {
- window.addEventListener('resize', this.$_resizeHandler)
- },
- beforeDestroy() {
- window.removeEventListener('resize', this.$_resizeHandler)
- },
- mounted() {
- const isMobile = this.$_isMobile()
- if (isMobile) {
- store.dispatch('app/toggleDevice', 'mobile')
- store.dispatch('app/closeSideBar', { withoutAnimation: true })
- }
- },
- methods: {
- // use $_ for mixins properties
- // https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
- $_isMobile() {
- const rect = body.getBoundingClientRect()
- return rect.width - 1 < WIDTH
- },
- $_resizeHandler() {
- if (!document.hidden) {
- const isMobile = this.$_isMobile()
- store.dispatch('app/toggleDevice', isMobile ? 'mobile' : 'desktop')
- if (isMobile) {
- store.dispatch('app/closeSideBar', { withoutAnimation: true })
- }
- }
- },
- // 以下方法提供给ag-grid使用
- numberParser(text) {
- console.log(text)
- return true
- },
- textCustomComparator(filter, value, text) {
- return true
- },
- hashValueGetter(params) {
- return params.node.rowIndex + 1
- },
- dateValueFormatter(params) {
- return unix2Date(params.value)
- },
- dateCustomComparator(valueA, valueB, nodeA, nodeB, isInverted) {
- console.log('a', new Date(valueA))
- if (valueB === null) {
- return 0
- }
- const cellDate = new Date(valueB)
- const day = cellDate.getDate()
- const month = cellDate.getMonth()
- const year = cellDate.getFullYear()
- const cellDateMidNight = new Date(year, month, day)
- console.log('b', cellDateMidNight)
- if (new Date(valueA) < cellDateMidNight) {
- return 1
- } else if (new Date(valueA) > cellDateMidNight) {
- return -1
- } else {
- return 0
- }
- }
- }
- }
|