refine settings
This commit is contained in:
		@@ -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,8 +15,8 @@ import router from './router'
 | 
			
		||||
 | 
			
		||||
import i18n from './lang' // Internationalization
 | 
			
		||||
import './icons' // icon
 | 
			
		||||
import './errorLog' // error log
 | 
			
		||||
import './permission' // permission control
 | 
			
		||||
import './utils/errorLog' // error log
 | 
			
		||||
 | 
			
		||||
import * as filters from './filters' // global filters
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
export default {
 | 
			
		||||
  title: 'vue-element-admin',
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * @type {boolean} true | false
 | 
			
		||||
@@ -16,7 +17,7 @@ export default {
 | 
			
		||||
   * @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']
 | 
			
		||||
   * If you want to also use it in dev, you can pass ['production','development']
 | 
			
		||||
   */
 | 
			
		||||
  errorLog: 'production'
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										35
									
								
								src/utils/errorLog.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/utils/errorLog.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
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
 | 
			
		||||
  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)
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -11,36 +11,41 @@ export function validUsername(str) {
 | 
			
		||||
  return valid_map.indexOf(str.trim()) >= 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 合法uri*/
 | 
			
		||||
export function validURL(url) {
 | 
			
		||||
  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
 | 
			
		||||
  return reg.test(url)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 小写字母*/
 | 
			
		||||
export function validLowerCase(str) {
 | 
			
		||||
  const reg = /^[a-z]+$/
 | 
			
		||||
  return reg.test(str)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 大写字母*/
 | 
			
		||||
export function validUpperCase(str) {
 | 
			
		||||
  const reg = /^[A-Z]+$/
 | 
			
		||||
  return reg.test(str)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 大小写字母*/
 | 
			
		||||
export function validAlphabets(str) {
 | 
			
		||||
  const reg = /^[A-Za-z]+$/
 | 
			
		||||
  return reg.test(str)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * validate email
 | 
			
		||||
 * @param email
 | 
			
		||||
 * @returns {boolean}
 | 
			
		||||
 */
 | 
			
		||||
export function validEmail(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,}))$/
 | 
			
		||||
  return re.test(email)
 | 
			
		||||
  const reg = /^(([^<>()\[\]\\.,;:\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 reg.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)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,12 @@
 | 
			
		||||
'use strict'
 | 
			
		||||
const path = require('path')
 | 
			
		||||
const settings = require('./src/settings.js')
 | 
			
		||||
const { name } = settings
 | 
			
		||||
 | 
			
		||||
function resolve(dir) {
 | 
			
		||||
  return path.join(__dirname, dir)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// TODO: change to Settings
 | 
			
		||||
const port = 9527
 | 
			
		||||
const name = 'vue-element-admin'
 | 
			
		||||
 | 
			
		||||
// Explanation of each configuration item You can find it in https://cli.vuejs.org/config/
 | 
			
		||||
module.exports = {
 | 
			
		||||
  /**
 | 
			
		||||
@@ -25,7 +23,7 @@ module.exports = {
 | 
			
		||||
  lintOnSave: process.env.NODE_ENV === 'development' ? 'error' : false,
 | 
			
		||||
  productionSourceMap: false,
 | 
			
		||||
  devServer: {
 | 
			
		||||
    port: port,
 | 
			
		||||
    port: 9527,
 | 
			
		||||
    open: true,
 | 
			
		||||
    overlay: {
 | 
			
		||||
      warnings: false,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user