File tree Expand file tree Collapse file tree 3 files changed +44
-8
lines changed Expand file tree Collapse file tree 3 files changed +44
-8
lines changed Original file line number Diff line number Diff line change 1
1
import Vue from 'vue' ;
2
- import { ErrorLogModule } from '@/store/modules/errorLog' ;
2
+ import { isArray , isString } from '@/utils/validate' ;
3
+ import { ErrorLogModule } from '@/store/modules/errorLog' ;
4
+ import settings from '@/settings' ;
5
+
6
+ // you can set in settings.js
7
+ // errorLog:'production' | ['production', 'development']
8
+ const { errorLog : needErrorLog } = settings ;
9
+
10
+ const checkNeed = ( ) => {
11
+ const env = process . env . NODE_ENV as string ;
12
+ if ( isString ( needErrorLog ) ) {
13
+ return env === needErrorLog ;
14
+ }
15
+ if ( isArray ( needErrorLog ) ) {
16
+ return needErrorLog . includes ( env ) ;
17
+ }
18
+ return false ;
19
+ } ;
3
20
4
21
// you can set only in production env show the error-log
5
- if ( process . env . NODE_ENV === 'production' ) {
22
+ if ( checkNeed ( ) ) {
6
23
Vue . config . errorHandler = ( err , vm , info ) => {
7
24
// Don't ask me why I use Vue.nextTick, it just a hack.
8
25
// detail see https://forum.vuejs.org/t/dispatch-in-vue-config-errorhandler-has-some-problem/23500
Original file line number Diff line number Diff line change 1
- export function isvalidUsername ( str : string ) {
1
+ export function isValidUsername ( str : string ) {
2
2
const validMap = [ 'admin' , 'editor' ] ;
3
3
return validMap . indexOf ( str . trim ( ) ) >= 0 ;
4
4
}
5
5
6
- /* 小写字母*/
6
+ // 小写字母
7
7
export function validateLowerCase ( str : string ) {
8
8
const reg = / ^ [ a - z ] + $ / ;
9
9
return reg . test ( str ) ;
10
10
}
11
11
12
- /* 大写字母*/
12
+ // 大写字母
13
13
export function validateUpperCase ( str : string ) {
14
14
const reg = / ^ [ A - Z ] + $ / ;
15
15
return reg . test ( str ) ;
16
16
}
17
17
18
- /* 大小写字母*/
18
+ // 大小写字母
19
19
export function validateAlphabets ( str : string ) {
20
20
const reg = / ^ [ A - Z a - z ] + $ / ;
21
21
return reg . test ( str ) ;
22
22
}
23
+
24
+ /**
25
+ * @param {Array } arg
26
+ * @returns {Boolean }
27
+ */
28
+ export function isArray ( arg : any ) {
29
+ if ( typeof Array . isArray === 'undefined' ) {
30
+ return Object . prototype . toString . call ( arg ) === '[object Array]' ;
31
+ }
32
+ return Array . isArray ( arg ) ;
33
+ }
34
+
35
+ /**
36
+ * @param {string } str
37
+ * @returns {Boolean }
38
+ */
39
+ export function isString ( str ) {
40
+ return typeof str === 'string' || str instanceof String ;
41
+ }
Original file line number Diff line number Diff line change 78
78
79
79
<script lang="ts">
80
80
import { Component , Vue , Watch } from ' vue-property-decorator' ;
81
- import { isvalidUsername } from ' @/utils/validate' ;
81
+ import { isValidUsername } from ' @/utils/validate' ;
82
82
import SocialSign from ' ./socialSignIn.vue' ;
83
83
import { LangSelect } from ' @/components' ;
84
84
import { Route } from ' vue-router' ;
87
87
import { UserModule } from ' @/store/modules/user' ;
88
88
89
89
const validateUsername = (rule , value : string , callback ) => {
90
- if (! isvalidUsername (value )) {
90
+ if (! isValidUsername (value )) {
91
91
callback (new Error (' Please enter the correct user name' ));
92
92
} else {
93
93
callback ();
You can’t perform that action at this time.
0 commit comments