beer-network 1.1.1-alpha.0 → 1.1.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ export default class Fetch {
21
21
  * 请求地址.
22
22
  */
23
23
  private readonly pathPrefix;
24
- private constructor();
24
+ constructor(pathPrefix: string);
25
25
  /**
26
26
  * 发送POST/JSON 请求.
27
27
  * @param path 路径.
@@ -40,8 +40,9 @@ export default class Fetch {
40
40
  * @param key 缓存Key.
41
41
  * @param callback 数据回执函数.
42
42
  * @param minute 缓存时间 (分钟).
43
+ * @param isCache 是否开启缓存.
43
44
  */
44
- cache<T>(key: string, callback: () => Promise<T>, minute: number): Promise<T>;
45
+ cache<T>(key: string, callback: () => Promise<T>, minute: number, isCache: boolean): Promise<T>;
45
46
  /**
46
47
  * 默认授权方式.
47
48
  */
@@ -51,15 +51,18 @@ class Fetch {
51
51
  * @param key 缓存Key.
52
52
  * @param callback 数据回执函数.
53
53
  * @param minute 缓存时间 (分钟).
54
+ * @param isCache 是否开启缓存.
54
55
  */
55
- async cache(key, callback, minute) {
56
+ async cache(key, callback, minute, isCache) {
56
57
  const cacheKey = 'CACHE_' + key;
57
- const cacheValue = localStorage.getItem(cacheKey);
58
- if (cacheValue !== null) {
59
- const result = JSON.parse(cacheValue);
60
- const { expireTime } = result;
61
- if (expireTime !== undefined && expireTime >= new Date().getTime()) {
62
- return result;
58
+ if (isCache) {
59
+ const cacheValue = localStorage.getItem(cacheKey);
60
+ if (cacheValue !== null) {
61
+ const result = JSON.parse(cacheValue);
62
+ const { expireTime } = result;
63
+ if (expireTime !== undefined && expireTime >= new Date().getTime()) {
64
+ return result;
65
+ }
63
66
  }
64
67
  }
65
68
  const response = await callback();
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "beer-network",
3
3
  "private": false,
4
- "version": "1.1.1-alpha.0",
4
+ "version": "1.1.1-alpha.2",
5
5
  "type": "module",
6
- "files": [
7
- "dist"
8
- ],
9
6
  "scripts": {
10
- "publish": "npm publish"
7
+ "pub-w": "copy package.json .\\dist\\package.json && npm publish ./dist"
11
8
  },
12
9
  "dependencies": {
13
10
  },
@@ -9,12 +9,12 @@ class Session {
9
9
  * <li>window.accessToken 设置身份令牌, 直接返回.</li>
10
10
  */
11
11
  static getBearer() {
12
- if (window.accessToken != undefined && window.accessToken !== '') {
12
+ if (window.accessToken !== undefined && window.accessToken !== '') {
13
13
  return window.accessToken;
14
14
  }
15
15
  const key = window.sessionKey || 'login_user';
16
16
  const loginUser = JSON.parse(localStorage.getItem(key) || '{}');
17
- if (window.accessTokenKey != undefined && window.accessTokenKey !== '') {
17
+ if (window.accessTokenKey !== undefined && window.accessTokenKey !== '') {
18
18
  return loginUser[window.accessTokenKey];
19
19
  }
20
20
  return loginUser.accessToken || loginUser.token || undefined;
File without changes
File without changes
File without changes