neo-cmp-cli 1.2.25 → 1.2.26
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/README.md +60 -6
- package/package.json +1 -1
- package/src/template/neo-custom-cmp-template/src/components/contact-form/index.tsx +20 -17
- package/src/template/neo-custom-cmp-template/src/components/contact-form/model.ts +7 -0
- package/src/template/neo-custom-cmp-template/src/components/object-form/README.md +176 -0
- package/src/template/neo-custom-cmp-template/src/components/object-form/index.tsx +621 -0
- package/src/template/neo-custom-cmp-template/src/components/object-form/model.ts +107 -0
- package/src/template/neo-custom-cmp-template/src/components/object-form/style.scss +371 -0
- package/src/template/neo-custom-cmp-template/src/components/xobject-table/index.tsx +2 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ npm i -g neo-cmp-cli
|
|
|
31
31
|
```bash
|
|
32
32
|
neo init -t=react-ts
|
|
33
33
|
```
|
|
34
|
-
3)
|
|
34
|
+
3) 进入自定义组件项目目录,安装依赖并运行
|
|
35
35
|
```bash
|
|
36
36
|
# 预览自定义组件内容
|
|
37
37
|
neo preview
|
|
@@ -76,21 +76,75 @@ npm run publish2oss
|
|
|
76
76
|
- **neo linkDebug**: 外链调试模式,在平台端页面设计器中调试自定义组件。
|
|
77
77
|
- **neo publish2oss**: 构建并上传到对象存储(可自定义配置对象存储)。
|
|
78
78
|
|
|
79
|
-
##
|
|
79
|
+
## 开发须知
|
|
80
|
+
#### 1、默认自动识别自定义组件
|
|
80
81
|
- **自动生成入口配置**: 当 `entry` 未配置时,自动从 `src/components` 目录下扫描并识别自定义组件,`src/components` 下的子目录名称作为自定义组件的 cmpType,并以其目录下的 `index.ts/.tsx/.js/.jsx` 文件作为组件内容文件,model.[tj]s 作为模型内容文件;
|
|
81
82
|
- **自动注册自定义组件**: 当 `entry` 未配置时,自动生成自定义组件注册文件和模型注册文件,并注入到构建脚本中,无需用户手动编写注册文件 [neo-register](https://www.npmjs.com/package/neo-register)。
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
#### 2、如何设置自定义组件配置项
|
|
85
|
+
通过 neo init 初始化的自定义组件,默认自带组件模型文件,所以和页面设计器关联的信息均在此文件定义(详细见 model 文件中的注释说明),其中 propsSchema 用于添加自定义组件的属性配置面板,当前可用的配置项类型请见 [neo-register 使用文档](https://www.npmjs.com/package/neo-register)。
|
|
86
|
+
|
|
87
|
+
#### 3、在自定义组件使用平台实体数据源
|
|
88
|
+
可使用 OpenAPI SDK 对接平台实体数据源,详细使用方法见 [neo-open-api](https://www.npmjs.com/package/neo-open-api)。
|
|
89
|
+
|
|
90
|
+
#### 4、支持本地构建并发布到对象存储(OSS)
|
|
84
91
|
执行 `neo publish2oss` 即可构建并上传到对象存储。发布前请确保:
|
|
85
92
|
- **package.json 的 name 唯一**
|
|
86
93
|
- **version 不重复**
|
|
87
94
|
- 已按需配置对象存储参数(支持自定义)
|
|
88
95
|
|
|
89
|
-
支持发布指定自定义组件:
|
|
96
|
+
##### 支持发布指定自定义组件:
|
|
90
97
|
执行 `neo publish2oss --cmpType=xxCmp`
|
|
91
98
|
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
##### 支持自定义对象存储配置
|
|
100
|
+
```javascript
|
|
101
|
+
module.exports = {
|
|
102
|
+
publish2oss: {
|
|
103
|
+
// 用于构建并发布至 OSS 的相关配置
|
|
104
|
+
//【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
|
|
105
|
+
// NODE_ENV: 'production',
|
|
106
|
+
// cssExtract: false, // 不额外提取css文件
|
|
107
|
+
ossType: 'ali', // oss类型:ali、baidu
|
|
108
|
+
ossConfig: {
|
|
109
|
+
endpoint: 'https://oss-cn-beijing.aliyuncs.com',
|
|
110
|
+
AccessKeyId: 'xxx',
|
|
111
|
+
AccessKeySecret: 'xx',
|
|
112
|
+
bucket: 'neo-cmp-xx-bucket' // 存储桶名称
|
|
113
|
+
},
|
|
114
|
+
assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### 5、默认复用平台第三方依赖
|
|
120
|
+
自定义组件构建过程中默认会剔除掉平台已有依赖模块(比如 antd、echarts、axios、lodash 等),确保自定义组件构建后的资源体积较小。
|
|
121
|
+
|
|
122
|
+
##### 自定义组件可直接使用的第三方依赖包(NeoCRM 平台预置):
|
|
123
|
+
- react: '^16.13.1',
|
|
124
|
+
- react-dom: '^16.13.1',
|
|
125
|
+
- mobx: '^6.3.0',
|
|
126
|
+
- mobx-react: '^7.0.0',
|
|
127
|
+
- mobx-state-tree' '^5.4.0',
|
|
128
|
+
- echarts: '5.4.2',
|
|
129
|
+
- antd: '4.9.4',
|
|
130
|
+
- antd-mobile: '2.3.4',
|
|
131
|
+
- @ant-design/icons: '^4.8.0',
|
|
132
|
+
- video-react: '0.14.1',
|
|
133
|
+
- axios: '^0.27.2',
|
|
134
|
+
- classnames: '^2.3.2',
|
|
135
|
+
- qs: '^6.11.0',
|
|
136
|
+
- lodash: '^4.17.21',
|
|
137
|
+
- neo-ui-component-web: '^1.0.0',
|
|
138
|
+
- neo-ui-common' '^1.0.0',
|
|
139
|
+
- neo-open-api: '^1.0.11',
|
|
140
|
+
- amis: '^1.1.5'
|
|
141
|
+
|
|
142
|
+
备注:自定义组件中请使用依赖包支持的版本,如版本不匹配运行时可能出现异常。
|
|
143
|
+
|
|
144
|
+
## 项目工程配置说明(neo.config.js)
|
|
145
|
+
neo-cmp-cli 默认提供完整配置;
|
|
146
|
+
如需自定义,使用 `neo config init` 生成 `neo.config.js` 并按需修改。
|
|
147
|
+
|
|
94
148
|
以下为常用配置示例(片段可自由组合)。
|
|
95
149
|
|
|
96
150
|
### 1) 基础规范与检查
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ import './style.scss';
|
|
|
8
8
|
|
|
9
9
|
interface ContactFormProps {
|
|
10
10
|
title: string;
|
|
11
|
+
showSubmitButton?: boolean;
|
|
11
12
|
data?: any;
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -150,7 +151,7 @@ export default class ContactForm extends React.PureComponent<
|
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
render() {
|
|
153
|
-
const { title } = this.props;
|
|
154
|
+
const { title, showSubmitButton } = this.props;
|
|
154
155
|
const { formData, loading, entityTypeList } = this.state;
|
|
155
156
|
const curAmisData = this.props.data || {};
|
|
156
157
|
const systemInfo = curAmisData.__NeoSystemInfo || {};
|
|
@@ -222,22 +223,24 @@ export default class ContactForm extends React.PureComponent<
|
|
|
222
223
|
</Select>
|
|
223
224
|
</Form.Item>
|
|
224
225
|
|
|
225
|
-
|
|
226
|
-
<
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
226
|
+
{showSubmitButton && (
|
|
227
|
+
<Form.Item className="form-actions">
|
|
228
|
+
<Button
|
|
229
|
+
onClick={this.resetForm}
|
|
230
|
+
disabled={loading}
|
|
231
|
+
style={{ marginRight: 8 }}
|
|
232
|
+
>
|
|
233
|
+
重置
|
|
234
|
+
</Button>
|
|
235
|
+
<Button
|
|
236
|
+
type="primary"
|
|
237
|
+
onClick={this.handleSubmit}
|
|
238
|
+
loading={loading}
|
|
239
|
+
>
|
|
240
|
+
保存联系人
|
|
241
|
+
</Button>
|
|
242
|
+
</Form.Item>
|
|
243
|
+
)}
|
|
241
244
|
</Form>
|
|
242
245
|
</Card>
|
|
243
246
|
</div>
|
|
@@ -25,6 +25,7 @@ export class ContactFormModel {
|
|
|
25
25
|
defaultComProps = {
|
|
26
26
|
title: '创建联系人',
|
|
27
27
|
label: '联系人表单',
|
|
28
|
+
showSubmitButton: true,
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
// 设计器端预览时展示的默认数据
|
|
@@ -43,6 +44,12 @@ export class ContactFormModel {
|
|
|
43
44
|
value: '创建联系人',
|
|
44
45
|
placeholder: '请输入表单标题',
|
|
45
46
|
},
|
|
47
|
+
{
|
|
48
|
+
type: 'switch',
|
|
49
|
+
name: 'showSubmitButton',
|
|
50
|
+
label: '显示提交按钮',
|
|
51
|
+
value: true,
|
|
52
|
+
},
|
|
46
53
|
];
|
|
47
54
|
|
|
48
55
|
// 支持 函数式写法:propsSchemaCreator,com 为组件实例。优先级比 propsSchema 高
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Object Form 对象表单组件
|
|
2
|
+
|
|
3
|
+
基于 XObject 的对象表单组件,专门用于新增对象数据,支持动态字段渲染和多种字段类型。
|
|
4
|
+
备注:使用 Neo Open API SDK(neo-open-api)提供的方法实现数据对象的新增操作。
|
|
5
|
+
|
|
6
|
+
## 功能特性
|
|
7
|
+
|
|
8
|
+
- 📝 **动态表单渲染**:根据 XObject 字段描述自动生成表单项
|
|
9
|
+
- ➕ **数据新增**:支持向 Neo 平台新增数据记录
|
|
10
|
+
- 🎨 **多种字段类型**:支持文本、数字、日期、下拉选择等多种字段类型
|
|
11
|
+
- 📐 **响应式布局**:支持单列和双列布局,适配不同屏幕尺寸
|
|
12
|
+
- ✅ **表单验证**:自动根据字段配置进行必填验证
|
|
13
|
+
- 🔄 **表单重置**:支持快速重置表单内容
|
|
14
|
+
- 🎯 **成功提示**:提交成功后显示友好的提示信息
|
|
15
|
+
- ⚙️ **属性配置**:支持通过编辑器配置组件属性
|
|
16
|
+
|
|
17
|
+
## 组件属性
|
|
18
|
+
|
|
19
|
+
| 属性名 | 类型 | 默认值 | 说明 |
|
|
20
|
+
|--------|------|--------|------|
|
|
21
|
+
| formTitle | string | '新增数据' | 表单标题 |
|
|
22
|
+
| xObjectDataApi | object | - | 实体数据源配置,包含 xObjectApiKey 和 fields |
|
|
23
|
+
| xObjectDataApi.xObjectApiKey | string | '' | 数据对象的 API Key |
|
|
24
|
+
| xObjectDataApi.fields | string[] | [] | 要显示的字段列表(可选,不传则显示所有字段) |
|
|
25
|
+
| columnCount | 1 \| 2 | 1 | 表单列数(1列或2列) |
|
|
26
|
+
| showResetButton | boolean | true | 是否显示重置按钮 |
|
|
27
|
+
| onSuccess | function | - | 提交成功后的回调函数 |
|
|
28
|
+
|
|
29
|
+
## 使用方法
|
|
30
|
+
|
|
31
|
+
### 1. 在编辑器中使用
|
|
32
|
+
|
|
33
|
+
1. 从组件面板拖拽 "对象表单" 组件到页面
|
|
34
|
+
2. 在右侧属性面板中选择要操作的数据对象
|
|
35
|
+
3. 选择要在表单中显示的字段
|
|
36
|
+
4. 配置表单标题、列数等属性
|
|
37
|
+
5. 保存并预览
|
|
38
|
+
|
|
39
|
+
### 2. 代码中使用
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import ObjectForm from './components/object-form';
|
|
43
|
+
|
|
44
|
+
// 基础使用
|
|
45
|
+
<ObjectForm
|
|
46
|
+
formTitle="新增联系人"
|
|
47
|
+
xObjectDataApi={{
|
|
48
|
+
xObjectApiKey: 'customContact__c',
|
|
49
|
+
fields: ['name', 'phone__c', 'email__c'],
|
|
50
|
+
}}
|
|
51
|
+
columnCount={2}
|
|
52
|
+
showResetButton={true}
|
|
53
|
+
onSuccess={(data) => {
|
|
54
|
+
console.log('提交成功:', data);
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 支持的字段类型
|
|
60
|
+
|
|
61
|
+
组件支持以下字段类型,并自动渲染对应的输入组件:
|
|
62
|
+
|
|
63
|
+
| 字段类型 | 输入组件 | 说明 |
|
|
64
|
+
|---------|---------|------|
|
|
65
|
+
| text | Input | 单行文本输入框 |
|
|
66
|
+
| textarea | TextArea | 多行文本输入框 |
|
|
67
|
+
| int / float | InputNumber | 数字输入框 |
|
|
68
|
+
| email | Input (email) | 邮箱输入框 |
|
|
69
|
+
| phone | Input (tel) | 电话号码输入框 |
|
|
70
|
+
| url | Input (url) | URL 输入框 |
|
|
71
|
+
| date | DatePicker | 日期选择器 |
|
|
72
|
+
| datetime | DatePicker | 日期时间选择器 |
|
|
73
|
+
| time | DatePicker | 时间选择器 |
|
|
74
|
+
| picklist | Select | 单选下拉框 |
|
|
75
|
+
| multipicklist | Select (multiple) | 多选下拉框 |
|
|
76
|
+
| entityType | Select | 业务类型选择器 |
|
|
77
|
+
|
|
78
|
+
## 技术实现
|
|
79
|
+
|
|
80
|
+
### 核心依赖
|
|
81
|
+
|
|
82
|
+
- **Ant Design**:UI 组件库
|
|
83
|
+
- **React**:前端框架
|
|
84
|
+
- **TypeScript**:类型支持
|
|
85
|
+
- **Neo Open API**:数据操作 SDK
|
|
86
|
+
|
|
87
|
+
### 数据流程
|
|
88
|
+
|
|
89
|
+
1. **初始化**:组件挂载时获取字段描述和业务类型列表
|
|
90
|
+
2. **表单生成**:根据字段描述动态生成表单项
|
|
91
|
+
3. **数据验证**:提交前进行必填字段验证
|
|
92
|
+
4. **数据提交**:使用 `xObject.create` 创建新记录
|
|
93
|
+
5. **结果反馈**:显示成功或失败提示
|
|
94
|
+
|
|
95
|
+
### 表单布局
|
|
96
|
+
|
|
97
|
+
组件支持两种布局模式:
|
|
98
|
+
|
|
99
|
+
- **单列布局**:适合字段较多或需要宽输入框的场景
|
|
100
|
+
- **双列布局**:适合字段较少或需要紧凑布局的场景
|
|
101
|
+
|
|
102
|
+
## 样式定制
|
|
103
|
+
|
|
104
|
+
组件提供了完整的 SCSS 样式文件,支持以下定制:
|
|
105
|
+
|
|
106
|
+
- 表单样式(标签、输入框、间距等)
|
|
107
|
+
- 按钮样式(颜色、大小、位置等)
|
|
108
|
+
- 成功提示样式(动画、颜色等)
|
|
109
|
+
- 响应式设计(移动端适配)
|
|
110
|
+
|
|
111
|
+
## 注意事项
|
|
112
|
+
|
|
113
|
+
1. **权限要求**:确保用户有对应 XObject 的写入权限
|
|
114
|
+
2. **必填字段**:表单会根据字段的 required 属性进行验证
|
|
115
|
+
3. **日期格式**:日期类型字段会自动转换为时间戳格式提交
|
|
116
|
+
4. **错误处理**:组件内置了完善的错误处理和用户提示
|
|
117
|
+
5. **字段过滤**:如果指定了 fields 参数,只会显示指定的字段
|
|
118
|
+
|
|
119
|
+
## 扩展开发
|
|
120
|
+
|
|
121
|
+
如需扩展功能,可以:
|
|
122
|
+
|
|
123
|
+
1. **添加字段类型支持**:在 `renderForm()` 方法中添加新的字段类型
|
|
124
|
+
2. **自定义验证规则**:在表单项的 rules 中添加自定义验证
|
|
125
|
+
3. **添加提交前处理**:在 `handleSubmit()` 方法中添加数据预处理逻辑
|
|
126
|
+
4. **自定义样式**:修改 `style.scss` 文件定制组件外观
|
|
127
|
+
5. **添加回调事件**:扩展组件 props 支持更多回调事件
|
|
128
|
+
|
|
129
|
+
## 示例场景
|
|
130
|
+
|
|
131
|
+
### 场景一:客户信息录入
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
<ObjectForm
|
|
135
|
+
formTitle="新增客户"
|
|
136
|
+
xObjectDataApi={{
|
|
137
|
+
xObjectApiKey: 'account',
|
|
138
|
+
fields: ['name', 'industry', 'phone', 'email', 'website'],
|
|
139
|
+
}}
|
|
140
|
+
columnCount={2}
|
|
141
|
+
onSuccess={(data) => {
|
|
142
|
+
message.success('客户创建成功');
|
|
143
|
+
// 跳转到客户详情页
|
|
144
|
+
}}
|
|
145
|
+
/>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 场景二:联系人快速录入
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
<ObjectForm
|
|
152
|
+
formTitle="新增联系人"
|
|
153
|
+
xObjectDataApi={{
|
|
154
|
+
xObjectApiKey: 'customContact__c',
|
|
155
|
+
fields: ['name', 'phone__c', 'email__c'],
|
|
156
|
+
}}
|
|
157
|
+
columnCount={1}
|
|
158
|
+
showResetButton={true}
|
|
159
|
+
/>
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 场景三:自定义对象数据录入
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
<ObjectForm
|
|
166
|
+
formTitle="新增订单"
|
|
167
|
+
xObjectDataApi={{
|
|
168
|
+
xObjectApiKey: 'customOrder__c',
|
|
169
|
+
}}
|
|
170
|
+
columnCount={2}
|
|
171
|
+
onSuccess={(data) => {
|
|
172
|
+
console.log('订单创建成功:', data);
|
|
173
|
+
}}
|
|
174
|
+
/>
|
|
175
|
+
```
|
|
176
|
+
|