refactor: remove enquireScreen function from device.js to util.js; 🌟

重构:把 enquireScreen 功能从 device.js 迁移至 util.js;
master
iczer 5 years ago
parent d4261bc401
commit 365dde7e66
  1. 9
      src/App.vue
  2. 15
      src/utils/device.js
  3. 14
      src/utils/util.js

@ -5,8 +5,8 @@
</template>
<script>
import enquireScreen from './utils/device'
import {mapState} from 'vuex'
import {enquireScreen} from './utils/util'
import {mapState, mapMutations} from 'vuex'
import themeUtil from '@/utils/themeUtil';
import {getI18nKey} from '@/utils/routerUtil'
@ -20,9 +20,7 @@ export default {
created () {
this.setHtmlTitle()
this.setLanguage(this.lang)
enquireScreen(isMobile => {
this.$store.commit('setting/setDevice', isMobile)
})
enquireScreen(isMobile => this.setDevice(isMobile))
},
mounted() {
this.setWeekModeTheme(this.weekMode)
@ -54,6 +52,7 @@ export default {
...mapState('setting', ['theme', 'weekMode', 'lang'])
},
methods: {
...mapMutations('setting', ['setDevice']),
setWeekModeTheme(weekMode) {
if (weekMode) {
document.body.classList.add('week-mode')

@ -1,15 +0,0 @@
import enquireJs from 'enquire.js'
const enquireScreen = function (call) {
const hanlder = {
match: function () {
call && call(true)
},
unmatch: function () {
call && call(false)
}
}
enquireJs.register('only screen and (max-width: 767.99px)', hanlder)
}
export default enquireScreen

@ -1,3 +1,5 @@
import enquireJs from 'enquire.js'
export function isDef (v){
return v !== undefined && v !== null
}
@ -18,4 +20,16 @@ export function isRegExp (v) {
return _toString.call(v) === '[object RegExp]'
}
export function enquireScreen(call) {
const handler = {
match: function () {
call && call(true)
},
unmatch: function () {
call && call(false)
}
}
enquireJs.register('only screen and (max-width: 767.99px)', handler)
}
const _toString = Object.prototype.toString

Loading…
Cancel
Save