@quansitech/antd-admin 1.0.0 → 1.0.1

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.
Files changed (40) hide show
  1. package/components/Column/Cascader.tsx +78 -78
  2. package/components/Column/File.tsx +165 -167
  3. package/components/Column/Image.tsx +76 -76
  4. package/components/{Table/Option → Column/Readonly/Action}/Link.tsx +77 -67
  5. package/components/{Table/Option → Column/Readonly/Action}/types.d.ts +5 -4
  6. package/components/Column/Readonly/Action.tsx +80 -0
  7. package/components/Column/Readonly/Cascader.tsx +50 -50
  8. package/components/Column/Readonly/File.tsx +52 -53
  9. package/components/Column/Readonly/Image.tsx +38 -77
  10. package/components/Column/Readonly/Ueditor.tsx +18 -0
  11. package/components/Column/Readonly/types.d.ts +9 -8
  12. package/components/Column/Ueditor.tsx +313 -313
  13. package/components/Column/types.d.ts +29 -28
  14. package/components/Form/Action/Button.tsx +128 -124
  15. package/components/Form/Action/types.d.ts +5 -4
  16. package/components/Form/Actions.tsx +38 -34
  17. package/components/Form.tsx +179 -170
  18. package/components/FormContext.ts +8 -7
  19. package/components/Layout/New.tsx +252 -0
  20. package/components/Layout.tsx +52 -237
  21. package/components/LayoutContext.ts +25 -25
  22. package/components/ModalContext.ts +15 -15
  23. package/components/Table/Action/Button.tsx +88 -88
  24. package/components/Table/Action/StartEditable.tsx +58 -58
  25. package/components/Table/Action/types.d.ts +7 -6
  26. package/components/Table/ToolbarActions.tsx +43 -38
  27. package/components/Table.scss +4 -7
  28. package/components/Table.tsx +283 -279
  29. package/components/TableContext.ts +14 -13
  30. package/components/Tabs.tsx +71 -71
  31. package/lib/container.ts +83 -81
  32. package/lib/customRule.ts +9 -9
  33. package/lib/global.ts +10 -10
  34. package/lib/helpers.tsx +145 -149
  35. package/lib/http.ts +73 -73
  36. package/lib/schemaHandler.ts +121 -121
  37. package/lib/upload.ts +177 -177
  38. package/package.json +2 -6
  39. package/readme.md +128 -128
  40. package/components/Column/Readonly/Option.tsx +0 -58
