@quansitech/antd-admin 1.1.1 → 1.1.2
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/dist/components/Column/Cascader.d.ts +3 -0
- package/dist/components/Column/Cascader.js +110 -0
- package/dist/components/Column/File.d.ts +18 -0
- package/dist/components/Column/File.js +176 -0
- package/dist/components/Column/Image.d.ts +10 -0
- package/dist/components/Column/Image.js +104 -0
- package/dist/components/Column/Readonly/Action/Link.d.ts +11 -0
- package/dist/components/Column/Readonly/Action/Link.js +114 -0
- package/dist/components/Column/Readonly/Action/index.d.ts +4 -0
- package/dist/components/Column/Readonly/Action/index.js +3 -0
- package/dist/components/Column/Readonly/Action.d.ts +12 -0
- package/dist/components/Column/Readonly/Action.js +96 -0
- package/dist/components/Column/Readonly/Cascader.d.ts +9 -0
- package/dist/components/Column/Readonly/Cascader.js +52 -0
- package/dist/components/Column/Readonly/File.d.ts +8 -0
- package/dist/components/Column/Readonly/File.js +54 -0
- package/dist/components/Column/Readonly/Image.d.ts +3 -0
- package/dist/components/Column/Readonly/Image.js +69 -0
- package/dist/components/Column/Readonly/Ueditor.d.ts +3 -0
- package/dist/components/Column/Readonly/Ueditor.js +24 -0
- package/dist/components/Column/Readonly/index.d.ts +8 -0
- package/dist/components/Column/Readonly/index.js +7 -0
- package/dist/components/Column/Ueditor.d.ts +27 -0
- package/dist/components/Column/Ueditor.js +333 -0
- package/dist/components/Column/index.d.ts +7 -0
- package/dist/components/Column/index.js +6 -0
- package/dist/components/Form/Action/Button.d.ts +15 -0
- package/dist/components/Form/Action/Button.js +194 -0
- package/dist/components/Form/Action/index.d.ts +4 -0
- package/dist/components/Form/Action/index.js +3 -0
- package/dist/components/Form/Actions.d.ts +6 -0
- package/dist/components/Form/Actions.js +48 -0
- package/dist/components/Form.d.ts +20 -0
- package/dist/components/Form.js +217 -0
- package/dist/components/FormContext.d.ts +7 -0
- package/dist/components/FormContext.js +2 -0
- package/dist/components/Layout/New.d.ts +7 -0
- package/dist/components/Layout/New.js +257 -0
- package/dist/components/Layout.d.ts +4 -0
- package/dist/components/Layout.js +67 -0
- package/dist/components/LayoutContext.d.ts +26 -0
- package/dist/components/LayoutContext.js +2 -0
- package/dist/components/ModalContext.d.ts +8 -0
- package/dist/components/ModalContext.js +6 -0
- package/dist/components/Table/Action/Button.d.ts +10 -0
- package/dist/components/Table/Action/Button.js +166 -0
- package/dist/components/Table/Action/StartEditable.d.ts +10 -0
- package/dist/components/Table/Action/StartEditable.js +79 -0
- package/dist/components/Table/Action/index.d.ts +5 -0
- package/dist/components/Table/Action/index.js +4 -0
- package/dist/components/Table/ToolbarActions.d.ts +6 -0
- package/dist/components/Table/ToolbarActions.js +52 -0
- package/dist/components/Table.d.ts +19 -0
- package/dist/components/Table.js +322 -0
- package/dist/components/TableContext.d.ts +14 -0
- package/dist/components/TableContext.js +2 -0
- package/dist/components/Tabs.d.ts +15 -0
- package/dist/components/Tabs.js +62 -0
- package/dist/env.d.ts +1 -0
- package/dist/global.d.ts +6 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/lib/container.d.ts +9 -0
- package/dist/lib/container.js +93 -0
- package/dist/lib/customRule.d.ts +3 -0
- package/dist/lib/customRule.js +7 -0
- package/dist/lib/global.d.ts +9 -0
- package/dist/lib/global.js +2 -0
- package/dist/lib/helpers.d.ts +14 -0
- package/dist/lib/helpers.js +183 -0
- package/dist/lib/http.d.ts +5 -0
- package/dist/lib/http.js +72 -0
- package/dist/lib/schemaHandler.d.ts +5 -0
- package/dist/lib/schemaHandler.js +133 -0
- package/dist/lib/upload.d.ts +20 -0
- package/dist/lib/upload.js +215 -0
- package/dist/lib/writeExtra.d.ts +1 -0
- package/dist/lib/writeExtra.js +28 -0
- package/dist/types.d.ts +25 -0
- package/package.json +13 -6
- package/components/Column/Cascader.tsx +0 -79
- package/components/Column/File.tsx +0 -166
- package/components/Column/Image.tsx +0 -77
- package/components/Column/Readonly/Action/Link.tsx +0 -78
- package/components/Column/Readonly/Action.tsx +0 -80
- package/components/Column/Readonly/Cascader.tsx +0 -51
- package/components/Column/Readonly/File.tsx +0 -53
- package/components/Column/Readonly/Image.tsx +0 -39
- package/components/Column/Readonly/Ueditor.tsx +0 -18
- package/components/Column/Ueditor.tsx +0 -314
- package/components/Form/Action/Button.tsx +0 -129
- package/components/Form/Actions.tsx +0 -39
- package/components/Form.tsx +0 -177
- package/components/FormContext.ts +0 -9
- package/components/Layout/New.tsx +0 -251
- package/components/Layout.tsx +0 -52
- package/components/LayoutContext.ts +0 -26
- package/components/ModalContext.ts +0 -16
- package/components/Table/Action/Button.tsx +0 -89
- package/components/Table/Action/StartEditable.tsx +0 -59
- package/components/Table/ToolbarActions.tsx +0 -44
- package/components/Table.tsx +0 -280
- package/components/TableContext.ts +0 -15
- package/components/Tabs.tsx +0 -72
- package/lib/container.ts +0 -84
- package/lib/customRule.ts +0 -10
- package/lib/global.ts +0 -11
- package/lib/helpers.tsx +0 -149
- package/lib/http.ts +0 -74
- package/lib/schemaHandler.ts +0 -122
- package/lib/upload.ts +0 -177
- package/lib/writeExtra.js +0 -31
- /package/{components → dist/components}/Column/Readonly/Action/types.d.ts +0 -0
- /package/{components → dist/components}/Column/Readonly/types.d.ts +0 -0
- /package/{components → dist/components}/Column/types.d.ts +0 -0
- /package/{components → dist/components}/Form/Action/types.d.ts +0 -0
- /package/{components → dist/components}/Table/Action/types.d.ts +0 -0
- /package/{components → dist/components}/Table.scss +0 -0
- /package/{components → dist/components}/types.d.ts +0 -0
package/lib/helpers.tsx
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {router} from "@inertiajs/react";
|
|
2
|
-
import {VisitOptions} from "@inertiajs/core/types/types";
|
|
3
|
-
import Schema from '@rc-component/async-validator';
|
|
4
|
-
import {Rules, ValidateError, ValidateFieldsError, Values} from "@rc-component/async-validator/lib/interface";
|
|
5
|
-
import {Spin} from "antd";
|
|
6
|
-
import http from "./http";
|
|
7
|
-
import container from "./container";
|
|
8
|
-
import {lazy, Suspense} from "react";
|
|
9
|
-
import global from "./global";
|
|
10
|
-
import {ModalContext} from "../components/ModalContext";
|
|
11
|
-
|
|
12
|
-
export function replaceUrl(url: string, params: any) {
|
|
13
|
-
return url.replace(/__([\w]+)__/g, (match, key) => {
|
|
14
|
-
return params[key] || match;
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function replaceParams(params: Record<string, any>, data: Record<string, any>) {
|
|
19
|
-
if (typeof params !== 'object') {
|
|
20
|
-
return params;
|
|
21
|
-
}
|
|
22
|
-
const res = Object.assign({}, params);
|
|
23
|
-
Object.keys(params).forEach(key => {
|
|
24
|
-
if (typeof params[key] === 'string') {
|
|
25
|
-
const m = params[key].match(/^__(\w+)__$/)
|
|
26
|
-
if (m) {
|
|
27
|
-
res[key] = data[m[1]];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
return res;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function routerNavigateTo(url: string, config?: VisitOptions) {
|
|
35
|
-
return router.visit(url, {
|
|
36
|
-
...config,
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function handleRules(dataRules: Rules, data: any) {
|
|
41
|
-
return new Promise(resolve => {
|
|
42
|
-
const validator = new Schema(dataRules);
|
|
43
|
-
validator.validate(data, (errors: ValidateError[] | null, fields: ValidateFieldsError | Values) => {
|
|
44
|
-
if (errors) {
|
|
45
|
-
resolve(false);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
resolve(true);
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function asyncFilter(arr: any[], predicate: (item: any) => PromiseLike<any>) {
|
|
56
|
-
return await Promise.all(arr.map(predicate))
|
|
57
|
-
.then((results) => arr.filter((_v, index) => results[index]))
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function filterObjectKeys(obj: Record<string, any>, keysToKeep: string[]) {
|
|
61
|
-
if (typeof obj !== 'object' || !obj) {
|
|
62
|
-
return obj;
|
|
63
|
-
}
|
|
64
|
-
return Object.keys(obj)
|
|
65
|
-
.filter(key => !keysToKeep.includes(key))
|
|
66
|
-
.reduce((newObj, key) => {
|
|
67
|
-
newObj[key] = obj[key];
|
|
68
|
-
return newObj;
|
|
69
|
-
}, {} as Record<string, any>);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export function createScript(url: string) {
|
|
74
|
-
let scriptTags = window.document.querySelectorAll('script')
|
|
75
|
-
let len = scriptTags.length
|
|
76
|
-
let i = 0
|
|
77
|
-
let _url = window.location.origin + url
|
|
78
|
-
return new Promise((resolve, reject) => {
|
|
79
|
-
for (i = 0; i < len; i++) {
|
|
80
|
-
var src = scriptTags[i].src
|
|
81
|
-
if (src && src === _url) {
|
|
82
|
-
scriptTags[i].parentElement?.removeChild(scriptTags[i])
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let node = document.createElement('script')
|
|
87
|
-
node.src = url
|
|
88
|
-
node.onload = resolve
|
|
89
|
-
document.body.appendChild(node)
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export async function modalShow(options: ModalOptions) {
|
|
94
|
-
let props = options.content.props
|
|
95
|
-
if (options.content.url) {
|
|
96
|
-
const res = await http({
|
|
97
|
-
method: 'get',
|
|
98
|
-
url: options.content.url,
|
|
99
|
-
headers: {
|
|
100
|
-
'X-Modal': '1',
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
if (typeof res.data === 'string') {
|
|
104
|
-
throw new Error('modal response is not vail')
|
|
105
|
-
}
|
|
106
|
-
props = res.data
|
|
107
|
-
}
|
|
108
|
-
if (!props) {
|
|
109
|
-
throw new Error('modal props is empty')
|
|
110
|
-
}
|
|
111
|
-
const Component = lazy(() => container.get('Modal.' + upperFirst(props.type)))
|
|
112
|
-
|
|
113
|
-
let afterClose = () => {
|
|
114
|
-
}
|
|
115
|
-
const modal = global.modal.info({
|
|
116
|
-
...options,
|
|
117
|
-
closable: true,
|
|
118
|
-
icon: null,
|
|
119
|
-
destroyOnClose: true,
|
|
120
|
-
footer: null,
|
|
121
|
-
content: (
|
|
122
|
-
<Suspense fallback={<Spin/>}>
|
|
123
|
-
<ModalContext.Provider value={{
|
|
124
|
-
inModal: true,
|
|
125
|
-
closeModal: () => {
|
|
126
|
-
modal?.destroy()
|
|
127
|
-
},
|
|
128
|
-
contexts: options.contexts,
|
|
129
|
-
setAfterClose(callback: () => void) {
|
|
130
|
-
afterClose = callback
|
|
131
|
-
}
|
|
132
|
-
}}>
|
|
133
|
-
<Component {...props} />
|
|
134
|
-
</ModalContext.Provider>
|
|
135
|
-
</Suspense>
|
|
136
|
-
),
|
|
137
|
-
afterClose: () => {
|
|
138
|
-
afterClose && afterClose()
|
|
139
|
-
},
|
|
140
|
-
})
|
|
141
|
-
return {
|
|
142
|
-
destroy: modal.destroy,
|
|
143
|
-
update: modal.update,
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function upperFirst(str: string) {
|
|
148
|
-
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
149
|
-
}
|
package/lib/http.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
|
-
export default http
|
package/lib/schemaHandler.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
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
|
-
}
|
package/lib/upload.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import http from "./http";
|
|
2
|
-
import {AxiosError} from "axios";
|
|
3
|
-
import {UploadRequestOption} from "rc-upload/lib/interface";
|
|
4
|
-
import {GetProp, message, Upload, UploadFile, UploadProps} from "antd";
|
|
5
|
-
import {md5} from "js-md5"
|
|
6
|
-
|
|
7
|
-
type QsUploadFile = UploadFile & {
|
|
8
|
-
hash_id?: string,
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export async function customRequest(options: UploadRequestOption & {
|
|
12
|
-
file: QsUploadFile
|
|
13
|
-
}) {
|
|
14
|
-
const policyRes = await http({
|
|
15
|
-
url: options.action,
|
|
16
|
-
method: 'get',
|
|
17
|
-
headers: options.headers,
|
|
18
|
-
fetchOptions: {
|
|
19
|
-
noHandle: true
|
|
20
|
-
},
|
|
21
|
-
params: {
|
|
22
|
-
title: options.file.name,
|
|
23
|
-
hash_id: options.file.hash_id,
|
|
24
|
-
file_type: options.file?.type || '' as string
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
if (policyRes.data.status) {
|
|
28
|
-
options.onSuccess && options.onSuccess({
|
|
29
|
-
...policyRes.data,
|
|
30
|
-
url: policyRes.data.url || policyRes.data.file_url
|
|
31
|
-
})
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const formData = new FormData();
|
|
36
|
-
let url = ''
|
|
37
|
-
if (policyRes.data.server_url) {
|
|
38
|
-
url = policyRes.data.server_url
|
|
39
|
-
} else if (policyRes.data.url) {
|
|
40
|
-
url = policyRes.data.url
|
|
41
|
-
}
|
|
42
|
-
if (policyRes.data.params) {
|
|
43
|
-
for (const key in policyRes.data.params) {
|
|
44
|
-
formData.append(key, policyRes.data.params[key])
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
formData.append('file', options.file)
|
|
49
|
-
try {
|
|
50
|
-
const res = await http({
|
|
51
|
-
url: url,
|
|
52
|
-
method: 'post',
|
|
53
|
-
data: formData,
|
|
54
|
-
fetchOptions: {
|
|
55
|
-
noHandle: true
|
|
56
|
-
},
|
|
57
|
-
headers: options.headers,
|
|
58
|
-
onUploadProgress(ev) {
|
|
59
|
-
options.onProgress && options.onProgress({
|
|
60
|
-
percent: (ev.progress || 0) * 100
|
|
61
|
-
})
|
|
62
|
-
},
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
if (res.data.info) {
|
|
66
|
-
message.error(res.data.info)
|
|
67
|
-
options.onError && options.onError(new Error(res.data.info), res.data)
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
options.onSuccess && options.onSuccess({
|
|
72
|
-
...res.data,
|
|
73
|
-
url: res.data.url || res.data.file_url
|
|
74
|
-
})
|
|
75
|
-
} catch (e) {
|
|
76
|
-
if (e instanceof AxiosError) {
|
|
77
|
-
options.onError && options.onError(e, e.response?.data)
|
|
78
|
-
}
|
|
79
|
-
if (e instanceof Error) {
|
|
80
|
-
options.onError && options.onError({
|
|
81
|
-
name: e.name,
|
|
82
|
-
message: e.message,
|
|
83
|
-
method: options.method,
|
|
84
|
-
url: options.action
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
throw e
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export type FileType = Parameters<GetProp<UploadProps, 'beforeUpload'>>[0];
|
|
92
|
-
|
|
93
|
-
export function getBase64(file: FileType): Promise<string> {
|
|
94
|
-
return new Promise((resolve, reject) => {
|
|
95
|
-
const reader = new FileReader();
|
|
96
|
-
reader.readAsDataURL(file);
|
|
97
|
-
reader.onload = () => resolve(reader.result as string);
|
|
98
|
-
reader.onerror = (error) => reject(error);
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* 计算文件MD5
|
|
104
|
-
* https://github.com/quansitech/file-md5-wasm/blob/master/js/calc_file_hash.js
|
|
105
|
-
* @param file
|
|
106
|
-
*/
|
|
107
|
-
export function calc_file_hash(file: File) {
|
|
108
|
-
const MD5_RANGE_SIZE = 10 * 1024 * 1024;
|
|
109
|
-
const CUT_LIMIT = 40 * 1024 * 1024;
|
|
110
|
-
|
|
111
|
-
function makeMd5Range(fileSize: number) {
|
|
112
|
-
if (CUT_LIMIT > fileSize) {
|
|
113
|
-
return [[0, fileSize]];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// MD5_RANGE_SIZE设置为10
|
|
117
|
-
const first = [0.0, MD5_RANGE_SIZE];
|
|
118
|
-
const last = [fileSize - MD5_RANGE_SIZE, fileSize];
|
|
119
|
-
|
|
120
|
-
// 中间段算法
|
|
121
|
-
const rangeMod = fileSize - 3.0 * MD5_RANGE_SIZE;
|
|
122
|
-
const midStart = fileSize % rangeMod;
|
|
123
|
-
const middle = [MD5_RANGE_SIZE + midStart, MD5_RANGE_SIZE + midStart + MD5_RANGE_SIZE];
|
|
124
|
-
|
|
125
|
-
return [first, middle, last];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return new Promise<string>(function (resolve, reject) {
|
|
129
|
-
const fileSize = file.size;
|
|
130
|
-
const range = makeMd5Range(fileSize);
|
|
131
|
-
|
|
132
|
-
let index = 0;
|
|
133
|
-
const hash = md5.create();// 创建MD5哈希对象
|
|
134
|
-
|
|
135
|
-
const reader = new FileReader();
|
|
136
|
-
|
|
137
|
-
reader.onload = function (e) {
|
|
138
|
-
// 处理当前分块的读取结果
|
|
139
|
-
const chunkData = e.target?.result;
|
|
140
|
-
|
|
141
|
-
hash.update(chunkData as string); // 更新哈希计算结果
|
|
142
|
-
|
|
143
|
-
if (index < range.length - 1) {
|
|
144
|
-
index++;
|
|
145
|
-
readNextChunk(range, index);
|
|
146
|
-
} else {
|
|
147
|
-
const fileMD5 = hash.hex(); // 计算文件的最终MD5哈希值
|
|
148
|
-
|
|
149
|
-
resolve(fileMD5);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
reader.onerror = function (e) {
|
|
154
|
-
reject(e);
|
|
155
|
-
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
function readNextChunk(chunkRange: number[][], index: number) {
|
|
159
|
-
const chunk = file.slice(chunkRange[index][0], chunkRange[index][1]);
|
|
160
|
-
reader.readAsArrayBuffer(chunk);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
readNextChunk(range, index);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export async function beforeUpload(file: File & {
|
|
169
|
-
hash_id?: string,
|
|
170
|
-
}, fileList: UploadFile[], allFileList: UploadFile[]) {
|
|
171
|
-
file.hash_id = await calc_file_hash(file)
|
|
172
|
-
const f = allFileList.filter((item: QsUploadFile) => !!item.hash_id).find((item: QsUploadFile) => item.hash_id === file.hash_id)
|
|
173
|
-
if (f) {
|
|
174
|
-
message.error(file.name + '文件已上传')
|
|
175
|
-
return Upload.LIST_IGNORE
|
|
176
|
-
}
|
|
177
|
-
}
|
package/lib/writeExtra.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs"
|
|
2
|
-
import path from "node:path"
|
|
3
|
-
import * as process from "node:process";
|
|
4
|
-
|
|
5
|
-
export default function () {
|
|
6
|
-
// 分析额外组件
|
|
7
|
-
if (!fs.existsSync(process.cwd() + '/vendor')) {
|
|
8
|
-
throw new Error('Please run `composer install` first.');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const installed = JSON.parse(fs.readFileSync(process.cwd() + '/vendor/composer/installed.json'))
|
|
12
|
-
const extras = installed.packages.filter(p => !!p.extra?.qscmf?.['antd-admin']).map(p => ({
|
|
13
|
-
name: p.name,
|
|
14
|
-
path: p['install-path'],
|
|
15
|
-
component: p.extra.qscmf['antd-admin'].component,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
const extra_script = `
|
|
19
|
-
import container from "@quansitech/antd-admin/lib/container.ts";
|
|
20
|
-
|
|
21
|
-
${extras.map(e => {
|
|
22
|
-
const cs = [];
|
|
23
|
-
for (const componentKey in e.component) {
|
|
24
|
-
cs.push(`container.register('${componentKey}', () => import('../../../vendor${path.join('/', e.path, e.component[componentKey])}'));`)
|
|
25
|
-
}
|
|
26
|
-
return cs.join('\n');
|
|
27
|
-
})}
|
|
28
|
-
`
|
|
29
|
-
|
|
30
|
-
fs.writeFileSync(process.cwd() + '/resources/js/backend/extra.ts', extra_script);
|
|
31
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|