Skip to content

Commit ad8b82a

Browse files
committed
Merge branch 'dev'
2 parents 66bd1ec + 6e3563b commit ad8b82a

File tree

39 files changed

+1113
-22
lines changed

39 files changed

+1113
-22
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# crui
22

3-
[![Build Status](https://www.travis-ci.org/rywaroy/crui.svg?branch=master)](https://www.travis-ci.org/rywaroy/crui) [![Version](https://img.shields.io/badge/npm-v2.2.1-blue.svg)](https://www.npmjs.com/package/crui)
3+
[![Build Status](https://www.travis-ci.org/rywaroy/crui.svg?branch=master)](https://www.travis-ci.org/rywaroy/crui) [![Version](https://img.shields.io/badge/npm-v2.6.0-blue.svg)](https://www.npmjs.com/package/crui)
44

55
> react 代码、模板快速生成工具
66
@@ -55,4 +55,6 @@ npm run start & npx crui
5555

5656
* [文档生成](docs/document.md)
5757

58+
* [mock数据](docs/mockData.md)
59+
5860
* [配置](docs/configlist.md)

docs/images/mockData_01.jpg

72.5 KB
Loading

docs/images/mockData_02.jpg

59.6 KB
Loading

docs/images/mockData_03.jpg

70.1 KB
Loading

docs/images/mockData_04.jpg

120 KB
Loading

docs/mockData.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# mock数据
2+
3+
基于mockjs,自动生成mock对象
4+
5+
![](images/mockData_01.jpg)
6+
7+
提供的功能:
8+
9+
1. 自定义操作,添加mock对象属性,支持对象、数组
10+
2. 导入json,直接生成mock对象(自定义主键)
11+
3. 支持mock对象、mock数据的同步展示
12+
13+
## 导入json
14+
15+
![](images/mockData_02.jpg)
16+
17+
添加json解析,可以配置主键,以主键为key生成mock对象,简便操作,可以配合table的columns对象使用
18+
19+
## 生成js
20+
21+
![](images/mockData_03.jpg)
22+
23+
可设置
24+
25+
1. api
26+
2. method
27+
3. mock文件夹/文件(选择文件夹还需设置文件,可生成对应文件)
28+
4. 如果需要services方法,还可以设置请求方法及请求方法及请求函数名
29+
30+
## 扩展功能
31+
32+
![](images/mockData_04.jpg)
33+
34+
在可视化搭建中,table组件添加了mock可选配置,启用mock功能会根据table所配置的columns对象中dataIndex属性来自动生成mock对象。默认生成在mock/api.js中。

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "crui",
3-
"version": "2.5.2",
3+
"version": "2.6.0",
44
"description": "react代码快速生成工具",
55
"scripts": {
66
"start": "umi dev",
@@ -10,7 +10,7 @@
1010
"precommit": "lint-staged",
1111
"commit": "git-cz",
1212
"dev:watch": "NODE_ENV=development npx nodemon server/index.js",
13-
"dev": "ts-node server/index.ts",
13+
"dev": "NODE_ENV=development node lib/index.js",
1414
"build:server": "tsc -p tsconfig.server.json"
1515
},
1616
"bin": {
@@ -23,6 +23,7 @@
2323
"ahooks": "^2.5.0",
2424
"antd": "^3.19.5",
2525
"axios": "^0.19.0",
26+
"behooks": "^0.7.1",
2627
"chalk": "^4.0.0",
2728
"clipboard": "^2.0.4",
2829
"commander": "^4.0.1",
@@ -38,6 +39,7 @@
3839
"koa-router": "^7.4.0",
3940
"koa-static": "^5.0.0",
4041
"loadsh": "^0.0.4",
42+
"mockjs": "^1.1.0",
4143
"prettier": "^2.0.2",
4244
"react": "^16.8.6",
4345
"react-dom": "^16.8.6",
@@ -54,6 +56,7 @@
5456
"@types/koa-cors": "^0.0.0",
5557
"@types/koa-router": "^7.0.35",
5658
"@types/koa-static": "^4.0.1",
59+
"@types/mockjs": "^1.0.3",
5760
"@types/node": "^14.0.13",
5861
"@types/socket.io": "^2.1.8",
5962
"@types/socket.io-client": "^1.4.33",

server/controller/file/isJsOrFolder.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ export default async function isJsOrFolder(ctx: IContext) {
77
if (fs.existsSync(base)) {
88
const stat = fs.statSync(base);
99
if (stat.isDirectory()) {
10-
ctx.success(200, '验证成功', null);
10+
ctx.success(200, '验证成功', { type: 'folder' });
1111
}
1212
if (stat.isFile()) {
13-
if (path.extname(base) === '.js' || path.extname(base) === '.jsx') {
14-
ctx.success(200, '验证成功', null);
13+
const extname = ['.js', '.jsx', '.ts', '.tsx'];
14+
if (extname.indexOf(path.extname(base)) > -1) {
15+
ctx.success(200, '验证成功', { type: path.extname(base) });
1516
} else {
1617
ctx.error(-1, '不是js文件', null);
1718
}

server/controller/file/isjs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default async function isjs(ctx: IContext) {
77
if (fs.existsSync(base)) {
88
const stat = fs.statSync(base);
99
if (stat.isFile()) {
10-
if (path.extname(base) === '.js' || path.extname(base) === '.jsx') {
10+
if (path.extname(base) === '.js' || path.extname(base) === '.jsx' || path.extname(base) === '.ts' || path.extname(base) === '.tsx') {
1111
ctx.success(200, '验证成功', null);
1212
} else {
1313
ctx.error(-1, '不是js文件', null);

server/controller/making/create.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface IBody {
1313
tabWith: number;
1414
}
1515

16-
export default function preview(ctx: IContext) {
16+
export default function create(ctx: IContext) {
1717
// @ts-ignore for travis
1818
const { materials, url, name, namespace, tabWith }: IBody = ctx.request.body;
1919

@@ -26,6 +26,7 @@ export default function preview(ctx: IContext) {
2626
name,
2727
namespace,
2828
tabWith,
29+
isCreate: true,
2930
});
3031
const files = generator.create();
3132
Object.keys(files).forEach(item => {

0 commit comments

Comments
 (0)