美文网首页
mixin的使用

mixin的使用

作者: 皇甫圣坤 | 来源:发表于2019-08-08 10:46 被阅读0次

@/store/index.js

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import state from './state.js'
import mutations from './mutations.js'
import actions from './actions.js'
import XXX from './modules/XXX'
import getters from './getters'

const store = new Vuex.Store(
  {
    modules: {
      XXX
    },
    getters,
    state,
    mutations,
    actions,
  }
);
export  default store

@/store/state.js

const state = {
  adminLogin:false, //管理员登录状态
  fistAircraft:{},//飞机列表的第一架飞机信息
  aircraftId: '', //警报处理页面中选中的报警发动机ID
  engineId:'', //警报处理页面选中的发动机的ID
};
export default state

@/store/actions.js

const actions = {
  setAdminStatus ({commit},data) {
    commit('SET_ADMINSTATUS',data)
  },
  setHealthWidth ({commit},data) {
    commit('SET_HEALRHWIDTH',data)
  },
  setHealthHeight ({commit},data) {
    commit('SET_HEALRHHEIGHT',data)
  },
  setAircraftId ({commit},data) {
    commit('SET_AIRCRAFTID',data)
  },
  setFistAircraft ({commit},data) {
    commit('SET_FISTAIRCAFT',data)
  },
  setEngineId ({commit},data) {
    commit('SET_ENGINEID',data)
  },
};
export default actions

@/store/getters.js

const getters = {
    healthWidth: state => state.healthmanage.healthWidth,
    healthHeight: state => state.healthmanage.healthHeight,
    adminLogin: state => state.adminLogin,
    fistAircraft: state => state.fistAircraft,
    aircraftId: state => state.aircraftId,
    engineId: state => state.engineId,
}
export default getters

@/store/mutations.js

const mutations = {
  /*管理员身份标识设置*/
  'SET_ADMINSTATUS': (state, status) => {
    state.adminLogin = status
  },
  'SET_AIRCRAFTID': (state, aircraftId) => {
    state.aircraftId = aircraftId
  },
  'SET_FISTAIRCAFT': (state,fistAircraft) => {
    state.fistAircraft = fistAircraft
  },
  'SET_ENGINEID': (state,engineId) => {
    state.engineId = engineId
  }
};
export default mutations

@/store/modules/XXX.js

const healthmanage = {
    state: {
        healthWidth: '',
        healthHeight: '',
    },
    mutations: {
        'SET_HEALRHWIDTH': (state, healthWidth) => {
            state.healthWidth = healthWidth
        },
        'SET_HEALRHHEIGHT': (state, healthHeight) => {
            state.healthHeight = healthHeight
        }
    }
}

export default healthmanage

@utils/miin.js

import {
  mapGetters,
  mapActions
} from 'vuex'

export const pmaMixin = {
  computed: {
    ...mapGetters([
      'healthWidth',
      'healthHeight',
      'adminLogin',
      'fistAircraft',
      'aircraftId',
      'engineId'
    ])
  },
  methods: {
    ...mapActions([
      'setHealthWidth',
      'setHealthHeight',
      'setAdminStatus',
      'setAircraftId',
      'setFistAircraft',
      'setEngineId'
    ]),
    computedPageSize() {
      let healthWidth =
        document.documentElement.clientWidth - 120 ||
        document.body.clientWidth - 120;
      let healthHeight =
        document.documentElement.clientHeight - 90 ||
        document.documentElement.clientHeight - 90;
        this.setHealthWidth(healthWidth)
        this.setHealthHeight(healthHeight)
    },
    // 判断一个对象中是否存在键值为空的项
    formSomeTrim (obj) {
      for(var key in obj) {
        if(!obj[key].trim()) {
          return true
        }
      }
      return false
    },
    // 判断一个对象中是否存在键值为字母
    formSomeMonogram (obj) {
      for(var key in obj) {
        if(+obj[key].trim() !== 0 && !+obj[key].trim()) {
          return true
        }
      }
      return false
    },
    getArguments(msg) {
      this.form.arguments = msg;
      // console.log(this.form);
    },
  }
}

相关文章

网友评论

      本文标题:mixin的使用

      本文链接:https://www.haomeiwen.com/subject/auxzrctx.html