neo-cmp-cli 1.5.0-beta.5 → 1.5.0-beta.6

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 (64) hide show
  1. package/README.md +11 -11
  2. package/package.json +1 -1
  3. package/src/cmpUtils/createCmpByTemplate.js +50 -0
  4. package/src/cmpUtils/createCommonModulesCode.js +15 -15
  5. package/src/cmpUtils/{getCmpModelRegister.js → getCmpModelRegisterCode.js} +2 -2
  6. package/src/cmpUtils/{getCmpPreview.js → getCmpPreviewCode.js} +2 -2
  7. package/src/cmpUtils/{getCmpRegister.js → getCmpRegisterCode.js} +2 -2
  8. package/src/cmpUtils/hasCmpTypeByDir.js +11 -0
  9. package/src/{module → cmpUtils}/previewCmp.js +2 -2
  10. package/src/cmpUtils/publishCmp.js +4 -4
  11. package/src/config/default.config.js +1 -1
  12. package/src/module/index.js +94 -19
  13. package/src/module/main.js +15 -11
  14. package/src/module/neoInit.js +3 -0
  15. package/src/module/neoInitByCopy.js +3 -0
  16. package/src/neo/neoRequire.js +7 -7
  17. package/src/neo/neoService.js +19 -19
  18. package/src/oss/publish2oss.js +1 -1
  19. package/src/projectUtils/createCmpProjectByTemplate.js +49 -0
  20. package/src/{cmpUtils → projectUtils}/getEntriesWithAutoRegister.js +4 -4
  21. package/src/template/antd-custom-cmp-template/README.md +2 -2
  22. package/src/template/antd-custom-cmp-template/neo.config.js +22 -14
  23. package/src/template/antd-custom-cmp-template/package.json +2 -2
  24. package/src/template/develop/neo-custom-cmp-template/neo.config.js +1 -1
  25. package/src/template/echarts-custom-cmp-template/README.md +2 -2
  26. package/src/template/echarts-custom-cmp-template/neo.config.js +19 -13
  27. package/src/template/echarts-custom-cmp-template/package.json +2 -2
  28. package/src/template/empty-cmp/index.tsx +51 -0
  29. package/src/template/empty-cmp/model.ts +77 -0
  30. package/src/template/empty-cmp/style.scss +72 -0
  31. package/src/template/empty-custom-cmp-template/.prettierrc.js +12 -0
  32. package/src/template/empty-custom-cmp-template/README.md +45 -0
  33. package/src/template/empty-custom-cmp-template/commitlint.config.js +59 -0
  34. package/src/template/empty-custom-cmp-template/neo.config.js +126 -0
  35. package/src/template/empty-custom-cmp-template/package.json +57 -0
  36. package/src/template/empty-custom-cmp-template/public/css/base.css +283 -0
  37. package/src/template/empty-custom-cmp-template/public/scripts/app/bluebird.js +6679 -0
  38. package/src/template/empty-custom-cmp-template/public/template.html +13 -0
  39. package/src/template/empty-custom-cmp-template/src/assets/css/common.scss +127 -0
  40. package/src/template/empty-custom-cmp-template/src/assets/css/mixin.scss +47 -0
  41. package/src/template/empty-custom-cmp-template/src/assets/img/NeoCRM.jpg +0 -0
  42. package/src/template/empty-custom-cmp-template/src/assets/img/custom-widget.svg +1 -0
  43. package/src/template/empty-custom-cmp-template/src/assets/img/favicon.png +0 -0
  44. package/src/template/empty-custom-cmp-template/src/assets/img/map.svg +1 -0
  45. package/src/template/empty-custom-cmp-template/src/components/README.md +3 -0
  46. package/src/template/empty-custom-cmp-template/tsconfig.json +68 -0
  47. package/src/template/neo-custom-cmp-template/README.md +2 -2
  48. package/src/template/neo-custom-cmp-template/neo.config.js +4 -25
  49. package/src/template/neo-custom-cmp-template/package.json +3 -5
  50. package/src/template/neo-custom-cmp-template/src/components/entity-detail/index.tsx +0 -8
  51. package/src/template/react-custom-cmp-template/README.md +2 -2
  52. package/src/template/react-custom-cmp-template/neo.config.js +20 -15
  53. package/src/template/react-custom-cmp-template/package.json +2 -2
  54. package/src/template/react-ts-custom-cmp-template/README.md +2 -2
  55. package/src/template/react-ts-custom-cmp-template/neo.config.js +19 -14
  56. package/src/template/react-ts-custom-cmp-template/package.json +2 -2
  57. package/src/template/vue2-custom-cmp-template/README.md +2 -2
  58. package/src/template/vue2-custom-cmp-template/neo.config.js +20 -15
  59. package/src/template/vue2-custom-cmp-template/package.json +2 -2
  60. package/src/utils/autoEntryRootDir.js +42 -0
  61. package/src/utils/replaceInFilesByMap.js +54 -0
  62. package/test/demo.js +2 -2
  63. /package/src/{cmpUtils → projectUtils}/getEntries.js +0 -0
  64. /package/src/{cmpUtils → projectUtils}/updatePublishLog.js +0 -0
