|
@@ -2,6 +2,8 @@ import { Injectable } from "@angular/core";
|
2
|
2
|
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
3
|
3
|
|
4
|
4
|
import host from "../../assets/js/http";
|
|
5
|
+import { resolve } from "q";
|
|
6
|
+import { Observable } from "rxjs";
|
5
|
7
|
|
6
|
8
|
@Injectable({
|
7
|
9
|
providedIn: "root",
|
|
@@ -45,14 +47,34 @@ export class MainService {
|
45
|
47
|
});
|
46
|
48
|
}
|
47
|
49
|
// 字典表
|
|
50
|
+ cachedDictionary = {}; //缓存到内存的字典
|
48
|
51
|
getDictionary(type, key): any {
|
49
|
52
|
const data = {
|
50
|
53
|
type: type,
|
51
|
54
|
key: key,
|
52
|
55
|
};
|
53
|
|
- return this.http.post(host.host + "/common/common/getDictionary", data, {
|
54
|
|
- headers: this.headers,
|
55
|
|
- });
|
|
56
|
+ console.log(this.cachedDictionary, "------------db");
|
|
57
|
+ if (this.cachedDictionary[key]) {
|
|
58
|
+ return new Observable((observer) => {
|
|
59
|
+ observer.next(this.cachedDictionary[key]);
|
|
60
|
+ });
|
|
61
|
+ } else {
|
|
62
|
+ return new Observable((observer) => {
|
|
63
|
+ this.http
|
|
64
|
+ .post(host.host + "/common/common/getDictionary", data, {
|
|
65
|
+ headers: this.headers,
|
|
66
|
+ })
|
|
67
|
+ .subscribe((result) => {
|
|
68
|
+ this.cachedDictionary[key] = result;
|
|
69
|
+ observer.next(result);
|
|
70
|
+ });
|
|
71
|
+ });
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+ //清除字典表缓存
|
|
75
|
+ clearDictionary() {
|
|
76
|
+ this.cachedDictionary = {};
|
|
77
|
+ console.log(this.cachedDictionary, "------clearDb");
|
56
|
78
|
}
|
57
|
79
|
// 列表搜索(通用)
|
58
|
80
|
getFetchDataList(type, target, data): any {
|