1.0.8 • Published 3 years ago

element-business v1.0.8

Weekly downloads
9
License
ISC
Repository
-
Last release
3 years ago

发布

npm version patch
npm publish

业务组件包

// main.js 中初始化

import {
  mCoreComponents,
  mCoreDirectives,
  mCoreAxios,
  mCoreRootHandel,
  layer,
  mCoreUtils
} from './assets/lib/m-business/index'


function mCoreInstall() {
 //自行设置 lang来源
  let lang = 'zhCN';
  let dict = require('./json/dict_' + lang + '.json');
  store.dispatch('mCore/setDictList', dict);
  let error = require('./json/error_' + lang + '.json');
  store.dispatch('mCore/setErrorList', error);
  //设置代理前缀
  store.commit('mCore/setProxy','iotDriver');
  
  Vue.prototype.$rh = {
    confirm:mCoreRootHandel.mconfirm
  }
  Vue.prototype.$mUtils = mCoreUtils;
  Vue.prototype.$layer = layer;
  Vue.prototype.$axios = new mCoreAxios({
    formData: true,//请求格式改成form
    timeout: 5000,// 请求超时时间
    retry: 2,//请求超时重复发次数
    retryDelay: 1000,//请求超时重复发间隔
    //发送请求之前回调
    onRequestBefore: function onRequestBefore(config) {
      var url = config.url;
      if (url.substr(0, 1) === '/') {
        url = url.substr(1);
      }
      if (process.env.NODE_ENV !== 'development') {
        config.url = config.url.replace(/^\/?magusdip/, '')
      }
      return config;
    },
    //返回成功回调
    onResponseSuccess: function onResponseSuccess(response) {
      if (response.data && response.data.flag === -999 && !logoutFlag) {
        console.warn("Timeout", response.config.url);
        logoutFlag = true;
        Store.dispatch("login/clearloginOut");
        if (response.config.url.indexOf("logout") < 0) {
          // alert('Timeout');
          // location = '/';
        }
      }
      return response;
    },
  });
  window.mBusinessEventBus = new Vue();
  for (let key in mCoreDirectives) {
    if (mCoreDirectives.hasOwnProperty(key)) {
      Vue.directive(key, mCoreDirectives[key]);
    }
  }
  for (let key in mCoreComponents) {
    if (mCoreComponents.hasOwnProperty(key)) {
      Vue.component(key, mCoreComponents[key]);
    }
  }

}

mCoreInstall();
//store 中引入 模块
import {mCoreStore} from "../assets/lib/m-business/index";

export default new Vuex.Store({
  state: {},
  mutations: {},
  actions: {},
  modules:{
    mCore:mCoreStore
  }
})
//需要初始化的时候 载入字典 我选择 在App.vue 中混入
const i18nMixins = {
  created() {
    let dict = require('../json/dict_' + (this.lang || 'zhCN') + '.json');
    this.$store.dispatch('mCore/getDictList', dict);
  },
  computed: {
    lang() {
      return this.$store.state.mCore.lang
    }
  },
  watch: {
    lang(n) {
      let dict = require('../json/dict_' + (n || 'zhCN') + '.json');
      this.$store.dispatch('mCore/getDictList', dict);
    }
  }
};
export {
  i18nMixins
}
1.0.8

3 years ago

1.0.7

3 years ago

1.0.2

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago