@ditari/bsui 1.1.28 → 1.1.30

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.
@@ -0,0 +1,107 @@
1
+ import axios from "axios";
2
+ import { message as Message, Modal } from "ant-design-vue";
3
+ import type {
4
+ AxiosInstance,
5
+ InternalAxiosRequestConfig,
6
+ AxiosResponse
7
+ } from "axios";
8
+
9
+ const cancelSource = axios.CancelToken.source();
10
+ const http: AxiosInstance = axios.create({
11
+ baseURL: "http://172.16.10.34:1243/",
12
+ timeout: 1000 * 10 * 60,
13
+ cancelToken: cancelSource.token,
14
+ withCredentials: true
15
+ });
16
+
17
+ // 因为现在的后台接口状态码真是TMD没统一
18
+ const SUCCESS_CODE = ["200", "0"];
19
+ // 登录失效状态码
20
+ const EXPIRED_STATUS_CODE = ["401", "403"];
21
+ // 超额状态码
22
+ const OVER_AMOUNT_CODE = ["1056"];
23
+ const BLACK_URL = ["/login"];
24
+
25
+ http.interceptors.request.use((config: InternalAxiosRequestConfig) => {
26
+ if (!BLACK_URL.includes(config.url as any)) {
27
+ // 没有包含login的url 才添加token
28
+ // config.headers["Authorization"] = getToken;
29
+ }
30
+ return config;
31
+ });
32
+
33
+ http.interceptors.response.use(
34
+ async ({ data }: AxiosResponse) => {
35
+ const { code, data: content, message } = data;
36
+ const successStatus = SUCCESS_CODE.includes(code);
37
+
38
+ // 状态码在SUCCESS_CODE 里面表示成功
39
+ if (successStatus) {
40
+ // 返回响应内容
41
+ return content;
42
+ }
43
+
44
+ switch (code) {
45
+ case EXPIRED_STATUS_CODE[0]:
46
+ case EXPIRED_STATUS_CODE[1]:
47
+ handleExpiredToken();
48
+ break;
49
+ case OVER_AMOUNT_CODE[0]:
50
+ handleOverAmount(message);
51
+ break;
52
+ default:
53
+ handleDefaultError(message);
54
+ break;
55
+ }
56
+ return Promise.reject(data);
57
+ },
58
+ (error) => {
59
+ // 网络超时异常处理
60
+ if (
61
+ error.code === "ECONNABORTED" ||
62
+ error.message === "Network Error" ||
63
+ error.message.includes("timeout")
64
+ ) {
65
+ handleTimeoutError();
66
+ }
67
+ return Promise.reject(error);
68
+ }
69
+ );
70
+
71
+ function handleExpiredToken() {
72
+ cancelSource.cancel("token失效,取消后续请求");
73
+ sessionStorage.clear();
74
+ Message.warn({ content: "登录失效,请重新登录", duration: 5 });
75
+ setTimeout(() => {
76
+ location.href = (import.meta.env.VITE_APP_BASE_URL || "") + "/login";
77
+ }, 2000);
78
+ }
79
+
80
+ function handleOverAmount(message: string) {
81
+ Modal.confirm({
82
+ title: "超额提示",
83
+ content: message,
84
+ centered: true,
85
+ okText: "明白",
86
+ cancelText: "关闭",
87
+ onCancel() {
88
+ Modal.destroyAll();
89
+ }
90
+ });
91
+ }
92
+
93
+ function handleDefaultError(message: string) {
94
+ Message.warn({
95
+ content: message || "未知错误,请联系后台开发人员!!!",
96
+ duration: 6
97
+ });
98
+ }
99
+
100
+ function handleTimeoutError() {
101
+ Message.error({
102
+ content: "请求超时,请稍后重试",
103
+ duration: 6
104
+ });
105
+ }
106
+
107
+ export default http;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditari/bsui",
3
- "version": "1.1.28",
3
+ "version": "1.1.30",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -71,11 +71,12 @@ const basePageClassName = `${prefixName}-pagination`;
71
71
  */
72
72
  const DXTable = defineComponent({
73
73
  name: "DTable",
74
+ inheritAttrs: false,
74
75
  props: tableProps(),
75
76
  // emits: { "update:keys": (keys: []) => void }
76
77
  // TODO 需要做调整
77
78
  emits: ["update:keys"],
78
- setup: function (props, { emit, slots }) {
79
+ setup: function (props, { emit, slots, attrs }) {
79
80
  //分页默认配置
80
81
  const paginationConfig = reactive({
81
82
  defaultPageSize: 20,
@@ -155,6 +156,7 @@ const DXTable = defineComponent({
155
156
  paginationHeight = useEleHeight(paginationEl as any) ?? 0;
156
157
  }
157
158
  tableHeight.value = height - (headerHeight + paginationHeight);
159
+
158
160
  // 设置body高度
159
161
  tableEl.getElementsByClassName("ant-table-body")[0].style.height =
160
162
  tableHeight.value + "px";
@@ -171,9 +173,9 @@ const DXTable = defineComponent({
171
173
  nextTick(() => {
172
174
  // 必须在组件挂载成功后 执行计算高度 否则无法正确获取元素的高度
173
175
  setTimeout(() => {
174
- // 如果表格头 有多行的清空下,获取到的头部高度不对,需要延迟执行获取高度方法
176
+ // 如果表格头有很多列的情况下,获取到的头部高度不对,需要延迟执行获取高度方法
175
177
  playHeight(props.height);
176
- }, 10);
178
+ }, 100);
177
179
  });
178
180
  }
179
181
  });
@@ -396,11 +398,12 @@ const DXTable = defineComponent({
396
398
  };
397
399
 
398
400
  return () => (
399
- <div ref={tableRootRef} style={{ height: "100%" }}>
401
+ <div ref={tableRootRef}>
400
402
  <Table
401
403
  ref={tableRef}
402
404
  row-key={props.rowKey}
403
405
  bordered={props.config.bordered}
406
+ {...attrs}
404
407
  columns={columns.value}
405
408
  dataSource={dataSource.value}
406
409
  loading={props.loading}