error.ts
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import store from '/@/store';
import { hotModuleUnregisterModule } from '/@/utils/helper/vuexHelper';
import { VuexModule, getModule, Module, Mutation } from 'vuex-module-decorators';
import { formatToDateTime } from '/@/utils/dateUtil';
export enum ErrorTypeEnum {
VUE = 'vue',
SCRIPT = 'script',
RESOURCE = 'resource',
AJAX = 'ajax',
PROMISE = 'promise',
}
export interface ErrorInfo {
type: ErrorTypeEnum;
file: string;
name?: string;
message: string;
stack?: string;
detail: string;
url: string;
time?: string;
}
export interface ErrorState {
errorInfoState: ErrorInfo[] | null;
errorListCountState: number;
}
const NAME = 'error';
hotModuleUnregisterModule(NAME);
@Module({ dynamic: true, namespaced: true, store, name: NAME })
class Error extends VuexModule implements ErrorState {
errorInfoState: ErrorInfo[] = [];
errorListCountState = 0;
get getErrorInfoState() {
return this.errorInfoState;
}
get getErrorListCountState() {
return this.errorListCountState;
}
@Mutation
commitErrorInfoState(info: ErrorInfo): void {
this.errorInfoState.unshift({
...info,
time: formatToDateTime(new Date()),
});
this.errorListCountState += 1;
}
@Mutation
commitErrorListCountState(count: number): void {
this.errorListCountState = count;
}
}
export { Error };
export const errorStore = getModule<Error>(Error);