tianheng-ui 0.1.68 → 0.1.69

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,99 @@
1
+ function Log() {}
2
+
3
+ Log.prototype.type = ["primary", "success", "warn", "error", "info"];
4
+
5
+ Log.prototype.typeColor = function(type) {
6
+ let color = "";
7
+ switch (type) {
8
+ case "primary":
9
+ color = "#2d8cf0";
10
+ break;
11
+ case "success":
12
+ color = "#19be6b";
13
+ break;
14
+ case "info":
15
+ color = "#909399";
16
+ break;
17
+ case "warn":
18
+ color = "#ff9900";
19
+ break;
20
+ case "error":
21
+ color = "#f03f14";
22
+ break;
23
+ default:
24
+ color = "#35495E";
25
+ break;
26
+ }
27
+ return color;
28
+ };
29
+
30
+ Log.prototype.isArray = function(obj) {
31
+ return Object.prototype.toString.call(obj) === "[object Array]";
32
+ };
33
+
34
+ Log.prototype.print = function(text, type = "default", back = false) {
35
+ if (typeof text === "object") {
36
+ // 如果是對象則調用打印對象方式
37
+ this.isArray(text) ? console.table(text) : console.dir(text);
38
+ return;
39
+ }
40
+ if (back) {
41
+ // 如果是打印帶背景圖的
42
+ console.log(`%c ${text} `, `background:${this.typeColor(type)}; padding: 2px; border-radius: 4px; color: #fff;`);
43
+ } else {
44
+ console.log(
45
+ `%c ${text} `,
46
+ `border: 1px solid ${this.typeColor(type)};
47
+ padding: 2px; border-radius: 4px;
48
+ color: ${this.typeColor(type)};`
49
+ );
50
+ }
51
+ };
52
+
53
+ Log.prototype.printBack = function(type = "primary", title) {
54
+ this.print(type, title, true);
55
+ };
56
+
57
+ Log.prototype.pretty = function(type = "primary", title, text) {
58
+ if (typeof text === "object") {
59
+ // console.group("Console Group", title);
60
+ console.log(
61
+ `%c ${title}`,
62
+ `background:${this.typeColor(type)};border:1px solid ${this.typeColor(type)};
63
+ padding: 1px; border-radius: 4px; color: #fff;`
64
+ );
65
+ this.isArray(text) ? console.table(text) : console.dir(text);
66
+ console.groupEnd();
67
+ return;
68
+ }
69
+ console.log(
70
+ `%c ${title} %c ${text} %c`,
71
+ `background:${this.typeColor(type)};border:1px solid ${this.typeColor(type)};
72
+ padding: 1px; border-radius: 4px 0 0 4px; color: #fff;`,
73
+ `border:1px solid ${this.typeColor(type)};
74
+ padding: 1px; border-radius: 0 4px 4px 0; color: ${this.typeColor(type)};`,
75
+ "background:transparent"
76
+ );
77
+ };
78
+
79
+ Log.prototype.prettyPrimary = function(title, ...text) {
80
+ text.forEach(t => this.pretty("primary", title, t));
81
+ };
82
+
83
+ Log.prototype.prettySuccess = function(title, ...text) {
84
+ text.forEach(t => this.pretty("success", title, t));
85
+ };
86
+
87
+ Log.prototype.prettyWarn = function(title, ...text) {
88
+ text.forEach(t => this.pretty("warn", title, t));
89
+ };
90
+
91
+ Log.prototype.prettyError = function(title, ...text) {
92
+ text.forEach(t => this.pretty("error", title, t));
93
+ };
94
+
95
+ Log.prototype.prettyInfo = function(title, ...text) {
96
+ text.forEach(t => this.pretty("info", title, t));
97
+ };
98
+
99
+ export default new Log();
@@ -112,7 +112,7 @@ export default function(config, type = "making") {
112
112
  },
113
113
  methods: {
114
114
  handleSubmit () {
115
- this.$refs.makingForm.getConfig().then(res => {
115
+ this.$refs.makingForm.getData().then(res => {
116
116
  console.log(res);
117
117
  });
118
118
  }
@@ -146,7 +146,7 @@ export default function(config, type = "making") {
146
146
  console.log(val);
147
147
  },
148
148
  handleSubmit () {
149
- this.$refs.generateForm.getConfig().then(res => {
149
+ this.$refs.generateForm.getData().then(res => {
150
150
  console.log(res);
151
151
  });
152
152
  }
@@ -0,0 +1,8 @@
1
+ export default {
2
+ title: "TableMaking",
3
+ logo: "",
4
+ version: "1.0.0",
5
+ storageKeys: {
6
+ oauthConfig: "_TH_OauthConfig"
7
+ }
8
+ };
@@ -84,7 +84,8 @@ import Search from "./custom/items/search/index-pc.vue";
84
84
  import Tools from "./custom/items/tools/index-pc.vue";
85
85
  import STable from "./custom/items/table/index-pc.vue";
86
86
  import Actions from "./custom/items/actions/index-pc.vue";
87
- import * as Axios from "lib/theme-chalk/js/axios";
87
+ import * as Axios from "./network/axios";
88
+ import appConfig from "./config/index";
88
89
  import { deepClone } from "../FormMaking/util";
89
90
  export default {
90
91
  name: "thTableGenerate",
@@ -169,7 +170,10 @@ export default {
169
170
  token: this.oauthConfig.token,
170
171
  baseUrl: this.oauthConfig.baseUrl
171
172
  };
172
- sessionStorage.setItem("th_oauth_info", JSON.stringify(oauthInfo));
173
+ sessionStorage.setItem(
174
+ appConfig.storageKeys.oauthConfig,
175
+ JSON.stringify(oauthInfo)
176
+ );
173
177
  } else if (this.oauthConfig.oauth) {
174
178
  // 模拟授权认证流程
175
179
  this.axios({
@@ -182,7 +186,10 @@ export default {
182
186
  token: res.data,
183
187
  baseUrl: this.oauthConfig.baseUrl
184
188
  };
185
- sessionStorage.setItem("th_oauth_info", JSON.stringify(oauthInfo));
189
+ sessionStorage.setItem(
190
+ appConfig.storageKeys.oauthConfig,
191
+ JSON.stringify(oauthInfo)
192
+ );
186
193
  // this.axios.defaults.baseURL = this.oauthConfig.baseUrl;
187
194
  });
188
195
  }
@@ -0,0 +1,88 @@
1
+ import axios from "axios";
2
+ import Log from "../util/Log";
3
+ import appConfig from "../config/index";
4
+ import { Notification } from "element-ui";
5
+
6
+ export const init = baseConfig => {
7
+ // 创建axios实例
8
+ const Axios = axios.create({
9
+ baseURL: baseConfig.baseUrl,
10
+ timeout: 60000 // 请求超时时间
11
+ // withCredentials: true, //允许携带cookie
12
+ });
13
+
14
+ // 添加请求拦截器
15
+ Axios.interceptors.request.use(
16
+ config => {
17
+ const info = sessionStorage.getItem(appConfig.storageKeys.oauthConfig);
18
+ if (info) {
19
+ const oauthInfo = JSON.parse(info);
20
+ config.baseURL = oauthInfo.baseUrl;
21
+ config.headers["Authorization"] = oauthInfo.token;
22
+ }
23
+ if (baseConfig.headers) {
24
+ config.headers = Object.assign(config.headers, baseConfig.headers);
25
+ }
26
+ return config;
27
+ },
28
+ error => {
29
+ Promise.reject(error);
30
+ }
31
+ );
32
+
33
+ // 添加响应拦截器
34
+ Axios.interceptors.response.use(
35
+ response => {
36
+ const code = response.status;
37
+ if (code < 200 || code > 300) {
38
+ Notification.error({
39
+ title: response.message
40
+ });
41
+ return Promise.reject("error");
42
+ }
43
+
44
+ const dataCode = response.data.code;
45
+ if (dataCode && dataCode !== 200) {
46
+ Notification.error({
47
+ title: response.data.message
48
+ });
49
+ return Promise.reject("error");
50
+ }
51
+
52
+ if (baseConfig.debug) {
53
+ Log.prettyPrimary("Request Url:", response.request.responseURL);
54
+ Log.prettySuccess("Request Res:", response);
55
+ }
56
+
57
+ return response.data;
58
+ },
59
+ error => {
60
+ let code = 0;
61
+ try {
62
+ code = error.response.data.status;
63
+ } catch (e) {
64
+ if (error.toString().indexOf("Error: timeout") !== -1) {
65
+ Notification.error({
66
+ title: "网络请求超时",
67
+ duration: 5000
68
+ });
69
+ return Promise.reject(error);
70
+ }
71
+ }
72
+ if (code) {
73
+ const errorMsg = error.response.data.message;
74
+ Notification.error({
75
+ title: errorMsg || "未知错误",
76
+ duration: 5000
77
+ });
78
+ } else {
79
+ Notification.error({
80
+ title: "接口请求失败",
81
+ duration: 5000
82
+ });
83
+ }
84
+ return Promise.reject(error);
85
+ }
86
+ );
87
+ return Axios;
88
+ };
@@ -0,0 +1,99 @@
1
+ function Log() {}
2
+
3
+ Log.prototype.type = ["primary", "success", "warn", "error", "info"];
4
+
5
+ Log.prototype.typeColor = function(type) {
6
+ let color = "";
7
+ switch (type) {
8
+ case "primary":
9
+ color = "#2d8cf0";
10
+ break;
11
+ case "success":
12
+ color = "#19be6b";
13
+ break;
14
+ case "info":
15
+ color = "#909399";
16
+ break;
17
+ case "warn":
18
+ color = "#ff9900";
19
+ break;
20
+ case "error":
21
+ color = "#f03f14";
22
+ break;
23
+ default:
24
+ color = "#35495E";
25
+ break;
26
+ }
27
+ return color;
28
+ };
29
+
30
+ Log.prototype.isArray = function(obj) {
31
+ return Object.prototype.toString.call(obj) === "[object Array]";
32
+ };
33
+
34
+ Log.prototype.print = function(text, type = "default", back = false) {
35
+ if (typeof text === "object") {
36
+ // 如果是對象則調用打印對象方式
37
+ this.isArray(text) ? console.table(text) : console.dir(text);
38
+ return;
39
+ }
40
+ if (back) {
41
+ // 如果是打印帶背景圖的
42
+ console.log(`%c ${text} `, `background:${this.typeColor(type)}; padding: 2px; border-radius: 4px; color: #fff;`);
43
+ } else {
44
+ console.log(
45
+ `%c ${text} `,
46
+ `border: 1px solid ${this.typeColor(type)};
47
+ padding: 2px; border-radius: 4px;
48
+ color: ${this.typeColor(type)};`
49
+ );
50
+ }
51
+ };
52
+
53
+ Log.prototype.printBack = function(type = "primary", title) {
54
+ this.print(type, title, true);
55
+ };
56
+
57
+ Log.prototype.pretty = function(type = "primary", title, text) {
58
+ if (typeof text === "object") {
59
+ // console.group("Console Group", title);
60
+ console.log(
61
+ `%c ${title}`,
62
+ `background:${this.typeColor(type)};border:1px solid ${this.typeColor(type)};
63
+ padding: 1px; border-radius: 4px; color: #fff;`
64
+ );
65
+ this.isArray(text) ? console.table(text) : console.dir(text);
66
+ console.groupEnd();
67
+ return;
68
+ }
69
+ console.log(
70
+ `%c ${title} %c ${text} %c`,
71
+ `background:${this.typeColor(type)};border:1px solid ${this.typeColor(type)};
72
+ padding: 1px; border-radius: 4px 0 0 4px; color: #fff;`,
73
+ `border:1px solid ${this.typeColor(type)};
74
+ padding: 1px; border-radius: 0 4px 4px 0; color: ${this.typeColor(type)};`,
75
+ "background:transparent"
76
+ );
77
+ };
78
+
79
+ Log.prototype.prettyPrimary = function(title, ...text) {
80
+ text.forEach(t => this.pretty("primary", title, t));
81
+ };
82
+
83
+ Log.prototype.prettySuccess = function(title, ...text) {
84
+ text.forEach(t => this.pretty("success", title, t));
85
+ };
86
+
87
+ Log.prototype.prettyWarn = function(title, ...text) {
88
+ text.forEach(t => this.pretty("warn", title, t));
89
+ };
90
+
91
+ Log.prototype.prettyError = function(title, ...text) {
92
+ text.forEach(t => this.pretty("error", title, t));
93
+ };
94
+
95
+ Log.prototype.prettyInfo = function(title, ...text) {
96
+ text.forEach(t => this.pretty("info", title, t));
97
+ };
98
+
99
+ export default new Log();
@@ -1,25 +0,0 @@
1
- import axios from "axios";
2
-
3
- const request = axios.create({
4
- withCredentials: false
5
- });
6
-
7
- request.interceptors.request.use(
8
- config => {
9
- return config;
10
- },
11
- error => {
12
- return Promise.reject(new Error(error).message);
13
- }
14
- );
15
-
16
- request.interceptors.response.use(
17
- response => {
18
- return response.data;
19
- },
20
- error => {
21
- return Promise.reject(new Error(error).message);
22
- }
23
- );
24
-
25
- export default request;