package/lib/http.ts CHANGED
@@ -1,74 +1,74 @@
1
- import axios, {AxiosError} from "axios";
2
- import {routerNavigateTo} from "./helpers";
3
- import global from "./global";
4
-
5
- /**
6
- * fetchOptions.noHandle 成功时不处理 url 和 info
7
- */
8
-
9
- const http = axios.create({})
10
-
11
- http.interceptors.request.use(config => {
12
- config.headers['Accept'] = 'application/json'
13
- // 设置异步模式
14
- config.headers['X-Requested-With'] = 'XMLHttpRequest'
15
- return config
16
- })
17
-
18
- http.interceptors.response.use(response => {
19
- const checkInfo = (data: { status?: number, info?: string }) => {
20
- if (!data?.info) {
21
- return false
22
- }
23
- switch (data.status) {
24
- case 0:
25
- global.notification.warning({
26
- message: data.info
27
- })
28
- break
29
- default:
30
- global.notification.success({
31
- message: data.info
32
- })
33
- }
34
- return true
35
- }
36
-
37
- if (response.config.fetchOptions?.noHandle) {
38
- return response
39
- }
40
- const showInfo = checkInfo(response.data)
41
-
42
- if (response.data.url) {
43
- setTimeout(() => {
44
- routerNavigateTo(response.data.url)
45
- }, showInfo ? 2000 : 0)
46
- }
47
- if (response.data.status == 0) {
48
- return Promise.reject(response.data.info)
49
- }
50
- return response
51
- }, error => {
52
- if (error instanceof AxiosError) {
53
- if (error.response?.headers['content-type'].includes('application/json')) {
54
- global.notification.error({
55
- message: error.response?.data?.info || '请求错误,请稍候重试'
56
- })
57
- } else if (error.response?.headers['content-type'].includes('text/html')) {
58
- const parser = new DOMParser;
59
- const doc = parser.parseFromString(error.response?.data, 'text/html');
60
- const title = doc.querySelector('title')?.textContent;
61
-
62
- global.notification.error({
63
- message: title || '请求错误,请稍候重试'
64
- })
65
- }
66
- } else {
67
- global.notification.error({
68
- message: '请求错误,请稍候重试'
69
- })
70
- }
71
- return Promise.reject(error)
72
- })
73
-
1
+ import axios, {AxiosError} from "axios";
2
+ import {routerNavigateTo} from "./helpers";
3
+ import global from "./global";
4
+
5
+ /**
6
+ * fetchOptions.noHandle 成功时不处理 url 和 info
7
+ */
8
+
9
+ const http = axios.create({})
10
+
11
+ http.interceptors.request.use(config => {
12
+ config.headers['Accept'] = 'application/json'
13
+ // 设置异步模式
14
+ config.headers['X-Requested-With'] = 'XMLHttpRequest'
15
+ return config
16
+ })
17
+
18
+ http.interceptors.response.use(response => {
19
+ const checkInfo = (data: { status?: number, info?: string }) => {
20
+ if (!data?.info) {
21
+ return false
22
+ }
23
+ switch (data.status) {
24
+ case 0:
25
+ global.notification.warning({
26
+ message: data.info
27
+ })
28
+ break
29
+ default:
30
+ global.notification.success({
31
+ message: data.info
32
+ })
33
+ }
34
+ return true
35
+ }
36
+
37
+ if (response.config.fetchOptions?.noHandle) {
38
+ return response
39
+ }
40
+ const showInfo = checkInfo(response.data)
41
+
42
+ if (response.data.url) {
43
+ setTimeout(() => {
44
+ routerNavigateTo(response.data.url)
45
+ }, showInfo ? 2000 : 0)
46
+ }
47
+ if (response.data.status == 0) {
48
+ return Promise.reject(response.data.info)
49
+ }
50
+ return response
51
+ }, error => {
52
+ if (error instanceof AxiosError) {
53
+ if (error.response?.headers['content-type'].includes('application/json')) {
54
+ global.notification.error({
55
+ message: error.response?.data?.info || '请求错误,请稍候重试'
56
+ })
57
+ } else if (error.response?.headers['content-type'].includes('text/html')) {
58
+ const parser = new DOMParser;
59
+ const doc = parser.parseFromString(error.response?.data, 'text/html');
60
+ const title = doc.querySelector('title')?.textContent;
61
+
62
+ global.notification.error({
63
+ message: title || '请求错误,请稍候重试'
64
+ })
65
+ }
66
+ } else {
67
+ global.notification.error({
68
+ message: '请求错误,请稍候重试'
69
+ })
70
+ }
71
+ return Promise.reject(error)
72
+ })
73
+
74
74
  export default http
