Skip to content

Commit

Permalink
Merge pull request #8 from garrett12138/dev
Browse files Browse the repository at this point in the history
effect生成可选
  • Loading branch information
garrett12138 authored Apr 25, 2020
2 parents d9a3559 + ffa7b7b commit 5798bd7
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 39 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT LICENSE

Copyright (c) 2015-present Ant UED, https://xtech.antfin.com/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ View--->Command Platte..., 查找 Ant Design Pro Code Generator 项运行

3. 先build一下antd-generator-core,如果antd-generator-core有修改,也要build一样其它两个项目才能引用到最新的代码。

4. 在antd-generator-ui目录下运行 npm start,ui运行端口默认3000,同时运行一个express 服务器,端口8081,web请求的链接通过代理到8081
4. 在antd-generator-ui目录下运行 npm start,ui运行端口默认3001,同时运行一个express 服务器,端口8081,web请求的链接通过代理到8081

## 调试web.js 和lib
## 调试web.js 和antd-generator-core

1. 在ui项目建调试配置,配置详情如下:

Expand Down
1 change: 1 addition & 0 deletions antd-generator-core/ApiObjectBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function resolve(apiDoc) {
queryParams: [],
formParams: [],
headerParams: [],
effect: true,
name: obj.operationId,
effectName: obj.operationId,
description: obj.description,
Expand Down
34 changes: 20 additions & 14 deletions antd-generator-core/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,34 @@ function generate(genParam) {
summary,
operate,
reducer,
effect,
state,
successText,
name: serviceFunction
} = api;
effects.push({
name: effectName,
summary: summary,
service: name,
serviceFunction,
operate,
reducer,
state,
successText
});
if (operate === operateType.PUT_REDUCER) {
states.push({ name: state, type: "object", value: "undefined" });
reducers.push({ name: reducer, stateName: state });
if (effect) {
effects.push({
name: effectName,
summary: summary,
service: name,
serviceFunction,
operate,
reducer,
state,
successText
});
if (operate === operateType.PUT_REDUCER) {
states.push({ name: state, type: "object", value: "undefined" });
reducers.push({ name: reducer, stateName: state });
}
}
}
return { name, namespace, states, reducers, effects };
});
generateModels(models, modelPath);
generateModels(
models.filter(m => m.effects.length > 0),
modelPath
);
}

function generateModels(models, distPath) {
Expand Down
25 changes: 13 additions & 12 deletions antd-generator-ui/config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ const {
override,
fixBabelImports,
removeModuleScopePlugin,
addWebpackResolve,
addWebpackModuleRule,
overrideDevServer,
watchAll
} = require("customize-cra");
Expand Down Expand Up @@ -63,18 +61,21 @@ module.exports = {
),
devServer: overrideDevServer(
// dev server plugin
config => ({
...config,
proxy: {
"/": {
target: "http://localhost:8081",
changeOrigin: true,
pathRewrite: {
"^/": ""
config => {
console.log("config....", config);
return {
...config,
proxy: {
"/": {
target: "http://localhost:8081",
changeOrigin: true,
pathRewrite: {
"^/": ""
}
}
}
}
}),
};
},
watchAll()
)
};
6 changes: 3 additions & 3 deletions antd-generator-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"typescript": "~3.7.2"
},
"scripts": {
"start": "concurrently \"nodemon web.js\" \"react-app-rewired start\"",
"ui": "react-app-rewired start",
"start": "concurrently \"nodemon web.js\" \"set PORT=3001 && react-app-rewired start\"",
"ui": "set PORT=3001 && react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test"
},
Expand All @@ -50,4 +50,4 @@
"last 1 safari version"
]
}
}
}
37 changes: 33 additions & 4 deletions antd-generator-ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
Form,
message,
Radio,
Modal
Modal,
Checkbox
} from "antd";
import {
EditOutlined,
Expand All @@ -16,7 +17,8 @@ import {
} from "@ant-design/icons";
import webService from "../webService";
import extService from "../extService";
import { operateType, objectToMap } from "./constants";
import { operateType } from "./constants";
import { objectToMap } from "antd-generator-core/utils";
import "./App.css";

const caseType = {
Expand Down Expand Up @@ -182,15 +184,15 @@ class App extends Component {
for (let tag of data.tags.values()) {
const apis = tag.apis.filter(api => selectKeySet.has(api.key));
for (let api of apis.values()) {
if (api.stateEditting && api.state === "") {
if (api.stateEditting && api.state === "" && api.effect) {
api.stateError = true;
this.setState({ data: { ...data } });
message.error("state name is required!", 2, () =>
this.errorRef.current.focus()
);
return false;
}
if (api.effectEditting && api.effectName === "") {
if (api.effectEditting && api.effectName === "" && api.effect) {
api.effectError = true;
this.setState({ data: { ...data } });
message.error("effect name is required!", 2, () =>
Expand Down Expand Up @@ -291,9 +293,30 @@ class App extends Component {
},
{
title: "Effect",
colSpan: 2,
dataIndex: "effect",
width: 20,
render: (val, record) => {
return (
<Checkbox
onChange={e => {
record.effect = e.target.checked;
this.setState({ data: { ...this.state.data } });
}}
checked={val}
></Checkbox>
);
}
},
{
title: "EffectName",
colSpan: 0,
dataIndex: "effectName",
width: 160,
render: (val, record) => {
if (record.effect === false) {
return "";
}
const accept = value => {
if (value === "") {
message.error("effectName is required!");
Expand Down Expand Up @@ -348,6 +371,9 @@ class App extends Component {
dataIndex: "operate",
width: 240,
render: (val, record) => {
if (record.effect === false) {
return "";
}
let text = "";
switch (val) {
case operateType.PUT_REDUCER:
Expand Down Expand Up @@ -375,6 +401,9 @@ class App extends Component {
title: "State",
dataIndex: "state",
render: (val, record) => {
if (record.effect === false) {
return "";
}
if (record.operate !== operateType.PUT_REDUCER) {
return "";
}
Expand Down
1 change: 1 addition & 0 deletions antd-pro-generator/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ test/**
jsconfig.json
vsc-extension-quickstart.md
.eslintrc.json
lib/**
3 changes: 2 additions & 1 deletion antd-pro-generator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ All notable changes to the "garrett-ant-generator" extension will be documented
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]
- Initial release
- Initial release 0.02
- Made Effect,Reducer Optional 0.03
2 changes: 1 addition & 1 deletion antd-pro-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Ant Design Pro Generator",
"description": "ant design pro service,mock,models generator",
"publisher": "garrett",
"version": "0.0.2",
"version": "0.0.3",
"icon": "icon.png",
"engines": {
"vscode": "^1.29.0"
Expand Down
6 changes: 4 additions & 2 deletions antd-pro-generator/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

## 截图

![](https://github.com/garrett12138/antd-pro-generator/blob/master/screen_shot.png)

![](https://github.com/garrett12138/antd-pro-generator/blob/master/screen_shot2.png)
![](https://github.com/garrett12138/antd-pro-generator/raw/master/screen_shot.png)

![](https://github.com/garrett12138/antd-pro-generator/raw/master/screen_shot2.png)


## 使用说明

Expand Down
Binary file modified screen_shot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5798bd7

Please sign in to comment.