error-log.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. import Vue from 'vue';
  11. import store from '@/store';
  12. import { isString, isArray } from '@/utils/validate';
  13. import settings from '@/settings';
  14. // you can set in settings.js
  15. // errorLog:'production' | ['production', 'development']
  16. const { errorLog: needErrorLog } = settings;
  17. function checkNeed() {
  18. const env = process.env.NODE_ENV;
  19. if (isString(needErrorLog)) {
  20. return env === needErrorLog;
  21. }
  22. if (isArray(needErrorLog)) {
  23. return needErrorLog.includes(env);
  24. }
  25. return false;
  26. }
  27. if (checkNeed()) {
  28. Vue.config.errorHandler = function (err, vm, info) {
  29. // Don't ask me why I use Vue.nextTick, it just a hack.
  30. // detail see https://forum.vuejs.org/t/dispatch-in-vue-config-errorhandler-has-some-problem/23500
  31. Vue.nextTick(() => {
  32. store.dispatch('errorLog/addErrorLog', {
  33. err,
  34. vm,
  35. info,
  36. url: window.location.href,
  37. });
  38. });
  39. };
  40. }