@@ -1,122 +1,122 @@
1
- import {ProColumnType, ProSchema} from "@ant-design/pro-components";
2
- import {UploadFile} from "antd";
3
- import http from "./http";
4
-
5
- type Handler = (schema: any) => ProSchema | ProColumnType
6
-
7
- const uploadValidator = (_: unknown, value: UploadFile[]) => {
8
- return new Promise((resolve, reject) => {
9
- if (!value) {
10
- resolve(true)
11
- return
12
- }
13
- for (let i = 0; i < value.length; i++) {
14
- switch (value[i].status) {
15
- case 'error':
16
- reject('存在上传失败文件,请删除失败文件后重新上传')
17
- return
18
- case 'uploading':
19
- reject('文件上传中,请稍后')
20
- return
21
- }
22
- }
23
- resolve(true)
24
- })
25
- }
26
-
27
- const uploadTransform = (value?: UploadFile[], _name?: string) => {
28
- if (value instanceof Array) {
29
- return value.filter(file => file.status === 'done')
30
- .map((file: UploadFile) => {
31
- return file.response?.file_id
32
- }).join(',')
33
- }
34
- return value
35
- }
36
-
37
- export const commonHandler: Handler = schema => {
38
- if (schema.valueEnum) {
39
- schema.valueEnum = new Map(schema.valueEnum)
40
- }
41
- return schema
42
- }
43
-
44
- export const schemaHandler: Record<string, Handler> = {
45
- dateTimeRange: schema => {
46
- if (schema.search !== false) {
47
- return {
48
- ...schema,
49
- search: {
50
- transform(value) {
51
- if (value) {
52
- return value.join(' - ')
53
- }
54
- return value
55
- }
56
- }
57
- }
58
- }
59
-
60
- return {
61
- ...schema,
62
- }
63
- },
64
- dateRange: schema => {
65
- if (schema.search !== false) {
66
- return {
67
- ...schema,
68
- search: {
69
- transform(value) {
70
- if (value) {
71
- return value.join(' - ')
72
- }
73
- return value
74
- }
75
- }
76
- }
77
- }
78
-
79
- return {
80
- ...schema,
81
- }
82
- },
83
-
84
- // 上传
85
- image: schema => {
86
- schema.formItemProps.rules.push({
87
- validator: uploadValidator,
88
- })
89
-
90
- return {
91
- ...schema,
92
- transform: uploadTransform,
93
- }
94
- },
95
- file: schema => {
96
- schema.formItemProps.rules.push({
97
- validator: uploadValidator,
98
- })
99
-
100
- return {
101
- ...schema,
102
- transform: uploadTransform,
103
- }
104
- },
105
-
106
- select(schema) {
107
- schema.searchOnChange = true
108
- if (schema.fieldProps?.searchUrl) {
109
- return {
110
- ...schema,
111
- request: async params => {
112
- const res = await http(schema.fieldProps.searchUrl, {params})
113
- return res.data.map((item: { value: any, label?: string }) => ({
114
- label: item.label || item.value,
115
- value: item.value
116
- }))
117
- }
118
- }
119
- }
120
- return schema
121
- },
1
+ import {ProColumnType, ProSchema} from "@ant-design/pro-components";
2
+ import {UploadFile} from "antd";
3
+ import http from "./http";
4
+
5
+ type Handler = (schema: any) => ProSchema | ProColumnType
6
+
7
+ const uploadValidator = (_: unknown, value: UploadFile[]) => {
8
+ return new Promise((resolve, reject) => {
9
+ if (!value) {
10
+ resolve(true)
11
+ return
12
+ }
13
+ for (let i = 0; i < value.length; i++) {
14
+ switch (value[i].status) {
15
+ case 'error':
16
+ reject('存在上传失败文件,请删除失败文件后重新上传')
17
+ return
18
+ case 'uploading':
19
+ reject('文件上传中,请稍后')
20
+ return
21
+ }
22
+ }
23
+ resolve(true)
24
+ })
25
+ }
26
+
27
+ const uploadTransform = (value?: UploadFile[], _name?: string) => {
28
+ if (value instanceof Array) {
29
+ return value.filter(file => file.status === 'done')
30
+ .map((file: UploadFile) => {
31
+ return file.response?.file_id
32
+ }).join(',')
33
+ }
34
+ return value
35
+ }
36
+
37
+ export const commonHandler: Handler = schema => {
38
+ if (schema.valueEnum) {
39
+ schema.valueEnum = new Map(schema.valueEnum)
40
+ }
41
+ return schema
42
+ }
43
+
44
+ export const schemaHandler: Record<string, Handler> = {
45
+ dateTimeRange: schema => {
46
+ if (schema.search !== false) {
47
+ return {
48
+ ...schema,
49
+ search: {
50
+ transform(value) {
51
+ if (value) {
52
+ return value.join(' - ')
53
+ }
54
+ return value
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ return {
61
+ ...schema,
62
+ }
63
+ },
64
+ dateRange: schema => {
65
+ if (schema.search !== false) {
66
+ return {
67
+ ...schema,
68
+ search: {
69
+ transform(value) {
70
+ if (value) {
71
+ return value.join(' - ')
72
+ }
73
+ return value
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ return {
80
+ ...schema,
81
+ }
82
+ },
83
+
84
+ // 上传
85
+ image: schema => {
86
+ schema.formItemProps.rules.push({
87
+ validator: uploadValidator,
88
+ })
89
+
90
+ return {
91
+ ...schema,
92
+ transform: uploadTransform,
93
+ }
94
+ },
95
+ file: schema => {
96
+ schema.formItemProps.rules.push({
97
+ validator: uploadValidator,
98
+ })
99
+
100
+ return {
101
+ ...schema,
102
+ transform: uploadTransform,
103
+ }
104
+ },
105
+
106
+ select(schema) {
107
+ schema.searchOnChange = true
108
+ if (schema.fieldProps?.searchUrl) {
109
+ return {
110
+ ...schema,
111
+ request: async params => {
112
+ const res = await http(schema.fieldProps.searchUrl, {params})
113
+ return res.data.map((item: { value: any, label?: string }) => ({
114
+ label: item.label || item.value,
115
+ value: item.value
116
+ }))
117
+ }
118
+ }
119
+ }
120
+ return schema
121
+ },
122
122
  }