@hzab/data-model 1.8.3 → 1.8.5

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # @hzab/data-model@1.8.5
2
+
3
+ fix: getToken opt.hasCookie 是否读取 cookie 的 token
4
+ fix: setToken 默认不设置到 cookie 上
5
+
6
+ # @hzab/data-model@1.8.4
7
+
8
+ fix: response undefined 兼容处理
9
+
1
10
  # @hzab/data-model@1.8.3
2
11
 
3
12
  fix: 无 response 默认返回网络异常文案
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/data-model",
3
- "version": "1.8.3",
3
+ "version": "1.8.5",
4
4
  "description": "data model",
5
5
  "main": "src",
6
6
  "scripts": {
package/src/axios.js CHANGED
@@ -10,9 +10,9 @@ export const TOKEN = "token";
10
10
  * @param {Object} opt
11
11
  */
12
12
  export function setToken(token = "", opt) {
13
- const { hasCookie } = opt || {};
13
+ const { hasCookie = false } = opt || {};
14
14
  const _t = token || "";
15
- if (hasCookie !== false) {
15
+ if (hasCookie) {
16
16
  const { cookieAttrs } = opt || {};
17
17
  const cookieOpt = _.merge(
18
18
  {
@@ -30,10 +30,13 @@ export function setToken(token = "", opt) {
30
30
  * 获取 token
31
31
  * @returns
32
32
  */
33
- export function getToken() {
34
- let token = Cookies.get(TOKEN) || "";
35
- if (token) {
36
- return token;
33
+ export function getToken(opt) {
34
+ const { hasCookie = false } = opt || {};
35
+ if (hasCookie) {
36
+ let token = Cookies.get(TOKEN) || "";
37
+ if (token) {
38
+ return token;
39
+ }
37
40
  }
38
41
  token = localStorage.getItem(TOKEN);
39
42
  return token;
package/src/data-model.js CHANGED
@@ -457,7 +457,7 @@ class DataModel {
457
457
  });
458
458
  }
459
459
 
460
- handleRes(response, resolve, reject) {
460
+ handleRes(response = {}, resolve, reject) {
461
461
  if (axios.isCancel(response)) {
462
462
  console.info("errorHandler axios.isCancel", response);
463
463
  return;
@@ -503,7 +503,7 @@ class DataModel {
503
503
  }
504
504
  }
505
505
 
506
- errorHandler(err, reject) {
506
+ errorHandler(err = {}, reject) {
507
507
  if (axios.isCancel(err)) {
508
508
  console.info("errorHandler axios.isCancel", err);
509
509
  return;