add errorLog option
This commit is contained in:
parent
663738262d
commit
4555f7b91b
|
@ -1,19 +0,0 @@
|
||||||
import Vue from 'vue'
|
|
||||||
import store from './store'
|
|
||||||
|
|
||||||
// you can set only in production env show the error-log
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
|
||||||
Vue.config.errorHandler = function(err, vm, info, a) {
|
|
||||||
// Don't ask me why I use Vue.nextTick, it just a hack.
|
|
||||||
// detail see https://forum.vuejs.org/t/dispatch-in-vue-config-errorhandler-has-some-problem/23500
|
|
||||||
Vue.nextTick(() => {
|
|
||||||
store.dispatch('addErrorLog', {
|
|
||||||
err,
|
|
||||||
vm,
|
|
||||||
info,
|
|
||||||
url: window.location.href
|
|
||||||
})
|
|
||||||
console.error(err, info)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,9 +15,9 @@ import store from './store'
|
||||||
|
|
||||||
import i18n from './lang' // Internationalization
|
import i18n from './lang' // Internationalization
|
||||||
import './icons' // icon
|
import './icons' // icon
|
||||||
import './errorLog' // error log
|
|
||||||
import './permission' // permission control
|
import './permission' // permission control
|
||||||
import './mock' // simulation data
|
import './mock' // simulation data
|
||||||
|
import './utils/errorLog' // error log
|
||||||
|
|
||||||
import * as filters from './filters' // global filters
|
import * as filters from './filters' // global filters
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,15 @@ export default {
|
||||||
* @type {boolean} true | false
|
* @type {boolean} true | false
|
||||||
* @description Need tagsView
|
* @description Need tagsView
|
||||||
*/
|
*/
|
||||||
tagsView: true
|
tagsView: true,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {string | array} 'production' | ['production','development']
|
||||||
|
* @description Need show err logs component.
|
||||||
|
* The default is only used in the production env
|
||||||
|
* If you want to use it in dev, you can pass ['production','development']
|
||||||
|
*/
|
||||||
|
errorLog: 'production'
|
||||||
|
|
||||||
// permission: true,
|
// permission: true,
|
||||||
// i18n: true
|
// i18n: true
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
import Vue from 'vue'
|
||||||
|
import store from '@/store'
|
||||||
|
import { isString, isArray } from '@/utils/validate'
|
||||||
|
import settings from '@/settings'
|
||||||
|
|
||||||
|
// you can set in settings.js
|
||||||
|
// errorLog:'production' | ['production','development']
|
||||||
|
const { errorLog: needErrorLog } = settings
|
||||||
|
|
||||||
|
function checkNeed(arg) {
|
||||||
|
const env = process.env.NODE_ENV
|
||||||
|
console.log(needErrorLog)
|
||||||
|
if (isString(needErrorLog)) {
|
||||||
|
return env === needErrorLog
|
||||||
|
}
|
||||||
|
if (isArray(needErrorLog)) {
|
||||||
|
return needErrorLog.includes(env)
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkNeed()) {
|
||||||
|
Vue.config.errorHandler = function(err, vm, info, a) {
|
||||||
|
// Don't ask me why I use Vue.nextTick, it just a hack.
|
||||||
|
// detail see https://forum.vuejs.org/t/dispatch-in-vue-config-errorhandler-has-some-problem/23500
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
store.dispatch('addErrorLog', {
|
||||||
|
err,
|
||||||
|
vm,
|
||||||
|
info,
|
||||||
|
url: window.location.href
|
||||||
|
})
|
||||||
|
console.error(err, info)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,3 +40,17 @@ export function validateEmail(email) {
|
||||||
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
||||||
return re.test(email)
|
return re.test(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isString(str) {
|
||||||
|
if (typeof str === 'string' || str instanceof String) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isArray(arg) {
|
||||||
|
if (typeof Array.isArray === 'undefined') {
|
||||||
|
return Object.prototype.toString.call(arg) === '[object Array]'
|
||||||
|
}
|
||||||
|
return Array.isArray(arg)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue