cosey 0.2.16 → 0.2.18
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/components/table/table-column/table-column.vue.js +17 -13
- package/package.json +1 -1
- package/request/Http.d.ts +13 -12
- package/request/Http.js +70 -49
- package/request/useRequest.d.ts +2 -1
- package/request/useRequest.js +19 -18
|
@@ -75,21 +75,25 @@ const TableColumn = defineComponent({
|
|
|
75
75
|
}
|
|
76
76
|
return result;
|
|
77
77
|
});
|
|
78
|
+
const renderLabel = () => createVNode("span", {
|
|
79
|
+
"class": `${prefixCls.value}-label`
|
|
80
|
+
}, [mergedProps.value.label]);
|
|
81
|
+
const renderTooltip = () => createVNode(Fragment, null, [createVNode(ElTooltip, {
|
|
82
|
+
"content": mergedProps.value.tooltip,
|
|
83
|
+
"placement": "top"
|
|
84
|
+
}, {
|
|
85
|
+
default: () => [createVNode(stdin_default$2, {
|
|
86
|
+
"name": "carbon:help",
|
|
87
|
+
"style": {
|
|
88
|
+
marginInlineStart: token.value.marginXXS + "px"
|
|
89
|
+
}
|
|
90
|
+
}, null)]
|
|
91
|
+
})]);
|
|
78
92
|
return () => mergedProps.value.hidden ? null : createVNode(ElTableColumn, mergedProps.value, {
|
|
79
93
|
...slots.value,
|
|
80
|
-
header: slots.value.header
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
"content": mergedProps.value.tooltip,
|
|
84
|
-
"placement": "top"
|
|
85
|
-
}, {
|
|
86
|
-
default: () => [createVNode(stdin_default$2, {
|
|
87
|
-
"name": "carbon:help",
|
|
88
|
-
"style": {
|
|
89
|
-
marginInlineStart: token.value.marginXXS + "px"
|
|
90
|
-
}
|
|
91
|
-
}, null)]
|
|
92
|
-
})]) : void 0),
|
|
94
|
+
header: slots.value.header && mergedProps.value.tooltip ? (...args) => {
|
|
95
|
+
return [slots.value.header(...args), renderTooltip()];
|
|
96
|
+
} : slots.value.header || (mergedProps.value.tooltip ? () => [renderLabel(), renderTooltip()] : void 0),
|
|
93
97
|
default: slotProps => mergedProps.value.columns ? mergedProps.value.columns.map(column => createVNode(TableColumn, column, null)) : slots.value.default?.(slotProps)
|
|
94
98
|
});
|
|
95
99
|
}
|
package/package.json
CHANGED
package/request/Http.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
1
|
+
import { AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { type HttpConfig } from '../config/http';
|
|
2
3
|
export declare class Http {
|
|
3
|
-
axiosFactory: () => AxiosInstance;
|
|
4
|
+
axiosFactory: (httpConfig?: HttpConfig) => AxiosInstance;
|
|
4
5
|
axiosIns: AxiosInstance | null;
|
|
5
6
|
controller: AbortController;
|
|
6
7
|
config: AxiosRequestConfig | null;
|
|
7
|
-
constructor(axiosFactory: () => AxiosInstance);
|
|
8
|
+
constructor(axiosFactory: (httpConfig?: HttpConfig) => AxiosInstance);
|
|
8
9
|
abort(): void;
|
|
9
|
-
_request<T = any, D = any>(config: AxiosRequestConfig<D
|
|
10
|
-
request<T = any, D = any>(config: AxiosRequestConfig<D
|
|
11
|
-
get<T = any, D = any>(url: string, config?: AxiosRequestConfig<D
|
|
12
|
-
delete<T = any, D = any>(url: string, config?: AxiosRequestConfig<D
|
|
13
|
-
head<T = any, D = any>(url: string, config?: AxiosRequestConfig<D
|
|
14
|
-
options<T = any, D = any>(url: string, config?: AxiosRequestConfig<D
|
|
15
|
-
post<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D
|
|
16
|
-
put<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D
|
|
17
|
-
patch<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D
|
|
10
|
+
_request<T = any, D = any>(config: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
11
|
+
request<T = any, D = any>(config: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
12
|
+
get<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
13
|
+
delete<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
14
|
+
head<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
15
|
+
options<T = any, D = any>(url: string, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
16
|
+
post<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
17
|
+
put<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
18
|
+
patch<T = any, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>, httpConfig?: HttpConfig): Promise<T>;
|
|
18
19
|
}
|
package/request/Http.js
CHANGED
|
@@ -12,69 +12,90 @@ class Http {
|
|
|
12
12
|
this.controller.abort();
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
_request(config) {
|
|
15
|
+
_request(config, httpConfig) {
|
|
16
16
|
if (!config.signal) {
|
|
17
17
|
config.signal = this.controller.signal;
|
|
18
18
|
}
|
|
19
19
|
if (!this.axiosIns) {
|
|
20
|
-
this.axiosIns = this.axiosFactory();
|
|
20
|
+
this.axiosIns = this.axiosFactory(httpConfig);
|
|
21
21
|
}
|
|
22
22
|
return this.axiosIns.request(config);
|
|
23
23
|
}
|
|
24
|
-
request(config) {
|
|
25
|
-
return this._request(config);
|
|
24
|
+
request(config, httpConfig) {
|
|
25
|
+
return this._request(config, httpConfig);
|
|
26
26
|
}
|
|
27
|
-
get(url, config) {
|
|
28
|
-
return this._request(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
get(url, config, httpConfig) {
|
|
28
|
+
return this._request(
|
|
29
|
+
{
|
|
30
|
+
...config,
|
|
31
|
+
url,
|
|
32
|
+
method: "get"
|
|
33
|
+
},
|
|
34
|
+
httpConfig
|
|
35
|
+
);
|
|
33
36
|
}
|
|
34
|
-
delete(url, config) {
|
|
35
|
-
return this._request(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
delete(url, config, httpConfig) {
|
|
38
|
+
return this._request(
|
|
39
|
+
{
|
|
40
|
+
...config,
|
|
41
|
+
url,
|
|
42
|
+
method: "delete"
|
|
43
|
+
},
|
|
44
|
+
httpConfig
|
|
45
|
+
);
|
|
40
46
|
}
|
|
41
|
-
head(url, config) {
|
|
42
|
-
return this._request(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
head(url, config, httpConfig) {
|
|
48
|
+
return this._request(
|
|
49
|
+
{
|
|
50
|
+
...config,
|
|
51
|
+
url,
|
|
52
|
+
method: "head"
|
|
53
|
+
},
|
|
54
|
+
httpConfig
|
|
55
|
+
);
|
|
47
56
|
}
|
|
48
|
-
options(url, config) {
|
|
49
|
-
return this._request(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
options(url, config, httpConfig) {
|
|
58
|
+
return this._request(
|
|
59
|
+
{
|
|
60
|
+
...config,
|
|
61
|
+
url,
|
|
62
|
+
method: "options"
|
|
63
|
+
},
|
|
64
|
+
httpConfig
|
|
65
|
+
);
|
|
54
66
|
}
|
|
55
|
-
post(url, data, config) {
|
|
56
|
-
return this._request(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
post(url, data, config, httpConfig) {
|
|
68
|
+
return this._request(
|
|
69
|
+
{
|
|
70
|
+
...config,
|
|
71
|
+
url,
|
|
72
|
+
data,
|
|
73
|
+
method: "post"
|
|
74
|
+
},
|
|
75
|
+
httpConfig
|
|
76
|
+
);
|
|
62
77
|
}
|
|
63
|
-
put(url, data, config) {
|
|
64
|
-
return this._request(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
put(url, data, config, httpConfig) {
|
|
79
|
+
return this._request(
|
|
80
|
+
{
|
|
81
|
+
...config,
|
|
82
|
+
url,
|
|
83
|
+
data,
|
|
84
|
+
method: "put"
|
|
85
|
+
},
|
|
86
|
+
httpConfig
|
|
87
|
+
);
|
|
70
88
|
}
|
|
71
|
-
patch(url, data, config) {
|
|
72
|
-
return this._request(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
89
|
+
patch(url, data, config, httpConfig) {
|
|
90
|
+
return this._request(
|
|
91
|
+
{
|
|
92
|
+
...config,
|
|
93
|
+
url,
|
|
94
|
+
data,
|
|
95
|
+
method: "patch"
|
|
96
|
+
},
|
|
97
|
+
httpConfig
|
|
98
|
+
);
|
|
78
99
|
}
|
|
79
100
|
}
|
|
80
101
|
|
package/request/useRequest.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type CreateAxiosDefaults } from 'axios';
|
|
2
2
|
import { Http } from './Http';
|
|
3
|
-
|
|
3
|
+
import { type HttpConfig } from '../config/http';
|
|
4
|
+
export declare function useRequest(config?: CreateAxiosDefaults, useHttpConfig?: HttpConfig): {
|
|
4
5
|
fn: <T extends (http: Http) => (...args: any[]) => any, R = {
|
|
5
6
|
(...args: Parameters<ReturnType<T>>): ReturnType<ReturnType<T>>;
|
|
6
7
|
abort: () => void;
|
package/request/useRequest.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRouter, useRoute } from 'vue-router';
|
|
2
2
|
import axios, { AxiosError } from 'axios';
|
|
3
3
|
import { ElMessage } from 'element-plus';
|
|
4
|
-
import { defaults, pick, get } from 'lodash-es';
|
|
4
|
+
import { merge, defaults, pick, get } from 'lodash-es';
|
|
5
5
|
import { useUserStore } from '../store/user.js';
|
|
6
6
|
import { TOKEN_NAME, ROUTER_TO } from '../constant.js';
|
|
7
7
|
import { Http } from './Http.js';
|
|
@@ -9,25 +9,25 @@ import { useGlobalConfig } from '../config/index.js';
|
|
|
9
9
|
import { usePersist } from '../hooks/usePersist.js';
|
|
10
10
|
import { isObject } from '../utils/is.js';
|
|
11
11
|
|
|
12
|
-
function useRequest(config = {}) {
|
|
12
|
+
function useRequest(config = {}, useHttpConfig) {
|
|
13
13
|
const persist = usePersist();
|
|
14
14
|
const userStore = useUserStore();
|
|
15
15
|
const router = useRouter();
|
|
16
16
|
const route = useRoute();
|
|
17
17
|
const { http: httpConfig, router: routerConfig } = useGlobalConfig();
|
|
18
|
-
const handleError = (resData) => {
|
|
19
|
-
const httpPath =
|
|
18
|
+
const handleError = (resData, mergedHttpConfig) => {
|
|
19
|
+
const httpPath = mergedHttpConfig.path;
|
|
20
20
|
const code = get(resData, httpPath.code);
|
|
21
21
|
const message = get(resData, httpPath.message) || "Error";
|
|
22
|
-
const data = get(resData, httpPath.data);
|
|
23
|
-
if (code !==
|
|
22
|
+
const data = httpPath.data ? get(resData, httpPath.data) : resData;
|
|
23
|
+
if (code !== mergedHttpConfig.code.success) {
|
|
24
24
|
ElMessage.error({
|
|
25
25
|
message,
|
|
26
|
-
duration:
|
|
26
|
+
duration: mergedHttpConfig.errorDuration
|
|
27
27
|
});
|
|
28
|
-
if (code ===
|
|
28
|
+
if (code === mergedHttpConfig.code.forbidden) {
|
|
29
29
|
router.push(routerConfig.homePath);
|
|
30
|
-
} else if (code ===
|
|
30
|
+
} else if (code === mergedHttpConfig.code.unauthorized) {
|
|
31
31
|
if (persist.get(TOKEN_NAME)) {
|
|
32
32
|
userStore.logout(persist.get(ROUTER_TO) || route.fullPath);
|
|
33
33
|
}
|
|
@@ -36,23 +36,24 @@ function useRequest(config = {}) {
|
|
|
36
36
|
}
|
|
37
37
|
return data;
|
|
38
38
|
};
|
|
39
|
-
const createAxios = () => {
|
|
39
|
+
const createAxios = (createHttpConfig) => {
|
|
40
|
+
const mergedHttpConfig = merge({}, httpConfig, useHttpConfig, createHttpConfig);
|
|
40
41
|
const axiosIns = axios.create(
|
|
41
|
-
defaults(config, pick(
|
|
42
|
+
defaults(config, pick(mergedHttpConfig, ["baseURL", "timeout", "headers"]))
|
|
42
43
|
);
|
|
43
44
|
axiosIns.interceptors.request.use(
|
|
44
45
|
(config2) => {
|
|
45
|
-
Object.assign(config2,
|
|
46
|
+
Object.assign(config2, mergedHttpConfig.headers);
|
|
46
47
|
const token = persist.get(TOKEN_NAME);
|
|
47
48
|
if (token) {
|
|
48
|
-
config2.headers[
|
|
49
|
+
config2.headers[mergedHttpConfig.authHeaderKey] = mergedHttpConfig.authScheme ? `${mergedHttpConfig.authScheme} ${token}` : token;
|
|
49
50
|
}
|
|
50
51
|
return config2;
|
|
51
52
|
},
|
|
52
53
|
(error) => {
|
|
53
54
|
ElMessage.error({
|
|
54
55
|
message: error,
|
|
55
|
-
duration:
|
|
56
|
+
duration: mergedHttpConfig.errorDuration
|
|
56
57
|
});
|
|
57
58
|
return Promise.reject(error);
|
|
58
59
|
}
|
|
@@ -60,15 +61,15 @@ function useRequest(config = {}) {
|
|
|
60
61
|
axiosIns.interceptors.response.use(
|
|
61
62
|
(response) => {
|
|
62
63
|
const { data: resData } = response;
|
|
63
|
-
return handleError(resData);
|
|
64
|
+
return handleError(resData, mergedHttpConfig);
|
|
64
65
|
},
|
|
65
66
|
(error) => {
|
|
66
|
-
if (error instanceof AxiosError && error.response && isObject(error.response.data) && get(error.response.data,
|
|
67
|
-
return handleError(error.response.data);
|
|
67
|
+
if (error instanceof AxiosError && error.response && isObject(error.response.data) && get(error.response.data, mergedHttpConfig.path.code)) {
|
|
68
|
+
return handleError(error.response.data, mergedHttpConfig);
|
|
68
69
|
} else {
|
|
69
70
|
ElMessage.error({
|
|
70
71
|
message: error.message,
|
|
71
|
-
duration:
|
|
72
|
+
duration: mergedHttpConfig.errorDuration
|
|
72
73
|
});
|
|
73
74
|
return Promise.reject(error);
|
|
74
75
|
}
|