neo-cmp-cli 1.2.7 → 1.2.9

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": "neo-cmp-cli",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "前端脚手架:自定义组件开发工具,支持react 和 vue2.0技术栈。",
5
5
  "keywords": [
6
6
  "neo-cli",
@@ -18,16 +18,6 @@ const getCmpPreview = (cmpsDir, cmpName) => {
18
18
  process.exit(1);
19
19
  }
20
20
 
21
- if (!fs.existsSync(cpmModelDir)) {
22
- return `
23
- import * as React from 'react';
24
- import ReactDOM from 'react-dom';
25
- import CustomCmp from '${cpmDir}';
26
- import '$public/css/base.css';
27
- ReactDOM.render(<CustomCmp />, document.getElementById('root'),);
28
- `;
29
- }
30
-
31
21
  return `
32
22
  import * as React from 'react';
33
23
  import ReactDOM from 'react-dom';
@@ -39,9 +29,6 @@ const curDefaultComProps = new CustomCmpModel().defaultComProps;
39
29
  const previewComProps = new CustomCmpModel().previewComProps;
40
30
  const curPreviewComProps = Object.assign(curDefaultComProps, previewComProps);
41
31
 
42
- /* 引入公共的静态资源 */
43
- import '$public/css/base.css';
44
-
45
32
  // 预览 自定义组件
46
33
  ReactDOM.render(
47
34
  <CustomCmp {...curPreviewComProps} />,
@@ -76,13 +76,11 @@ yargs
76
76
  value: 'echarts',
77
77
  short: 'echarts'
78
78
  },
79
- /*
80
79
  {
81
80
  name: 'Neo 自定义组件',
82
81
  value: 'neo',
83
82
  short: 'neo'
84
83
  },
85
- */
86
84
  {
87
85
  name: 'react 自定义组件',
88
86
  value: 'react',
@@ -47,7 +47,7 @@
47
47
  "@commitlint/config-conventional": "^9.1.1",
48
48
  "@types/react": "^16.9.11",
49
49
  "@types/react-dom": "^16.9.15",
50
- "neo-cmp-cli": "^1.2.3",
50
+ "neo-cmp-cli": "^1.2.9",
51
51
  "husky": "^4.2.5",
52
52
  "lint-staged": "^10.2.9",
53
53
  "prettier": "^2.0.5"
@@ -51,7 +51,7 @@
51
51
  "@types/react": "^16.9.11",
52
52
  "@types/react-dom": "^16.9.15",
53
53
  "@types/axios": "^0.14.0",
54
- "neo-cmp-cli": "^1.2.3",
54
+ "neo-cmp-cli": "^1.2.9",
55
55
  "husky": "^4.2.5",
56
56
  "lint-staged": "^10.2.9",
57
57
  "prettier": "^2.0.5"
@@ -47,7 +47,7 @@
47
47
  "@commitlint/config-conventional": "^9.1.1",
48
48
  "@types/react": "^16.9.11",
49
49
  "@types/react-dom": "^16.9.15",
50
- "neo-cmp-cli": "^1.2.3",
50
+ "neo-cmp-cli": "^1.2.9",
51
51
  "husky": "^4.2.5",
52
52
  "lint-staged": "^10.2.9",
53
53
  "prettier": "^2.0.5",
@@ -23,7 +23,7 @@ module.exports = {
23
23
  '@': resolve('src'),
24
24
  $assets: resolve('src/assets'),
25
25
  $public: resolve('public'),
26
- '@utils': resolve('src/utils'),
26
+ $utils: resolve('src/utils'),
27
27
  },
28
28
  },
29
29
  // sassResources中的sass文件会自动注入每一个sass文件中
@@ -43,7 +43,8 @@
43
43
  "react-dom": "^16.9.0",
44
44
  "axios": "^0.27.2",
45
45
  "antd": "^4.9.4",
46
- "lodash": "^4.17.21"
46
+ "lodash": "^4.17.21",
47
+ "neo-open-api": "^1.0.2"
47
48
  },
48
49
  "devDependencies": {
49
50
  "@commitlint/cli": "^8.3.5",
@@ -51,7 +52,7 @@
51
52
  "@types/react": "^16.9.11",
52
53
  "@types/react-dom": "^16.9.15",
53
54
  "@types/axios": "^0.14.0",
54
- "neo-cmp-cli": "^1.2.3",
55
+ "neo-cmp-cli": "^1.2.9",
55
56
  "husky": "^4.2.5",
56
57
  "lint-staged": "^10.2.9",
57
58
  "prettier": "^2.0.5"
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { Card, Row, Col, Spin, Empty, Avatar, Button } from 'antd';
3
3
  import { UserOutlined, PhoneOutlined, ReloadOutlined } from '@ant-design/icons';
4
- import { queryXObjectData } from '@utils/queryObjectData';
4
+ // @ts-ignore
5
+ import { xObject } from 'neo-open-api'; // Neo Open API
5
6
  import './style.scss';
6
7
 
7
8
  interface ContactCardListProps {
@@ -47,16 +48,15 @@ export default class ContactCardList extends React.PureComponent<
47
48
  this.setState({ loading: true, error: null });
48
49
 
49
50
  try {
50
- // 使用 queryXObjectData 获取 customContact__c 数据
51
- const response = await queryXObjectData({
51
+ // 使用 Neo Open API 获取 customContact__c 数据
52
+ const result = await xObject.query({
52
53
  xObjectApiKey: 'customContact__c',
53
54
  fields: ['id', 'name', 'phone__c'],
54
55
  });
55
56
 
56
- if (response && response.code === 200) {
57
- const curResult = response.result || {};
58
- const records = curResult.records || [];
59
- const totalSize = curResult.totalSize || 0;
57
+ if (result?.status) {
58
+ const records = result.data || [];
59
+ const totalSize = result.totalSize || 0;
60
60
  this.setState({
61
61
  contactList: records,
62
62
  totalSize,
@@ -64,12 +64,11 @@ export default class ContactCardList extends React.PureComponent<
64
64
  });
65
65
  } else {
66
66
  this.setState({
67
- error: response?.message || '获取联系人数据失败',
67
+ error: result?.msg || '获取联系人数据失败',
68
68
  loading: false,
69
69
  });
70
70
  }
71
71
  } catch (error: any) {
72
- console.error('获取联系人数据失败:', error);
73
72
  this.setState({
74
73
  error: error.message || '获取联系人数据失败',
75
74
  loading: false,
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { Form, Input, Select, Button, message, Card } from 'antd';
3
- import { getEntityTypeList, createXObject } from '@utils/xobjects';
3
+ // @ts-ignore
4
+ import { xObject } from 'neo-open-api'; // Neo Open API
4
5
  const { Option } = Select;
5
6
 
6
7
  import './style.scss';
@@ -39,11 +40,10 @@ export default class ContactForm extends React.PureComponent<
39
40
  };
40
41
 
41
42
  // 获取业务类型列表
42
- getEntityTypeList('customContact__c').then((res: any) => {
43
- if (res && res.code === '200') {
44
- const result = res.data || {};
43
+ xObject.getEntityTypeList('customContact__c').then((res: any) => {
44
+ if (res && res.status) {
45
45
  this.setState({
46
- entityTypeList: result.records || [],
46
+ entityTypeList: res.data || [],
47
47
  });
48
48
  }
49
49
  });
@@ -115,19 +115,19 @@ export default class ContactForm extends React.PureComponent<
115
115
  }
116
116
 
117
117
  // 调用 API 提交数据
118
- const response: any = await createXObject('customContact__c', {
118
+ const response: any = await xObject.create('customContact__c', {
119
119
  method: 'POST',
120
120
  data: submitData,
121
121
  });
122
122
 
123
- if (response && response.code === '200') {
123
+ if (response && response.status) {
124
124
  message.success('联系人创建成功!');
125
125
  // 成功后重置表单
126
126
  setTimeout(() => {
127
127
  this.resetForm();
128
128
  }, 1000);
129
129
  } else {
130
- message.error('创建联系人失败:', response.message);
130
+ message.error('创建联系人失败:', response.msg);
131
131
  }
132
132
  } catch (error: any) {
133
133
  message.error('创建联系人失败:', error);
@@ -29,14 +29,14 @@ import {
29
29
  ReloadOutlined,
30
30
  } from '@ant-design/icons';
31
31
  import moment from 'moment';
32
- import { queryXObjectData } from '@utils/queryObjectData';
32
+ import { queryXObjectData } from '$utils/queryObjectData';
33
33
  import {
34
34
  getEntityTypeList,
35
35
  getXObjectDesc,
36
36
  createXObject,
37
37
  updateXObject,
38
38
  deleteXObject,
39
- } from '@utils/xobjects';
39
+ } from '$utils/xobjects';
40
40
  import './style.scss';
41
41
 
42
42
  const { Option } = Select;
@@ -297,16 +297,15 @@ export default class XObjectTable extends React.PureComponent<
297
297
  try {
298
298
  // 获取所有字段的 API Key
299
299
  const fields = this.state.fieldList.map((field) => field.apiKey);
300
- const response = await queryXObjectData({
300
+ const result = await queryXObjectData({
301
301
  xObjectApiKey,
302
302
  fields,
303
303
  page,
304
304
  pageSize,
305
305
  });
306
306
 
307
- if (response && response.code === 200) {
308
- const result = response.result || {};
309
- const records = result.records || [];
307
+ if (result && result.status) {
308
+ const records = result.data || [];
310
309
  const totalSize = result.totalSize || 0;
311
310
 
312
311
  this.setState({
@@ -320,12 +319,11 @@ export default class XObjectTable extends React.PureComponent<
320
319
  });
321
320
  } else {
322
321
  this.setState({
323
- error: response?.message || '获取数据失败',
322
+ error: result?.msg || '获取数据失败',
324
323
  loading: false,
325
324
  });
326
325
  }
327
326
  } catch (error: any) {
328
- console.error('获取数据失败:', error);
329
327
  this.setState({
330
328
  error: error.message || '获取数据失败',
331
329
  loading: false,
@@ -0,0 +1,113 @@
1
+ # XObject 数据表格组件
2
+ 基于 XObject 的数据表格组件,支持增删改查操作,表格列根据 `getXObjectDesc` 返回的 fields 动态生成。
3
+
4
+ - 对应的生成指令
5
+ ```
6
+ @utils/ 请根据这里提供的方法,参照 @contact-card-list/ 使用 antd 组件 写一个 表格组件,展示属性配置 xobject 对应的 业务数据列表,支持创建、编辑、删除操作。其中表格展示的列 根据 getXObjectDesc 返回的 fields 生成,表格的 Title 根据 其返回的 label 显示。另外 请使用 propsSchemaCreator 生成自定义组件的属性配置,支持 xobject 选择配置,其中 xobject 的选项 使用 getEntityList获取。
7
+ ```
8
+
9
+ ## 功能特性
10
+
11
+ - 📊 **动态表格列**:根据 XObject 字段描述自动生成表格列
12
+ - ➕ **新增记录**:支持通过弹窗表单新增数据记录
13
+ - ✏️ **编辑记录**:支持编辑现有数据记录
14
+ - 🗑️ **删除记录**:支持删除数据记录,带确认提示
15
+ - 🔄 **数据刷新**:支持手动刷新数据
16
+ - 📄 **分页支持**:支持分页显示,可配置每页显示条数
17
+ - 🎨 **响应式设计**:适配不同屏幕尺寸
18
+ - ⚙️ **属性配置**:支持通过编辑器配置组件属性
19
+
20
+ ## 组件属性
21
+
22
+ | 属性名 | 类型 | 默认值 | 说明 |
23
+ |--------|------|--------|------|
24
+ | title | string | '数据表格' | 表格标题 |
25
+ | xObjectApiKey | string | '' | 数据对象的 API Key |
26
+ | pageSize | number | 10 | 每页显示条数 |
27
+ | showPagination | boolean | true | 是否显示分页 |
28
+ | showAddButton | boolean | true | 是否显示新增按钮 |
29
+ | showEditButton | boolean | true | 是否显示编辑按钮 |
30
+ | showDeleteButton | boolean | true | 是否显示删除按钮 |
31
+
32
+ ## 使用方法
33
+
34
+ ### 1. 在编辑器中使用
35
+
36
+ 1. 从组件面板拖拽 "XObject 数据表格" 组件到页面
37
+ 2. 在右侧属性面板中选择要操作的数据对象
38
+ 3. 配置其他属性(可选)
39
+ 4. 保存并预览
40
+
41
+ ### 2. 代码中使用
42
+
43
+ ```tsx
44
+ import XObjectTable from './components/xobject-table';
45
+
46
+ // 使用组件
47
+ <XObjectTable
48
+ title="联系人列表"
49
+ xObjectApiKey="customContact__c"
50
+ pageSize={20}
51
+ showPagination={true}
52
+ showAddButton={true}
53
+ showEditButton={true}
54
+ showDeleteButton={true}
55
+ />
56
+ ```
57
+
58
+ ## 技术实现
59
+
60
+ ### 核心依赖
61
+
62
+ - **Ant Design**:UI 组件库
63
+ - **React**:前端框架
64
+ - **TypeScript**:类型支持
65
+
66
+ ### 主要方法
67
+
68
+ - `getXObjectDesc()`:获取 XObject 字段描述
69
+ - `getEntityList()`:获取实体列表
70
+ - `queryXObjectData()`:查询数据列表
71
+ - `createXObject()`:创建数据记录
72
+ - `updateXObject()`:更新数据记录
73
+ - `deleteXObject()`:删除数据记录
74
+
75
+ ### 数据流程
76
+
77
+ 1. **初始化**:组件挂载时获取实体列表和字段描述
78
+ 2. **列生成**:根据字段描述动态生成表格列
79
+ 3. **数据加载**:使用 `queryXObjectData` 获取数据列表
80
+ 4. **操作处理**:通过对应的 API 方法处理增删改操作
81
+
82
+ ## 样式定制
83
+
84
+ 组件提供了完整的 SCSS 样式文件,支持以下定制:
85
+
86
+ - 表格样式(边框、悬停效果等)
87
+ - 按钮样式(颜色、大小、间距等)
88
+ - 弹窗样式(表单布局、输入框样式等)
89
+ - 响应式设计(移动端适配)
90
+
91
+ ## 注意事项
92
+
93
+ 1. **权限要求**:确保用户有对应 XObject 的读写权限
94
+ 2. **字段类型**:目前支持 text、textarea、select 等基础字段类型
95
+ 3. **必填字段**:表单会根据字段的 required 属性进行验证
96
+ 4. **错误处理**:组件内置了完善的错误处理和用户提示
97
+
98
+ ## 扩展开发
99
+
100
+ 如需扩展功能,可以:
101
+
102
+ 1. **添加字段类型支持**:在 `renderForm()` 方法中添加新的字段类型
103
+ 2. **自定义操作列**:修改 `generateColumns()` 方法中的操作列配置
104
+ 3. **添加批量操作**:扩展表格功能支持批量删除等操作
105
+ 4. **自定义样式**:修改 `style.scss` 文件定制组件外观
106
+
107
+ ## 更新日志
108
+
109
+ ### v1.0.0
110
+ - 初始版本发布
111
+ - 支持基础的增删改查功能
112
+ - 支持动态列生成
113
+ - 支持属性配置面板