@@ -3,7 +3,7 @@ const FormData = require('form-data');
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const _ = require('lodash');
6
- const updatePublishLog = require('../cmpUtils/updatePublishLog');
6
+ const updatePublishLog = require('../projectUtils/updatePublishLog');
7
7
 
8
8
  // NeoCRM 平台默认 API 配置
9
9
  const NeoCrmAPI = {
@@ -23,32 +23,32 @@ class NeoService {
23
23
  * @param {object} config 配置信息
24
24
  * @param {string} config.neoBaseURL Neo 平台根地址
25
25
  * @param {string} config.tokenAPI Token 获取接口地址
26
- * @param {object} config.authorization 授权信息
27
- * @param {string} config.authorization.client_id 客户端 ID
28
- * @param {string} config.authorization.client_secret 客户端密钥
29
- * @param {string} config.authorization.username 用户名
30
- * @param {string} config.authorization.password 密码
26
+ * @param {object} config.authConfig 授权信息
27
+ * @param {string} config.authConfig.client_id 客户端 ID
28
+ * @param {string} config.authConfig.client_secret 客户端密钥
29
+ * @param {string} config.authConfig.username 用户名
30
+ * @param {string} config.authConfig.password 密码
31
31
  */
32
32
  constructor(config = {}) {
33
- const { assetsRoot, neoBaseURL, tokenAPI, authorization } = config;
34
- if (!authorization) {
35
- throw new Error('authorization 不能为空');
33
+ const { assetsRoot, neoBaseURL, tokenAPI, authConfig } = config;
34
+ if (!authConfig) {
35
+ throw new Error('authConfig 不能为空');
36
36
  }
37
37
  if (
38
- !authorization.client_id ||
39
- !authorization.client_secret ||
40
- !authorization.username ||
41
- !authorization.password
38
+ !authConfig.client_id ||
39
+ !authConfig.client_secret ||
40
+ !authConfig.username ||
41
+ !authConfig.password
42
42
  ) {
43
43
  throw new Error(
44
- 'authorization 配置不完整,需要包含 client_id、client_secret、username、password'
44
+ 'authConfig 配置不完整,需要包含 client_id、client_secret、username、password'
45
45
  );
46
46
  }
47
47
 
48
48
  this.assetsRoot = assetsRoot;
49
49
  this.neoBaseURL = neoBaseURL || NeoCrmAPI.neoBaseURL;
50
50
  this.tokenAPI = tokenAPI || NeoCrmAPI.tokenAPI;
51
- this.authorization = authorization;
51
+ this.authConfig = authConfig;
52
52
 
53
53
  // Token 缓存
54
54
  this.tokenCache = {
@@ -106,10 +106,10 @@ class NeoService {
106
106
  // 构建表单数据格式的请求参数
107
107
  const formData = new URLSearchParams();
108
108
  formData.append('grant_type', 'password');
109
- formData.append('client_id', this.authorization.client_id);
110
- formData.append('client_secret', this.authorization.client_secret);
111
- formData.append('username', this.authorization.username);
112
- formData.append('password', this.authorization.password);
109
+ formData.append('client_id', this.authConfig.client_id);
110
+ formData.append('client_secret', this.authConfig.client_secret);
111
+ formData.append('username', this.authConfig.username);
112
+ formData.append('password', this.authConfig.password);
113
113
 
114
114
  const tokenUrl = this.buildFullUrl(this.tokenAPI);
115
115
 
@@ -4,7 +4,7 @@ const path = require('path');
4
4
  const _ = require('lodash');
5
5
  const { catchCurPackageJson } = require('../utils/pathUtils');
6
6
  const getConfigObj = require('../utils/getConfigObj');
7
- const updatePublishLog = require('../cmpUtils/updatePublishLog');
7
+ const updatePublishLog = require('../projectUtils/updatePublishLog');
8
8
 
9
9
  // 获取当前项目的package文件
10
10
  const currentPackageJsonDir = catchCurPackageJson();
@@ -0,0 +1,49 @@
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const { consoleTag } = require('../utils/neoParams'); // 输出标记
4
+ const { replaceInPackage } = require('../utils/replaceInPackage');
5
+ const { resetPackageVersion } = require('../utils/resetPackageVersion');
6
+ const autoEntryRootDir = require('../utils/autoEntryRootDir');
7
+
8
+ const cmpTemplateList = {
9
+ 'react-ts': {
10
+ projectName: 'empty-custom-cmp-template',
11
+ dir: path.resolve(__dirname, '../template/empty-custom-cmp-template')
12
+ }
13
+ };
14
+
15
+ /**
16
+ * 通过拷贝模板创建自定义组件
17
+ * @param {*} projectName 自定义组件项目名称
18
+ * @param {*} type 自定义组件类型
19
+ */
20
+ module.exports = function (projectName, type = 'react-ts') {
21
+ const finalProjectPath = path.resolve(process.cwd(), projectName);
22
+
23
+ if (fs.existsSync(finalProjectPath)) {
24
+ console.error(`${consoleTag}创建自定义组件失败,当前已存在(${projectName})项目,请勿创建重名项目。`);
25
+ process.exit(1);
26
+ }
27
+
28
+ const curCmpTemplate = cmpTemplateList[type];
29
+ if (!curCmpTemplate) {
30
+ console.error(`${consoleTag}创建自定义组件失败,当前不支持${type}类型。`);
31
+ process.exit(1);
32
+ }
33
+
34
+ const currentTemplateDir = curCmpTemplate.dir;
35
+ const finalProjectName = projectName || 'neoCustomCmp';
36
+
37
+ fs.copy(currentTemplateDir, finalProjectPath)
38
+ .then(() => {
39
+ replaceInPackage(finalProjectPath, curCmpTemplate.projectName, finalProjectName);
40
+ replaceInPackage(finalProjectPath, 'wibetter', 'xxx');
41
+ replaceInPackage(finalProjectPath, 'neo自定义组件模板', 'neo自定义组件');
42
+ resetPackageVersion(finalProjectPath);
43
+
44
+ console.log(`${consoleTag}已创建自定义组件(${finalProjectName})!`);
45
+ // 自动切换到项目根目录
46
+ autoEntryRootDir(finalProjectPath);
47
+ })
48
+ .catch((err) => console.error(`${consoleTag}自定义组件模板下载失败:`, err));
49
+ };
@@ -2,8 +2,8 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const _ = require('lodash');
4
4
  const { resolveToCurrentRoot } = require('../utils/pathUtils');
5
- const getCmpRegister = require('./getCmpRegister');
6
- const getCmpModelRegister = require('./getCmpModelRegister');
5
+ const getCmpRegisterCode = require('./getCmpRegisterCode');
6
+ const getCmpModelRegisterCode = require('./getCmpModelRegisterCode');
7
7
  /**
8
8
  * 从指定目录获取组件入口文件,并自动创建对应的注册文件
9
9
  * @param {*} defaultComponentsDir 默认组件目录
@@ -68,7 +68,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
68
68
  .forEach((filePath) => {
69
69
  if (filePath.match(/index\.[tj]sx?$/)) {
70
70
  // 自动创建对应的注册文件
71
- const registerContent = getCmpRegister(componentsBaseDir, curCmpName);
71
+ const registerContent = getCmpRegisterCode(componentsBaseDir, curCmpName);
72
72
  const registerDir = `${cmpTempDir}/register.js`;
73
73
 
74
74
  // 写入注册文件
@@ -78,7 +78,7 @@ module.exports = (defaultComponentsDir = './src/components', cmpType) => {
78
78
  linkDebugEntries.index.push(registerDir);
79
79
  } else if (filePath.match(/model\.[tj]sx?$/)) {
80
80
  // 自动创建对应的模型注册文件
81
- const modelRegisterContent = getCmpModelRegister(componentsBaseDir, curCmpName);
81
+ const modelRegisterContent = getCmpModelRegisterCode(componentsBaseDir, curCmpName);
82
82
  const modelRegisterDir = `${cmpTempDir}/model.js`;
83
83
 
84
84
  // 写入模型注册文件
@@ -37,10 +37,10 @@ $ npm run preview
37
37
  $ npm run linkDebug
38
38
  ```
39
39
 
40
- 4. **发布到对象存储服务中**
40
+ 4. **发布到 NeoCRM 平台**
41
41
  > 需要确保 package.json 中的 name 值唯一,version 值不重复。
42
42
  ```bash
43
- $ npm run publish2oss
43
+ $ npm run pushCmp
44
44
  ```
45
45
 
46
46
  ### 配置项说明(neo-cmp-cli)
@@ -41,10 +41,12 @@ module.exports = {
41
41
  // 用于添加 Neo 共享依赖模块和剔除模块
42
42
  /*
43
43
  neoCommonModule: {
44
- remotes: ['chart-widget'], // 远程自定义组件,表示当前自定义组件会用到的远程组件
45
- neoExternals: ['chart-widget'], // 自定义组件中需要剔除的模块,仅支持数组写法,需要和 remotes 配合使用
46
44
  // neoExports: ['xxModule'], // 自定义组件 共享出来的模块,支持数组和对象形式
47
- // neoExports: { 'xxModule': path.resolve('./src/components/xxModule') }, // 对象写法
45
+ neoExports: { // 对象写法
46
+ 'xx-module': path.resolve('./src/components/xx-module'), // 导出 xx组件 或 xx模块
47
+ },
48
+ // remoteDeps: ['xxCmpType'], // 远程依赖组件,表示当前自定义组件会用到的依赖组件,需要和 neoExternals 配合使用
49
+ // neoExternals: ['xxModule'], // 自定义组件中需要剔除的模块(仅支持数组写法)
48
50
  },
49
51
  */
50
52
  preview: {
@@ -95,23 +97,29 @@ module.exports = {
95
97
  }
96
98
  */
97
99
  },
98
- publish2oss: {
99
- // 用于构建并发布至 OSS 的相关配置
100
+ pushCmp: {
101
+ // 用于构建并发布至 NeoCRM 的相关配置
102
+ neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
103
+ tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
104
+ // NeoCRM 授权配置
105
+ authConfig: {
106
+ client_id: 'xx', // 客户端 ID,从创建连接器的客户端信息中获取(Client_Id)
107
+ client_secret: 'xxx', // 客户端秘钥,从创建连接器的客户端信息中获取(Client_Secret)
108
+ username: 'xx', // 用户在销售易系统中的用户名
109
+ /**
110
+ * password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
111
+ * 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
112
+ */
113
+ password: 'xx xx' // 用户账户密码 + 8 位安全令牌
114
+ },
100
115
  /*
101
116
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
102
117
  NODE_ENV: 'production',
103
118
  entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
104
- InfoCardModel: './src/components/info-card/model.ts',
105
- infoCard: './src/components/info-card/register.ts'
119
+ InfoCardModel: './src/components/entity-form/model.ts',
120
+ infoCard: './src/components/entity-form/register.ts'
106
121
  },
107
122
  cssExtract: false, // 不额外提取css文件
108
- ossType: 'ali', // oss类型:ali、baidu
109
- ossConfig: {
110
- endpoint: 'https://oss-cn-beijing.aliyuncs.com',
111
- AccessKeyId: 'xxx',
112
- AccessKeySecret: 'xx',
113
- bucket: 'neo-widgets' // 存储桶名称
114
- },
115
123
  assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
116
124
  */
117
125
  },
@@ -10,9 +10,9 @@
10
10
  "author": "wibetter",
11
11
  "license": "MIT",
12
12
  "scripts": {
13
- "preview": "neo preview --cmpType=data-dashboard",
13
+ "preview": "neo preview",
14
14
  "linkDebug": "neo linkDebug",
15
- "publish2oss": "neo publish2oss",
15
+ "pushCmp": "neo pushCmp",
16
16
  "format": "prettier --write \"src/**/**/*.{js,jsx,ts,tsx,vue,scss,json}\""
17
17
  },
18
18
  "files": [
@@ -46,8 +46,8 @@ module.exports = {
46
46
  'chart-widget': path.resolve('./src/components/chart-widget'), // 导出图表自定义组件
47
47
  'neo-register': 'neo-register', // 导出 Neo 注册模块
48
48
  },
49
+ // remoteDeps: ['xxModule'], // 远程依赖组件,表示当前自定义组件会用到的远程依赖组件,需要和 neoExternals 配合使用
49
50
  // neoExternals: ['xxModule'], // 自定义组件中需要剔除的模块,仅支持数组写法
50
- // remotes: ['xxModule'], // 远程组件,表示当前自定义组件会用到的远程组件,需要和 neoExternals 配合使用
51
51
  },
52
52
  */
53
53
  preview: {
@@ -81,10 +81,10 @@ $ npm run preview
81
81
  $ npm run linkDebug
82
82
  ```
83
83
 
84
- 4. **发布到对象存储服务中**
84
+ 4. **发布到 NeoCRM 平台**
85
85
  > 需要确保 package.json 中的 name 值唯一,version 值不重复。
86
86
  ```bash
87
- $ npm run publish2oss
87
+ $ npm run pushCmp
88
88
  ```
89
89
 
90
90
  ### 配置项说明(neo-cmp-cli)
@@ -46,8 +46,8 @@ module.exports = {
46
46
  'chart-widget': path.resolve('./src/components/chart-widget'), // 导出图表自定义组件
47
47
  'neo-register': 'neo-register', // 导出 Neo 注册模块
48
48
  },
49
- // remotes: ['xxModule'], // 远程组件,表示当前自定义组件会用到的远程组件
50
- // neoExternals: ['xxModule'], // 自定义组件中需要剔除的模块,仅支持数组写法,需要和 remotes 配合使用
49
+ // remoteDeps: ['xxCmpType'], // 远程依赖组件,表示当前自定义组件会用到的依赖组件,需要和 neoExternals 配合使用
50
+ // neoExternals: ['xxModule'], // 自定义组件中需要剔除的模块,仅支持数组写法
51
51
  },
52
52
  //*/
53
53
  preview: {
@@ -98,23 +98,29 @@ module.exports = {
98
98
  }
99
99
  */
100
100
  },
101
- publish2oss: {
102
- // 用于构建并发布至 OSS 的相关配置
101
+ pushCmp: {
102
+ // 用于构建并发布至 NeoCRM 的相关配置
103
+ neoBaseURL: 'https://crm-cd.xiaoshouyi.com', // 平台根地址(默认:https://crm.xiaoshouyi.com)
104
+ tokenAPI: 'https://login-cd.xiaoshouyi.com/auc/oauth2/token', // Token 获取接口地址(默认:https://login.xiaoshouyi.com/auc/oauth2/token)
105
+ // NeoCRM 授权配置
106
+ authConfig: {
107
+ client_id: 'xx', // 客户端 ID,从创建连接器的客户端信息中获取(Client_Id)
108
+ client_secret: 'xxx', // 客户端秘钥,从创建连接器的客户端信息中获取(Client_Secret)
109
+ username: 'xx', // 用户在销售易系统中的用户名
110
+ /**
111
+ * password 为 用户在销售易系统中的账号密码加上 8 位安全令牌。
112
+ * 例如,用户密码为 123456,安全令牌为 ABCDEFGH,则 password 的值应为 123456ABCDEFGH。
113
+ */
114
+ password: 'xx xx' // 用户账户密码 + 8 位安全令牌
115
+ },
103
116
  /*
104
117
  【特别说明】以下配置项都自带默认值,非必填。如需自定义请自行配置。
105
118
  NODE_ENV: 'production',
106
119
  entry: { // 根据 src/components 目录下的文件自动生成 entry 相关配置
107
- InfoCardModel: './src/components/info-card/model.ts',
108
- infoCard: './src/components/info-card/register.ts'
120
+ InfoCardModel: './src/components/entity-form/model.ts',
121
+ infoCard: './src/components/entity-form/register.ts'
109
122
  },
110
123
  cssExtract: false, // 不额外提取css文件
111
- ossType: 'ali', // oss类型:ali、baidu
112
- ossConfig: {
113
- endpoint: 'https://oss-cn-beijing.aliyuncs.com',
114
- AccessKeyId: 'xxx',
115
- AccessKeySecret: 'xx',
116
- bucket: 'neo-widgets' // 存储桶名称
117
- },
118
124
  assetsRoot: resolve('dist') // 上传指定目录下的脚本文件
119
125
  */
120
126
  },
@@ -10,9 +10,9 @@
10
10
  "author": "wibetter",
11
11
  "license": "MIT",
12
12
  "scripts": {
13
- "preview": "neo preview --cmpType=chart-widget",
13
+ "preview": "neo preview",
14
14
  "linkDebug": "neo linkDebug",
15
- "publish2oss": "neo publish2oss",
15
+ "pushCmp": "neo pushCmp",
16
16
  "format": "prettier --write \"src/**/**/*.{js,jsx,ts,tsx,vue,scss,json}\""
17
17
  },
18
18
  "files": [
@@ -0,0 +1,51 @@
1
+ import * as React from 'react';
2
+ import './style.scss'; // 组件内容样式
3
+
4
+ interface CustomCmpProps {
5
+ title: string;
6
+ backgroundImage: string;
7
+ imgCount: number;
8
+ commentCount: number;
9
+ data?: any;
10
+ }
11
+
12
+ export default class CustomCmp extends React.PureComponent<CustomCmpProps> {
13
+ constructor(props: CustomCmpProps) {
14
+ super(props);
15
+ this.agreeDataFormat = this.agreeDataFormat.bind(this);
16
+ }
17
+
18
+ agreeDataFormat(agreeData: number) {
19
+ if (agreeData && agreeData <= 9999) {
20
+ return agreeData;
21
+ }
22
+ if (agreeData && agreeData > 9999) {
23
+ return `${Math.floor(agreeData / 1000) / 10}w`;
24
+ }
25
+ return '';
26
+ }
27
+
28
+ render() {
29
+ const { title, backgroundImage, imgCount, commentCount } = this.props;
30
+ console.log('当前自定义组件:', this.props, this);
31
+
32
+ const curBackgroundImage =
33
+ backgroundImage || 'https://neo-widgets.bj.bcebos.com/NeoCRM.jpg';
34
+ return (
35
+ <div className="custom-cmp-container">
36
+ <div className="news-title">
37
+ {title ||
38
+ '营销服全场景智能CRM,帮助企业搭建数字化客户经营平台,实现业绩高质量增长。'}
39
+ </div>
40
+ <div className="news-info">
41
+ <div className="left media-mark">NeoCRM · 低代码平台</div>
42
+ {commentCount && commentCount > 0 && (
43
+ <div className="cmt-num right">
44
+ {this.agreeDataFormat(commentCount)}评
45
+ </div>
46
+ )}
47
+ </div>
48
+ </div>
49
+ );
50
+ }
51
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @file 自定义组件对接编辑器的描述文件
3
+ */
4
+ export class CustomCmpModel {
5
+ /**
6
+ * cmpType 为自定义组件名称,用于标识组件的唯一性
7
+ * 在构建时根据当前组件目录名称自动生成
8
+ */
9
+ // cmpType: string = 'xx-custom-cmp';
10
+
11
+ // 组件名称,用于设置在编辑器左侧组件面板中展示的名称
12
+ label: string = 'xx组件';
13
+
14
+ // 组件描述,用于设置在编辑器左侧组件面板中展示的描述
15
+ description: string = 'xx自定义组件详细描述';
16
+
17
+ // 分类标签,用于设置在编辑器左侧组件面板哪个分类中展示(可设置多个分类标签)
18
+ tags: string[] = ['自定义组件'];
19
+
20
+ // 组件图标,用于设置在编辑器左侧组件面板中展示的图标
21
+ iconSrc: string = 'https://neo-widgets.bj.bcebos.com/custom-widget.svg';
22
+
23
+ // 初次插入页面的默认属性数据
24
+ defaultComProps = {
25
+ title:
26
+ '营销服全场景智能CRM,帮助企业搭建数字化客户经营平台,实现业绩高质量增长。',
27
+ label: '信息卡片',
28
+ backgroundImage: 'https://neo-widgets.bj.bcebos.com/NeoCRM.jpg',
29
+ imgCount: 3,
30
+ commentCount: 2025,
31
+ };
32
+
33
+ // 设计器端预览时展示的默认数据
34
+ previewComProps = {
35
+ label: '信息卡片',
36
+ };
37
+
38
+ /**
39
+ * 组件面板配置,用于生成编辑器右侧属性配置面板内容
40
+ */
41
+ propsSchema = [
42
+ {
43
+ type: 'textarea',
44
+ name: 'title',
45
+ label: '卡片title',
46
+ value:
47
+ '营销服全场景智能CRM,帮助企业搭建数字化客户经营平台,实现业绩高质量增长。',
48
+ },
49
+ {
50
+ type: 'text',
51
+ name: 'backgroundImage',
52
+ label: '展示图片',
53
+ value: 'https://neo-widgets.bj.bcebos.com/NeoCRM.jpg',
54
+ },
55
+ {
56
+ type: 'number',
57
+ name: 'imgCount',
58
+ label: '图片数量',
59
+ value: 3,
60
+ },
61
+ {
62
+ type: 'number',
63
+ name: 'commentCount',
64
+ label: '评论数',
65
+ value: 2025,
66
+ },
67
+ ];
68
+
69
+ // 支持 函数式写法:propsSchemaCreator,com 为组件实例。优先级比 propsSchema 高
70
+ /*
71
+ propsSchemaCreator = (com: any) => {
72
+ return [];
73
+ };
74
+ */
75
+ }
76
+
77
+ export default CustomCmpModel;
@@ -0,0 +1,72 @@
1
+ :root {
2
+ --padding-bottom: 12px;
3
+ }
4
+
5
+ .custom-cmp-container {
6
+ position: relative;
7
+ box-sizing: border-box;
8
+
9
+ /* border-bottom: 1px solid #ececec; */
10
+ margin: 6px 12px;
11
+ padding: 6px var(--padding-bottom);
12
+ background-color: #fff;
13
+
14
+ .news-title {
15
+ padding: 6px 0;
16
+ font-family: PingFangSC-Regular;
17
+ font-size: 16px;
18
+ line-height: 22px;
19
+ color: #5f5e5e;
20
+ }
21
+
22
+ .item-imgbox {
23
+ position: relative;
24
+ height: 395px;
25
+ background: #f0f0f0;
26
+ cursor: pointer;
27
+ box-sizing: border-box;
28
+ text-align: center;
29
+ overflow: hidden;
30
+
31
+ .news-img {
32
+ width: 100%;
33
+ height: 100%;
34
+ box-sizing: border-box;
35
+ background-size: contain;
36
+ }
37
+
38
+ .img-count {
39
+ position: absolute;
40
+ top: 0;
41
+ right: 0;
42
+ padding: 6px 8px;
43
+ color: #fff;
44
+ min-width: 60px;
45
+ text-align: center;
46
+ line-height: 1.2;
47
+ background: rgb(0 0 0 / 40%);
48
+ font-size: 25px;
49
+ box-sizing: border-box;
50
+ overflow: hidden;
51
+ }
52
+ }
53
+
54
+ .news-info {
55
+ font-family: PingFangSC-Light;
56
+ height: 28px;
57
+ box-sizing: border-box;
58
+ display: flex;
59
+ justify-content: space-between;
60
+ align-items: center;
61
+ }
62
+
63
+ .media-mark,
64
+ .cmt-num {
65
+ display: inline-block;
66
+ height: 28px;
67
+ line-height: 28px;
68
+ font-family: PingFangSC-Light;
69
+ font-size: 18px;
70
+ color: #828282;
71
+ }
72
+ }
@@ -0,0 +1,12 @@
1
+ /*
2
+ prettier 配置文件
3
+ 更多配置信息:https://prettier.io/docs/en/options.html
4
+ */
5
+ module.exports = {
6
+ semi: true, // Semicolons 分号,默认需要分号
7
+ tabWidth: 2, // 空格,默认 2,
8
+ useTabs: false,
9
+ singleQuote: true, // 单引号还是双引号,默认为false 双引号
10
+ trailingComma: 'all', // 逗号
11
+ jsxBracketSameLine: false, // 默认为false,Put the > of a multi-line JSX element at the end of the last line instead of being alone on the next line (does not apply to self closing elements).
12
+ };
@@ -0,0 +1,45 @@
1
+ ### 目录说明
2
+ - src: 自定义组件源码;
3
+ - src/assets: 存放组件静态资源,比如 css、img等;
4
+ - src/components: 存放自定义组件代码,每个自定义组件以自身名称(cmpType 数值)作为目录进行存放;
5
+ - neo.config.js: neo-cmp-cli 配置文件。
6
+
7
+ ### 组件开发规范
8
+ - 存放在 src/components 目录下的自定义组件,默认 index 为自定义组件源码入口文件,register.[tj]s 为注册 自定义组件的脚本文件,model.[tj]s 为自定义组件的模型文件(对接页面设计器需要);
9
+ - 当 neo.config.js 中的 entry 为空或者不存在时,cli 将根据 src/components 目录下的自定义组件结构生成对应的 entry 配置(可在命令控制台查看生成的 entry 配置);
10
+ - 自定义组件中可用的配置项类型 请见 [当前可用表单项](https://github.com/wibetter/neo-register/blob/master/docs/FormItemType.md);
11
+ - 自定义组件最外层请设置一个唯一的 ClassName(比如 xx-cmpType-container),所有内容样式请放在该 ClassName 中,避免自定义组件样式相互干扰;
12
+ - 默认开启代码规范检测(含样式内容),如需关闭,请调整 neo.config.js 相关配置;
13
+ - 请使用 react 16版本。
14
+
15
+ ### 自定义组件注册器使用说明
16
+ - [neo-register 使用说明](https://www.npmjs.com/package/neo-register?activeTab=readme)
17
+ 备注:预览、调试(linkDebug)和构建发布时 cli 会自动创建对应的注册文件(含 neo-register 的使用),用户无需关注 neo-register。
18
+
19
+ ### 开发说明
20
+
21
+ 1. **安装依赖**
22
+ ```bash
23
+ $ npm i 或者 yarn
24
+ ```
25
+
26
+ 2. **preview: 组件预览模式(带热更新)**
27
+ > preview模式:用于预览自定义组件内容。
28
+ ```bash
29
+ $ npm run preview
30
+ ```
31
+
32
+ 3. **linkDebug: 外链调试(在线上页面设计器端预览自定义组件)**
33
+ > linkDebug模式:用于在线上页面设计器中预览和调试自定义组件。
34
+ ```bash
35
+ $ npm run linkDebug
36
+ ```
37
+
38
+ 4. **发布到 NeoCRM 中**
39
+ > 需要确保 package.json 中的 name 值唯一,version 值不重复。
40
+ ```bash
41
+ $ npm run pushCmp
42
+ ```
43
+
44
+ ### 配置项说明(neo-cmp-cli)
45
+ [请查看neo-cmp-cli](https://github.com/wibetter/neo-cmp-cli)
@@ -0,0 +1,59 @@
1
+ /**
2
+ * https://www.npmjs.com/package/@commitlint/config-conventional\
3
+ *
4
+ * Git提交规范-配置文件
5
+ * Commit message 由Header、Body 和 Footer三个部分组成,其格式如下:
6
+ * <type>(<scope>): <subject>
7
+ * <BLANK LINE>
8
+ * <body>
9
+ * <BLANK LINE>
10
+ * <footer>
11
+ *
12
+ *【备注】
13
+ * type 用于说明 commit 的类别,常用下面 7 个标识:
14
+ * scope 用于说明当前功能点作用于哪个页面或者哪个功能模块;
15
+ * subject 用于简短的描述当前commit,不超过50个字符;
16
+ * body 用于填写对本次 commit 的详细描述,可以分成多行;
17
+ * footer 不兼容变动声明,或者关闭 Issue。
18
+ *
19
+ * 【type类型取值类型】
20
+ * feat:新功能(feature)
21
+ * fix:功能优化
22
+ * bug:修补bug
23
+ * docs:文档(documentation)
24
+ * style:格式(不影响代码运行的变动)
25
+ * refactor:重构(即不是新增功能,也不是修改bug的代码变动)
26
+ * test:增加测试
27
+ * chore:构建过程或辅助工具的变动
28
+ * build:影响构建系统或外部依赖项的更改(示例范围:gulp,broccoli,npm)
29
+ * ci:对 CI 配置文件和脚本的更改(示例范围:Travis,Circle,BrowserStack,SauceLabs)
30
+ * perf:改进性能的代码更改
31
+ *
32
+ */
33
+
34
+ module.exports = {
35
+ extends: ['@commitlint/config-conventional'],
36
+ rules: {
37
+ 'type-enum': [
38
+ 2,
39
+ 'always',
40
+ [
41
+ 'feat',
42
+ 'fix',
43
+ 'bug',
44
+ 'docs',
45
+ 'style',
46
+ 'refactor',
47
+ 'test',
48
+ 'chore',
49
+ 'perf',
50
+ 'build',
51
+ 'ci',
52
+ ],
53
+ ],
54
+ 'type-empty': [2, 'never'],
55
+ 'scope-empty': [1, 'never'],
56
+ 'subject-full-stop': [0, 'never'],
57
+ 'subject-case': [0, 'never'],
58
+ },
59
+ };