@yorha2b-lab/autodev 1.0.20 → 1.0.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "基于视觉大模型的前端(Umi+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -2,32 +2,39 @@ import { formNode } from './index'
2
2
  import { Form, Space, Button } from 'antd'
3
3
  import { PlusOutlined, PlusCircleOutlined, MinusCircleOutlined } from '@ant-design/icons'
4
4
 
5
- export const MyBaseForm = ({ item, form }) => {
5
+ const getValueFromEvent = e => {
6
+ if (Array.isArray(e)) {
7
+ return e
8
+ }
9
+ return e?.fileList
10
+ }
6
11
 
7
- const renderFormContent = ({ item }) => {
12
+ const renderFormContent = ({ item }) => {
8
13
 
9
- if (!item.name) {
10
- return item.value
11
- }
14
+ if (!item.name) {
15
+ return item.value
16
+ }
12
17
 
13
- const inputNode = (
14
- <Form.Item noStyle name={item.name} rules={item.rules} initialValue={item.value} valuePropName={item.valuePropName}>
15
- {formNode({ item })}
16
- </Form.Item>
18
+ const inputNode = (
19
+ <Form.Item noStyle name={item.name} rules={item.rules} initialValue={item.value} {...(item.type === 'upload' ? { getValueFromEvent, valuePropName: 'fileList' } : { valuePropName: item.valuePropName })}>
20
+ {formNode({ item })}
21
+ </Form.Item>
22
+ )
23
+
24
+ if (item.unit) {
25
+ return (
26
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
27
+ <div style={{ flex: 1, minWidth: 0 }}>{inputNode}</div>
28
+ <span style={{ color: '#888', whiteSpace: 'nowrap' }}>{item.unit}</span>
29
+ </div>
17
30
  )
31
+ }
18
32
 
19
- if (item.unit) {
20
- return (
21
- <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
22
- <div style={{ flex: 1, minWidth: 0 }}>{inputNode}</div>
23
- <span style={{ color: '#888', whiteSpace: 'nowrap' }}>{item.unit}</span>
24
- </div>
25
- )
26
- }
33
+ return inputNode
34
+ }
27
35
 
28
- return inputNode
29
- }
30
36
 
37
+ export const MyBaseForm = ({ item, form }) => {
31
38
  return (
32
39
  item.isList ?
33
40
  <Form.List name={item.name} initialValue={item.value}>
@@ -1,4 +1,70 @@
1
- import { Tree, Radio, Input, Upload, Select, Cascader, Checkbox, DatePicker, InputNumber, TreeSelect, AutoComplete } from 'antd'
1
+ import { useState, useEffect } from 'react'
2
+ import { UploadOutlined } from '@ant-design/icons'
3
+ import { Button, Tree, Radio, Input, Upload, Select, Cascader, Checkbox, DatePicker, InputNumber, TreeSelect, AutoComplete } from 'antd'
4
+
5
+ const initOss = async () => {
6
+ /* 初始化OSS客户端,请自行实现 */
7
+ }
8
+
9
+ const AliyunOSSUpload = ({ style, value, disabled, onChange }) => {
10
+
11
+ const [OSSData, setOSSData] = useState()
12
+
13
+ const init = async () => {
14
+ try {
15
+ const result = await initOss()
16
+ setOSSData(result)
17
+ } catch (err) {
18
+ console.log(err)
19
+ }
20
+ }
21
+
22
+ useEffect(() => {
23
+ init()
24
+ }, [])
25
+
26
+ const handleChange = ({ fileList }) => onChange?.([...fileList])
27
+
28
+ const onRemove = file => {
29
+ const files = (value || []).filter(v => v.url !== file.url)
30
+ onChange?.(files)
31
+ }
32
+
33
+ const getExtraData = file => ({
34
+ key: file.url,
35
+ policy: OSSData?.policy,
36
+ Signature: OSSData?.signature,
37
+ OSSAccessKeyId: OSSData?.accessId,
38
+ })
39
+
40
+ const beforeUpload = async file => {
41
+ if (!OSSData) {
42
+ return false
43
+ }
44
+ const expire = Number(OSSData.expire) * 1000
45
+ if (expire < Date.now()) {
46
+ await init()
47
+ }
48
+ file.url = `${OSSData.dir}/${file.name}`.replace(/\/\//g, '/')
49
+ return file
50
+ }
51
+
52
+ const uploadProps = {
53
+ onRemove,
54
+ name: 'file',
55
+ beforeUpload,
56
+ fileList: value,
57
+ data: getExtraData,
58
+ action: OSSData?.host,
59
+ onChange: handleChange,
60
+ }
61
+
62
+ return (
63
+ <Upload {...uploadProps} disabled={disabled} style={style}>
64
+ <Button icon={<UploadOutlined />}>选择文件</Button>
65
+ </Upload>
66
+ )
67
+ }
2
68
 
3
69
  export const formNode = ({ item }) => {
4
70
 
@@ -14,6 +80,8 @@ export const formNode = ({ item }) => {
14
80
  return <DatePicker {...commonProps} />
15
81
  case 'number':
16
82
  return <InputNumber {...commonProps} />
83
+ case 'ossUpload':
84
+ return <AliyunOSSUpload {...commonProps} />
17
85
  case 'daterange':
18
86
  return <DatePicker.RangePicker {...commonProps} />
19
87
  case 'radio':